Many small changes to remove useless annoying warnings.

This commit is contained in:
Paolo Cignoni 2014-02-13 15:52:17 +00:00
parent 15bec03c89
commit 6efdd91ecc
6 changed files with 674 additions and 687 deletions

View File

@ -230,7 +230,8 @@ static ScalarType EdgeLenghtVariationIfVertexRotated(const FaceType &f, int w0)
pi = pf->cFFi( pi );
pi = (pi+1)%3; // FaceType::Next( pf->FFi( pi ) );
pf = t;
assert(guard++<100);
guard++;
assert(guard<100);
} while (pf != &f);
assert (na == n);
return (after-before);
@ -251,8 +252,6 @@ static ScalarType QuadQualityVariationIfVertexRotated(const FaceType &f, int w0)
// rotate arond vertex
const FaceType* pf = &f;
int pi = w0;
int nb = 0; // vertex valency
int na = 0;
std::vector<const VertexType *> s; // 1 star around v
do {
// ScalarType triEdge = (pf->P0(pi) - pf->P1(pi) ).Norm();
@ -272,7 +271,8 @@ static ScalarType QuadQualityVariationIfVertexRotated(const FaceType &f, int w0)
pi = pf->cFFi( pi );
pi = (pi+1)%3; // FaceType::Next( pf->FFi( pi ) );
pf = t;
assert(guard++<100);
guard++;
assert(guard<100);
} while (pf != &f);
assert(s.size()%2==0);
@ -285,7 +285,6 @@ static ScalarType QuadQualityVariationIfVertexRotated(const FaceType &f, int w0)
after+=quadQuality( s[h]->P(),s[i]->P(),s[j]->P(),f.P(w0) );
}
assert (na == nb);
return (after-before);
}
@ -595,7 +594,8 @@ static bool IsDoubletFF(const FaceType& f, int wedge){
pi = pf->cFFi( pi );
pi = (pi+1)%3; // FaceType::Next( pf->FFi( pi ) );
pf = t;
assert(guard++<100);
guard++;
assert(guard<100);
} while (pf != &f);
return (res == 2);
}
@ -631,7 +631,8 @@ static bool IsSingletFF(const FaceType& f, int wedge){
pi = pf->cFFi( pi );
pi = (pi+1)%3; // FaceType::Next( pf->FFi( pi ) );
pf = t;
assert(guard++<100);
guard++;
assert(guard<100);
} while (pf != &f);
return (res == 1);
}

View File

@ -113,38 +113,38 @@ public:
static void FillEdgeVector(MeshType &m, std::vector<PEdge> &e, bool includeFauxEdge=true)
{
FaceIterator pf;
typename std::vector<PEdge>::iterator p;
FaceIterator pf;
typename std::vector<PEdge>::iterator p;
// Alloco il vettore ausiliario
//e.resize(m.fn*3);
FaceIterator fi;
int n_edges = 0;
for(fi = m.face.begin(); fi != m.face.end(); ++fi) if(! (*fi).IsD()) n_edges+=(*fi).VN();
e.resize(n_edges);
// Alloco il vettore ausiliario
//e.resize(m.fn*3);
FaceIterator fi;
int n_edges = 0;
for(fi = m.face.begin(); fi != m.face.end(); ++fi) if(! (*fi).IsD()) n_edges+=(*fi).VN();
e.resize(n_edges);
p = e.begin();
for(pf=m.face.begin();pf!=m.face.end();++pf)
if( ! (*pf).IsD() )
for(int j=0;j<(*pf).VN();++j)
if(includeFauxEdge || !(*pf).IsF(j))
{
(*p).Set(&(*pf),j);
++p;
}
p = e.begin();
for(pf=m.face.begin();pf!=m.face.end();++pf)
if( ! (*pf).IsD() )
for(int j=0;j<(*pf).VN();++j)
if(includeFauxEdge || !(*pf).IsF(j))
{
(*p).Set(&(*pf),j);
++p;
}
if(includeFauxEdge) assert(p==e.end());
else e.resize(p-e.begin());
if(includeFauxEdge) assert(p==e.end());
else e.resize(p-e.begin());
}
static void FillUniqueEdgeVector(MeshType &m, std::vector<PEdge> &Edges, bool includeFauxEdge=true)
{
FillEdgeVector(m,Edges,includeFauxEdge);
sort(Edges.begin(), Edges.end()); // Lo ordino per vertici
FillEdgeVector(m,Edges,includeFauxEdge);
sort(Edges.begin(), Edges.end()); // Lo ordino per vertici
typename std::vector< PEdge>::iterator newEnd = std::unique(Edges.begin(), Edges.end());
typename std::vector< PEdge>::iterator newEnd = std::unique(Edges.begin(), Edges.end());
Edges.resize(newEnd-Edges.begin());
Edges.resize(newEnd-Edges.begin());
}
/*! \brief Initialize the edge vector all the edges that can be inferred from current face vector, setting up all the current adjacency relations
@ -365,57 +365,57 @@ static void FaceFaceFromTexCoord(MeshType &m)
if( m.fn == 0 ) return;
// e.resize(m.fn*3); // Alloco il vettore ausiliario
FaceIterator fi;
int n_edges = 0;
for(fi = m.face.begin(); fi != m.face.end(); ++fi) if(! (*fi).IsD()) n_edges+=(*fi).VN();
e.resize(n_edges);
FaceIterator fi;
int n_edges = 0;
for(fi = m.face.begin(); fi != m.face.end(); ++fi) if(! (*fi).IsD()) n_edges+=(*fi).VN();
e.resize(n_edges);
p = e.begin();
for(pf=m.face.begin();pf!=m.face.end();++pf) // Lo riempio con i dati delle facce
if( ! (*pf).IsD() )
for(int j=0;j<(*pf).VN();++j)
{
if( (*pf).WT(j) != (*pf).WT((*pf).Next(j)))
{
(*p).Set(&(*pf),j);
++p;
}
}
p = e.begin();
for(pf=m.face.begin();pf!=m.face.end();++pf) // Lo riempio con i dati delle facce
if( ! (*pf).IsD() )
for(int j=0;j<(*pf).VN();++j)
{
if( (*pf).WT(j) != (*pf).WT((*pf).Next(j)))
{
(*p).Set(&(*pf),j);
++p;
}
}
e.resize(p-e.begin()); // remove from the end of the edge vector the unitiailized ones
//assert(p==e.end()); // this formulation of the assert argument is not really correct, will crash on visual studio
sort(e.begin(), e.end());
e.resize(p-e.begin()); // remove from the end of the edge vector the unitiailized ones
//assert(p==e.end()); // this formulation of the assert argument is not really correct, will crash on visual studio
sort(e.begin(), e.end());
int ne = 0; // number of real edges
typename std::vector<PEdgeTex>::iterator pe,ps;
ps = e.begin();pe=e.begin();
//for(ps = e.begin(),pe=e.begin();pe<=e.end();++pe) // Scansione vettore ausiliario
do
{
if( pe==e.end() || (*pe) != (*ps) ) // Trovo blocco di edge uguali
{
typename std::vector<PEdgeTex>::iterator q,q_next;
for (q=ps;q<pe-1;++q) // Scansione facce associate
{
assert((*q).z>=0);
assert((*q).z< 3);
q_next = q;
++q_next;
assert((*q_next).z>=0);
assert((*q_next).z< (*q_next).f->VN());
(*q).f->FFp(q->z) = (*q_next).f; // Collegamento in lista delle facce
(*q).f->FFi(q->z) = (*q_next).z;
}
assert((*q).z>=0);
assert((*q).z< (*q).f->VN());
(*q).f->FFp((*q).z) = ps->f;
(*q).f->FFi((*q).z) = ps->z;
ps = pe;
++ne; // Aggiorno il numero di edge
}
if(pe==e.end()) break;
++pe;
} while(true);
int ne = 0; // number of real edges
typename std::vector<PEdgeTex>::iterator pe,ps;
ps = e.begin();pe=e.begin();
//for(ps = e.begin(),pe=e.begin();pe<=e.end();++pe) // Scansione vettore ausiliario
do
{
if( pe==e.end() || (*pe) != (*ps) ) // Trovo blocco di edge uguali
{
typename std::vector<PEdgeTex>::iterator q,q_next;
for (q=ps;q<pe-1;++q) // Scansione facce associate
{
assert((*q).z>=0);
assert((*q).z< 3);
q_next = q;
++q_next;
assert((*q_next).z>=0);
assert((*q_next).z< (*q_next).f->VN());
(*q).f->FFp(q->z) = (*q_next).f; // Collegamento in lista delle facce
(*q).f->FFi(q->z) = (*q_next).z;
}
assert((*q).z>=0);
assert((*q).z< (*q).f->VN());
(*q).f->FFp((*q).z) = ps->f;
(*q).f->FFi((*q).z) = ps->z;
ps = pe;
++ne; // Aggiorno il numero di edge
}
if(pe==e.end()) break;
++pe;
} while(true);
}
@ -429,42 +429,40 @@ static void TestVertexFace(MeshType &m)
assert(tri::HasPerVertexVFAdjacency(m));
FaceIterator fi;
for(fi=m.face.begin();fi!=m.face.end();++fi)
{
if (!(*fi).IsD())
{
numVertex[(*fi).V0(0)]++;
numVertex[(*fi).V1(0)]++;
numVertex[(*fi).V2(0)]++;
}
}
FaceIterator fi;
for(fi=m.face.begin();fi!=m.face.end();++fi)
{
if (!(*fi).IsD())
{
numVertex[(*fi).V0(0)]++;
numVertex[(*fi).V1(0)]++;
numVertex[(*fi).V2(0)]++;
}
}
VertexIterator vi;
vcg::face::VFIterator<FaceType> VFi;
VertexIterator vi;
vcg::face::VFIterator<FaceType> VFi;
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
{
if (!vi->IsD())
if(vi->VFp()!=0) // unreferenced vertices MUST have VF == 0;
{
int num=0;
assert(vi->VFp() >= &*m.face.begin());
assert(vi->VFp() <= &m.face.back());
VFi.f=vi->VFp();
VFi.z=vi->VFi();
while (!VFi.End())
{
num++;
assert(!VFi.F()->IsD());
assert((VFi.F()->V(VFi.I()))==&(*vi));
++VFi;
}
int num1=numVertex[&(*vi)];
assert(num==num1);
/*assert(num>1);*/
}
}
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
{
if (!vi->IsD())
if(vi->VFp()!=0) // unreferenced vertices MUST have VF == 0;
{
int num=0;
assert(vi->VFp() >= &*m.face.begin());
assert(vi->VFp() <= &m.face.back());
VFi.f=vi->VFp();
VFi.z=vi->VFi();
while (!VFi.End())
{
num++;
assert(!VFi.F()->IsD());
assert((VFi.F()->V(VFi.I()))==&(*vi));
++VFi;
}
assert(num==numVertex[&(*vi)]);
}
}
}
/// \brief Test correctness of FFtopology (only for 2Manifold Meshes!)
@ -496,8 +494,8 @@ static void TestFaceFace(MeshType &m)
assert( (ffv1i==v0i) || (ffv1i==v1i) );
}
}
}
}
}
}
/// Auxiliairy data structure for computing edge edge adjacency information.

View File

@ -239,8 +239,9 @@ void FFDetach(FaceType & f, const int e)
{
assert(FFCorrectness<FaceType>(f,e));
assert(!IsBorder<FaceType>(f,e)); // Never try to detach a border edge!
int complexity;
assert(complexity=ComplexSize(f,e));
int complexity=ComplexSize(f,e);
(void) complexity;
assert(complexity>0);
Pos< FaceType > FirstFace(&f,e); // Build the half edge
Pos< FaceType > LastFace(&f,e); // Build the half edge
@ -343,13 +344,14 @@ void FFSetBorder(FaceType * &f1, int z1)
template <class FaceType>
void AssertAdj(FaceType & f)
{
assert(f.FFp(0)->FFp(f.FFi(0))==&f);
assert(f.FFp(1)->FFp(f.FFi(1))==&f);
assert(f.FFp(2)->FFp(f.FFi(2))==&f);
(void)f;
assert(f.FFp(0)->FFp(f.FFi(0))==&f);
assert(f.FFp(1)->FFp(f.FFi(1))==&f);
assert(f.FFp(2)->FFp(f.FFi(2))==&f);
assert(f.FFp(0)->FFi(f.FFi(0))==0);
assert(f.FFp(1)->FFi(f.FFi(1))==1);
assert(f.FFp(2)->FFi(f.FFi(2))==2);
assert(f.FFp(0)->FFi(f.FFi(0))==0);
assert(f.FFp(1)->FFi(f.FFi(1))==1);
assert(f.FFp(2)->FFi(f.FFi(2))==2);
}
/**
@ -435,11 +437,10 @@ void SwapEdge(FaceType &f, const int z)
* Basic link conditions
*
*/
template <class MeshType>
bool FFLinkCondition(typename MeshType::FaceType &f, const int z)
template <class FaceType>
bool FFLinkCondition(FaceType &f, const int z)
{
typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::VertexType VertexType;
typedef typename FaceType::VertexType VertexType;
typedef typename vcg::face::Pos< FaceType > PosType;
VertexType *v0=f.V0(z);

View File

@ -8,7 +8,7 @@
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
@ -105,7 +105,7 @@ namespace vcg {
/**
The templated class for representing a point in 3D space.
The class is templated over the ScalarType class that is used to represent coordinates. All the usual
operator overloading (* + - ...) is present.
operator overloading (* + - ...) is present.
*/
template <class T> class Box3;
@ -113,86 +113,86 @@ template <class P3ScalarType> class Point3
{
protected:
/// The only data member. Hidden to user.
P3ScalarType _v[3];
P3ScalarType _v[3];
public:
typedef P3ScalarType ScalarType;
enum {Dimension = 3};
typedef P3ScalarType ScalarType;
enum {Dimension = 3};
//@{
/** @name Standard Constructors and Initializers
/** @name Standard Constructors and Initializers
No casting operators have been introduced to avoid automatic unattended (and costly) conversion between different point types
**/
inline Point3 () { }
inline Point3 ( const P3ScalarType nx, const P3ScalarType ny, const P3ScalarType nz )
{
_v[0] = nx;
_v[1] = ny;
_v[2] = nz;
}
inline Point3 ( Point3 const & p )
{
_v[0]= p._v[0];
_v[1]= p._v[1];
_v[2]= p._v[2];
}
inline Point3 ( const P3ScalarType nv[3] )
{
_v[0] = nv[0];
_v[1] = nv[1];
_v[2] = nv[2];
}
inline Point3 & operator =( Point3 const & p )
{
_v[0]= p._v[0]; _v[1]= p._v[1]; _v[2]= p._v[2];
return *this;
}
inline void SetZero()
{
_v[0] = 0;
_v[1] = 0;
_v[2] = 0;
}
/// Padding function: give a default 0 value to all the elements that are not in the [0..2] range.
/// Useful for managing in a consistent way object that could have point2 / point3 / point4
inline P3ScalarType Ext( const int i ) const
{
if(i>=0 && i<=2) return _v[i];
else return 0;
}
inline Point3 ( const P3ScalarType nx, const P3ScalarType ny, const P3ScalarType nz )
{
_v[0] = nx;
_v[1] = ny;
_v[2] = nz;
}
inline Point3 ( Point3 const & p )
{
_v[0]= p._v[0];
_v[1]= p._v[1];
_v[2]= p._v[2];
}
inline Point3 ( const P3ScalarType nv[3] )
{
_v[0] = nv[0];
_v[1] = nv[1];
_v[2] = nv[2];
}
inline Point3 & operator =( Point3 const & p )
{
_v[0]= p._v[0]; _v[1]= p._v[1]; _v[2]= p._v[2];
return *this;
}
inline void SetZero()
{
_v[0] = 0;
_v[1] = 0;
_v[2] = 0;
}
template <class Q>
inline void Import( const Point3<Q> & b )
{
_v[0] = P3ScalarType(b[0]);
_v[1] = P3ScalarType(b[1]);
_v[2] = P3ScalarType(b[2]);
}
template <class EigenVector>
inline void FromEigenVector( const EigenVector & b )
{
_v[0] = P3ScalarType(b[0]);
_v[1] = P3ScalarType(b[1]);
_v[2] = P3ScalarType(b[2]);
}
template <class EigenVector>
inline void ToEigenVector( EigenVector & b ) const
{
b[0]=_v[0] ;
b[1]=_v[1] ;
b[2]=_v[2] ;
}
template <class Q>
/// Padding function: give a default 0 value to all the elements that are not in the [0..2] range.
/// Useful for managing in a consistent way object that could have point2 / point3 / point4
inline P3ScalarType Ext( const int i ) const
{
if(i>=0 && i<=2) return _v[i];
else return 0;
}
template <class Q>
inline void Import( const Point3<Q> & b )
{
_v[0] = P3ScalarType(b[0]);
_v[1] = P3ScalarType(b[1]);
_v[2] = P3ScalarType(b[2]);
}
template <class EigenVector>
inline void FromEigenVector( const EigenVector & b )
{
_v[0] = P3ScalarType(b[0]);
_v[1] = P3ScalarType(b[1]);
_v[2] = P3ScalarType(b[2]);
}
template <class EigenVector>
inline void ToEigenVector( EigenVector & b ) const
{
b[0]=_v[0] ;
b[1]=_v[1] ;
b[2]=_v[2] ;
}
template <class Q>
static inline Point3 Construct( const Point3<Q> & b )
{
return Point3(P3ScalarType(b[0]),P3ScalarType(b[1]),P3ScalarType(b[2]));
}
template <class Q>
template <class Q>
static inline Point3 Construct( const Q & P0, const Q & P1, const Q & P2)
{
return Point3(P3ScalarType(P0),P3ScalarType(P1),P3ScalarType(P2));
@ -207,227 +207,227 @@ public:
//@{
/** @name Data Access.
/** @name Data Access.
access to data is done by overloading of [] or explicit naming of coords (x,y,z)**/
inline P3ScalarType & operator [] ( const int i )
{
assert(i>=0 && i<3);
return _v[i];
}
inline const P3ScalarType & operator [] ( const int i ) const
{
assert(i>=0 && i<3);
return _v[i];
}
inline const P3ScalarType &X() const { return _v[0]; }
inline const P3ScalarType &Y() const { return _v[1]; }
inline const P3ScalarType &Z() const { return _v[2]; }
inline P3ScalarType &X() { return _v[0]; }
inline P3ScalarType &Y() { return _v[1]; }
inline P3ScalarType &Z() { return _v[2]; }
inline const P3ScalarType * V() const
{
return _v;
}
inline P3ScalarType * V()
{
return _v;
}
inline P3ScalarType & V( const int i )
{
assert(i>=0 && i<3);
return _v[i];
}
inline const P3ScalarType & V( const int i ) const
{
assert(i>=0 && i<3);
return _v[i];
}
inline P3ScalarType & operator [] ( const int i )
{
assert(i>=0 && i<3);
return _v[i];
}
inline const P3ScalarType & operator [] ( const int i ) const
{
assert(i>=0 && i<3);
return _v[i];
}
inline const P3ScalarType &X() const { return _v[0]; }
inline const P3ScalarType &Y() const { return _v[1]; }
inline const P3ScalarType &Z() const { return _v[2]; }
inline P3ScalarType &X() { return _v[0]; }
inline P3ScalarType &Y() { return _v[1]; }
inline P3ScalarType &Z() { return _v[2]; }
inline const P3ScalarType * V() const
{
return _v;
}
inline P3ScalarType * V()
{
return _v;
}
inline P3ScalarType & V( const int i )
{
assert(i>=0 && i<3);
return _v[i];
}
inline const P3ScalarType & V( const int i ) const
{
assert(i>=0 && i<3);
return _v[i];
}
//@}
//@{
/** @name Classical overloading of operators
Note
/** @name Classical overloading of operators
Note
**/
inline Point3 operator + ( Point3 const & p) const
{
return Point3<P3ScalarType>( _v[0]+p._v[0], _v[1]+p._v[1], _v[2]+p._v[2] );
}
inline Point3 operator - ( Point3 const & p) const
{
return Point3<P3ScalarType>( _v[0]-p._v[0], _v[1]-p._v[1], _v[2]-p._v[2] );
}
inline Point3 operator * ( const P3ScalarType s ) const
{
return Point3<P3ScalarType>( _v[0]*s, _v[1]*s, _v[2]*s );
}
inline Point3 operator / ( const P3ScalarType s ) const
{
return Point3<P3ScalarType>( _v[0]/s, _v[1]/s, _v[2]/s );
}
/// Dot product
inline P3ScalarType operator * ( Point3 const & p ) const
{
return ( _v[0]*p._v[0] + _v[1]*p._v[1] + _v[2]*p._v[2] );
}
inline P3ScalarType dot( const Point3 & p ) const { return (*this) * p; }
/// Cross product
inline Point3 operator ^ ( Point3 const & p ) const
{
return Point3 <P3ScalarType>
(
_v[1]*p._v[2] - _v[2]*p._v[1],
_v[2]*p._v[0] - _v[0]*p._v[2],
_v[0]*p._v[1] - _v[1]*p._v[0]
);
}
inline Point3 operator + ( Point3 const & p) const
{
return Point3<P3ScalarType>( _v[0]+p._v[0], _v[1]+p._v[1], _v[2]+p._v[2] );
}
inline Point3 operator - ( Point3 const & p) const
{
return Point3<P3ScalarType>( _v[0]-p._v[0], _v[1]-p._v[1], _v[2]-p._v[2] );
}
inline Point3 operator * ( const P3ScalarType s ) const
{
return Point3<P3ScalarType>( _v[0]*s, _v[1]*s, _v[2]*s );
}
inline Point3 operator / ( const P3ScalarType s ) const
{
return Point3<P3ScalarType>( _v[0]/s, _v[1]/s, _v[2]/s );
}
/// Dot product
inline P3ScalarType operator * ( Point3 const & p ) const
{
return ( _v[0]*p._v[0] + _v[1]*p._v[1] + _v[2]*p._v[2] );
}
inline P3ScalarType dot( const Point3 & p ) const { return (*this) * p; }
/// Cross product
inline Point3 operator ^ ( Point3 const & p ) const
{
return Point3 <P3ScalarType>
(
_v[1]*p._v[2] - _v[2]*p._v[1],
_v[2]*p._v[0] - _v[0]*p._v[2],
_v[0]*p._v[1] - _v[1]*p._v[0]
);
}
inline Point3 & operator += ( Point3 const & p)
{
_v[0] += p._v[0];
_v[1] += p._v[1];
_v[2] += p._v[2];
return *this;
}
inline Point3 & operator -= ( Point3 const & p)
{
_v[0] -= p._v[0];
_v[1] -= p._v[1];
_v[2] -= p._v[2];
return *this;
}
inline Point3 & operator *= ( const P3ScalarType s )
{
_v[0] *= s;
_v[1] *= s;
_v[2] *= s;
return *this;
}
inline Point3 & operator /= ( const P3ScalarType s )
{
_v[0] /= s;
_v[1] /= s;
_v[2] /= s;
return *this;
}
// Norme
inline P3ScalarType Norm() const
{
inline Point3 & operator += ( Point3 const & p)
{
_v[0] += p._v[0];
_v[1] += p._v[1];
_v[2] += p._v[2];
return *this;
}
inline Point3 & operator -= ( Point3 const & p)
{
_v[0] -= p._v[0];
_v[1] -= p._v[1];
_v[2] -= p._v[2];
return *this;
}
inline Point3 & operator *= ( const P3ScalarType s )
{
_v[0] *= s;
_v[1] *= s;
_v[2] *= s;
return *this;
}
inline Point3 & operator /= ( const P3ScalarType s )
{
_v[0] /= s;
_v[1] /= s;
_v[2] /= s;
return *this;
}
// Norme
inline P3ScalarType Norm() const
{
return math::Sqrt( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] );
}
inline P3ScalarType SquaredNorm() const
{
return ( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] );
}
// Scalatura differenziata
inline Point3 & Scale( const P3ScalarType sx, const P3ScalarType sy, const P3ScalarType sz )
{
_v[0] *= sx;
_v[1] *= sy;
_v[2] *= sz;
return *this;
}
inline Point3 & Scale( const Point3 & p )
{
_v[0] *= p._v[0];
_v[1] *= p._v[1];
_v[2] *= p._v[2];
return *this;
}
}
inline P3ScalarType SquaredNorm() const
{
return ( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] );
}
// Scalatura differenziata
inline Point3 & Scale( const P3ScalarType sx, const P3ScalarType sy, const P3ScalarType sz )
{
_v[0] *= sx;
_v[1] *= sy;
_v[2] *= sz;
return *this;
}
inline Point3 & Scale( const Point3 & p )
{
_v[0] *= p._v[0];
_v[1] *= p._v[1];
_v[2] *= p._v[2];
return *this;
}
// Normalizzazione
inline Point3 & Normalize()
{
P3ScalarType n = P3ScalarType(math::Sqrt(_v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2]));
if (n > P3ScalarType(0)) { _v[0] /= n; _v[1] /= n; _v[2] /= n; }
return *this;
}
// Normalizzazione
inline Point3 & Normalize()
{
P3ScalarType n = P3ScalarType(math::Sqrt(_v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2]));
if (n > P3ScalarType(0)) { _v[0] /= n; _v[1] /= n; _v[2] /= n; }
return *this;
}
// for compatibility with eigen port
inline Point3 & normalized() { return Normalize(); }
/**
* Convert to polar coordinates from cartesian coordinates.
*
* Theta is the azimuth angle and ranges between [0, 2PI) degrees.
* Phi is the elevation angle (not the polar angle) and ranges between [-PI/2, PI/2] degrees.
*
* /note Note that instead of the classical polar angle, which ranges between
* 0 and PI degrees we opt for the elevation angle to obtain a more
* intuitive spherical coordinate system.
*/
void ToPolarRad(P3ScalarType &ro, P3ScalarType &theta, P3ScalarType &phi) const
{
ro = Norm();
theta = (P3ScalarType)atan2(_v[2], _v[0]);
phi = (P3ScalarType)asin(_v[1]/ro);
}
// for compatibility with eigen port
inline Point3 & normalized() { return Normalize(); }
/**
* Convert from polar coordinates to cartesian coordinates.
*
* Theta is the azimuth angle and ranges between [0, 2PI) radians.
* Phi is the elevation angle (not the polar angle) and ranges between [-PI/2, PI/2] radians.
*
* \note Note that instead of the classical polar angle, which ranges between
* 0 and PI degrees, we opt for the elevation angle to obtain a more
* intuitive spherical coordinate system.
*/
/**
* Convert to polar coordinates from cartesian coordinates.
*
* Theta is the azimuth angle and ranges between [0, 2PI) degrees.
* Phi is the elevation angle (not the polar angle) and ranges between [-PI/2, PI/2] degrees.
*
* /note Note that instead of the classical polar angle, which ranges between
* 0 and PI degrees we opt for the elevation angle to obtain a more
* intuitive spherical coordinate system.
*/
void ToPolarRad(P3ScalarType &ro, P3ScalarType &theta, P3ScalarType &phi) const
{
ro = Norm();
theta = (P3ScalarType)atan2(_v[2], _v[0]);
phi = (P3ScalarType)asin(_v[1]/ro);
}
/**
* Convert from polar coordinates to cartesian coordinates.
*
* Theta is the azimuth angle and ranges between [0, 2PI) radians.
* Phi is the elevation angle (not the polar angle) and ranges between [-PI/2, PI/2] radians.
*
* \note Note that instead of the classical polar angle, which ranges between
* 0 and PI degrees, we opt for the elevation angle to obtain a more
* intuitive spherical coordinate system.
*/
void FromPolarRad(const P3ScalarType &ro, const P3ScalarType &theta, const P3ScalarType &phi)
{
{
_v[0]= ro*cos(theta)*cos(phi);
_v[1]= ro*sin(phi);
_v[2]= ro*sin(theta)*cos(phi);
}
}
Box3<P3ScalarType> GetBBox(Box3<P3ScalarType> &bb) const;
//@}
//@{
/** @name Comparison Operators.
/** @name Comparison Operators.
Note that the reverse z prioritized ordering, useful in many situations.
**/
inline bool operator == ( Point3 const & p ) const
{
return _v[0]==p._v[0] && _v[1]==p._v[1] && _v[2]==p._v[2];
}
inline bool operator != ( Point3 const & p ) const
{
return _v[0]!=p._v[0] || _v[1]!=p._v[1] || _v[2]!=p._v[2];
}
inline bool operator < ( Point3 const & p ) const
{
return (_v[2]!=p._v[2])?(_v[2]<p._v[2]):
(_v[1]!=p._v[1])?(_v[1]<p._v[1]):
(_v[0]<p._v[0]);
}
inline bool operator > ( Point3 const & p ) const
{
return (_v[2]!=p._v[2])?(_v[2]>p._v[2]):
(_v[1]!=p._v[1])?(_v[1]>p._v[1]):
(_v[0]>p._v[0]);
}
inline bool operator <= ( Point3 const & p ) const
{
return (_v[2]!=p._v[2])?(_v[2]< p._v[2]):
(_v[1]!=p._v[1])?(_v[1]< p._v[1]):
(_v[0]<=p._v[0]);
}
inline bool operator >= ( Point3 const & p ) const
{
return (_v[2]!=p._v[2])?(_v[2]> p._v[2]):
(_v[1]!=p._v[1])?(_v[1]> p._v[1]):
(_v[0]>=p._v[0]);
}
{
return _v[0]==p._v[0] && _v[1]==p._v[1] && _v[2]==p._v[2];
}
inline bool operator != ( Point3 const & p ) const
{
return _v[0]!=p._v[0] || _v[1]!=p._v[1] || _v[2]!=p._v[2];
}
inline bool operator < ( Point3 const & p ) const
{
return (_v[2]!=p._v[2])?(_v[2]<p._v[2]):
(_v[1]!=p._v[1])?(_v[1]<p._v[1]):
(_v[0]<p._v[0]);
}
inline bool operator > ( Point3 const & p ) const
{
return (_v[2]!=p._v[2])?(_v[2]>p._v[2]):
(_v[1]!=p._v[1])?(_v[1]>p._v[1]):
(_v[0]>p._v[0]);
}
inline bool operator <= ( Point3 const & p ) const
{
return (_v[2]!=p._v[2])?(_v[2]< p._v[2]):
(_v[1]!=p._v[1])?(_v[1]< p._v[1]):
(_v[0]<=p._v[0]);
}
inline bool operator >= ( Point3 const & p ) const
{
return (_v[2]!=p._v[2])?(_v[2]> p._v[2]):
(_v[1]!=p._v[1])?(_v[1]> p._v[1]):
(_v[0]>=p._v[0]);
}
inline Point3 operator - () const
{
return Point3<P3ScalarType> ( -_v[0], -_v[1], -_v[2] );
}
inline Point3 operator - () const
{
return Point3<P3ScalarType> ( -_v[0], -_v[1], -_v[2] );
}
//@}
}; // end class definition
@ -436,11 +436,11 @@ inline bool operator == ( Point3 const & p ) const
template <class P3ScalarType>
inline P3ScalarType Angle( Point3<P3ScalarType> const & p1, Point3<P3ScalarType> const & p2 )
{
P3ScalarType w = p1.Norm()*p2.Norm();
if(w==0) return -1;
P3ScalarType t = (p1*p2)/w;
if(t>1) t = 1;
else if(t<-1) t = -1;
P3ScalarType w = p1.Norm()*p2.Norm();
if(w==0) return -1;
P3ScalarType t = (p1*p2)/w;
if(t>1) t = 1;
else if(t<-1) t = -1;
return (P3ScalarType) acos(t);
}
@ -448,11 +448,11 @@ inline P3ScalarType Angle( Point3<P3ScalarType> const & p1, Point3<P3ScalarType>
template <class P3ScalarType>
inline P3ScalarType AngleN( Point3<P3ScalarType> const & p1, Point3<P3ScalarType> const & p2 )
{
P3ScalarType w = p1*p2;
if(w>1)
w = 1;
else if(w<-1)
w=-1;
P3ScalarType w = p1*p2;
if(w>1)
w = 1;
else if(w<-1)
w=-1;
return (P3ScalarType) acos(w);
}
@ -460,7 +460,7 @@ inline P3ScalarType AngleN( Point3<P3ScalarType> const & p1, Point3<P3ScalarType
template <class P3ScalarType>
inline P3ScalarType Norm( Point3<P3ScalarType> const & p )
{
return p.Norm();
return p.Norm();
}
template <class P3ScalarType>
@ -503,52 +503,52 @@ P3ScalarType ApproximateGeodesicDistance(const Point3<P3ScalarType>& p0, const P
}
// Dot product preciso numericamente (solo double!!)
// Implementazione: si sommano i prodotti per ordine di esponente
// (prima le piu' grandi)
// Dot product preciso numericamente (solo double!!)
// Implementazione: si sommano i prodotti per ordine di esponente
// (prima le piu' grandi)
template<class P3ScalarType>
double stable_dot ( Point3<P3ScalarType> const & p0, Point3<P3ScalarType> const & p1 )
{
P3ScalarType k0 = p0._v[0]*p1._v[0];
P3ScalarType k1 = p0._v[1]*p1._v[1];
P3ScalarType k2 = p0._v[2]*p1._v[2];
P3ScalarType k0 = p0._v[0]*p1._v[0];
P3ScalarType k1 = p0._v[1]*p1._v[1];
P3ScalarType k2 = p0._v[2]*p1._v[2];
int exp0,exp1,exp2;
int exp0,exp1,exp2;
frexp( double(k0), &exp0 );
frexp( double(k1), &exp1 );
frexp( double(k2), &exp2 );
frexp( double(k0), &exp0 );
frexp( double(k1), &exp1 );
frexp( double(k2), &exp2 );
if( exp0<exp1 )
{
if(exp0<exp2)
return (k1+k2)+k0;
else
return (k0+k1)+k2;
}
else
{
if(exp1<exp2)
return(k0+k2)+k1;
else
return (k0+k1)+k2;
}
}
if( exp0<exp1 )
{
if(exp0<exp2)
return (k1+k2)+k0;
else
return (k0+k1)+k2;
}
else
{
if(exp1<exp2)
return(k0+k2)+k1;
else
return (k0+k1)+k2;
}
}
/// Point(p) Edge(v1-v2) dist, q is the point in v1-v2 with min dist
template<class P3ScalarType>
P3ScalarType PSDist( const Point3<P3ScalarType> & p,
const Point3<P3ScalarType> & v1,
const Point3<P3ScalarType> & v2,
Point3<P3ScalarType> & q )
const Point3<P3ScalarType> & v1,
const Point3<P3ScalarType> & v2,
Point3<P3ScalarType> & q )
{
Point3<P3ScalarType> e = v2-v1;
P3ScalarType t = ((p-v1)*e)/e.SquaredNorm();
if(t<0) t = 0;
else if(t>1) t = 1;
q = v1+e*t;
else if(t>1) t = 1;
q = v1+e*t;
return Distance(p,q);
}
@ -556,31 +556,30 @@ P3ScalarType PSDist( const Point3<P3ScalarType> & p,
template <class P3ScalarType>
void GetUV( Point3<P3ScalarType> &n,Point3<P3ScalarType> &u, Point3<P3ScalarType> &v, Point3<P3ScalarType> up=(Point3<P3ScalarType>(0,1,0)) )
{
n.Normalize();
const double LocEps=double(1e-7);
u=n^up;
n.Normalize();
const double LocEps=double(1e-7);
u=n^up;
double len = u.Norm();
if(len < LocEps)
{
if(fabs(n[0])<fabs(n[1])){
if(fabs(n[0])<fabs(n[2])) up=Point3<P3ScalarType>(1,0,0); // x is the min
else up=Point3<P3ScalarType>(0,0,1); // z is the min
}else {
if(fabs(n[1])<fabs(n[2])) up=Point3<P3ScalarType>(0,1,0); // y is the min
else up=Point3<P3ScalarType>(0,0,1); // z is the min
}
u=n^up;
}
u.Normalize();
v=n^u;
v.Normalize();
Point3<P3ScalarType> uv=u^v;
if(len < LocEps)
{
if(fabs(n[0])<fabs(n[1])){
if(fabs(n[0])<fabs(n[2])) up=Point3<P3ScalarType>(1,0,0); // x is the min
else up=Point3<P3ScalarType>(0,0,1); // z is the min
}else {
if(fabs(n[1])<fabs(n[2])) up=Point3<P3ScalarType>(0,1,0); // y is the min
else up=Point3<P3ScalarType>(0,0,1); // z is the min
}
u=n^up;
}
u.Normalize();
v=n^u;
v.Normalize();
}
template <class SCALARTYPE>
inline Point3<SCALARTYPE> Abs(const Point3<SCALARTYPE> & p) {
return (Point3<SCALARTYPE>(math::Abs(p[0]), math::Abs(p[1]), math::Abs(p[2])));
return (Point3<SCALARTYPE>(math::Abs(p[0]), math::Abs(p[1]), math::Abs(p[2])));
}
// probably a more uniform naming should be defined...
template <class SCALARTYPE>

View File

@ -8,7 +8,7 @@
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
@ -19,53 +19,36 @@
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
/****************************************************************************
History
$Log: not supported by cvs2svn $
Revision 1.1 2007/02/14 01:20:37 ganovelli
working draft of VCG Mesh Image importer and exporter. Does not consider optional attributes. The mesh atributes are only vn and fn (no bbox, texture coordiantes)
****************************************************************************/
#ifndef __VCGLIB_EXPORT_VMI
#define __VCGLIB_EXPORT_VMI
/*
VMI VCG Mesh Image.
The vmi image file consists of a header containing the description of the vertex and face type,
the length of vectors containing vertices of faces and the memory image of the object mesh as it is when
passed to the function Save(SaveMeshType m).
NOTE: THIS IS NOT A FILE FORMAT. IT IS ONLY USEFUL FOR DUMPING MESH IMAGES FOR DEBUG PURPOSE.
Example of use: say you are running a time consuming mesh processing and you want to save intermediate
state, but no file format support all the attributes you need in your vertex/face type.
NOTE2: At the present if you add members to your TriMesh these will NOT be saved. More precisely, this file and
import_vmi must be updated to reflect changes in vcg/complex/trimesh/base.h
*/
VMI VCG Mesh Image.
The vmi image file consists of a header containing the description of the vertex and face type,
the length of vectors containing vertices of faces and the memory image of the object mesh as it is when
passed to the function Save(SaveMeshType m).
NOTE: THIS IS NOT A FILE FORMAT. IT IS ONLY USEFUL FOR DUMPING MESH IMAGES FOR DEBUG PURPOSE.
Example of use: say you are running a time consuming mesh processing and you want to save intermediate
state, but no file format support all the attributes you need in your vertex/face type.
NOTE2: At the present if you add members to your TriMesh these will NOT be saved. More precisely, this file and
import_vmi must be updated to reflect changes in vcg/complex/trimesh/base.h
*/
#include <vcg/complex/complex.h>
//#include <vcg/simplex/face/component.h>
//#include <vcg/simplex/face/component_ocf.h>
//#include <vcg/simplex/vertex/component.h>
//#include <vcg/simplex/vertex/component_ocf.h>
namespace vcg {
namespace tri {
namespace io {
template <int N> struct PlaceHolderType{ char A[N];};
template <int N> struct PlaceHolderType{ char A[N];};
template <class SaveMeshType>
class ExporterVMI
{
template <class SaveMeshType>
class ExporterVMI
{
static char * & Out_mem(){static char * out_mem; return out_mem;}
@ -83,178 +66,180 @@ namespace io {
case 1: return fwrite_mem(src, size,count); break;
case 2: return fwrite(src, size,count, F() ); break;
}
assert(0);
return 0;
}
static void WriteString( const char * in) { unsigned int l = strlen(in); WriteOut(&l,4,1 ); WriteOut(in,1,l );}
static void WriteInt (const unsigned int i) { WriteOut(&i,1,4 );}
static void WriteInt (const unsigned int i) { WriteOut(&i,1,4 );}
static void WriteFloat( const float v) { WriteOut(&v,1,sizeof(float) );}
static void WriteFloat( const float v) { WriteOut(&v,1,sizeof(float) );}
/* save Ocf Vertex Components */
template <typename OpenMeshType,typename CONT>
struct SaveVertexOcf{
/* save Ocf Vertex Components */
template <typename OpenMeshType,typename CONT>
struct SaveVertexOcf{
SaveVertexOcf( const CONT & /*vert*/, bool only_header){
// do nothing, it is a std::vector
if(only_header){
WriteString( "NOT_HAS_VERTEX_QUALITY_OCF");
WriteString( "NOT_HAS_VERTEX_COLOR_OCF");
WriteString( "NOT_HAS_VERTEX_NORMAL_OCF");
WriteString( "NOT_HAS_VERTEX_MARK_OCF");
WriteString( "NOT_HAS_VERTEX_TEXCOORD_OCF");
WriteString( "NOT_HAS_VERTEX_VFADJACENCY_OCF");
WriteString( "NOT_HAS_VERTEX_CURVATURE_OCF");
WriteString( "NOT_HAS_VERTEX_CURVATUREDIR_OCF");
WriteString( "NOT_HAS_VERTEX_RADIUS_OCF");
}
}
};
// do nothing, it is a std::vector
if(only_header){
WriteString( "NOT_HAS_VERTEX_QUALITY_OCF");
WriteString( "NOT_HAS_VERTEX_COLOR_OCF");
WriteString( "NOT_HAS_VERTEX_NORMAL_OCF");
WriteString( "NOT_HAS_VERTEX_MARK_OCF");
WriteString( "NOT_HAS_VERTEX_TEXCOORD_OCF");
WriteString( "NOT_HAS_VERTEX_VFADJACENCY_OCF");
WriteString( "NOT_HAS_VERTEX_CURVATURE_OCF");
WriteString( "NOT_HAS_VERTEX_CURVATUREDIR_OCF");
WriteString( "NOT_HAS_VERTEX_RADIUS_OCF");
}
}
};
/* partial specialization for vector_ocf */
template <typename MeshType>
struct SaveVertexOcf<MeshType, vertex::vector_ocf<typename MeshType::VertexType> >{
typedef typename MeshType::VertexType VertexType;
SaveVertexOcf( const vertex::vector_ocf<VertexType> & vert, bool only_header){
/* partial specialization for vector_ocf */
template <typename MeshType>
struct SaveVertexOcf<MeshType, vertex::vector_ocf<typename MeshType::VertexType> >{
typedef typename MeshType::VertexType VertexType;
SaveVertexOcf( const vertex::vector_ocf<VertexType> & vert, bool only_header){
if( VertexType::HasQualityOcf() && vert.IsQualityEnabled()){
WriteString( "HAS_VERTEX_QUALITY_OCF");
WriteString( "HAS_VERTEX_QUALITY_OCF");
if(!only_header) WriteOut(&vert.QV[0],sizeof(typename VertexType::QualityType),vert.size() );
}else WriteString( "NOT_HAS_VERTEX_QUALITY_OCF");
}else WriteString( "NOT_HAS_VERTEX_QUALITY_OCF");
if( VertexType::HasColorOcf() && vert.IsColorEnabled()){
WriteString( "HAS_VERTEX_COLOR_OCF");
WriteString( "HAS_VERTEX_COLOR_OCF");
if(!only_header) WriteOut(&vert.CV[0],sizeof(typename VertexType::ColorType),vert.size() );
}else WriteString( "NOT_HAS_VERTEX_COLOR_OCF");
}else WriteString( "NOT_HAS_VERTEX_COLOR_OCF");
if( VertexType::HasNormalOcf() && vert.IsNormalEnabled()){
WriteString( "HAS_VERTEX_NORMAL_OCF");
WriteString( "HAS_VERTEX_NORMAL_OCF");
if(!only_header) WriteOut(&vert.NV[0],sizeof(typename VertexType::NormalType),vert.size() );
}else WriteString( "NOT_HAS_VERTEX_NORMAL_OCF");
}else WriteString( "NOT_HAS_VERTEX_NORMAL_OCF");
if( VertexType::HasMarkOcf() && vert.IsMarkEnabled()){
WriteString( "HAS_VERTEX_MARK_OCF");
if(!only_header) WriteOut(&vert.MV[0],sizeof(typename VertexType::MarkType),vert.size() );
}else WriteString( "NOT_HAS_VERTEX_MARK_OCF");
if( VertexType::HasTexCoordOcf() && vert.IsTexCoordEnabled()){
WriteString( "HAS_VERTEX_TEXCOORD_OCF");
if( VertexType::HasTexCoordOcf() && vert.IsTexCoordEnabled()){
WriteString( "HAS_VERTEX_TEXCOORD_OCF");
if(!only_header) WriteOut(&vert.TV[0],sizeof(typename VertexType::TexCoordType),vert.size() );
}else WriteString( "NOT_HAS_VERTEX_TEXCOORD_OCF");
}else WriteString( "NOT_HAS_VERTEX_TEXCOORD_OCF");
if( VertexType::HasVFAdjacencyOcf() && vert.IsVFAdjacencyEnabled()){
WriteString( "HAS_VERTEX_VFADJACENCY_OCF");
if( VertexType::HasVFAdjacencyOcf() && vert.IsVFAdjacencyEnabled()){
WriteString( "HAS_VERTEX_VFADJACENCY_OCF");
if(!only_header) WriteOut(&vert.AV[0],sizeof(typename vertex::vector_ocf<VertexType>::VFAdjType),vert.size() );
}else WriteString( "NOT_HAS_VERTEX_VFADJACENCY_OCF");
}else WriteString( "NOT_HAS_VERTEX_VFADJACENCY_OCF");
if( VertexType::HasCurvatureOcf() && vert.IsCurvatureEnabled()){
WriteString( "HAS_VERTEX_CURVATURE_OCF");
if( VertexType::HasCurvatureOcf() && vert.IsCurvatureEnabled()){
WriteString( "HAS_VERTEX_CURVATURE_OCF");
if(!only_header) WriteOut(&vert.CuV[0],sizeof(typename VertexType::CurvatureType),vert.size() );
}else WriteString( "NOT_HAS_VERTEX_CURVATURE_OCF");
}else WriteString( "NOT_HAS_VERTEX_CURVATURE_OCF");
if( VertexType::HasCurvatureDirOcf() && vert.IsCurvatureDirEnabled()){
WriteString( "HAS_VERTEX_CURVATUREDIR_OCF");
if( VertexType::HasCurvatureDirOcf() && vert.IsCurvatureDirEnabled()){
WriteString( "HAS_VERTEX_CURVATUREDIR_OCF");
if(!only_header) WriteOut(&vert.CuDV[0],sizeof(typename VertexType::CurvatureDirType),vert.size() );
}else WriteString( "NOT_HAS_VERTEX_CURVATUREDIR_OCF");
}else WriteString( "NOT_HAS_VERTEX_CURVATUREDIR_OCF");
if( VertexType::HasRadiusOcf() && vert.IsRadiusEnabled()){
WriteString( "HAS_VERTEX_RADIUS_OCF");
if( VertexType::HasRadiusOcf() && vert.IsRadiusEnabled()){
WriteString( "HAS_VERTEX_RADIUS_OCF");
if(!only_header) WriteOut(&vert.RadiusV[0],sizeof(typename VertexType::RadiusType),vert.size() );
}else WriteString( "NOT_HAS_VERTEX_RADIUS_OCF");
}else WriteString( "NOT_HAS_VERTEX_RADIUS_OCF");
}
};
}
};
/* save Ocf Face Components */
template <typename MeshType,typename CONT>
struct SaveFaceOcf{
/* save Ocf Face Components */
template <typename MeshType,typename CONT>
struct SaveFaceOcf{
SaveFaceOcf( const CONT & /*face*/, bool only_header){
// it is a std::vector
if(only_header){
WriteString( "NOT_HAS_FACE_QUALITY_OCF");
WriteString( "NOT_HAS_FACE_COLOR_OCF");
WriteString( "NOT_HAS_FACE_NORMAL_OCF");
WriteString( "NOT_HAS_FACE_MARK_OCF");
WriteString( "NOT_HAS_FACE_WEDGETEXCOORD_OCF");
WriteString( "NOT_HAS_FACE_FFADJACENCY_OCF");
WriteString( "NOT_HAS_FACE_VFADJACENCY_OCF");
WriteString( "NOT_HAS_FACE_WEDGECOLOR_OCF");
WriteString( "NOT_HAS_FACE_WEDGENORMAL_OCF");
}
}
};
// it is a std::vector
if(only_header){
WriteString( "NOT_HAS_FACE_QUALITY_OCF");
WriteString( "NOT_HAS_FACE_COLOR_OCF");
WriteString( "NOT_HAS_FACE_NORMAL_OCF");
WriteString( "NOT_HAS_FACE_MARK_OCF");
WriteString( "NOT_HAS_FACE_WEDGETEXCOORD_OCF");
WriteString( "NOT_HAS_FACE_FFADJACENCY_OCF");
WriteString( "NOT_HAS_FACE_VFADJACENCY_OCF");
WriteString( "NOT_HAS_FACE_WEDGECOLOR_OCF");
WriteString( "NOT_HAS_FACE_WEDGENORMAL_OCF");
}
}
};
/* partial specialization for vector_ocf */
template <typename MeshType>
struct SaveFaceOcf< MeshType, face::vector_ocf<typename MeshType::FaceType> >{
typedef typename MeshType::FaceType FaceType;
SaveFaceOcf( const face::vector_ocf<FaceType> & face, bool only_header){
/* partial specialization for vector_ocf */
template <typename MeshType>
struct SaveFaceOcf< MeshType, face::vector_ocf<typename MeshType::FaceType> >{
typedef typename MeshType::FaceType FaceType;
SaveFaceOcf( const face::vector_ocf<FaceType> & face, bool only_header){
if( FaceType::HasQualityOcf() && face.IsQualityEnabled()){
WriteString( "HAS_FACE_QUALITY_OCF");
if( FaceType::HasQualityOcf() && face.IsQualityEnabled()){
WriteString( "HAS_FACE_QUALITY_OCF");
if(!only_header) WriteOut(&face.QV[0],sizeof(typename FaceType::QualityType),face.size() );
}else WriteString( "NOT_HAS_FACE_QUALITY_OCF");
}else WriteString( "NOT_HAS_FACE_QUALITY_OCF");
if( FaceType::HasColorOcf() && face.IsColorEnabled()){
WriteString( "HAS_FACE_COLOR_OCF");
if( FaceType::HasColorOcf() && face.IsColorEnabled()){
WriteString( "HAS_FACE_COLOR_OCF");
if(!only_header) WriteOut(&face.CV[0],sizeof(typename FaceType::ColorType),face.size() );
}else WriteString( "NOT_HAS_FACE_COLOR_OCF");
}else WriteString( "NOT_HAS_FACE_COLOR_OCF");
if( FaceType::HasNormalOcf() && face.IsNormalEnabled()){
WriteString( "HAS_FACE_NORMAL_OCF");
if( FaceType::HasNormalOcf() && face.IsNormalEnabled()){
WriteString( "HAS_FACE_NORMAL_OCF");
if(!only_header) WriteOut(&face.NV[0],sizeof(typename FaceType::NormalType),face.size() );
}else WriteString( "NOT_HAS_FACE_NORMAL_OCF");
}else WriteString( "NOT_HAS_FACE_NORMAL_OCF");
if( FaceType::HasMarkOcf() && face.IsMarkEnabled()){
WriteString( "HAS_FACE_MARK_OCF");
if( FaceType::HasMarkOcf() && face.IsMarkEnabled()){
WriteString( "HAS_FACE_MARK_OCF");
if(!only_header) WriteOut(&face.MV[0],sizeof(typename FaceType::MarkType),face.size() );
}else WriteString( "NOT_HAS_FACE_MARK_OCF");
}else WriteString( "NOT_HAS_FACE_MARK_OCF");
if( FaceType::HasWedgeTexCoordOcf() && face.IsWedgeTexCoordEnabled()){
WriteString( "HAS_FACE_WEDGETEXCOORD_OCF");
if( FaceType::HasWedgeTexCoordOcf() && face.IsWedgeTexCoordEnabled()){
WriteString( "HAS_FACE_WEDGETEXCOORD_OCF");
if(!only_header) WriteOut(&face.WTV[0],sizeof(typename FaceType::WedgeTexCoordType),face.size() );
}else WriteString( "NOT_HAS_FACE_WEDGETEXCOORD_OCF");
}else WriteString( "NOT_HAS_FACE_WEDGETEXCOORD_OCF");
if( FaceType::HasFFAdjacencyOcf() && face.IsFFAdjacencyEnabled()){
WriteString( "HAS_FACE_FFADJACENCY_OCF");
if( FaceType::HasFFAdjacencyOcf() && face.IsFFAdjacencyEnabled()){
WriteString( "HAS_FACE_FFADJACENCY_OCF");
if(!only_header) WriteOut(&face.AF[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size() );
}else WriteString( "NOT_HAS_FACE_FFADJACENCY_OCF");
}else WriteString( "NOT_HAS_FACE_FFADJACENCY_OCF");
if( FaceType::HasVFAdjacencyOcf() && face.IsVFAdjacencyEnabled()){
WriteString( "HAS_FACE_VFADJACENCY_OCF");
if( FaceType::HasVFAdjacencyOcf() && face.IsVFAdjacencyEnabled()){
WriteString( "HAS_FACE_VFADJACENCY_OCF");
if(!only_header) WriteOut(&face.AV[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size() );
}else WriteString( "NOT_HAS_FACE_VFADJACENCY_OCF");
}else WriteString( "NOT_HAS_FACE_VFADJACENCY_OCF");
if( FaceType::HasWedgeColorOcf() && face.IsWedgeColorEnabled()){
WriteString( "HAS_FACE_WEDGECOLOR_OCF");
if( FaceType::HasWedgeColorOcf() && face.IsWedgeColorEnabled()){
WriteString( "HAS_FACE_WEDGECOLOR_OCF");
if(!only_header) WriteOut(&face.WCV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeColorTypePack),face.size() );
}else WriteString( "NOT_HAS_FACE_WEDGECOLOR_OCF");
}else WriteString( "NOT_HAS_FACE_WEDGECOLOR_OCF");
if( FaceType::HasWedgeNormalOcf() && face.IsWedgeNormalEnabled()){
WriteString( "HAS_FACE_WEDGENORMAL_OCF");
if( FaceType::HasWedgeNormalOcf() && face.IsWedgeNormalEnabled()){
WriteString( "HAS_FACE_WEDGENORMAL_OCF");
if(!only_header) WriteOut(&face.WNV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeNormalTypePack),face.size() );
}else WriteString( "NOT_HAS_FACE_WEDGENORMAL_OCF");
}
};
}else WriteString( "NOT_HAS_FACE_WEDGENORMAL_OCF");
}
};
static FILE *& F(){static FILE * f; return f;}
static FILE *& F(){static FILE * f; return f;}
typedef typename SaveMeshType::FaceContainer FaceContainer;
typedef typename SaveMeshType::FaceIterator FaceIterator;
typedef typename SaveMeshType::VertContainer VertContainer;
typedef typename SaveMeshType::VertexIterator VertexIterator;
typedef typename SaveMeshType::VertexType VertexType;
typedef typename SaveMeshType::FaceType FaceType;
typedef typename SaveMeshType::FaceContainer FaceContainer;
typedef typename SaveMeshType::FaceIterator FaceIterator;
typedef typename SaveMeshType::VertContainer VertContainer;
typedef typename SaveMeshType::VertexIterator VertexIterator;
typedef typename SaveMeshType::VertexType VertexType;
typedef typename SaveMeshType::FaceType FaceType;
typedef SimpleTempDataBase STDBv;
typedef SimpleTempDataBase STDBf;
// typedef typename SaveMeshType::Attribute <SaveMeshType::FaceContainer> STDBm;
/* save Ocf Components */
// typedef typename SaveMeshType::Attribute <SaveMeshType::FaceContainer> STDBm;
/* save Ocf Components */
public:
public:
static int Save(const SaveMeshType &m,const char * filename){
Out_mode() = 2;
@ -279,53 +264,53 @@ namespace io {
static int Serialize(const SaveMeshType &m){
unsigned int i;
unsigned int vertSize,faceSize;
unsigned int i;
unsigned int vertSize,faceSize;
std::vector<std::string> nameF,nameV;
SaveMeshType::FaceType::Name(nameF);
SaveMeshType::VertexType::Name(nameV);
vertSize = m.vert.size();
faceSize = m.face.size();
SaveMeshType::FaceType::Name(nameF);
SaveMeshType::VertexType::Name(nameV);
vertSize = m.vert.size();
faceSize = m.face.size();
/* write header */
WriteString( "FACE_TYPE");
WriteInt( nameF.size());
/* write header */
WriteString( "FACE_TYPE");
WriteInt( nameF.size());
for(i=0; i < nameF.size(); ++i) WriteString( nameF[i].c_str());
SaveFaceOcf<SaveMeshType,FaceContainer>( m.face,true);
WriteString( "SIZE_VECTOR_FACES");
WriteInt( faceSize );
for(i=0; i < nameF.size(); ++i) WriteString( nameF[i].c_str());
SaveFaceOcf<SaveMeshType,FaceContainer>( m.face,true);
WriteString( "SIZE_VECTOR_FACES");
WriteInt( faceSize );
WriteString( "VERTEX_TYPE");
WriteInt( nameV.size());
WriteString( "VERTEX_TYPE");
WriteInt( nameV.size());
for(i=0; i < nameV.size(); ++i) WriteString( nameV[i].c_str());
SaveVertexOcf<SaveMeshType,VertContainer>( m.vert,true);
for(i=0; i < nameV.size(); ++i) WriteString( nameV[i].c_str());
SaveVertexOcf<SaveMeshType,VertContainer>( m.vert,true);
WriteString( "SIZE_VECTOR_VERTS");
WriteInt( vertSize);
WriteString( "SIZE_VECTOR_VERTS");
WriteInt( vertSize);
WriteString( "BOUNDING_BOX");
float float_value;
for(unsigned int i =0; i < 2; ++i){float_value = m.bbox.min[i]; WriteFloat( float_value);}
for(unsigned int i =0; i < 2; ++i){float_value = m.bbox.max[i]; WriteFloat( float_value);}
WriteString( "BOUNDING_BOX");
float float_value;
for(unsigned int i =0; i < 2; ++i){float_value = m.bbox.min[i]; WriteFloat( float_value);}
for(unsigned int i =0; i < 2; ++i){float_value = m.bbox.max[i]; WriteFloat( float_value);}
WriteString( "end_header");
/* end header */
WriteString( "end_header");
/* end header */
if(vertSize!=0){
void * offsetV = (void*) &m.vert[0];
/* write the address of the first vertex */
/* write the address of the first vertex */
WriteOut(&offsetV,sizeof(void *),1 );
}
}
if(faceSize!=0){
if(faceSize!=0){
void * offsetF= (void*)&m.face[0];
/* write the address of the first face */
/* write the address of the first face */
WriteOut(&offsetF,sizeof( void *),1 );
}
}
/* save the object mesh */
/* save the object mesh */
WriteOut(&m.shot,sizeof(Shot<typename SaveMeshType::ScalarType>),1 );
WriteOut(&m.vn,sizeof(int),1 );
WriteOut(&m.fn,sizeof(int),1 );
@ -333,99 +318,99 @@ namespace io {
WriteOut(&m.bbox,sizeof(Box3<typename SaveMeshType::ScalarType>),1 );
WriteOut(&m.C(),sizeof(Color4b),1 );
unsigned int written;
unsigned int written;
if(vertSize!=0){
/* save the vertices */
if(vertSize!=0){
/* save the vertices */
written = WriteOut((void*)&m.vert[0],sizeof(typename SaveMeshType::VertexType),m.vert.size() );
SaveVertexOcf<SaveMeshType,VertContainer>( m.vert,false);
}
SaveVertexOcf<SaveMeshType,VertContainer>( m.vert,false);
}
if(faceSize!=0){
/* save the faces */
if(faceSize!=0){
/* save the faces */
written = WriteOut((void*)&m.face[0],sizeof(typename SaveMeshType::FaceType),faceSize );
SaveFaceOcf<SaveMeshType,FaceContainer>( m.face,false);
SaveFaceOcf<SaveMeshType,FaceContainer>( m.face,false);
}
}
/* save the attributes */
/* save the attributes */
typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai;
/* save the per vertex attributes */
{
typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai;
unsigned int n_named_attr = 0;
for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty();
WriteString( "N_PER_VERTEX_ATTRIBUTES"); WriteInt ( n_named_attr);
for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai)
if(!(*ai)._name.empty())
{
STDBv * stdb = (STDBv *) (*ai)._handle;
/* save the per vertex attributes */
{
typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai;
unsigned int n_named_attr = 0;
for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty();
WriteString( "PER_VERTEX_ATTR_NAME");
WriteString( (*ai)._name.c_str() );
WriteString( "N_PER_VERTEX_ATTRIBUTES"); WriteInt ( n_named_attr);
for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai)
if(!(*ai)._name.empty())
{
STDBv * stdb = (STDBv *) (*ai)._handle;
WriteString( "PER_VERTEX_ATTR_SIZE");
WriteInt( stdb->SizeOf());
WriteString( "PER_VERTEX_ATTR_NAME");
WriteString( (*ai)._name.c_str() );
WriteString( "PER_VERTEX_ATTR_SIZE");
WriteInt( stdb->SizeOf());
WriteOut(stdb->DataBegin(),m.vert.size(),stdb->SizeOf() );
}
}
}
}
/* save the per face attributes */
{
typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai;
unsigned int n_named_attr = 0;
for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty();
/* save the per face attributes */
{
typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai;
unsigned int n_named_attr = 0;
for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty();
WriteString( "N_PER_FACE_ATTRIBUTES");
WriteInt ( n_named_attr);
WriteString( "N_PER_FACE_ATTRIBUTES");
WriteInt ( n_named_attr);
for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai)
if(!(*ai)._name.empty())
{
STDBf * stdb = (STDBf *) (*ai)._handle;
for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai)
if(!(*ai)._name.empty())
{
STDBf * stdb = (STDBf *) (*ai)._handle;
WriteString( "PER_FACE_ATTR_NAME");
WriteString( (*ai)._name.c_str());
WriteString( "PER_FACE_ATTR_NAME");
WriteString( (*ai)._name.c_str());
WriteString( "PER_FACE_ATTR_SIZE");
WriteInt( stdb->SizeOf());
WriteString( "PER_FACE_ATTR_SIZE");
WriteInt( stdb->SizeOf());
WriteOut(stdb->DataBegin(),m.face.size(),stdb->SizeOf() );
}
}
}
}
///* save the per mesh attributes */
{
typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai;
unsigned int n_named_attr = 0;
for(ai = m.mesh_attr.begin(); ai != m.mesh_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty();
WriteString( "N_PER_MESH_ATTRIBUTES"); WriteInt( n_named_attr);
for(ai = m.mesh_attr.begin(); ai != m.mesh_attr.end(); ++ai)
if(!(*ai)._name.empty())
{
///* save the per mesh attributes */
{
typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai;
unsigned int n_named_attr = 0;
for(ai = m.mesh_attr.begin(); ai != m.mesh_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty();
WriteString( "N_PER_MESH_ATTRIBUTES"); WriteInt( n_named_attr);
for(ai = m.mesh_attr.begin(); ai != m.mesh_attr.end(); ++ai)
if(!(*ai)._name.empty())
{
SimpleTempDataBase * handle = (SimpleTempDataBase *) (*ai)._handle ;
WriteString( "PER_MESH_ATTR_NAME");
WriteString( (*ai)._name.c_str());
WriteString( "PER_MESH_ATTR_SIZE");
WriteInt( handle->SizeOf());
WriteString( "PER_MESH_ATTR_NAME");
WriteString( (*ai)._name.c_str());
WriteString( "PER_MESH_ATTR_SIZE");
WriteInt( handle->SizeOf());
WriteOut(handle->DataBegin(),1,handle->SizeOf() );
}
}
}
}
// fflush(F());
// fflush(F());
return 0;
}
}
static const char *ErrorMsg(int error)
{
static std::vector<std::string> off_error_msg;
@ -439,7 +424,7 @@ namespace io {
if(error>1 || error<0) return "Unknown error";
else return off_error_msg[error].c_str();
}
}; // end class
}; // end class
} // end Namespace tri
} // end Namespace io

View File

@ -128,6 +128,7 @@ namespace io {
m.vert_attr.erase(res);
pa._padding = padd;
std::pair<HWIte,bool > new_pa = m.vert_attr.insert(pa);
(void)new_pa;
assert(new_pa.second);
}
else
@ -155,6 +156,7 @@ namespace io {
m.face_attr.erase(res);
pa._padding = padd;
std::pair<HWIte,bool > new_pa = m.face_attr.insert(pa);
(void)new_pa;
assert(new_pa.second);
}
else
@ -180,6 +182,7 @@ namespace io {
m.mesh_attr.erase(res);
pa._padding = padd;
std::pair<HWIte,bool > new_pa = m.mesh_attr.insert(pa);
(void)new_pa;
assert(new_pa.second);
}
else