osgprimitive.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __OSGPRIMITIVE_H
00026 #define __OSGPRIMITIVE_H
00027
00028 #include <string>
00029 #include <vector>
00030 #include <osg/ref_ptr>
00031 #include "osgforwarddecl.h"
00032 #include "osghandle.h"
00033 #include <osgDB/ReadFile>
00034 #include <osgText/Text>
00035
00036 namespace lpzrobots {
00037
00038
00039
00040
00041
00042 class TextureDescr {
00043 public:
00044 TextureDescr(){}
00045
00046
00047
00048 TextureDescr(const std::string& filename, double repeatOnR, double repeatOnS)
00049 : filename(filename), repeatOnR(repeatOnR), repeatOnS(repeatOnS)
00050 {
00051 }
00052 std::string filename;
00053 double repeatOnR;
00054 double repeatOnS;
00055 };
00056
00057
00058
00059
00060
00061
00062 class OSGPrimitive {
00063 public:
00064 enum Quality {Low, Middle, High};
00065
00066 OSGPrimitive ();
00067 virtual ~OSGPrimitive ();
00068
00069
00070 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle) = 0;
00071
00072 virtual void setMatrix( const osg::Matrix& m4x4 );
00073
00074 virtual osg::Group* getGroup();
00075
00076 virtual void setTexture(const std::string& filename);
00077
00078 virtual void setTexture(const TextureDescr& texture);
00079
00080 virtual void setTexture(int surface, const TextureDescr& texture);
00081
00082 virtual void setTextures(const std::vector<TextureDescr>& textures);
00083
00084 virtual std::vector<TextureDescr> getTextures() const;
00085
00086 virtual void setColor(const Color& color);
00087
00088 virtual void setColor(const std::string& color);
00089
00090 virtual Color getColor();
00091
00092
00093 virtual osg::Transform* getTransform();
00094
00095 virtual const OsgHandle& getOsgHandle();
00096
00097 protected:
00098
00099 virtual void applyTextures();
00100
00101 osg::ref_ptr<osg::Geode> geode;
00102 osg::ref_ptr<osg::MatrixTransform> transform;
00103 osg::ref_ptr<osg::ShapeDrawable> shape;
00104
00105 std::vector<TextureDescr > textures;
00106
00107 OsgHandle osgHandle;
00108 };
00109
00110
00111
00112
00113 class OSGDummy : public OSGPrimitive {
00114 public:
00115 OSGDummy();
00116
00117 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00118 virtual void setMatrix( const osg::Matrix& m4x4 );
00119 virtual osg::Group* getGroup();
00120 virtual void setTexture(const std::string& filename);
00121 virtual void setColor(const Color& color);
00122
00123 virtual osg::Transform* getTransform();
00124 };
00125
00126
00127
00128
00129
00130 class OSGPlane : public OSGPrimitive {
00131 public:
00132 OSGPlane();
00133
00134 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00135 };
00136
00137
00138
00139
00140
00141 class OSGBox : public OSGPrimitive {
00142 public:
00143 OSGBox(float lengthX, float lengthY, float lengthZ);
00144 OSGBox(osg::Vec3 dim);
00145
00146 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00147
00148 virtual osg::Vec3 getDim();
00149 virtual void setDim(osg::Vec3);
00150
00151 protected:
00152 osg::Vec3 dim;
00153 osg::Box* box;
00154 };
00155
00156
00157
00158
00159 class OSGBoxTex : public OSGPrimitive {
00160 public:
00161 OSGBoxTex(float lengthX, float lengthY, float lengthZ);
00162 OSGBoxTex(osg::Vec3 dim);
00163
00164 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00165
00166 virtual osg::Vec3 getDim() const { return dim;}
00167 virtual void setDim(const osg::Vec3& _dim) { dim = _dim;}
00168
00169 virtual void setColor(const Color& color);
00170
00171 protected:
00172
00173 virtual void applyTextures();
00174
00175 osg::Vec3 dim;
00176
00177 osg::ref_ptr<osg::Geode> faces[6];
00178 };
00179
00180
00181
00182
00183
00184 class OSGSphere : public OSGPrimitive {
00185 public:
00186 OSGSphere(float radius);
00187
00188 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00189
00190 float getRadius() { return radius; }
00191 protected:
00192 float radius;
00193 };
00194
00195
00196
00197
00198 class OSGCapsule : public OSGPrimitive {
00199 public:
00200 OSGCapsule(float radius, float height);
00201
00202 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00203
00204 float getRadius() { return radius; }
00205 float getHeight() { return height; }
00206 protected:
00207 float radius;
00208 float height;
00209 };
00210
00211
00212
00213
00214
00215 class OSGCylinder : public OSGPrimitive {
00216 public:
00217 OSGCylinder(float radius, float height);
00218
00219 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00220
00221 float getRadius() { return radius; }
00222 float getHeight() { return height; }
00223 protected:
00224 float radius;
00225 float height;
00226 };
00227
00228
00229
00230
00231
00232 class OSGMesh : public OSGPrimitive {
00233 public:
00234
00235
00236
00237
00238
00239
00240 OSGMesh(const std::string& filename, float scale = 1, const osgDB::ReaderWriter::Options* options = 0);
00241 ~OSGMesh();
00242 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00243
00244
00245
00246
00247
00248 virtual void virtualInit(const OsgHandle& osgHandle);
00249 virtual float getRadius();
00250 float getScale() { return scale; }
00251
00252 protected:
00253 std::string filename;
00254 float scale;
00255 const osgDB::ReaderWriter::Options* options;
00256 osg::ref_ptr<osg::Node> mesh;
00257 osg::ref_ptr<osg::MatrixTransform> scaletrans;
00258
00259 virtual void internInit(const OsgHandle& osgHandle, bool loadAndDisplayMesh, Quality quality = Middle);
00260
00261 };
00262
00263
00264
00265
00266 class OSGText : public OSGPrimitive {
00267 public:
00268 OSGText(const std::string& text, int fontsize = 12,
00269 osgText::Text::AlignmentType align = osgText::Text::LEFT_BASE_LINE);
00270
00271 virtual ~OSGText();
00272
00273 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00274 virtual void setMatrix( const osg::Matrix& m4x4 );
00275 virtual osg::Group* getGroup();
00276 virtual void setColor(const Color& color);
00277
00278 virtual osg::Transform* getTransform();
00279 private:
00280 osgText::Text* osgText;
00281 };
00282
00283
00284 }
00285
00286 #endif
00287