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

Generated on Tue Jan 16 02:14:37 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8