Robotsystem from Robot Group Leipzig: osgprimitive.h Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- 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.1.2.9  2006/04/04 14:13:24  fhesse
    00031  *   documentation improved
    00032  *
    00033  *   Revision 1.1.2.8  2006/03/29 15:06:40  martius
    00034  *   OSGMesh
    00035  *
    00036  *   Revision 1.1.2.7  2005/12/22 14:14:12  martius
    00037  *   quality level
    00038  *
    00039  *   Revision 1.1.2.6  2005/12/15 17:03:43  martius
    00040  *   cameramanupulator setPose is working
    00041  *   joints have setter and getter parameters
    00042  *   Primitives are not longer inherited from OSGPrimitive, moreover
    00043  *   they aggregate them
    00044  *
    00045  *   Revision 1.1.2.5  2005/12/14 15:36:45  martius
    00046  *   joints are visible now
    00047  *
    00048  *   Revision 1.1.2.4  2005/12/13 18:11:13  martius
    00049  *   transform primitive added, some joints stuff done, forward declaration
    00050  *
    00051  *   Revision 1.1.2.3  2005/12/11 23:35:08  martius
    00052  *   *** empty log message ***
    00053  *
    00054  *   Revision 1.1.2.2  2005/12/09 16:54:16  martius
    00055  *   camera is woring now
    00056  *
    00057  *   Revision 1.1.2.1  2005/12/06 10:13:24  martius
    00058  *   openscenegraph integration started
    00059  *
    00060  *                                                                 *
    00061  *                                                                         *
    00062  ***************************************************************************/
    00063 #ifndef __OSGPRIMITIVE_H
    00064 #define __OSGPRIMITIVE_H
    00065
    00066 #include <string>
    00067 #include <osg/ref_ptr>
    00068 #include "osgforwarddecl.h"
    00069 #include "osghandle.h"
    00070 #include <osgDB/ReadFile>
    00071
    00072 namespace lpzrobots {
    00073
    00074   /**
    00075      Interface class for graphic primitives like spheres, boxes, and meshes,
    00076      which can be drawn by OSG. The idea is to hide all the details of the OSG
    00077      implementation.
    00078   */
    00079   class OSGPrimitive {
    00080   public:
    00081
    00082     typedef enum Quality {Low, Middle, High};
    00083
    00084     OSGPrimitive ();
    00085     virtual ~OSGPrimitive ();
    00086     /** Initialisation of the primitive. Must in order to place the object into the scene.
    00087         This function should be overloaded */
    00088     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle) = 0;
    00089     /// Sets the transformation matrix of this object (position and orientation)
    00090     virtual void setMatrix( const osg::Matrix& m4x4 );
    00091     /// returns the group object which is the root of all subcomponents of this primitive
    00092     virtual osg::Group* getGroup();
    00093     /// assigns a texture to the primitive
    00094     virtual void setTexture(const std::string& filename);
    00095     /// sets the color for painting this primitive
    00096     virtual void setColor(const Color& color);
    00097     /// returns a osg transformation object;
    00098     virtual osg::Transform* getTransform();
    00099
    00100   protected:
    00101     osg::ref_ptr<osg::Geode> geode;
    00102     osg::ref_ptr<osg::MatrixTransform> transform;
    00103     osg::ref_ptr<osg::ShapeDrawable> shape;
    00104   };
    00105
    00106   /**
    00107      A dummy graphical object, which has no representation in the graphical world.
    00108   */
    00109   class OSGDummy : public OSGPrimitive {
    00110   public:
    00111     OSGDummy();
    00112
    00113     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00114     virtual void setMatrix( const osg::Matrix& m4x4 );
    00115     virtual osg::Group* getGroup();
    00116     virtual void setTexture(const std::string& filename);
    00117     virtual void setColor(const Color& color);
    00118     /// returns a osg transformation object;
    00119     virtual osg::Transform* getTransform();
    00120   };
    00121
    00122
    00123   /**
    00124      Graphical plane (represented as a large thin box, because OSG does not draw planes)
    00125   */
    00126   class OSGPlane : public OSGPrimitive {
    00127   public:
    00128     OSGPlane();
    00129
    00130     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00131   };
    00132
    00133
    00134   /**
    00135      Graphical box
    00136   */
    00137   class OSGBox : public OSGPrimitive {
    00138   public:
    00139     OSGBox(float lengthX, float lengthY, float lengthZ);
    00140
    00141     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00142
    00143     float getLengthX() { return lengthX; }
    00144     float getLengthY() { return lengthY; }
    00145     float getLengthZ() { return lengthZ; }
    00146
    00147   protected:
    00148     float lengthX;
    00149     float lengthY;
    00150     float lengthZ;
    00151   };
    00152
    00153
    00154   /**
    00155      Graphical sphere
    00156   */
    00157   class OSGSphere : public OSGPrimitive {
    00158   public:
    00159     OSGSphere(float radius);
    00160
    00161     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00162
    00163     float getRadius() { return radius; }
    00164   protected:
    00165     float radius;
    00166   };
    00167
    00168   /**
    00169      Graphical capsule (a cylinder with round ends)
    00170   */
    00171   class OSGCapsule : public OSGPrimitive {
    00172   public:
    00173     OSGCapsule(float radius, float height);
    00174
    00175     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00176
    00177     float getRadius() { return radius; }
    00178     float getHeight() { return height; }
    00179   protected:
    00180     float radius;
    00181     float height;
    00182   };
    00183
    00184
    00185   /**
    00186      Graphical cylinder
    00187   */
    00188   class OSGCylinder : public OSGPrimitive {
    00189   public:
    00190     OSGCylinder(float radius, float height);
    00191
    00192     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00193
    00194     float getRadius() { return radius; }
    00195     float getHeight() { return height; }
    00196   protected:
    00197     float radius;
    00198     float height;
    00199   };
    00200
    00201
    00202   /**
    00203      Graphical Mesh or arbitrary OSG model.
    00204   */
    00205   class OSGMesh : public OSGPrimitive {
    00206   public:
    00207     /**
    00208        Constuctor
    00209        @param filename filename of the model file (search path is osg data path)
    00210        @param scale scale factor used for scaling the model
    00211        @options options for model reader
    00212      */
    00213     OSGMesh(const std::string& filename, float scale = 1, const osgDB::ReaderWriter::Options* options = 0);
    00214     ~OSGMesh();
    00215     virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
    00216
    00217     float getScale() { return scale; }
    00218   protected:
    00219     std::string filename;
    00220     float scale;
    00221     const osgDB::ReaderWriter::Options* options;
    00222     osg::ref_ptr<osg::Node> mesh;
    00223     osg::ref_ptr<osg::MatrixTransform> scaletrans;
    00224
    00225   };
    00226
    00227 }
    00228
    00229 #endif
    00230