Robotsystem of the Robot Group Leipzig: osgprimitive.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# osgprimitive.h

Go to the documentation of this file.

    00001
    00002 /***************************************************************************
    00003  *   Copyright (C) 2005 by Robot Group Leipzig                             *
    00004  *    martius@informatik.uni-leipzig.de                                    *
    00005  *    fhesse@informatik.uni-leipzig.de                                     *
    00006  *    der@informatik.uni-leipzig.de                                        *
    00007  *                                                                         *
    00008  *   This program is free software; you can redistribute it and/or modify  *
    00009  *   it under the terms of the GNU General Public License as published by  *
    00010  *   the Free Software Foundation; either version 2 of the License, or     *
    00011  *   (at your option) any later version.                                   *
    00012  *                                                                         *
    00013  *   This program is distributed in the hope that it will be useful,       *
    00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00016  *   GNU General Public License for more details.                          *
    00017  *                                                                         *
    00018  *   You should have received a copy of the GNU General Public License     *
    00019  *   along with this program; if not, write to the                         *
    00020  *   Free Software Foundation, Inc.,                                       *
    00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00022  *                                                                         *
    00023  ***************************************************************************
    00024  *                                                                         *
    00025  *   This file provides basic primitives for openscenegraph usage.         *
    00026  *                                                                         *
    00027  *                                                                         *
    00028  *                                                                         *
    00029  *   $Log: osgprimitive.h,v $
    00030  *   Revision 1.4  2008/05/07 16:45:51  martius
    00031  *   code cosmetics and documentation
    00032  *
    00033  *   Revision 1.3  2007/08/23 14:52:26  martius
    00034  *   box is resizeable
    00035  *
    00036  *   Revision 1.2  2006/07/14 12:23:35  martius
    00037  *   selforg becomes HEAD
    00038  *
    00039  *   Revision 1.1.2.13  2006/07/14 11:23:38  martius
    00040  *   revert to older revision of robot3
    00041  *
    00042  *   Revision 1.1.2.11  2006/05/24 12:23:10  robot3
    00043  *   -passive_mesh works now (simple bound_version)
    00044  *   -Primitive Mesh now exists (simple bound_version)
    00045  *
    00046  *   Revision 1.1.2.10  2006/05/18 07:39:41  robot3
    00047  *   -setTexture(string& filename,bool repeatOnX, bool repeatOnY) added
    00048  *    note that this does not work yet (the bool parameter have no effect)
    00049  *
    00050  *   Revision 1.1.2.9  2006/04/04 14:13:24  fhesse
    00051  *   documentation improved
    00052  *
    00053  *   Revision 1.1.2.8  2006/03/29 15:06:40  martius
    00054  *   OSGMesh
    00055  *
    00056  *   Revision 1.1.2.7  2005/12/22 14:14:12  martius
    00057  *   quality level
    00058  *
    00059  *   Revision 1.1.2.6  2005/12/15 17:03:43  martius
    00060  *   cameramanupulator setPose is working
    00061  *   joints have setter and getter parameters
    00062  *   Primitives are not longer inherited from OSGPrimitive, moreover
    00063  *   they aggregate them
    00064  *
    00065  *   Revision 1.1.2.5  2005/12/14 15:36:45  martius
    00066  *   joints are visible now
    00067  *
    00068  *   Revision 1.1.2.4  2005/12/13 18:11:13  martius
    00069  *   transform primitive added, some joints stuff done, forward declaration
    00070  *
    00071  *   Revision 1.1.2.3  2005/12/11 23:35:08  martius
    00072  *   *** empty log message ***
    00073  *
    00074  *   Revision 1.1.2.2  2005/12/09 16:54:16  martius
    00075  *   camera is woring now
    00076  *
    00077  *   Revision 1.1.2.1  2005/12/06 10:13:24  martius
    00078  *   openscenegraph integration started
    00079  *
    00080  *                                                                 *
    00081  *                                                                         *
    00082  ***************************************************************************/
    00083 #ifndef __OSGPRIMITIVE_H
    00084 #define __OSGPRIMITIVE_H
    00085
    00086 #include <string>
    00087 #include <osg/ref_ptr>
    00088 #include "osgforwarddecl.h"
    00089 #include "osghandle.h"
    00090 #include <osgDB/ReadFile>
    00091
    00092 namespace lpzrobots {
    00093
    00094   /**
    00095      Interface class for graphic primitives like spheres, boxes, and meshes,
    00096      which can be drawn by OSG. The idea is to hide all the details of the OSG
    00097      implementation.
    00098   */
    00099   class OSGPrimitive {
    00100   public:
    00101     typedef enum Quality {Low, Middle, High};
    00102
    00103     OSGPrimitive ();
    00104     virtual ~OSGPrimitive ();
    00105     /** Initialisation of the primitive. Must in order to place the object into the scene.
    00106         This function should be overloaded */
    00107     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle) = 0;
    00108     /// Sets the transformation matrix of this object (position and orientation)
    00109     virtual void setMatrix( const osg::Matrix& m4x4 );
    00110     /// returns the group object which is the root of all subcomponents of this primitive
    00111     virtual osg::Group* getGroup();
    00112     /// assigns a texture to the primitive
    00113     virtual void setTexture(const std::string& filename);
    00114     /// assigns a texture to the primitive, you can choose if the texture should be repeated
    00115     virtual void setTexture(const std::string& filename, bool repeatOnX, bool repeatOnY);
    00116     /// sets the color for painting this primitive
    00117     virtual void setColor(const Color& color);
    00118     /// returns a osg transformation object;
    00119     virtual osg::Transform* getTransform();
    00120
    00121   protected:
    00122     osg::ref_ptr<osg::Geode> geode;
    00123     osg::ref_ptr<osg::MatrixTransform> transform;
    00124     osg::ref_ptr<osg::ShapeDrawable> shape;
    00125   };
    00126
    00127   /**
    00128      A dummy graphical object, which has no representation in the graphical world.
    00129   */
    00130   class OSGDummy : public OSGPrimitive {
    00131   public:
    00132     OSGDummy();
    00133
    00134     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00135     virtual void setMatrix( const osg::Matrix& m4x4 );
    00136     virtual osg::Group* getGroup();
    00137     virtual void setTexture(const std::string& filename);
    00138     virtual void setColor(const Color& color);
    00139     /// returns a osg transformation object;
    00140     virtual osg::Transform* getTransform();
    00141   };
    00142
    00143
    00144   /**
    00145      Graphical plane (represented as a large thin box, because OSG does not draw planes)
    00146   */
    00147   class OSGPlane : public OSGPrimitive {
    00148   public:
    00149     OSGPlane();
    00150
    00151     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00152   };
    00153
    00154
    00155   /**
    00156      Graphical box
    00157   */
    00158   class OSGBox : public OSGPrimitive {
    00159   public:
    00160     OSGBox(float lengthX, float lengthY, float lengthZ);
    00161     OSGBox(osg::Vec3 dim);
    00162
    00163     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00164
    00165     osg::Vec3 getDim();
    00166     void setDim(osg::Vec3);
    00167
    00168   protected:
    00169     osg::Vec3 dim;
    00170     osg::Box* box;
    00171   };
    00172
    00173
    00174   /**
    00175      Graphical sphere
    00176   */
    00177   class OSGSphere : public OSGPrimitive {
    00178   public:
    00179     OSGSphere(float radius);
    00180
    00181     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00182
    00183     float getRadius() { return radius; }
    00184   protected:
    00185     float radius;
    00186   };
    00187
    00188   /**
    00189      Graphical capsule (a cylinder with round ends)
    00190   */
    00191   class OSGCapsule : public OSGPrimitive {
    00192   public:
    00193     OSGCapsule(float radius, float height);
    00194
    00195     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00196
    00197     float getRadius() { return radius; }
    00198     float getHeight() { return height; }
    00199   protected:
    00200     float radius;
    00201     float height;
    00202   };
    00203
    00204
    00205   /**
    00206      Graphical cylinder
    00207   */
    00208   class OSGCylinder : public OSGPrimitive {
    00209   public:
    00210     OSGCylinder(float radius, float height);
    00211
    00212     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00213
    00214     float getRadius() { return radius; }
    00215     float getHeight() { return height; }
    00216   protected:
    00217     float radius;
    00218     float height;
    00219   };
    00220
    00221
    00222   /**
    00223      Graphical Mesh or arbitrary OSG model.
    00224   */
    00225   class OSGMesh : public OSGPrimitive {
    00226   public:
    00227     /**
    00228        Constuctor
    00229        @param filename filename of the model file (search path is osg data path)
    00230        @param scale scale factor used for scaling the model
    00231        @param options for model reader
    00232      */
    00233     OSGMesh(const std::string& filename, float scale = 1, const osgDB::ReaderWriter::Options* options = 0);
    00234     ~OSGMesh();
    00235     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00236     virtual float getRadius();
    00237     float getScale() { return scale; }
    00238
    00239   protected:
    00240     std::string filename;
    00241     float scale;
    00242     const osgDB::ReaderWriter::Options* options;
    00243     osg::ref_ptr<osg::Node> mesh;
    00244     osg::ref_ptr<osg::MatrixTransform> scaletrans;
    00245
    00246   };
    00247
    00248 }
    00249
    00250 #endif
    00251