00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __VCG_OSG_VERTEX_PLUS_COMPONENT
00025 #define __VCG_OSG_VERTEX_PLUS_COMPONENT
00026
00027
00028 #include <vector>
00029 #include <vcg/space/point3.h>
00030 #include <vcg/space/texcoord2.h>
00031 #include <vcg/space/color4.h>
00032
00033 #include <opensg/osggeometry.h>
00034
00035
00036 namespace vcg {
00037
00038 namespace vert {
00039
00041
00043
00044 template< class T > class EmptyOSGInfo : public T { public : OSG::GeometryPtr Geo() { assert(0); return NULL; } };
00045
00046 template< class T > class OSGInfo : public T
00047 {
00048 public :
00049 OSG::GeometryPtr & Geo() { return _geop; }
00050 int & Index() { return _vertexi; }
00051 private :
00052 OSG::GeometryPtr _geop;
00053 int _vertexi;
00054 };
00055
00057
00059 template< class T > class OSGCoordCore
00060 {
00061 public :
00062 typedef T CoordType;
00063 typedef typename CoordType::ValueType ScalarType;
00064 OSGCoordCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; }
00065 ~OSGCoordCore() { _vertexindex = -1; }
00066 CoordType & operator=( CoordType & p2 )
00067 {
00069 OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() );
00070 OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
00071 pos->setValue( p2, _vertexindex );
00072 OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
00073 return p2;
00074 }
00075 ScalarType X()
00076 {
00078 OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() );
00079 OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
00080 OSG::Pnt3f p; pos->getValue( p, _vertexindex );
00081 OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
00082 return p.x();
00083 }
00084 ScalarType Y()
00085 {
00087 OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() );
00088 OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
00089 OSG::Pnt3f p; pos->getValue( p, _vertexindex );
00090 OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
00091 return p.y();
00092 }
00093 ScalarType Z()
00094 {
00096 OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() );
00097 OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
00098 OSG::Pnt3f p; pos->getValue( p, _vertexindex );
00099 OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
00100 return p.z();
00101 }
00102 private :
00103 OSG::GeometryPtr _geopointer;
00104 int _vertexindex;
00105 };
00106
00107 template< class T > class EmptyOSGCoord : public T
00108 {
00109 public :
00110 typedef OSG::Pnt3f CoordType;
00111 typedef OSG::Real32 ScalarType;
00112 CoordType & P() { assert(0); return CoordType(); }
00113 const CoordType & P() const { assert(0); return CoordType(); }
00114 const CoordType & cP() const { assert(0); return CoordType(); }
00115 CoordType & UberP() { assert(0); return CoordType(); }
00116 static bool HasCoord() { return false; }
00117 static void Name( std::vector< std::string > & name ) { T::Name(name); }
00118 };
00119
00120 template< class A, class T > class OSGCoord : public T
00121 {
00122 public :
00123 typedef A CoordType;
00124 typedef typename CoordType::ValueType ScalarType;
00125 typedef typename OSGCoordCore< CoordType > CoreType;
00126 OSGCoord() { _corep = NULL; }
00127 ~OSGCoord() { if( _corep != NULL ) delete _corep; }
00128 CoreType & P()
00129 {
00130 CoreType * tmpcorep = _corep;
00131 _corep = new CoreType( Geo(), Index() );
00132 if( tmpcorep != NULL ) delete tmpcorep;
00133 return *_corep;
00134 }
00135 static bool HasCoord() { return true; }
00136 static void Name( std::vector< std::string > & name ) { name.push_back( std::string("OSGCoord") ); T::Name(name); }
00137 private :
00138 CoreType * _corep;
00139 };
00140
00141 class OSGCoordCore3f : public OSGCoordCore< OSG::Pnt3f > {};
00142
00143 template< class T > class OSGCoord3f : public OSGCoord< OSG::Pnt3f, T >
00144 { public : static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGCoord3f" ) ); T::Name(name); } };
00145
00146
00148
00149 template< class T > class OSGNormalCore
00150 {
00151 public :
00152 typedef T NormalType;
00153 typedef typename NormalType::ValueType ScalarType;
00154 OSGNormalCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; }
00155 ~OSGNormalCore() { _vertexindex = -1; }
00156 NormalType & operator=( NormalType & n2 )
00157 {
00159 OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() );
00160 OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
00161 norm->setValue( n2, _vertexindex );
00162 OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
00163 return n2;
00164 }
00165 ScalarType X()
00166 {
00168 OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() );
00169 OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
00170 OSG::Vec3f n; norm->getValue( n, _vertexindex );
00171 OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
00172 return n.x();
00173 }
00174 ScalarType Y()
00175 {
00177 OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() );
00178 OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
00179 OSG::Vec3f n; norm->getValue( n, _vertexindex );
00180 OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
00181 return n.y();
00182 }
00183 ScalarType Z()
00184 {
00186 OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() );
00187 OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
00188 OSG::Vec3f n; norm->getValue( n, _vertexindex );
00189 OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
00190 return n.z();
00191 }
00192 private :
00193 OSG::GeometryPtr _geopointer;
00194 int _vertexindex;
00195 };
00196
00197 template< class T > class EmptyOSGNormal : public T
00198 {
00199 public :
00200 typedef OSG::Vec3f NormalType;
00201 typedef OSG::Real32 ScalarType;
00202 NormalType & N() { assert(0); return NormalType(); }
00203 const NormalType cN()const { assert(0); return NormalType(); }
00204 static bool HasNormal() { return false; }
00205 static bool HasNormalOcc() { return false; }
00206 static void Name( std::vector< std::string > & name ) { T::Name(name); }
00207 };
00208
00209 template< class A, class T > class OSGNormal : public T
00210 {
00211 public :
00212 typedef A NormalType;
00213 typedef typename NormalType::ValueType ScalarType;
00214 typedef typename OSGNormalCore< NormalType > CoreType;
00215 OSGNormal() { _corep = NULL; }
00216 ~OSGNormal() { if( _corep == NULL ) delete _corep; }
00217 CoreType & N()
00218 {
00219 CoreType * tmpcorep = _corep;
00220 _corep = new CoreType( Geo(), Index() );
00221 if( tmpcorep == NULL ) delete tmpcorep;
00222 return *_corep;
00223 }
00224 static bool HasNormal() { return true; }
00225 static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGNormal" ) );T::Name(name); }
00226 private :
00227 CoreType * _corep;
00228 };
00229
00230 class OSGNormalCore3f : public OSGNormalCore< OSG::Vec3f > {};
00231
00232 template< class T > class OSGNormal3f : public OSGNormal< OSG::Vec3f, T >
00233 { public : static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGNormal3f" ) ); T::Name(name); } };
00234
00235
00237
00238 template< class T > class OSGColorCore
00239 {
00240 public :
00241 typedef T ColorType;
00242 typedef typename ColorType::ValueType ScalarType;
00243 OSGColorCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; }
00244 ~OSGColorCore() { _vertexindex = -1; }
00245 ColorType & operator=( ColorType & c2 )
00246 {
00248 OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() );
00249 OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
00250 colp->setValue( c2, _vertexindex );
00251 OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
00252 return c2;
00253 }
00254 ScalarType R()
00255 {
00257 OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() );
00258 OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
00259 OSG::Color3f c; colp->getValue( c, _vertexindex );
00260 OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
00261 return c.red();
00262 }
00263 ScalarType G()
00264 {
00266 OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() );
00267 OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
00268 OSG::Color3f c; colp->getValue( c, _vertexindex );
00269 OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
00270 return c.green();
00271 }
00272 ScalarType B()
00273 {
00275 OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() );
00276 OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
00277 OSG::Color3f c; colp->getValue( c, _vertexindex );
00278 OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
00279 return c.blue();
00280 }
00281 private :
00282 OSG::GeometryPtr _geopointer;
00283 int _vertexindex;
00284 };
00285
00286 template< class T > class EmptyOSGColor : public T
00287 {
00288 public :
00289 typedef OSG::Color3f ColorType;
00290 typedef OSG::Real32 ScalarType;
00291 ColorType & C() { assert(0); return ColorType(); }
00292 static bool HasColor() { return false; }
00293 static void Name( std::vector< std::string > & name ) { T::Name(name); }
00294 };
00295
00296 template< class A, class T > class OSGColor : public T
00297 {
00298 public :
00299 typedef A ColorType;
00300 typedef typename ColorType::ValueType ScalarType;
00301 typedef typename OSGColorCore< ColorType > CoreType;
00302 OSGColor() { _corep = NULL; }
00303 ~OSGColor() { if( _corep != NULL ) delete _corep; }
00304 CoreType & C()
00305 {
00306 CoreType * tmpcorep = _corep;
00307 _corep = new CoreType( Geo(), Index() );
00308 if( tmpcorep != NULL ) delete tmpcorep;
00309 return *_corep;
00310 }
00311 static bool HasColor() { return true; }
00312 static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGColor" ) ); T::Name(name); }
00313 private :
00314 CoreType * _corep;
00315 };
00316
00317 class OSGColorCore3f : public OSGColorCore< OSG::Color3f > {};
00318
00319 template< class T > class OSGColor3f : public OSGColor< OSG::Color3f, T >
00320 { static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGColor3f" ) ); T::Name(name); } };
00321
00322
00323 }
00324
00325 }
00326
00327
00328 #endif
00329
00330