From bc3fd845e1cacbe2fe703ea5abc9017cc63dd8fd Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 25 Oct 2012 13:17:47 +0000 Subject: [PATCH] Updated many importer to do not use anymore the useless, deprecated, removed, etc etc --- wrap/io_tetramesh/export_ply.h | 26 +- wrap/io_tetramesh/import_ply.h | 22 +- wrap/io_tetramesh/import_ts.h | 176 +++++----- wrap/io_trimesh/export_gts.h | 18 +- wrap/io_trimesh/export_off.h | 10 +- wrap/io_trimesh/export_ply.h | 4 +- wrap/io_trimesh/import_ply.h | 5 +- wrap/opensg/vertex_component.h | 618 ++++++++++++++++----------------- 8 files changed, 430 insertions(+), 449 deletions(-) diff --git a/wrap/io_tetramesh/export_ply.h b/wrap/io_tetramesh/export_ply.h index f41e9b51..3f8af4a8 100644 --- a/wrap/io_tetramesh/export_ply.h +++ b/wrap/io_tetramesh/export_ply.h @@ -319,19 +319,19 @@ static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo & for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) { vp=&(*vi); - FlagV.push_back(vp->UberFlags()); // Salva in ogni caso flag del vertice + FlagV.push_back(vp->Flags()); // Salva in ogni caso flag del vertice if( ! vp->IsD() ) { if(binary) { float t; - t = float(vp->UberP()[0]); fwrite(&t,sizeof(float),1,fpout); - t = float(vp->UberP()[1]); fwrite(&t,sizeof(float),1,fpout); - t = float(vp->UberP()[2]); fwrite(&t,sizeof(float),1,fpout); + t = float(vp->P()[0]); fwrite(&t,sizeof(float),1,fpout); + t = float(vp->P()[1]); fwrite(&t,sizeof(float),1,fpout); + t = float(vp->P()[2]); fwrite(&t,sizeof(float),1,fpout); if( pi.mask & ply::PLYMask::PM_VERTFLAGS ) - fwrite(&(vp->UberFlags()),sizeof(int),1,fpout); + fwrite(&(vp->Flags()),sizeof(int),1,fpout); if( HasPerVertexColor(m) && (pi.mask & ply::PLYMask::PM_VERTCOLOR) ) fwrite(&( vp->C() ),sizeof(char),4,fpout); @@ -360,7 +360,7 @@ static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo & fprintf(fpout,"%g %g %g " ,vp->P()[0],vp->P()[1],vp->P()[2]); if( pi.mask & ply::PLYMask::PM_VERTFLAGS ) - fprintf(fpout,"%d ",vp->UberFlags()); + fprintf(fpout,"%d ",vp->Flags()); if( HasPerVertexColor(m) && (pi.mask & ply::PLYMask::PM_VERTCOLOR) ) fprintf(fpout,"%d %d %d %d ",vp->C()[0],vp->C()[1],vp->C()[2],vp->C()[3] ); @@ -387,7 +387,7 @@ static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo & fprintf(fpout,"\n"); } - vp->UberFlags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato! + vp->Flags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato! j++; } } @@ -407,10 +407,10 @@ static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo & { fcnt++; if(binary) { - vv[0]=fp->cV(0)->UberFlags(); - vv[1]=fp->cV(1)->UberFlags(); - vv[2]=fp->cV(2)->UberFlags(); - vv[3]=fp->cV(2)->UberFlags(); + vv[0]=fp->cV(0)->Flags(); + vv[1]=fp->cV(1)->Flags(); + vv[2]=fp->cV(2)->Flags(); + vv[3]=fp->cV(2)->Flags(); fwrite(&c,1,1,fpout); fwrite(vv,sizeof(int),4,fpout); @@ -484,7 +484,7 @@ static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo & else // ***** ASCII ***** { fprintf(fpout,"3 %d %d %d ", - fp->cV(0)->UberFlags(), fp->cV(1)->UberFlags(), fp->cV(2)->UberFlags() ); + fp->cV(0)->Flags(), fp->cV(1)->Flags(), fp->cV(2)->Flags() ); if( pi.mask & ply::PLYMask::PM_TETRAFLAGS ) fprintf(fpout,"%d ",fp->Flags()); @@ -563,7 +563,7 @@ static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo & // Recupera i flag originali for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) - (*vi).UberFlags()=FlagV[j++]; + (*vi).Flags()=FlagV[j++]; return 0; } diff --git a/wrap/io_tetramesh/import_ply.h b/wrap/io_tetramesh/import_ply.h index 0da4c1f4..74c70dba 100644 --- a/wrap/io_tetramesh/import_ply.h +++ b/wrap/io_tetramesh/import_ply.h @@ -244,28 +244,11 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi ) LoadPly_VertAux va; pi.mask = 0; - bool multit = false; // true if texture has a per face int spec the texture index va.flags = 42; pi.status = ::vcg::ply::E_NOERROR; - // init defaults - VertexType tv; - tv.UberFlags() = 0; - if( VertexType::HasQuality() ) tv.Q()=1.0; - if( VertexType::HasColor() ) tv.C()=Color4b(Color4b::White); - - TetraType tf; - tf.UberFlags() = 0; - //if( FaceType::HasFaceQuality() ) tf.Q()=1.0; - //if( FaceType::HasWedgeColor() ) tf.WC(0)=tf.WC(1)=tf.WC(2)=Color4b(Color4b::White); - //if( FaceType::HasFaceColor() ) tf.C()=Color4b(Color4b::White); - // Descrittori delle strutture - - //bool isvflags = false; // Il file contiene i flags - - // The main descriptor of the ply file vcg::ply::PlyFile pf; @@ -442,7 +425,6 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi ) for(j=0;j -#include - -namespace vcg { -namespace tetra { -namespace io { - -template -class ImporterTS{ - typedef MESHTYPE Tetramesh; - typedef typename Tetramesh::VertexPointer VertexPointer; - typedef typename Tetramesh::VertexType VertexType; - typedef typename Tetramesh::TetraType FaceType; - typedef typename Tetramesh::VertexIterator VertexIterator; - typedef typename Tetramesh::TetraIterator FaceIterator; - typedef typename Tetramesh::ScalarType ScalarType; - typedef Point3 Point3x; - - static FILE *& F(){static FILE * f; return f;} - - inline static void ReadPos( Point3 &p){ - fscanf(F(),"%lg %lg %lg",&p[0],&p[1],&p[2]); - } - inline static void ReadPos( Point3 &p){ - fscanf(F(),"%f %f %f",&p[0],&p[1],&p[2]); - } - inline static void ReadPos( Point4 &p){ - fscanf(F(),"%g %g %g %g",&p[0],&p[1],&p[2],&p[3]); - } -public: -static int Open( Tetramesh & m, const char * filename ) -{ - int nvertex; - int ntetra; - int tp0; - int tp1; - int tp2; - int tp3; - typename Tetramesh::VertexType p1; - F() = fopen(filename,"r"); - if(F() == NULL ) - { - printf( "The file was not opened\n" ); - return -1; - } - else - { - fscanf(F(), "%i", &nvertex ); - fscanf(F(), "%i", &ntetra ); - m.tetra.reserve(ntetra); - m.vert.reserve(nvertex); - int j; - for (j=0;j +#include + +namespace vcg { +namespace tetra { +namespace io { + +template +class ImporterTS{ + typedef MESHTYPE Tetramesh; + typedef typename Tetramesh::VertexPointer VertexPointer; + typedef typename Tetramesh::VertexType VertexType; + typedef typename Tetramesh::TetraType FaceType; + typedef typename Tetramesh::VertexIterator VertexIterator; + typedef typename Tetramesh::TetraIterator FaceIterator; + typedef typename Tetramesh::ScalarType ScalarType; + typedef Point3 Point3x; + + static FILE *& F(){static FILE * f; return f;} + + inline static void ReadPos( Point3 &p){ + fscanf(F(),"%lg %lg %lg",&p[0],&p[1],&p[2]); + } + inline static void ReadPos( Point3 &p){ + fscanf(F(),"%f %f %f",&p[0],&p[1],&p[2]); + } + inline static void ReadPos( Point4 &p){ + fscanf(F(),"%g %g %g %g",&p[0],&p[1],&p[2],&p[3]); + } +public: +static int Open( Tetramesh & m, const char * filename ) +{ + int nvertex; + int ntetra; + int tp0; + int tp1; + int tp2; + int tp3; + typename Tetramesh::VertexType p1; + F() = fopen(filename,"r"); + if(F() == NULL ) + { + printf( "The file was not opened\n" ); + return -1; + } + else + { + fscanf(F(), "%i", &nvertex ); + fscanf(F(), "%i", &ntetra ); + m.tetra.reserve(ntetra); + m.vert.reserve(nvertex); + int j; + for (j=0;jUberFlags()); + FlagV.push_back(vp->Flags()); if (!vp->IsD()) { - vp->UberFlags() = j; + vp->Flags() = j; j++; } } @@ -94,8 +94,8 @@ namespace vcg { { for (int k=0; k<3; ++k) { - int a = fp->cV(k)->UberFlags(); - int b = fp->cV((k+1)%3)->UberFlags(); + int a = fp->cV(k)->Flags(); + int b = fp->cV((k+1)%3)->Flags(); if (a>b) std::swap(a,b); Edge e(a,b); @@ -132,8 +132,8 @@ namespace vcg { { for (int k=0; k<3; ++k) { - int a = fp->cV(k)->UberFlags(); - int b = fp->cV((k+1)%3)->UberFlags(); + int a = fp->cV(k)->Flags(); + int b = fp->cV((k+1)%3)->Flags(); if (a>b) std::swap(a,b); Edge e(a,b); @@ -154,8 +154,8 @@ namespace vcg { { for (int k=0; k<3; ++k) { - int a = fp->cV(k)->UberFlags(); - int b = fp->cV((k+1)%3)->UberFlags(); + int a = fp->cV(k)->Flags(); + int b = fp->cV((k+1)%3)->Flags(); if (a>b) std::swap(a,b); Edge e(a,b); @@ -171,7 +171,7 @@ namespace vcg { // Recupera i flag originali for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) - (*vi).UberFlags()=FlagV[j++]; + (*vi).Flags()=FlagV[j++]; return 0; } diff --git a/wrap/io_trimesh/export_off.h b/wrap/io_trimesh/export_off.h index 54d89a5c..36d799a0 100644 --- a/wrap/io_trimesh/export_off.h +++ b/wrap/io_trimesh/export_off.h @@ -85,7 +85,7 @@ namespace vcg { for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) { vp=&(*vi); - FlagV.push_back(vp->UberFlags()); // Save vertex flags + FlagV.push_back(vp->Flags()); // Save vertex flags if( ! vp->IsD() ) { // ***** ASCII ***** @@ -102,7 +102,7 @@ namespace vcg { fprintf(fpout,"\n"); - vp->UberFlags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato! + vp->Flags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato! j++; } } @@ -119,7 +119,7 @@ namespace vcg { if(!polygon.empty()) { fprintf(fpout,"%d ", int(polygon.size()) ); - for (size_t i=0; iUberFlags() ); + for (size_t i=0; iFlags() ); fprintf(fpout,"\n"); } } @@ -130,7 +130,7 @@ namespace vcg { FacePointer fp=&(*fi); if( ! fp->IsD() ) { fprintf(fpout,"3 %d %d %d\n", - fp->cV(0)->UberFlags(), fp->cV(1)->UberFlags(), fp->cV(2)->UberFlags() ); + fp->cV(0)->Flags(), fp->cV(1)->Flags(), fp->cV(2)->Flags() ); } } } @@ -140,7 +140,7 @@ namespace vcg { // Recupera i flag originali j=0; for(vi=m.vert.begin();vi!=m.vert.end();++vi) - (*vi).UberFlags()=FlagV[j++]; + (*vi).Flags()=FlagV[j++]; return 0; } diff --git a/wrap/io_trimesh/export_ply.h b/wrap/io_trimesh/export_ply.h index 321cf390..c48ba21d 100644 --- a/wrap/io_trimesh/export_ply.h +++ b/wrap/io_trimesh/export_ply.h @@ -466,7 +466,7 @@ static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &p t = float(vp->N()[2]); fwrite(&t,sizeof(float),1,fpout); } if( HasPerVertexFlags(m) && (pi.mask & Mask::IOM_VERTFLAGS) ) - fwrite(&(vp->UberFlags()),sizeof(int),1,fpout); + fwrite(&(vp->Flags()),sizeof(int),1,fpout); if( HasPerVertexColor(m) && (pi.mask & Mask::IOM_VERTCOLOR) ) fwrite(&( vp->C() ),sizeof(char),4,fpout); @@ -506,7 +506,7 @@ static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &p fprintf(fpout,"%g %g %g " ,double(vp->N()[0]),double(vp->N()[1]),double(vp->N()[2])); if( HasPerVertexFlags(m) && (pi.mask & Mask::IOM_VERTFLAGS)) - fprintf(fpout,"%d ",vp->UberFlags()); + fprintf(fpout,"%d ",vp->Flags()); if( HasPerVertexColor(m) && (pi.mask & Mask::IOM_VERTCOLOR) ) fprintf(fpout,"%d %d %d %d ",vp->C()[0],vp->C()[1],vp->C()[2],vp->C()[3] ); diff --git a/wrap/io_trimesh/import_ply.h b/wrap/io_trimesh/import_ply.h index 13eaa301..8eadb708 100644 --- a/wrap/io_trimesh/import_ply.h +++ b/wrap/io_trimesh/import_ply.h @@ -640,7 +640,6 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi ) for(j=0;j -#include -#include -#include - -#include - - -namespace vcg { - -namespace vert { - -/// Some Naming Rules : All the Components that can be added to a vertex should be defined in the namespace vert: - -/// ------------------------- OPENSGINFO ----------------------------------------- - -template< class T > class EmptyOSGInfo : public T { public : OSG::GeometryPtr Geo() { assert(0); return NULL; } }; - -template< class T > class OSGInfo : public T -{ -public : - OSG::GeometryPtr & Geo() { return _geop; } - int & Index() { return _vertexi; } -private : - OSG::GeometryPtr _geop; /// Maybe we can use pointers to buffers directly but now we really don't now if these pointers change in time ... !!! - int _vertexi; /// OSG vertex index -}; - -/// ------------------------- COORD ----------------------------------------- - -/// Core for the coordinate component templated with the coordinate type of the component -template< class T > class OSGCoordCore -{ -public : - typedef T CoordType; - typedef typename CoordType::ValueType ScalarType; - OSGCoordCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; } - ~OSGCoordCore() { _vertexindex = -1; } - CoordType & operator=( CoordType & p2 ) - { - /// Set coordinates - OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() ); - OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); - pos->setValue( p2, _vertexindex ); - OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); - return p2; /// Warning : instead of returning the left side operand we return the right one !!! - } - ScalarType X() - { - /// Get coordinates - OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() ); - OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); - OSG::Pnt3f p; pos->getValue( p, _vertexindex ); - OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); - return p.x(); - } - ScalarType Y() - { - /// Get coordinates - OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() ); - OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); - OSG::Pnt3f p; pos->getValue( p, _vertexindex ); - OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); - return p.y(); - } - ScalarType Z() - { - /// Get coordinates - OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() ); - OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); - OSG::Pnt3f p; pos->getValue( p, _vertexindex ); - OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); - return p.z(); - } -private : - OSG::GeometryPtr _geopointer; - int _vertexindex; -}; - -template< class T > class EmptyOSGCoord : public T -{ -public : - typedef OSG::Pnt3f CoordType; - typedef OSG::Real32 ScalarType; - CoordType & P() { assert(0); return CoordType(); } - const CoordType & P() const { assert(0); return CoordType(); } - const CoordType & cP() const { assert(0); return CoordType(); } - CoordType & UberP() { assert(0); return CoordType(); } - static bool HasCoord() { return false; } - static void Name( std::vector< std::string > & name ) { T::Name(name); } -}; - -template< class A, class T > class OSGCoord : public T -{ -public : - typedef A CoordType; /// Must be a OSG::Pnt3 type as : OSG::Pnt3s, OSG:Pnt3f, OSG::Pnt3d etc... - typedef typename CoordType::ValueType ScalarType; /// Can be a OSG basic type as : OSG::Int16, OSG::Real32, OSG::Real64 etc... - typedef typename OSGCoordCore< CoordType > CoreType; - OSGCoord() { _corep = NULL; } - ~OSGCoord() { if( _corep != NULL ) delete _corep; } - CoreType & P() - { - CoreType * tmpcorep = _corep; - _corep = new CoreType( Geo(), Index() ); - if( tmpcorep != NULL ) delete tmpcorep; - return *_corep; - } - static bool HasCoord() { return true; } - static void Name( std::vector< std::string > & name ) { name.push_back( std::string("OSGCoord") ); T::Name(name); } -private : - CoreType * _corep; -}; - -class OSGCoordCore3f : public OSGCoordCore< OSG::Pnt3f > {}; - -template< class T > class OSGCoord3f : public OSGCoord< OSG::Pnt3f, T > -{ public : static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGCoord3f" ) ); T::Name(name); } }; - - -/// -------------------------- NORMAL ---------------------------------------- - -template< class T > class OSGNormalCore -{ -public : - typedef T NormalType; - typedef typename NormalType::ValueType ScalarType; - OSGNormalCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; } - ~OSGNormalCore() { _vertexindex = -1; } - NormalType & operator=( NormalType & n2 ) - { - /// Set coordinates - OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() ); - OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); - norm->setValue( n2, _vertexindex ); - OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); - return n2; /// Warning : instead of returning the left side operand we return the right one !!! - } - ScalarType X() - { - /// Get coordinates - OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() ); - OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); - OSG::Vec3f n; norm->getValue( n, _vertexindex ); - OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); - return n.x(); - } - ScalarType Y() - { - /// Get coordinates - OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() ); - OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); - OSG::Vec3f n; norm->getValue( n, _vertexindex ); - OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); - return n.y(); - } - ScalarType Z() - { - /// Get coordinates - OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() ); - OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); - OSG::Vec3f n; norm->getValue( n, _vertexindex ); - OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); - return n.z(); - } -private : - OSG::GeometryPtr _geopointer; - int _vertexindex; -}; - -template< class T > class EmptyOSGNormal : public T -{ -public : - typedef OSG::Vec3f NormalType; - typedef OSG::Real32 ScalarType; - NormalType & N() { assert(0); return NormalType(); } - const NormalType cN()const { assert(0); return NormalType(); } - static bool HasNormal() { return false; } - static bool HasNormalOcc() { return false; } - static void Name( std::vector< std::string > & name ) { T::Name(name); } -}; - -template< class A, class T > class OSGNormal : public T -{ -public : - typedef A NormalType; /// Must be a OSG::Vec3 type as : OSG::Vec3s, OSG:Vec3f, OSG::Vec3d etc... - typedef typename NormalType::ValueType ScalarType; /// Can be a OSG basic type as : OSG::Int16, OSG::Real32, OSG::Real64 etc... - typedef typename OSGNormalCore< NormalType > CoreType; - OSGNormal() { _corep = NULL; } - ~OSGNormal() { if( _corep == NULL ) delete _corep; } - CoreType & N() - { - CoreType * tmpcorep = _corep; - _corep = new CoreType( Geo(), Index() ); - if( tmpcorep == NULL ) delete tmpcorep; - return *_corep; - } - static bool HasNormal() { return true; } - static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGNormal" ) );T::Name(name); } -private : - CoreType * _corep; -}; - -class OSGNormalCore3f : public OSGNormalCore< OSG::Vec3f > {}; - -template< class T > class OSGNormal3f : public OSGNormal< OSG::Vec3f, T > -{ public : static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGNormal3f" ) ); T::Name(name); } }; - - -/// -------------------------- COLOR ---------------------------------- - -template< class T > class OSGColorCore -{ -public : - typedef T ColorType; - typedef typename ColorType::ValueType ScalarType; - OSGColorCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; } - ~OSGColorCore() { _vertexindex = -1; } - ColorType & operator=( ColorType & c2 ) - { - /// Set color - OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() ); - OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); - colp->setValue( c2, _vertexindex ); - OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); - return c2; /// Warning : instead of returning the left side operand we return the right one !!! - } - ScalarType R() - { - /// Get coordinates - OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() ); - OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); - OSG::Color3f c; colp->getValue( c, _vertexindex ); - OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); - return c.red(); - } - ScalarType G() - { - /// Get coordinates - OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() ); - OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); - OSG::Color3f c; colp->getValue( c, _vertexindex ); - OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); - return c.green(); - } - ScalarType B() - { - /// Get coordinates - OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() ); - OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); - OSG::Color3f c; colp->getValue( c, _vertexindex ); - OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); - return c.blue(); - } -private : - OSG::GeometryPtr _geopointer; - int _vertexindex; -}; - -template< class T > class EmptyOSGColor : public T -{ -public : - typedef OSG::Color3f ColorType; - typedef OSG::Real32 ScalarType; - ColorType & C() { assert(0); return ColorType(); } - static bool HasColor() { return false; } - static void Name( std::vector< std::string > & name ) { T::Name(name); } -}; - -template< class A, class T > class OSGColor : public T -{ -public : - typedef A ColorType; /// Must be a OSG::Color3 type as : OSG::Color3ub, OSG:Color3f etc... - typedef typename ColorType::ValueType ScalarType; /// Can be a OSG basic type as : OSG::UInt8, OSG::Real32 etc... - typedef typename OSGColorCore< ColorType > CoreType; - OSGColor() { _corep = NULL; } - ~OSGColor() { if( _corep != NULL ) delete _corep; } - CoreType & C() - { - CoreType * tmpcorep = _corep; - _corep = new CoreType( Geo(), Index() ); - if( tmpcorep != NULL ) delete tmpcorep; - return *_corep; - } - static bool HasColor() { return true; } - static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGColor" ) ); T::Name(name); } -private : - CoreType * _corep; -}; - -class OSGColorCore3f : public OSGColorCore< OSG::Color3f > {}; - -template< class T > class OSGColor3f : public OSGColor< OSG::Color3f, T > -{ static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGColor3f" ) ); T::Name(name); } }; - - -} /// end namespace vert - -} /// end namespace vcg - - -#endif - - +****************************************************************************/ + +#ifndef __VCG_OSG_VERTEX_PLUS_COMPONENT +#define __VCG_OSG_VERTEX_PLUS_COMPONENT + + +#include +#include +#include +#include + +#include + + +namespace vcg { + +namespace vert { + +/// Some Naming Rules : All the Components that can be added to a vertex should be defined in the namespace vert: + +/// ------------------------- OPENSGINFO ----------------------------------------- + +template< class T > class EmptyOSGInfo : public T { public : OSG::GeometryPtr Geo() { assert(0); return NULL; } }; + +template< class T > class OSGInfo : public T +{ +public : + OSG::GeometryPtr & Geo() { return _geop; } + int & Index() { return _vertexi; } +private : + OSG::GeometryPtr _geop; /// Maybe we can use pointers to buffers directly but now we really don't now if these pointers change in time ... !!! + int _vertexi; /// OSG vertex index +}; + +/// ------------------------- COORD ----------------------------------------- + +/// Core for the coordinate component templated with the coordinate type of the component +template< class T > class OSGCoordCore +{ +public : + typedef T CoordType; + typedef typename CoordType::ValueType ScalarType; + OSGCoordCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; } + ~OSGCoordCore() { _vertexindex = -1; } + CoordType & operator=( CoordType & p2 ) + { + /// Set coordinates + OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() ); + OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); + pos->setValue( p2, _vertexindex ); + OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); + return p2; /// Warning : instead of returning the left side operand we return the right one !!! + } + ScalarType X() + { + /// Get coordinates + OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() ); + OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); + OSG::Pnt3f p; pos->getValue( p, _vertexindex ); + OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); + return p.x(); + } + ScalarType Y() + { + /// Get coordinates + OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() ); + OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); + OSG::Pnt3f p; pos->getValue( p, _vertexindex ); + OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); + return p.y(); + } + ScalarType Z() + { + /// Get coordinates + OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() ); + OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); + OSG::Pnt3f p; pos->getValue( p, _vertexindex ); + OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); + return p.z(); + } +private : + OSG::GeometryPtr _geopointer; + int _vertexindex; +}; + +template< class T > class EmptyOSGCoord : public T +{ +public : + typedef OSG::Pnt3f CoordType; + typedef OSG::Real32 ScalarType; + CoordType & P() { assert(0); return CoordType(); } + const CoordType & P() const { assert(0); return CoordType(); } + const CoordType & cP() const { assert(0); return CoordType(); } + CoordType & P() { assert(0); return CoordType(); } + static bool HasCoord() { return false; } + static void Name( std::vector< std::string > & name ) { T::Name(name); } +}; + +template< class A, class T > class OSGCoord : public T +{ +public : + typedef A CoordType; /// Must be a OSG::Pnt3 type as : OSG::Pnt3s, OSG:Pnt3f, OSG::Pnt3d etc... + typedef typename CoordType::ValueType ScalarType; /// Can be a OSG basic type as : OSG::Int16, OSG::Real32, OSG::Real64 etc... + typedef typename OSGCoordCore< CoordType > CoreType; + OSGCoord() { _corep = NULL; } + ~OSGCoord() { if( _corep != NULL ) delete _corep; } + CoreType & P() + { + CoreType * tmpcorep = _corep; + _corep = new CoreType( Geo(), Index() ); + if( tmpcorep != NULL ) delete tmpcorep; + return *_corep; + } + static bool HasCoord() { return true; } + static void Name( std::vector< std::string > & name ) { name.push_back( std::string("OSGCoord") ); T::Name(name); } +private : + CoreType * _corep; +}; + +class OSGCoordCore3f : public OSGCoordCore< OSG::Pnt3f > {}; + +template< class T > class OSGCoord3f : public OSGCoord< OSG::Pnt3f, T > +{ public : static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGCoord3f" ) ); T::Name(name); } }; + + +/// -------------------------- NORMAL ---------------------------------------- + +template< class T > class OSGNormalCore +{ +public : + typedef T NormalType; + typedef typename NormalType::ValueType ScalarType; + OSGNormalCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; } + ~OSGNormalCore() { _vertexindex = -1; } + NormalType & operator=( NormalType & n2 ) + { + /// Set coordinates + OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() ); + OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); + norm->setValue( n2, _vertexindex ); + OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); + return n2; /// Warning : instead of returning the left side operand we return the right one !!! + } + ScalarType X() + { + /// Get coordinates + OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() ); + OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); + OSG::Vec3f n; norm->getValue( n, _vertexindex ); + OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); + return n.x(); + } + ScalarType Y() + { + /// Get coordinates + OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() ); + OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); + OSG::Vec3f n; norm->getValue( n, _vertexindex ); + OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); + return n.y(); + } + ScalarType Z() + { + /// Get coordinates + OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() ); + OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); + OSG::Vec3f n; norm->getValue( n, _vertexindex ); + OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); + return n.z(); + } +private : + OSG::GeometryPtr _geopointer; + int _vertexindex; +}; + +template< class T > class EmptyOSGNormal : public T +{ +public : + typedef OSG::Vec3f NormalType; + typedef OSG::Real32 ScalarType; + NormalType & N() { assert(0); return NormalType(); } + const NormalType cN()const { assert(0); return NormalType(); } + static bool HasNormal() { return false; } + static bool HasNormalOcc() { return false; } + static void Name( std::vector< std::string > & name ) { T::Name(name); } +}; + +template< class A, class T > class OSGNormal : public T +{ +public : + typedef A NormalType; /// Must be a OSG::Vec3 type as : OSG::Vec3s, OSG:Vec3f, OSG::Vec3d etc... + typedef typename NormalType::ValueType ScalarType; /// Can be a OSG basic type as : OSG::Int16, OSG::Real32, OSG::Real64 etc... + typedef typename OSGNormalCore< NormalType > CoreType; + OSGNormal() { _corep = NULL; } + ~OSGNormal() { if( _corep == NULL ) delete _corep; } + CoreType & N() + { + CoreType * tmpcorep = _corep; + _corep = new CoreType( Geo(), Index() ); + if( tmpcorep == NULL ) delete tmpcorep; + return *_corep; + } + static bool HasNormal() { return true; } + static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGNormal" ) );T::Name(name); } +private : + CoreType * _corep; +}; + +class OSGNormalCore3f : public OSGNormalCore< OSG::Vec3f > {}; + +template< class T > class OSGNormal3f : public OSGNormal< OSG::Vec3f, T > +{ public : static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGNormal3f" ) ); T::Name(name); } }; + + +/// -------------------------- COLOR ---------------------------------- + +template< class T > class OSGColorCore +{ +public : + typedef T ColorType; + typedef typename ColorType::ValueType ScalarType; + OSGColorCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; } + ~OSGColorCore() { _vertexindex = -1; } + ColorType & operator=( ColorType & c2 ) + { + /// Set color + OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() ); + OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); + colp->setValue( c2, _vertexindex ); + OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); + return c2; /// Warning : instead of returning the left side operand we return the right one !!! + } + ScalarType R() + { + /// Get coordinates + OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() ); + OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); + OSG::Color3f c; colp->getValue( c, _vertexindex ); + OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); + return c.red(); + } + ScalarType G() + { + /// Get coordinates + OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() ); + OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); + OSG::Color3f c; colp->getValue( c, _vertexindex ); + OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); + return c.green(); + } + ScalarType B() + { + /// Get coordinates + OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() ); + OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); + OSG::Color3f c; colp->getValue( c, _vertexindex ); + OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); + return c.blue(); + } +private : + OSG::GeometryPtr _geopointer; + int _vertexindex; +}; + +template< class T > class EmptyOSGColor : public T +{ +public : + typedef OSG::Color3f ColorType; + typedef OSG::Real32 ScalarType; + ColorType & C() { assert(0); return ColorType(); } + static bool HasColor() { return false; } + static void Name( std::vector< std::string > & name ) { T::Name(name); } +}; + +template< class A, class T > class OSGColor : public T +{ +public : + typedef A ColorType; /// Must be a OSG::Color3 type as : OSG::Color3ub, OSG:Color3f etc... + typedef typename ColorType::ValueType ScalarType; /// Can be a OSG basic type as : OSG::UInt8, OSG::Real32 etc... + typedef typename OSGColorCore< ColorType > CoreType; + OSGColor() { _corep = NULL; } + ~OSGColor() { if( _corep != NULL ) delete _corep; } + CoreType & C() + { + CoreType * tmpcorep = _corep; + _corep = new CoreType( Geo(), Index() ); + if( tmpcorep != NULL ) delete tmpcorep; + return *_corep; + } + static bool HasColor() { return true; } + static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGColor" ) ); T::Name(name); } +private : + CoreType * _corep; +}; + +class OSGColorCore3f : public OSGColorCore< OSG::Color3f > {}; + +template< class T > class OSGColor3f : public OSGColor< OSG::Color3f, T > +{ static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGColor3f" ) ); T::Name(name); } }; + + +} /// end namespace vert + +} /// end namespace vcg + + +#endif + +