Yet another cr lf mismatch

This commit is contained in:
Paolo Cignoni 2004-03-03 15:35:53 +00:00
parent cd85d6ca7d
commit 0556b33b65
2 changed files with 309 additions and 276 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.1 2004/02/24 21:36:42 cignoni
grouped documentation, changed typenames and reflection mechanism
Revision 1.1 2004/02/19 13:11:06 cignoni Revision 1.1 2004/02/19 13:11:06 cignoni
Initial commit Initial commit
@ -39,22 +42,34 @@ class Allocator
public: public:
typedef AllocateMeshType MeshType; typedef AllocateMeshType MeshType;
typedef typename MeshType::VertexType VertexType;
typedef typename MeshType::VertexPointer VertexPointer; typedef typename MeshType::VertexPointer VertexPointer;
typedef typename MeshType::VertexIterator VertexIterator; typedef typename MeshType::VertexIterator VertexIterator;
typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::FacePointer FacePointer; typedef typename MeshType::FacePointer FacePointer;
typedef typename MeshType::FaceIterator FaceIterator; typedef typename MeshType::FaceIterator FaceIterator;
/* This class is used to */ /* This class is used when allocating new vertex and faces to update
the pointer that can be changed when resizing the vector of vertex or faces.
It can also be used to prevent any update of the various mesh fields
(e.g. in case you are building all the connections by hand as in a importer);
*/
template<class SimplexPointerType> template<class SimplexPointerType>
class PointerUpdater class PointerUpdater
{ {
public: public:
void Clear(); void Clear(){newBase=oldBase=newEnd=oldEnd=0;preventUpdateFlag=false;};
void Update(SimplexPointerType &vp); void Update(SimplexPointerType &vp)
bool NeedUpdate(); {
vp=newBase+(vp-oldBase);
}
bool NeedUpdate() {if(newBase!=oldBase && !preventUpdateFlag) return true; else return false;}
SimplexPointerType oldBase; SimplexPointerType oldBase;
SimplexPointerType newBase; SimplexPointerType newBase;
SimplexPointerType newEnd;
SimplexPointerType oldEnd;
bool preventUpdateFlag; // when true no update is considered necessary.
}; };
@ -96,7 +111,7 @@ static VertexIterator AddVertices(MeshType &m,int n, PointerUpdater<VertexPointe
if(last!=0) if(last!=0)
{ {
last = m.vert.begin(); last = m.vert.begin();
advance(last,siz+1); advance(last,n);
} }
else last=m.vert.begin(); else last=m.vert.begin();
} }
@ -120,17 +135,10 @@ static FaceIterator AddFaces(MeshType &m, int n)
} }
/** Function to add n faces to the mesh. /** Function to add n faces to the mesh.
NOTA: Aggiorna fn; NOTA: Aggiorna fn;
The second parameter hold a vector of
pointers to pointer to elements of the mesh that should be updated after a
possible vector realloc.
@param n Facce da aggiungere
@param local_var Vettore di variabili locali che rappresentano puntatori a facce, occorre,
perche' questi valori siano consistenti, aggiornarli ogni qual volta venga eseguito un resize
del contenitore delle facce.
*/ */
static FaceIterator AddFaces(MeshType &m, int n, PointerUpdater<FacePointer> &pu) static FaceIterator AddFaces(MeshType &m, int n, PointerUpdater<FacePointer> &pu)
{ {
FaceIterator last=m.vert.end(); FaceIterator last=m.face.end();
pu.Clear(); pu.Clear();
if(m.face.empty()) pu.oldBase=0; // if the vector is empty we cannot find the last valid element if(m.face.empty()) pu.oldBase=0; // if the vector is empty we cannot find the last valid element
else pu.oldBase=&*m.face.begin(); else pu.oldBase=&*m.face.begin();
@ -145,50 +153,40 @@ static FaceIterator AddFaces(MeshType &m, int n, PointerUpdater<FacePointer> &pu
pu.newBase = &*m.face.begin(); pu.newBase = &*m.face.begin();
FaceIterator oldbegin, newbegin; if(pu.NeedUpdate())
oldbegin = face.begin();
FaceIterator last=face.end();
if(face.empty()) last=0;
else last--;
unsigned int siz=0;
MFTYPE dum;
dum.Supervisor_Flags()=0;
for(int i=0; i<n; ++i)
face.push_back(dum);
fn+=n;
newbegin = face.begin();
if(newbegin != oldbegin)// se e' cambiato lo spazio (vector abbastanza grande o lista)
{ {
if(MFTYPE::OBJ_TYPE & MFTYPE::OBJ_TYPE_A) FaceIterator fi;
for (fi=m.face.begin(); fi!=m.face.end(); ++fi)
if(!(*fi).IsD())
{ {
FaceIterator f; if(FaceType::HasFFAdjacency())
for (f=face.begin(); f!=face.end(); ++f) {
for(int k=0; k<(*f).size(); ++k)if(!(*f).IsD()) pu.Update((*fi).F(0));
(*f).F(k) = (*f).F(k)-&*oldbegin+&*newbegin; pu.Update((*fi).F(1));
pu.Update((*fi).F(2));
} }
vector<face_base **>::iterator jit; }
for(jit=local_var.begin(); jit!=local_var.end(); ++jit) VertexIterator vi;
if((**jit) !=0 ) **jit = **jit-&*oldbegin+&*newbegin; for (vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
if(!(*vi).IsD())
// deve restituire l'iteratore alla prima faccia aggiunta; {
if(VertexType::HasVFAdjacency())
{
pu.Update((*fi).F(0));
pu.Update((*fi).F(1));
pu.Update((*fi).F(2));
}
}
// e poiche' lo spazio e' cambiato si ricalcola anche last da zero
if(last!=0) if(last!=0)
{ {
last = face.begin(); last = m.face.begin();
advance(last,siz+1); advance(last,n);
} }
else last=face.begin(); else last=m.face.begin();
}
else //
{ assert(newbegin == oldbegin);
// se non e'cambiato lo spazio (vector abbastanza grande o lista)
if(last==0) last = face.begin(); // se il vettore era vuoto si restituisce begin
else advance(last,1); // altrimenti il primo dopo quello che era in precedenza l'ultimo valido.
} }
return last; return last;
} }
}; // end class }; // end class

View File

@ -21,8 +21,35 @@
* * * *
****************************************************************************/ ****************************************************************************/
bool Save_STL(const char * filename , bool binary =true, const char *objectname=0) /****************************************************************************
History
$Log: not supported by cvs2svn $
Revision 1.3 2004/02/19 15:28:01 ponchio
*** empty log message ***
Revision 1.2 2004/02/13 02:18:57 cignoni
Edited Comments and GPL license
****************************************************************************/
#ifndef __VCGLIB_EXPORT_STL
#define __VCGLIB_EXPORT_STL
#include <stdio.h>
namespace vcg {
namespace tri {
namespace io {
template <class SaveMeshType>
class ExporterSTL
{ {
public:
static bool Save(SaveMeshType &m, const char * filename , bool binary =true, const char *objectname=0)
{
typedef typename SaveMeshType::FaceIterator FaceIterator;
FILE *fp; FILE *fp;
fp = fopen(filename,"wb"); fp = fopen(filename,"wb");
@ -36,12 +63,12 @@ bool Save_STL(const char * filename , bool binary =true, const char *objectname=
if(objectname) strncpy(header,objectname,80); if(objectname) strncpy(header,objectname,80);
fwrite(header,80,1,fp); fwrite(header,80,1,fp);
// write number of facets // write number of facets
fwrite(&fn,1,sizeof(int),fp); fwrite(&m.fn,1,sizeof(int),fp);
face_iterator fi;
Point3f p; Point3f p;
unsigned short attributes=0; unsigned short attributes=0;
for(fi=face.begin(); fi!=face.end(); ++fi) if( !(*fi).IsD() ) FaceIterator fi;
for(fi=m.face.begin(); fi!=m.face.end(); ++fi) if( !(*fi).IsD() )
{ {
// For each triangle write the normal, the three coords and a short set to zero // For each triangle write the normal, the three coords and a short set to zero
p.Import(vcg::NormalizedNormal((*fi).V(0)->P(), (*fi).V(1)->P(), (*fi).V(2)->P())); p.Import(vcg::NormalizedNormal((*fi).V(0)->P(), (*fi).V(1)->P(), (*fi).V(2)->P()));
@ -60,8 +87,8 @@ bool Save_STL(const char * filename , bool binary =true, const char *objectname=
else fprintf(fp,"solid vcg\n"); else fprintf(fp,"solid vcg\n");
Point3f p; Point3f p;
face_iterator fi; FaceIterator fi;
for(fi=face.begin(); fi!=face.end(); ++fi) if( !(*fi).IsD() ) for(fi=m.face.begin(); fi!=m.face.end(); ++fi) if( !(*fi).IsD() )
{ {
// For each triangle write the normal, the three coords and a short set to zero // For each triangle write the normal, the three coords and a short set to zero
p.Import(vcg::NormalizedNormal((*fi).V(0)->P(), (*fi).V(1)->P(), (*fi).V(2)->P())); p.Import(vcg::NormalizedNormal((*fi).V(0)->P(), (*fi).V(1)->P(), (*fi).V(2)->P()));
@ -79,5 +106,13 @@ bool Save_STL(const char * filename , bool binary =true, const char *objectname=
fclose(fp); fclose(fp);
return true; return true;
} }
}; // end class
} // end Namespace tri
} // end Namespace io
} // end Namespace vcg
//@} //@}
#endif