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)
{
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;
}

View File

@ -244,28 +244,11 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
LoadPly_VertAux<ScalarType> 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<n;++j)
{
if(pi.cb && (j%1000)==0) pi.cb(j*50/n,"Vertex Loading");
(*vi).UberFlags()=0;
if( pf.Read( (void *)&(va) )==-1 )
{
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];
if( pi.mask & ply::PLYMask::PM_VERTFLAGS )
(*vi).UberFlags() = va.flags;
(*vi).Flags() = va.flags;
if( pi.mask & ply::PLYMask::PM_VERTQUALITY )
(*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 )
{
(*fi).UberFlags() = fa.flags;
(*fi).Flags() = fa.flags;
}
if( pi.mask & ply::PLYMask::PM_TETRAQUALITY )

View File

@ -19,91 +19,91 @@
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#ifndef __VCGLIB_IMPORTERTS
#define __VCGLIB_IMPORTERTS
#define NULL 0
#include <vcg/space/point3.h>
#include <vcg/space/point4.h>
namespace vcg {
namespace tetra {
namespace io {
template <typename MESHTYPE>
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<ScalarType> Point3x;
static FILE *& F(){static FILE * f; return f;}
inline static void ReadPos( Point3<double> &p){
fscanf(F(),"%lg %lg %lg",&p[0],&p[1],&p[2]);
}
inline static void ReadPos( Point3<float> &p){
fscanf(F(),"%f %f %f",&p[0],&p[1],&p[2]);
}
inline static void ReadPos( Point4<ScalarType> &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<nvertex;j++)
{
m.vert.push_back(VertexType());
ReadPos(m.vert.back().P());
m.vert.back().ClearFlags();
}
for (j=0;j<ntetra;j++)
{
fscanf(F(), "%i", &tp0 );
fscanf(F(), "%i", &tp1 );
fscanf(F(), "%i", &tp2 );
fscanf(F(), "%i", &tp3 );
m.tetra.push_back(typename Tetramesh::TetraType());
m.tetra.back().V(0) = &m.vert[tp0];
m.tetra.back().V(1) = &m.vert[tp1];
m.tetra.back().V(2) = &m.vert[tp2];
m.tetra.back().V(3) = &m.vert[tp3];
m.tetra.back().UberFlags() = 0;
}
}
m.vn = nvertex;
m.tn = ntetra;
return 0;
}
};// end class
};// end of io
};// end of tetra
};// end of vcg
#endif
****************************************************************************/
#ifndef __VCGLIB_IMPORTERTS
#define __VCGLIB_IMPORTERTS
#define NULL 0
#include <vcg/space/point3.h>
#include <vcg/space/point4.h>
namespace vcg {
namespace tetra {
namespace io {
template <typename MESHTYPE>
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<ScalarType> Point3x;
static FILE *& F(){static FILE * f; return f;}
inline static void ReadPos( Point3<double> &p){
fscanf(F(),"%lg %lg %lg",&p[0],&p[1],&p[2]);
}
inline static void ReadPos( Point3<float> &p){
fscanf(F(),"%f %f %f",&p[0],&p[1],&p[2]);
}
inline static void ReadPos( Point4<ScalarType> &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<nvertex;j++)
{
m.vert.push_back(VertexType());
ReadPos(m.vert.back().P());
m.vert.back().ClearFlags();
}
for (j=0;j<ntetra;j++)
{
fscanf(F(), "%i", &tp0 );
fscanf(F(), "%i", &tp1 );
fscanf(F(), "%i", &tp2 );
fscanf(F(), "%i", &tp3 );
m.tetra.push_back(typename Tetramesh::TetraType());
m.tetra.back().V(0) = &m.vert[tp0];
m.tetra.back().V(1) = &m.vert[tp1];
m.tetra.back().V(2) = &m.vert[tp2];
m.tetra.back().V(3) = &m.vert[tp3];
m.tetra.back().Flags() = 0;
}
}
m.vn = nvertex;
m.tn = ntetra;
return 0;
}
};// end class
}// end of io
}// end of tetra
}// end of vcg
#endif

View File

@ -69,10 +69,10 @@ namespace vcg {
for(j=0,vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
{
vp = &(*vi);
FlagV.push_back(vp->UberFlags());
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;
}

View File

@ -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; 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");
}
}
@ -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;
}

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);
}
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] );

View File

@ -640,7 +640,6 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
for(j=0;j<n;++j)
{
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 )
{
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];
if( HasPerVertexFlags(m) && (pi.mask & Mask::IOM_VERTFLAGS) )
(*vi).UberFlags() = va.flags;
(*vi).Flags() = va.flags;
if( pi.mask & Mask::IOM_VERTQUALITY )
(*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) )
{
(*fi).UberFlags() = fa.flags;
(*fi).Flags() = fa.flags;
}
if( pi.mask & Mask::IOM_FACEQUALITY )

View File

@ -19,312 +19,312 @@
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#ifndef __VCG_OSG_VERTEX_PLUS_COMPONENT
#define __VCG_OSG_VERTEX_PLUS_COMPONENT
#include <vector>
#include <vcg/space/point3.h>
#include <vcg/space/texcoord2.h>
#include <vcg/space/color4.h>
#include <opensg/osggeometry.h>
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 <vector>
#include <vcg/space/point3.h>
#include <vcg/space/texcoord2.h>
#include <vcg/space/color4.h>
#include <opensg/osggeometry.h>
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