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 #ifndef __OSGPRIMITIVE_H
00095 #define __OSGPRIMITIVE_H
00096
00097 #include <string>
00098 #include <vector>
00099 #include <osg/ref_ptr>
00100 #include "osgforwarddecl.h"
00101 #include "osghandle.h"
00102 #include <osgDB/ReadFile>
00103
00104 namespace lpzrobots {
00105
00106
00107
00108
00109
00110 class TextureDescr {
00111 public:
00112 TextureDescr(){}
00113
00114
00115
00116 TextureDescr(const std::string& filename, double repeatOnR, double repeatOnS)
00117 : filename(filename), repeatOnR(repeatOnR), repeatOnS(repeatOnS)
00118 {
00119 }
00120 std::string filename;
00121 double repeatOnR;
00122 double repeatOnS;
00123 };
00124
00125
00126
00127
00128
00129
00130 class OSGPrimitive {
00131 public:
00132 enum Quality {Low, Middle, High};
00133
00134 OSGPrimitive ();
00135 virtual ~OSGPrimitive ();
00136
00137
00138 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle) = 0;
00139
00140 virtual void setMatrix( const osg::Matrix& m4x4 );
00141
00142 virtual osg::Group* getGroup();
00143
00144 virtual void setTexture(const std::string& filename);
00145
00146 virtual void setTexture(const std::string& filename, double repeatOnR, double repeatOnS);
00147
00148 virtual void setTexture(int surface, const std::string& filename, double repeatOnR, double repeatOnS);
00149
00150 virtual std::vector<TextureDescr> getTextures();
00151
00152 virtual void setColor(const Color& color);
00153
00154 virtual osg::Transform* getTransform();
00155
00156 protected:
00157
00158 virtual void applyTextures();
00159
00160 osg::ref_ptr<osg::Geode> geode;
00161 osg::ref_ptr<osg::MatrixTransform> transform;
00162 osg::ref_ptr<osg::ShapeDrawable> shape;
00163
00164 std::vector<TextureDescr > textures;
00165
00166 const OsgHandle* osgHandle;
00167 };
00168
00169
00170
00171
00172 class OSGDummy : public OSGPrimitive {
00173 public:
00174 OSGDummy();
00175
00176 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00177 virtual void setMatrix( const osg::Matrix& m4x4 );
00178 virtual osg::Group* getGroup();
00179 virtual void setTexture(const std::string& filename);
00180 virtual void setColor(const Color& color);
00181
00182 virtual osg::Transform* getTransform();
00183 };
00184
00185
00186
00187
00188
00189 class OSGPlane : public OSGPrimitive {
00190 public:
00191 OSGPlane();
00192
00193 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00194 };
00195
00196
00197
00198
00199
00200 class OSGBox : public OSGPrimitive {
00201 public:
00202 OSGBox(float lengthX, float lengthY, float lengthZ);
00203 OSGBox(osg::Vec3 dim);
00204
00205 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00206
00207 osg::Vec3 getDim();
00208 void setDim(osg::Vec3);
00209
00210 protected:
00211 osg::Vec3 dim;
00212 osg::Box* box;
00213 };
00214
00215
00216
00217
00218 class OSGBoxTex : public OSGPrimitive {
00219 public:
00220 OSGBoxTex(float lengthX, float lengthY, float lengthZ);
00221 OSGBoxTex(osg::Vec3 dim);
00222
00223 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00224
00225 osg::Vec3 getDim() const { return dim;}
00226 void setDim(const osg::Vec3& _dim) { dim = _dim;}
00227
00228 virtual void setColor(const Color& color);
00229
00230 protected:
00231
00232 virtual void applyTextures();
00233
00234 osg::Vec3 dim;
00235
00236 osg::ref_ptr<osg::Geode> faces[6];
00237 };
00238
00239
00240
00241
00242
00243 class OSGSphere : public OSGPrimitive {
00244 public:
00245 OSGSphere(float radius);
00246
00247 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00248
00249 float getRadius() { return radius; }
00250 protected:
00251 float radius;
00252 };
00253
00254
00255
00256
00257 class OSGCapsule : public OSGPrimitive {
00258 public:
00259 OSGCapsule(float radius, float height);
00260
00261 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00262
00263 float getRadius() { return radius; }
00264 float getHeight() { return height; }
00265 protected:
00266 float radius;
00267 float height;
00268 };
00269
00270
00271
00272
00273
00274 class OSGCylinder : public OSGPrimitive {
00275 public:
00276 OSGCylinder(float radius, float height);
00277
00278 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00279
00280 float getRadius() { return radius; }
00281 float getHeight() { return height; }
00282 protected:
00283 float radius;
00284 float height;
00285 };
00286
00287
00288
00289
00290
00291 class OSGMesh : public OSGPrimitive {
00292 public:
00293
00294
00295
00296
00297
00298
00299 OSGMesh(const std::string& filename, float scale = 1, const osgDB::ReaderWriter::Options* options = 0);
00300 ~OSGMesh();
00301 virtual void init(const OsgHandle& osgHandle, Quality quality = Middle);
00302 virtual float getRadius();
00303 float getScale() { return scale; }
00304
00305 protected:
00306 std::string filename;
00307 float scale;
00308 const osgDB::ReaderWriter::Options* options;
00309 osg::ref_ptr<osg::Node> mesh;
00310 osg::ref_ptr<osg::MatrixTransform> scaletrans;
00311
00312 };
00313
00314 }
00315
00316 #endif
00317