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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 #ifndef __OSGPRIMITIVE_H
00106 #define __OSGPRIMITIVE_H
00107
00108 #include <string>
00109 #include <vector>
00110 #include <osg/ref_ptr>
00111 #include "osgforwarddecl.h"
00112 #include "osghandle.h"
00113 #include <osgDB/ReadFile>
00114
00115 namespace lpzrobots {
00116
00117
00118
00119
00120
00121 class TextureDescr {
00122 public:
00123 TextureDescr(){}
00124
00125
00126
00127 TextureDescr(const std::string& filename, double repeatOnR, double repeatOnS)
00128 : filename(filename), repeatOnR(repeatOnR), repeatOnS(repeatOnS)
00129 {
00130 }
00131 std::string filename;
00132 double repeatOnR;
00133 double repeatOnS;
00134 };
00135
00136
00137
00138
00139
00140
00141 class OSGPrimitive {
00142 public:
00143 enum Quality {Low, Middle, High};
00144
00145 OSGPrimitive ();
00146 virtual ~OSGPrimitive ();
00147
00148
00149 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle) = 0;
00150
00151 virtual void setMatrix( const osg::Matrix& m4x4 );
00152
00153 virtual osg::Group* getGroup();
00154
00155 virtual void setTexture(const std::string& filename);
00156
00157 virtual void setTexture(const std::string& filename, double repeatOnR, double repeatOnS);
00158
00159 virtual void setTexture(int surface, const std::string& filename, double repeatOnR, double repeatOnS);
00160
00161 virtual std::vector<TextureDescr> getTextures();
00162
00163 virtual void setColor(const Color& color);
00164
00165 virtual osg::Transform* getTransform();
00166
00167 protected:
00168
00169 virtual void applyTextures();
00170
00171 osg::ref_ptr<osg::Geode> geode;
00172 osg::ref_ptr<osg::MatrixTransform> transform;
00173 osg::ref_ptr<osg::ShapeDrawable> shape;
00174
00175 std::vector<TextureDescr > textures;
00176
00177 OsgHandle osgHandle;
00178 };
00179
00180
00181
00182
00183 class OSGDummy : public OSGPrimitive {
00184 public:
00185 OSGDummy();
00186
00187 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00188 virtual void setMatrix( const osg::Matrix& m4x4 );
00189 virtual osg::Group* getGroup();
00190 virtual void setTexture(const std::string& filename);
00191 virtual void setColor(const Color& color);
00192
00193 virtual osg::Transform* getTransform();
00194 };
00195
00196
00197
00198
00199
00200 class OSGPlane : public OSGPrimitive {
00201 public:
00202 OSGPlane();
00203
00204 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00205 };
00206
00207
00208
00209
00210
00211 class OSGBox : public OSGPrimitive {
00212 public:
00213 OSGBox(float lengthX, float lengthY, float lengthZ);
00214 OSGBox(osg::Vec3 dim);
00215
00216 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00217
00218 osg::Vec3 getDim();
00219 void setDim(osg::Vec3);
00220
00221 protected:
00222 osg::Vec3 dim;
00223 osg::Box* box;
00224 };
00225
00226
00227
00228
00229 class OSGBoxTex : public OSGPrimitive {
00230 public:
00231 OSGBoxTex(float lengthX, float lengthY, float lengthZ);
00232 OSGBoxTex(osg::Vec3 dim);
00233
00234 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00235
00236 osg::Vec3 getDim() const { return dim;}
00237 void setDim(const osg::Vec3& _dim) { dim = _dim;}
00238
00239 virtual void setColor(const Color& color);
00240
00241 protected:
00242
00243 virtual void applyTextures();
00244
00245 osg::Vec3 dim;
00246
00247 osg::ref_ptr<osg::Geode> faces[6];
00248 };
00249
00250
00251
00252
00253
00254 class OSGSphere : public OSGPrimitive {
00255 public:
00256 OSGSphere(float radius);
00257
00258 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00259
00260 float getRadius() { return radius; }
00261 protected:
00262 float radius;
00263 };
00264
00265
00266
00267
00268 class OSGCapsule : public OSGPrimitive {
00269 public:
00270 OSGCapsule(float radius, float height);
00271
00272 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00273
00274 float getRadius() { return radius; }
00275 float getHeight() { return height; }
00276 protected:
00277 float radius;
00278 float height;
00279 };
00280
00281
00282
00283
00284
00285 class OSGCylinder : public OSGPrimitive {
00286 public:
00287 OSGCylinder(float radius, float height);
00288
00289 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00290
00291 float getRadius() { return radius; }
00292 float getHeight() { return height; }
00293 protected:
00294 float radius;
00295 float height;
00296 };
00297
00298
00299
00300
00301
00302 class OSGMesh : public OSGPrimitive {
00303 public:
00304
00305
00306
00307
00308
00309
00310 OSGMesh(const std::string& filename, float scale = 1, const osgDB::ReaderWriter::Options* options = 0);
00311 ~OSGMesh();
00312 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00313
00314
00315
00316
00317
00318 virtual void virtualInit(const OsgHandle& osgHandle);
00319 virtual float getRadius();
00320 float getScale() { return scale; }
00321
00322 protected:
00323 std::string filename;
00324 float scale;
00325 const osgDB::ReaderWriter::Options* options;
00326 osg::ref_ptr<osg::Node> mesh;
00327 osg::ref_ptr<osg::MatrixTransform> scaletrans;
00328
00329 virtual void internInit(const OsgHandle& osgHandle, bool loadAndDisplayMesh, Quality quality = Middle);
00330
00331 };
00332
00333 }
00334
00335 #endif
00336