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

@ -1,196 +1,194 @@
/**************************************************************************** /****************************************************************************
* VCGLib o o * * VCGLib o o *
* Visual and Computer Graphics Library o o * * Visual and Computer Graphics Library o o *
* _ O _ * * _ O _ *
* Copyright(C) 2004 \/)\/ * * Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| * * Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | * * ISTI - Italian National Research Council | *
* \ * * \ *
* All rights reserved. * * 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 * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
* This program is distributed in the hope that it will be useful, * * This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. * * for more details. *
* * * *
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
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
****************************************************************************/ ****************************************************************************/
namespace vcg { namespace vcg {
namespace tri { namespace tri {
template <class AllocateMeshType> template <class AllocateMeshType>
class Allocator class Allocator
{ {
public: public:
typedef AllocateMeshType MeshType; typedef AllocateMeshType MeshType;
typedef typename MeshType::VertexPointer VertexPointer; typedef typename MeshType::VertexType VertexType;
typedef typename MeshType::VertexIterator VertexIterator; typedef typename MeshType::VertexPointer VertexPointer;
typedef typename MeshType::FacePointer FacePointer; typedef typename MeshType::VertexIterator VertexIterator;
typedef typename MeshType::FaceIterator FaceIterator; typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::FacePointer FacePointer;
/* This class is used to */ typedef typename MeshType::FaceIterator FaceIterator;
template<class SimplexPointerType>
class PointerUpdater /* 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.
public: It can also be used to prevent any update of the various mesh fields
void Clear(); (e.g. in case you are building all the connections by hand as in a importer);
void Update(SimplexPointerType &vp); */
bool NeedUpdate(); template<class SimplexPointerType>
class PointerUpdater
SimplexPointerType oldBase; {
SimplexPointerType newBase; public:
}; void Clear(){newBase=oldBase=newEnd=oldEnd=0;preventUpdateFlag=false;};
void Update(SimplexPointerType &vp)
{
/** Function to add n vertices to the mesh. The second parameter hold a vector of vp=newBase+(vp-oldBase);
pointers to pointer to elements of the mesh that should be updated after a }
possible vector realloc. bool NeedUpdate() {if(newBase!=oldBase && !preventUpdateFlag) return true; else return false;}
@param n Il numero di vertici che si vuole aggiungere alla mesh.
@param local_var Vettore di variabili locali che rappresentano puntatori a vertici. SimplexPointerType oldBase;
restituisce l'iteratore al primo elemento aggiunto. SimplexPointerType newBase;
*/ SimplexPointerType newEnd;
static VertexIterator AddVertices(MeshType &m,int n, PointerUpdater<VertexPointer> &pu) SimplexPointerType oldEnd;
{ bool preventUpdateFlag; // when true no update is considered necessary.
VertexIterator last=m.vert.end(); };
pu.Clear();
if(m.vert.empty()) pu.oldBase=0; // if the vector is empty we cannot find the last valid element
else pu.oldBase=&*m.vert.begin(); /** Function to add n vertices to the mesh. The second parameter hold a vector of
pointers to pointer to elements of the mesh that should be updated after a
for(int i=0; i<n; ++i) possible vector realloc.
{ @param n Il numero di vertici che si vuole aggiungere alla mesh.
m.vert.push_back(MeshType::VertexType()); @param local_var Vettore di variabili locali che rappresentano puntatori a vertici.
m.vert.back().ClearFlags(); restituisce l'iteratore al primo elemento aggiunto.
} */
static VertexIterator AddVertices(MeshType &m,int n, PointerUpdater<VertexPointer> &pu)
m.vn+=n; {
VertexIterator last=m.vert.end();
pu.newBase = &*m.vert.begin(); pu.Clear();
if(pu.NeedUpdate()) if(m.vert.empty()) pu.oldBase=0; // if the vector is empty we cannot find the last valid element
{ else pu.oldBase=&*m.vert.begin();
FaceIterator fi;
for (fi=m.face.begin(); fi!=m.face.end(); ++fi) for(int i=0; i<n; ++i)
if(!(*fi).IsD()) {
{ m.vert.push_back(MeshType::VertexType());
pu.Update((*fi).V(0)); m.vert.back().ClearFlags();
pu.Update((*fi).V(1)); }
pu.Update((*fi).V(2));
} m.vn+=n;
// e poiche' lo spazio e' cambiato si ricalcola anche last da zero pu.newBase = &*m.vert.begin();
if(last!=0) if(pu.NeedUpdate())
{ {
last = m.vert.begin(); FaceIterator fi;
advance(last,siz+1); for (fi=m.face.begin(); fi!=m.face.end(); ++fi)
} if(!(*fi).IsD())
else last=m.vert.begin(); {
} pu.Update((*fi).V(0));
pu.Update((*fi).V(1));
return last;// deve restituire l'iteratore alla prima faccia aggiunta; pu.Update((*fi).V(2));
} }
static VertexIterator AddVertices(MeshType &m, int n) // e poiche' lo spazio e' cambiato si ricalcola anche last da zero
{ if(last!=0)
PointerUpdater<VertexPointer> pu; {
return AddVertices(m, n,pu); last = m.vert.begin();
} advance(last,n);
}
/** Function to add n faces to the mesh. else last=m.vert.begin();
@param n Il numero di facce che si vuole aggiungere alla mesh }
*/
static FaceIterator AddFaces(MeshType &m, int n) return last;// deve restituire l'iteratore alla prima faccia aggiunta;
{ }
PointerUpdater<FacePointer> pu;
return AddFaces(m,n,pu); static VertexIterator AddVertices(MeshType &m, int n)
} {
/** Function to add n faces to the mesh. PointerUpdater<VertexPointer> pu;
NOTA: Aggiorna fn; return AddVertices(m, n,pu);
The second parameter hold a vector of }
pointers to pointer to elements of the mesh that should be updated after a
possible vector realloc. /** Function to add n faces to the mesh.
@param n Facce da aggiungere @param n Il numero di facce che si vuole aggiungere alla mesh
@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 static FaceIterator AddFaces(MeshType &m, int n)
del contenitore delle facce. {
*/ PointerUpdater<FacePointer> pu;
static FaceIterator AddFaces(MeshType &m, int n, PointerUpdater<FacePointer> &pu) return AddFaces(m,n,pu);
{ }
FaceIterator last=m.vert.end(); /** Function to add n faces to the mesh.
pu.Clear(); NOTA: Aggiorna fn;
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(); static FaceIterator AddFaces(MeshType &m, int n, PointerUpdater<FacePointer> &pu)
{
unsigned int siz=0; for(int i=0; i<n; ++i) FaceIterator last=m.face.end();
{ pu.Clear();
m.face.push_back(MeshType::FaceType()); if(m.face.empty()) pu.oldBase=0; // if the vector is empty we cannot find the last valid element
m.face.back().ClearFlags(); else pu.oldBase=&*m.face.begin();
}
unsigned int siz=0; for(int i=0; i<n; ++i)
m.fn+=n; {
m.face.push_back(MeshType::FaceType());
pu.newBase = &*m.face.begin(); m.face.back().ClearFlags();
}
FaceIterator oldbegin, newbegin;
oldbegin = face.begin(); m.fn+=n;
FaceIterator last=face.end();
if(face.empty()) last=0; pu.newBase = &*m.face.begin();
else last--;
if(pu.NeedUpdate())
unsigned int siz=0; {
MFTYPE dum; FaceIterator fi;
dum.Supervisor_Flags()=0; for (fi=m.face.begin(); fi!=m.face.end(); ++fi)
for(int i=0; i<n; ++i) if(!(*fi).IsD())
face.push_back(dum); {
if(FaceType::HasFFAdjacency())
fn+=n; {
newbegin = face.begin(); pu.Update((*fi).F(0));
if(newbegin != oldbegin)// se e' cambiato lo spazio (vector abbastanza grande o lista) pu.Update((*fi).F(1));
{ pu.Update((*fi).F(2));
if(MFTYPE::OBJ_TYPE & MFTYPE::OBJ_TYPE_A) }
{ }
FaceIterator f; VertexIterator vi;
for (f=face.begin(); f!=face.end(); ++f) for (vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
for(int k=0; k<(*f).size(); ++k)if(!(*f).IsD()) if(!(*vi).IsD())
(*f).F(k) = (*f).F(k)-&*oldbegin+&*newbegin; {
} if(VertexType::HasVFAdjacency())
vector<face_base **>::iterator jit; {
for(jit=local_var.begin(); jit!=local_var.end(); ++jit) pu.Update((*fi).F(0));
if((**jit) !=0 ) **jit = **jit-&*oldbegin+&*newbegin; pu.Update((*fi).F(1));
pu.Update((*fi).F(2));
// deve restituire l'iteratore alla prima faccia aggiunta; }
if(last!=0) }
{ // e poiche' lo spazio e' cambiato si ricalcola anche last da zero
last = face.begin(); if(last!=0)
advance(last,siz+1); {
} last = m.face.begin();
else last=face.begin(); advance(last,n);
} }
else // else last=m.face.begin();
{ 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 return last;
else advance(last,1); // altrimenti il primo dopo quello che era in precedenza l'ultimo valido. }
}
}; // end class
return last; } // End Namespace TriMesh
} // End Namespace vcg
}
}; // end class
} // End Namespace TriMesh
} // End Namespace vcg

View File

@ -1,83 +1,118 @@
/**************************************************************************** /****************************************************************************
* VCGLib o o * * VCGLib o o *
* Visual and Computer Graphics Library o o * * Visual and Computer Graphics Library o o *
* _ O _ * * _ O _ *
* Copyright(C) 2004 \/)\/ * * Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| * * Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | * * ISTI - Italian National Research Council | *
* \ * * \ *
* All rights reserved. * * 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 * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
* This program is distributed in the hope that it will be useful, * * This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. * * for more details. *
* * * *
****************************************************************************/ ****************************************************************************/
bool Save_STL(const char * filename , bool binary =true, const char *objectname=0) /****************************************************************************
{ History
FILE *fp;
$Log: not supported by cvs2svn $
fp = fopen(filename,"wb"); Revision 1.3 2004/02/19 15:28:01 ponchio
if(fp==0) *** empty log message ***
return false;
Revision 1.2 2004/02/13 02:18:57 cignoni
if(binary) Edited Comments and GPL license
{
// Write Header
char *header="VCG "; ****************************************************************************/
if(objectname) strncpy(header,objectname,80);
fwrite(header,80,1,fp); #ifndef __VCGLIB_EXPORT_STL
// write number of facets #define __VCGLIB_EXPORT_STL
fwrite(&fn,1,sizeof(int),fp);
face_iterator fi; #include <stdio.h>
Point3f p;
unsigned short attributes=0; namespace vcg {
namespace tri {
for(fi=face.begin(); fi!=face.end(); ++fi) if( !(*fi).IsD() ) namespace io {
{
// For each triangle write the normal, the three coords and a short set to zero template <class SaveMeshType>
p.Import(vcg::NormalizedNormal((*fi).V(0)->P(), (*fi).V(1)->P(), (*fi).V(2)->P())); class ExporterSTL
fwrite(p.V(),3,sizeof(float),fp); {
public:
for(int k=0;k<3;++k){ static bool Save(SaveMeshType &m, const char * filename , bool binary =true, const char *objectname=0)
p.Import((*fi).V(k)->P()); {
fwrite(p.V(),3,sizeof(float),fp); typedef typename SaveMeshType::FaceIterator FaceIterator;
} FILE *fp;
fwrite(&attributes,1,sizeof(short),fp);
} fp = fopen(filename,"wb");
} if(fp==0)
else return false;
{
if(objectname) fprintf(fp,"solid %s\n",objectname); if(binary)
else fprintf(fp,"solid vcg\n"); {
// Write Header
Point3f p; char *header="VCG ";
face_iterator fi; if(objectname) strncpy(header,objectname,80);
for(fi=face.begin(); fi!=face.end(); ++fi) if( !(*fi).IsD() ) fwrite(header,80,1,fp);
{ // write number of facets
// For each triangle write the normal, the three coords and a short set to zero fwrite(&m.fn,1,sizeof(int),fp);
p.Import(vcg::NormalizedNormal((*fi).V(0)->P(), (*fi).V(1)->P(), (*fi).V(2)->P())); Point3f p;
fprintf(fp," facet normal %13e %13e %13e\n",p[0],p[1],p[2]); unsigned short attributes=0;
fprintf(fp," outer loop\n");
for(int k=0;k<3;++k){ FaceIterator fi;
p.Import((*fi).V(k)->P()); for(fi=m.face.begin(); fi!=m.face.end(); ++fi) if( !(*fi).IsD() )
fprintf(fp," vertex %13e %13e %13e\n",p[0],p[1],p[2]); {
} // For each triangle write the normal, the three coords and a short set to zero
fprintf(fp," endloop\n"); p.Import(vcg::NormalizedNormal((*fi).V(0)->P(), (*fi).V(1)->P(), (*fi).V(2)->P()));
fprintf(fp," endfacet\n"); fwrite(p.V(),3,sizeof(float),fp);
}
fprintf(fp,"endsolid vcg\n"); for(int k=0;k<3;++k){
} p.Import((*fi).V(k)->P());
fclose(fp); fwrite(p.V(),3,sizeof(float),fp);
return true; }
} fwrite(&attributes,1,sizeof(short),fp);
}
//@} }
else
{
if(objectname) fprintf(fp,"solid %s\n",objectname);
else fprintf(fp,"solid vcg\n");
Point3f p;
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
p.Import(vcg::NormalizedNormal((*fi).V(0)->P(), (*fi).V(1)->P(), (*fi).V(2)->P()));
fprintf(fp," facet normal %13e %13e %13e\n",p[0],p[1],p[2]);
fprintf(fp," outer loop\n");
for(int k=0;k<3;++k){
p.Import((*fi).V(k)->P());
fprintf(fp," vertex %13e %13e %13e\n",p[0],p[1],p[2]);
}
fprintf(fp," endloop\n");
fprintf(fp," endfacet\n");
}
fprintf(fp,"endsolid vcg\n");
}
fclose(fp);
return true;
}
}; // end class
} // end Namespace tri
} // end Namespace io
} // end Namespace vcg
//@}
#endif