Updated many importer to do not use anymore the useless, deprecated, removed, etc etc <uber>

This commit is contained in:
Paolo Cignoni 2012-10-25 13:17:47 +00:00
parent 049c996846
commit bc3fd845e1
8 changed files with 430 additions and 449 deletions

View File

@ -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) for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi)
{ {
vp=&(*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( ! vp->IsD() )
{ {
if(binary) if(binary)
{ {
float t; float t;
t = float(vp->UberP()[0]); fwrite(&t,sizeof(float),1,fpout); t = float(vp->P()[0]); fwrite(&t,sizeof(float),1,fpout);
t = float(vp->UberP()[1]); fwrite(&t,sizeof(float),1,fpout); t = float(vp->P()[1]); fwrite(&t,sizeof(float),1,fpout);
t = float(vp->UberP()[2]); fwrite(&t,sizeof(float),1,fpout); t = float(vp->P()[2]); fwrite(&t,sizeof(float),1,fpout);
if( pi.mask & ply::PLYMask::PM_VERTFLAGS ) 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) ) if( HasPerVertexColor(m) && (pi.mask & ply::PLYMask::PM_VERTCOLOR) )
fwrite(&( vp->C() ),sizeof(char),4,fpout); 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]); fprintf(fpout,"%g %g %g " ,vp->P()[0],vp->P()[1],vp->P()[2]);
if( pi.mask & ply::PLYMask::PM_VERTFLAGS ) 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) ) 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] ); 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"); 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++; j++;
} }
} }
@ -407,10 +407,10 @@ static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &
{ fcnt++; { fcnt++;
if(binary) if(binary)
{ {
vv[0]=fp->cV(0)->UberFlags(); vv[0]=fp->cV(0)->Flags();
vv[1]=fp->cV(1)->UberFlags(); vv[1]=fp->cV(1)->Flags();
vv[2]=fp->cV(2)->UberFlags(); vv[2]=fp->cV(2)->Flags();
vv[3]=fp->cV(2)->UberFlags(); vv[3]=fp->cV(2)->Flags();
fwrite(&c,1,1,fpout); fwrite(&c,1,1,fpout);
fwrite(vv,sizeof(int),4,fpout); fwrite(vv,sizeof(int),4,fpout);
@ -484,7 +484,7 @@ static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &
else // ***** ASCII ***** else // ***** ASCII *****
{ {
fprintf(fpout,"3 %d %d %d ", 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 ) if( pi.mask & ply::PLYMask::PM_TETRAFLAGS )
fprintf(fpout,"%d ",fp->Flags()); fprintf(fpout,"%d ",fp->Flags());
@ -563,7 +563,7 @@ static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &
// Recupera i flag originali // Recupera i flag originali
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi)
(*vi).UberFlags()=FlagV[j++]; (*vi).Flags()=FlagV[j++];
return 0; return 0;
} }

View File

@ -244,28 +244,11 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
LoadPly_VertAux<ScalarType> va; LoadPly_VertAux<ScalarType> va;
pi.mask = 0; pi.mask = 0;
bool multit = false; // true if texture has a per face int spec the texture index
va.flags = 42; va.flags = 42;
pi.status = ::vcg::ply::E_NOERROR; 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 // The main descriptor of the ply file
vcg::ply::PlyFile pf; vcg::ply::PlyFile pf;
@ -442,7 +425,6 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
for(j=0;j<n;++j) for(j=0;j<n;++j)
{ {
if(pi.cb && (j%1000)==0) pi.cb(j*50/n,"Vertex Loading"); if(pi.cb && (j%1000)==0) pi.cb(j*50/n,"Vertex Loading");
(*vi).UberFlags()=0;
if( pf.Read( (void *)&(va) )==-1 ) if( pf.Read( (void *)&(va) )==-1 )
{ {
pi.status = PlyInfo::E_SHORTFILE; pi.status = PlyInfo::E_SHORTFILE;
@ -454,7 +436,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
(*vi).P()[2] = va.p[2]; (*vi).P()[2] = va.p[2];
if( pi.mask & ply::PLYMask::PM_VERTFLAGS ) if( pi.mask & ply::PLYMask::PM_VERTFLAGS )
(*vi).UberFlags() = va.flags; (*vi).Flags() = va.flags;
if( pi.mask & ply::PLYMask::PM_VERTQUALITY ) if( pi.mask & ply::PLYMask::PM_VERTQUALITY )
(*vi).Q() = va.q; (*vi).Q() = va.q;
@ -514,7 +496,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
if( pi.mask & ply::PLYMask::PM_TETRAFLAGS ) if( pi.mask & ply::PLYMask::PM_TETRAFLAGS )
{ {
(*fi).UberFlags() = fa.flags; (*fi).Flags() = fa.flags;
} }
if( pi.mask & ply::PLYMask::PM_TETRAQUALITY ) if( pi.mask & ply::PLYMask::PM_TETRAQUALITY )

View File

@ -19,91 +19,91 @@
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. * * for more details. *
* * * *
****************************************************************************/ ****************************************************************************/
#ifndef __VCGLIB_IMPORTERTS #ifndef __VCGLIB_IMPORTERTS
#define __VCGLIB_IMPORTERTS #define __VCGLIB_IMPORTERTS
#define NULL 0 #define NULL 0
#include <vcg/space/point3.h> #include <vcg/space/point3.h>
#include <vcg/space/point4.h> #include <vcg/space/point4.h>
namespace vcg { namespace vcg {
namespace tetra { namespace tetra {
namespace io { namespace io {
template <typename MESHTYPE> template <typename MESHTYPE>
class ImporterTS{ class ImporterTS{
typedef MESHTYPE Tetramesh; typedef MESHTYPE Tetramesh;
typedef typename Tetramesh::VertexPointer VertexPointer; typedef typename Tetramesh::VertexPointer VertexPointer;
typedef typename Tetramesh::VertexType VertexType; typedef typename Tetramesh::VertexType VertexType;
typedef typename Tetramesh::TetraType FaceType; typedef typename Tetramesh::TetraType FaceType;
typedef typename Tetramesh::VertexIterator VertexIterator; typedef typename Tetramesh::VertexIterator VertexIterator;
typedef typename Tetramesh::TetraIterator FaceIterator; typedef typename Tetramesh::TetraIterator FaceIterator;
typedef typename Tetramesh::ScalarType ScalarType; typedef typename Tetramesh::ScalarType ScalarType;
typedef Point3<ScalarType> Point3x; typedef Point3<ScalarType> Point3x;
static FILE *& F(){static FILE * f; return f;} static FILE *& F(){static FILE * f; return f;}
inline static void ReadPos( Point3<double> &p){ inline static void ReadPos( Point3<double> &p){
fscanf(F(),"%lg %lg %lg",&p[0],&p[1],&p[2]); fscanf(F(),"%lg %lg %lg",&p[0],&p[1],&p[2]);
} }
inline static void ReadPos( Point3<float> &p){ inline static void ReadPos( Point3<float> &p){
fscanf(F(),"%f %f %f",&p[0],&p[1],&p[2]); fscanf(F(),"%f %f %f",&p[0],&p[1],&p[2]);
} }
inline static void ReadPos( Point4<ScalarType> &p){ inline static void ReadPos( Point4<ScalarType> &p){
fscanf(F(),"%g %g %g %g",&p[0],&p[1],&p[2],&p[3]); fscanf(F(),"%g %g %g %g",&p[0],&p[1],&p[2],&p[3]);
} }
public: public:
static int Open( Tetramesh & m, const char * filename ) static int Open( Tetramesh & m, const char * filename )
{ {
int nvertex; int nvertex;
int ntetra; int ntetra;
int tp0; int tp0;
int tp1; int tp1;
int tp2; int tp2;
int tp3; int tp3;
typename Tetramesh::VertexType p1; typename Tetramesh::VertexType p1;
F() = fopen(filename,"r"); F() = fopen(filename,"r");
if(F() == NULL ) if(F() == NULL )
{ {
printf( "The file was not opened\n" ); printf( "The file was not opened\n" );
return -1; return -1;
} }
else else
{ {
fscanf(F(), "%i", &nvertex ); fscanf(F(), "%i", &nvertex );
fscanf(F(), "%i", &ntetra ); fscanf(F(), "%i", &ntetra );
m.tetra.reserve(ntetra); m.tetra.reserve(ntetra);
m.vert.reserve(nvertex); m.vert.reserve(nvertex);
int j; int j;
for (j=0;j<nvertex;j++) for (j=0;j<nvertex;j++)
{ {
m.vert.push_back(VertexType()); m.vert.push_back(VertexType());
ReadPos(m.vert.back().P()); ReadPos(m.vert.back().P());
m.vert.back().ClearFlags(); m.vert.back().ClearFlags();
} }
for (j=0;j<ntetra;j++) for (j=0;j<ntetra;j++)
{ {
fscanf(F(), "%i", &tp0 ); fscanf(F(), "%i", &tp0 );
fscanf(F(), "%i", &tp1 ); fscanf(F(), "%i", &tp1 );
fscanf(F(), "%i", &tp2 ); fscanf(F(), "%i", &tp2 );
fscanf(F(), "%i", &tp3 ); fscanf(F(), "%i", &tp3 );
m.tetra.push_back(typename Tetramesh::TetraType()); m.tetra.push_back(typename Tetramesh::TetraType());
m.tetra.back().V(0) = &m.vert[tp0]; m.tetra.back().V(0) = &m.vert[tp0];
m.tetra.back().V(1) = &m.vert[tp1]; m.tetra.back().V(1) = &m.vert[tp1];
m.tetra.back().V(2) = &m.vert[tp2]; m.tetra.back().V(2) = &m.vert[tp2];
m.tetra.back().V(3) = &m.vert[tp3]; m.tetra.back().V(3) = &m.vert[tp3];
m.tetra.back().UberFlags() = 0; m.tetra.back().Flags() = 0;
} }
} }
m.vn = nvertex; m.vn = nvertex;
m.tn = ntetra; m.tn = ntetra;
return 0; return 0;
} }
};// end class };// end class
};// end of io }// end of io
};// end of tetra }// end of tetra
};// end of vcg }// end of vcg
#endif #endif

View File

@ -69,10 +69,10 @@ namespace vcg {
for(j=0,vi=m.vert.begin(); vi!=m.vert.end(); ++vi) for(j=0,vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
{ {
vp = &(*vi); vp = &(*vi);
FlagV.push_back(vp->UberFlags()); FlagV.push_back(vp->Flags());
if (!vp->IsD()) if (!vp->IsD())
{ {
vp->UberFlags() = j; vp->Flags() = j;
j++; j++;
} }
} }
@ -94,8 +94,8 @@ namespace vcg {
{ {
for (int k=0; k<3; ++k) for (int k=0; k<3; ++k)
{ {
int a = fp->cV(k)->UberFlags(); int a = fp->cV(k)->Flags();
int b = fp->cV((k+1)%3)->UberFlags(); int b = fp->cV((k+1)%3)->Flags();
if (a>b) if (a>b)
std::swap(a,b); std::swap(a,b);
Edge e(a,b); Edge e(a,b);
@ -132,8 +132,8 @@ namespace vcg {
{ {
for (int k=0; k<3; ++k) for (int k=0; k<3; ++k)
{ {
int a = fp->cV(k)->UberFlags(); int a = fp->cV(k)->Flags();
int b = fp->cV((k+1)%3)->UberFlags(); int b = fp->cV((k+1)%3)->Flags();
if (a>b) if (a>b)
std::swap(a,b); std::swap(a,b);
Edge e(a,b); Edge e(a,b);
@ -154,8 +154,8 @@ namespace vcg {
{ {
for (int k=0; k<3; ++k) for (int k=0; k<3; ++k)
{ {
int a = fp->cV(k)->UberFlags(); int a = fp->cV(k)->Flags();
int b = fp->cV((k+1)%3)->UberFlags(); int b = fp->cV((k+1)%3)->Flags();
if (a>b) if (a>b)
std::swap(a,b); std::swap(a,b);
Edge e(a,b); Edge e(a,b);
@ -171,7 +171,7 @@ namespace vcg {
// Recupera i flag originali // Recupera i flag originali
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi)
(*vi).UberFlags()=FlagV[j++]; (*vi).Flags()=FlagV[j++];
return 0; return 0;
} }

View File

@ -85,7 +85,7 @@ namespace vcg {
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi)
{ {
vp=&(*vi); vp=&(*vi);
FlagV.push_back(vp->UberFlags()); // Save vertex flags FlagV.push_back(vp->Flags()); // Save vertex flags
if( ! vp->IsD() ) if( ! vp->IsD() )
{ // ***** ASCII ***** { // ***** ASCII *****
@ -102,7 +102,7 @@ namespace vcg {
fprintf(fpout,"\n"); 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++; j++;
} }
} }
@ -119,7 +119,7 @@ namespace vcg {
if(!polygon.empty()) if(!polygon.empty())
{ {
fprintf(fpout,"%d ", int(polygon.size()) ); fprintf(fpout,"%d ", int(polygon.size()) );
for (size_t i=0; i<polygon.size(); i++) fprintf(fpout,"%d ", polygon[i]->UberFlags() ); for (size_t i=0; i<polygon.size(); i++) fprintf(fpout,"%d ", polygon[i]->Flags() );
fprintf(fpout,"\n"); fprintf(fpout,"\n");
} }
} }
@ -130,7 +130,7 @@ namespace vcg {
FacePointer fp=&(*fi); FacePointer fp=&(*fi);
if( ! fp->IsD() ) if( ! fp->IsD() )
{ fprintf(fpout,"3 %d %d %d\n", { 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 // Recupera i flag originali
j=0; j=0;
for(vi=m.vert.begin();vi!=m.vert.end();++vi) for(vi=m.vert.begin();vi!=m.vert.end();++vi)
(*vi).UberFlags()=FlagV[j++]; (*vi).Flags()=FlagV[j++];
return 0; return 0;
} }

View File

@ -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); t = float(vp->N()[2]); fwrite(&t,sizeof(float),1,fpout);
} }
if( HasPerVertexFlags(m) && (pi.mask & Mask::IOM_VERTFLAGS) ) 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) ) if( HasPerVertexColor(m) && (pi.mask & Mask::IOM_VERTCOLOR) )
fwrite(&( vp->C() ),sizeof(char),4,fpout); 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])); 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)) 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) ) 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] ); fprintf(fpout,"%d %d %d %d ",vp->C()[0],vp->C()[1],vp->C()[2],vp->C()[3] );

View File

@ -640,7 +640,6 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
for(j=0;j<n;++j) for(j=0;j<n;++j)
{ {
if(pi.cb && (j%1000)==0) pi.cb(j*50/n,"Vertex Loading"); if(pi.cb && (j%1000)==0) pi.cb(j*50/n,"Vertex Loading");
//(*vi).UberFlags()=0; // No more necessary, since 9/2005 flags are set to zero in the constuctor.
if( pf.Read( (void *)&(va) )==-1 ) if( pf.Read( (void *)&(va) )==-1 )
{ {
pi.status = PlyInfo::E_SHORTFILE; pi.status = PlyInfo::E_SHORTFILE;
@ -652,7 +651,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
(*vi).P()[2] = va.p[2]; (*vi).P()[2] = va.p[2];
if( HasPerVertexFlags(m) && (pi.mask & Mask::IOM_VERTFLAGS) ) if( HasPerVertexFlags(m) && (pi.mask & Mask::IOM_VERTFLAGS) )
(*vi).UberFlags() = va.flags; (*vi).Flags() = va.flags;
if( pi.mask & Mask::IOM_VERTQUALITY ) if( pi.mask & Mask::IOM_VERTQUALITY )
(*vi).Q() = (typename OpenMeshType::VertexType::QualityType)va.q; (*vi).Q() = (typename OpenMeshType::VertexType::QualityType)va.q;
@ -750,7 +749,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
if(HasPerFaceFlags(m) &&( pi.mask & Mask::IOM_FACEFLAGS) ) if(HasPerFaceFlags(m) &&( pi.mask & Mask::IOM_FACEFLAGS) )
{ {
(*fi).UberFlags() = fa.flags; (*fi).Flags() = fa.flags;
} }
if( pi.mask & Mask::IOM_FACEQUALITY ) if( pi.mask & Mask::IOM_FACEQUALITY )

View File

@ -19,312 +19,312 @@
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. * * for more details. *
* * * *
****************************************************************************/ ****************************************************************************/
#ifndef __VCG_OSG_VERTEX_PLUS_COMPONENT #ifndef __VCG_OSG_VERTEX_PLUS_COMPONENT
#define __VCG_OSG_VERTEX_PLUS_COMPONENT #define __VCG_OSG_VERTEX_PLUS_COMPONENT
#include <vector> #include <vector>
#include <vcg/space/point3.h> #include <vcg/space/point3.h>
#include <vcg/space/texcoord2.h> #include <vcg/space/texcoord2.h>
#include <vcg/space/color4.h> #include <vcg/space/color4.h>
#include <opensg/osggeometry.h> #include <opensg/osggeometry.h>
namespace vcg { namespace vcg {
namespace vert { namespace vert {
/// Some Naming Rules : All the Components that can be added to a vertex should be defined in the namespace vert: /// Some Naming Rules : All the Components that can be added to a vertex should be defined in the namespace vert:
/// ------------------------- OPENSGINFO ----------------------------------------- /// ------------------------- OPENSGINFO -----------------------------------------
template< class T > class EmptyOSGInfo : public T { public : OSG::GeometryPtr Geo() { assert(0); return NULL; } }; template< class T > class EmptyOSGInfo : public T { public : OSG::GeometryPtr Geo() { assert(0); return NULL; } };
template< class T > class OSGInfo : public T template< class T > class OSGInfo : public T
{ {
public : public :
OSG::GeometryPtr & Geo() { return _geop; } OSG::GeometryPtr & Geo() { return _geop; }
int & Index() { return _vertexi; } int & Index() { return _vertexi; }
private : 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 ... !!! 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 int _vertexi; /// OSG vertex index
}; };
/// ------------------------- COORD ----------------------------------------- /// ------------------------- COORD -----------------------------------------
/// Core for the coordinate component templated with the coordinate type of the component /// Core for the coordinate component templated with the coordinate type of the component
template< class T > class OSGCoordCore template< class T > class OSGCoordCore
{ {
public : public :
typedef T CoordType; typedef T CoordType;
typedef typename CoordType::ValueType ScalarType; typedef typename CoordType::ValueType ScalarType;
OSGCoordCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; } OSGCoordCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; }
~OSGCoordCore() { _vertexindex = -1; } ~OSGCoordCore() { _vertexindex = -1; }
CoordType & operator=( CoordType & p2 ) CoordType & operator=( CoordType & p2 )
{ {
/// Set coordinates /// Set coordinates
OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() ); OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() );
OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
pos->setValue( p2, _vertexindex ); pos->setValue( p2, _vertexindex );
OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
return p2; /// Warning : instead of returning the left side operand we return the right one !!! return p2; /// Warning : instead of returning the left side operand we return the right one !!!
} }
ScalarType X() ScalarType X()
{ {
/// Get coordinates /// Get coordinates
OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() ); OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() );
OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
OSG::Pnt3f p; pos->getValue( p, _vertexindex ); OSG::Pnt3f p; pos->getValue( p, _vertexindex );
OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
return p.x(); return p.x();
} }
ScalarType Y() ScalarType Y()
{ {
/// Get coordinates /// Get coordinates
OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() ); OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() );
OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
OSG::Pnt3f p; pos->getValue( p, _vertexindex ); OSG::Pnt3f p; pos->getValue( p, _vertexindex );
OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
return p.y(); return p.y();
} }
ScalarType Z() ScalarType Z()
{ {
/// Get coordinates /// Get coordinates
OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() ); OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() );
OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
OSG::Pnt3f p; pos->getValue( p, _vertexindex ); OSG::Pnt3f p; pos->getValue( p, _vertexindex );
OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask ); OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
return p.z(); return p.z();
} }
private : private :
OSG::GeometryPtr _geopointer; OSG::GeometryPtr _geopointer;
int _vertexindex; int _vertexindex;
}; };
template< class T > class EmptyOSGCoord : public T template< class T > class EmptyOSGCoord : public T
{ {
public : public :
typedef OSG::Pnt3f CoordType; typedef OSG::Pnt3f CoordType;
typedef OSG::Real32 ScalarType; typedef OSG::Real32 ScalarType;
CoordType & P() { assert(0); return CoordType(); } CoordType & P() { assert(0); return CoordType(); }
const CoordType & P() const { assert(0); return CoordType(); } const CoordType & P() const { assert(0); return CoordType(); }
const CoordType & cP() const { assert(0); return CoordType(); } const CoordType & cP() const { assert(0); return CoordType(); }
CoordType & UberP() { assert(0); return CoordType(); } CoordType & P() { assert(0); return CoordType(); }
static bool HasCoord() { return false; } static bool HasCoord() { return false; }
static void Name( std::vector< std::string > & name ) { T::Name(name); } static void Name( std::vector< std::string > & name ) { T::Name(name); }
}; };
template< class A, class T > class OSGCoord : public T template< class A, class T > class OSGCoord : public T
{ {
public : public :
typedef A CoordType; /// Must be a OSG::Pnt3 type as : OSG::Pnt3s, OSG:Pnt3f, OSG::Pnt3d etc... 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 CoordType::ValueType ScalarType; /// Can be a OSG basic type as : OSG::Int16, OSG::Real32, OSG::Real64 etc...
typedef typename OSGCoordCore< CoordType > CoreType; typedef typename OSGCoordCore< CoordType > CoreType;
OSGCoord() { _corep = NULL; } OSGCoord() { _corep = NULL; }
~OSGCoord() { if( _corep != NULL ) delete _corep; } ~OSGCoord() { if( _corep != NULL ) delete _corep; }
CoreType & P() CoreType & P()
{ {
CoreType * tmpcorep = _corep; CoreType * tmpcorep = _corep;
_corep = new CoreType( Geo(), Index() ); _corep = new CoreType( Geo(), Index() );
if( tmpcorep != NULL ) delete tmpcorep; if( tmpcorep != NULL ) delete tmpcorep;
return *_corep; return *_corep;
} }
static bool HasCoord() { return true; } static bool HasCoord() { return true; }
static void Name( std::vector< std::string > & name ) { name.push_back( std::string("OSGCoord") ); T::Name(name); } static void Name( std::vector< std::string > & name ) { name.push_back( std::string("OSGCoord") ); T::Name(name); }
private : private :
CoreType * _corep; CoreType * _corep;
}; };
class OSGCoordCore3f : public OSGCoordCore< OSG::Pnt3f > {}; class OSGCoordCore3f : public OSGCoordCore< OSG::Pnt3f > {};
template< class T > class OSGCoord3f : public OSGCoord< OSG::Pnt3f, T > 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); } }; { public : static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGCoord3f" ) ); T::Name(name); } };
/// -------------------------- NORMAL ---------------------------------------- /// -------------------------- NORMAL ----------------------------------------
template< class T > class OSGNormalCore template< class T > class OSGNormalCore
{ {
public : public :
typedef T NormalType; typedef T NormalType;
typedef typename NormalType::ValueType ScalarType; typedef typename NormalType::ValueType ScalarType;
OSGNormalCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; } OSGNormalCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; }
~OSGNormalCore() { _vertexindex = -1; } ~OSGNormalCore() { _vertexindex = -1; }
NormalType & operator=( NormalType & n2 ) NormalType & operator=( NormalType & n2 )
{ {
/// Set coordinates /// Set coordinates
OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() ); OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() );
OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
norm->setValue( n2, _vertexindex ); norm->setValue( n2, _vertexindex );
OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
return n2; /// Warning : instead of returning the left side operand we return the right one !!! return n2; /// Warning : instead of returning the left side operand we return the right one !!!
} }
ScalarType X() ScalarType X()
{ {
/// Get coordinates /// Get coordinates
OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() ); OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() );
OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
OSG::Vec3f n; norm->getValue( n, _vertexindex ); OSG::Vec3f n; norm->getValue( n, _vertexindex );
OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
return n.x(); return n.x();
} }
ScalarType Y() ScalarType Y()
{ {
/// Get coordinates /// Get coordinates
OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() ); OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() );
OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
OSG::Vec3f n; norm->getValue( n, _vertexindex ); OSG::Vec3f n; norm->getValue( n, _vertexindex );
OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
return n.y(); return n.y();
} }
ScalarType Z() ScalarType Z()
{ {
/// Get coordinates /// Get coordinates
OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() ); OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() );
OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
OSG::Vec3f n; norm->getValue( n, _vertexindex ); OSG::Vec3f n; norm->getValue( n, _vertexindex );
OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask ); OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
return n.z(); return n.z();
} }
private : private :
OSG::GeometryPtr _geopointer; OSG::GeometryPtr _geopointer;
int _vertexindex; int _vertexindex;
}; };
template< class T > class EmptyOSGNormal : public T template< class T > class EmptyOSGNormal : public T
{ {
public : public :
typedef OSG::Vec3f NormalType; typedef OSG::Vec3f NormalType;
typedef OSG::Real32 ScalarType; typedef OSG::Real32 ScalarType;
NormalType & N() { assert(0); return NormalType(); } NormalType & N() { assert(0); return NormalType(); }
const NormalType cN()const { assert(0); return NormalType(); } const NormalType cN()const { assert(0); return NormalType(); }
static bool HasNormal() { return false; } static bool HasNormal() { return false; }
static bool HasNormalOcc() { return false; } static bool HasNormalOcc() { return false; }
static void Name( std::vector< std::string > & name ) { T::Name(name); } static void Name( std::vector< std::string > & name ) { T::Name(name); }
}; };
template< class A, class T > class OSGNormal : public T template< class A, class T > class OSGNormal : public T
{ {
public : public :
typedef A NormalType; /// Must be a OSG::Vec3 type as : OSG::Vec3s, OSG:Vec3f, OSG::Vec3d etc... 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 NormalType::ValueType ScalarType; /// Can be a OSG basic type as : OSG::Int16, OSG::Real32, OSG::Real64 etc...
typedef typename OSGNormalCore< NormalType > CoreType; typedef typename OSGNormalCore< NormalType > CoreType;
OSGNormal() { _corep = NULL; } OSGNormal() { _corep = NULL; }
~OSGNormal() { if( _corep == NULL ) delete _corep; } ~OSGNormal() { if( _corep == NULL ) delete _corep; }
CoreType & N() CoreType & N()
{ {
CoreType * tmpcorep = _corep; CoreType * tmpcorep = _corep;
_corep = new CoreType( Geo(), Index() ); _corep = new CoreType( Geo(), Index() );
if( tmpcorep == NULL ) delete tmpcorep; if( tmpcorep == NULL ) delete tmpcorep;
return *_corep; return *_corep;
} }
static bool HasNormal() { return true; } static bool HasNormal() { return true; }
static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGNormal" ) );T::Name(name); } static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGNormal" ) );T::Name(name); }
private : private :
CoreType * _corep; CoreType * _corep;
}; };
class OSGNormalCore3f : public OSGNormalCore< OSG::Vec3f > {}; class OSGNormalCore3f : public OSGNormalCore< OSG::Vec3f > {};
template< class T > class OSGNormal3f : public OSGNormal< OSG::Vec3f, T > 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); } }; { public : static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGNormal3f" ) ); T::Name(name); } };
/// -------------------------- COLOR ---------------------------------- /// -------------------------- COLOR ----------------------------------
template< class T > class OSGColorCore template< class T > class OSGColorCore
{ {
public : public :
typedef T ColorType; typedef T ColorType;
typedef typename ColorType::ValueType ScalarType; typedef typename ColorType::ValueType ScalarType;
OSGColorCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; } OSGColorCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; }
~OSGColorCore() { _vertexindex = -1; } ~OSGColorCore() { _vertexindex = -1; }
ColorType & operator=( ColorType & c2 ) ColorType & operator=( ColorType & c2 )
{ {
/// Set color /// Set color
OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() ); OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() );
OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
colp->setValue( c2, _vertexindex ); colp->setValue( c2, _vertexindex );
OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
return c2; /// Warning : instead of returning the left side operand we return the right one !!! return c2; /// Warning : instead of returning the left side operand we return the right one !!!
} }
ScalarType R() ScalarType R()
{ {
/// Get coordinates /// Get coordinates
OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() ); OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() );
OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
OSG::Color3f c; colp->getValue( c, _vertexindex ); OSG::Color3f c; colp->getValue( c, _vertexindex );
OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
return c.red(); return c.red();
} }
ScalarType G() ScalarType G()
{ {
/// Get coordinates /// Get coordinates
OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() ); OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() );
OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
OSG::Color3f c; colp->getValue( c, _vertexindex ); OSG::Color3f c; colp->getValue( c, _vertexindex );
OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
return c.green(); return c.green();
} }
ScalarType B() ScalarType B()
{ {
/// Get coordinates /// Get coordinates
OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() ); OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() );
OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
OSG::Color3f c; colp->getValue( c, _vertexindex ); OSG::Color3f c; colp->getValue( c, _vertexindex );
OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask ); OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
return c.blue(); return c.blue();
} }
private : private :
OSG::GeometryPtr _geopointer; OSG::GeometryPtr _geopointer;
int _vertexindex; int _vertexindex;
}; };
template< class T > class EmptyOSGColor : public T template< class T > class EmptyOSGColor : public T
{ {
public : public :
typedef OSG::Color3f ColorType; typedef OSG::Color3f ColorType;
typedef OSG::Real32 ScalarType; typedef OSG::Real32 ScalarType;
ColorType & C() { assert(0); return ColorType(); } ColorType & C() { assert(0); return ColorType(); }
static bool HasColor() { return false; } static bool HasColor() { return false; }
static void Name( std::vector< std::string > & name ) { T::Name(name); } static void Name( std::vector< std::string > & name ) { T::Name(name); }
}; };
template< class A, class T > class OSGColor : public T template< class A, class T > class OSGColor : public T
{ {
public : public :
typedef A ColorType; /// Must be a OSG::Color3 type as : OSG::Color3ub, OSG:Color3f etc... 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 ColorType::ValueType ScalarType; /// Can be a OSG basic type as : OSG::UInt8, OSG::Real32 etc...
typedef typename OSGColorCore< ColorType > CoreType; typedef typename OSGColorCore< ColorType > CoreType;
OSGColor() { _corep = NULL; } OSGColor() { _corep = NULL; }
~OSGColor() { if( _corep != NULL ) delete _corep; } ~OSGColor() { if( _corep != NULL ) delete _corep; }
CoreType & C() CoreType & C()
{ {
CoreType * tmpcorep = _corep; CoreType * tmpcorep = _corep;
_corep = new CoreType( Geo(), Index() ); _corep = new CoreType( Geo(), Index() );
if( tmpcorep != NULL ) delete tmpcorep; if( tmpcorep != NULL ) delete tmpcorep;
return *_corep; return *_corep;
} }
static bool HasColor() { return true; } static bool HasColor() { return true; }
static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGColor" ) ); T::Name(name); } static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGColor" ) ); T::Name(name); }
private : private :
CoreType * _corep; CoreType * _corep;
}; };
class OSGColorCore3f : public OSGColorCore< OSG::Color3f > {}; class OSGColorCore3f : public OSGColorCore< OSG::Color3f > {};
template< class T > class OSGColor3f : public OSGColor< OSG::Color3f, T > 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); } }; { static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGColor3f" ) ); T::Name(name); } };
} /// end namespace vert } /// end namespace vert
} /// end namespace vcg } /// end namespace vcg
#endif #endif