25 #if GEOM_PSEUDO3D==GEOM_TRUE
26 namespace GEOM_FADE25D {
27 #elif GEOM_PSEUDO3D==GEOM_FALSE
28 namespace GEOM_FADE2D {
30 #error GEOM_PSEUDO3D is not defined
45 numCustomIndices(0),numTriangles(0),numPoints(0),
46 aCoords(NULL),aCustomIndices(NULL),aTriangles(NULL)
48 #if GEOM_PSEUDO3D==GEOM_TRUE
79 size_t siz(3*numTriangles);
80 aTriangles=
new int[siz];
85 size_t siz(dim*numPoints);
86 aCoords=
new double[siz];
91 aCustomIndices=
new int[numCustomIndices];
102 if(aCoords!=NULL)
delete [] aCoords;
103 if(aCustomIndices!=NULL)
delete [] aCustomIndices;
104 if(aTriangles!=NULL)
delete [] aTriangles;
125 bool writeObj(
const char* filename)
const;
128 void extractTriangleNeighborships(std::vector<std::pair<int,int> >& vNeigs)
const;
135 void getCornerIndices(
int triIdx,
int& vtxIdx0,
int& vtxIdx1,
int& vtxIdx2)
const;
143 int getCustomIndex(
int vtxIdx)
const;
145 #if GEOM_PSEUDO3D==GEOM_TRUE
147 void getNormal(
int triIdx,
double& x,
double& y,
double& z)
const;
150 #if GEOM_PSEUDO3D==GEOM_TRUE
156 void getCoordinates(
int vtxIdx,
double& x,
double& y,
double& z)
const;
163 void getCoordinates(
int vtxIdx,
double& x,
double& y)
const;
165 bool operator==(
const FadeExport& other)
const;
176 inline FadeExport::~FadeExport()
178 if(aCoords!=NULL)
delete [] aCoords;
179 if(aCustomIndices!=NULL)
delete [] aCustomIndices;
180 if(aTriangles!=NULL)
delete [] aTriangles;
186 inline bool FadeExport::operator==(
const FadeExport& other)
const
188 if(numTriangles != other.numTriangles)
return false;
189 if(numPoints != other.numPoints)
return false;
191 for(
int vtxIdx=0;vtxIdx<numPoints;++vtxIdx)
193 for(
int component=0;component<dim;++component)
195 size_t addr(dim*vtxIdx+component);
196 if(aCoords[addr]!=other.aCoords[addr])
return false;
200 for(
int triIdx=0;triIdx<numTriangles;++triIdx)
203 getCornerIndices(
int(triIdx),v0,v1,v2);
205 other.getCornerIndices(
int(triIdx),va,vb,vc);
206 if(v0!=va || v1!=vb || v2!=vc)
return false;
216 vtxIdx0=aTriangles[base];
217 vtxIdx1=aTriangles[base+1];
218 vtxIdx2=aTriangles[base+2];
224 for(
int vtxIdx=0;vtxIdx<numPoints;++vtxIdx)
227 if(numCustomIndices>0) customIndex=aCustomIndices[vtxIdx];
228 std::cout<<
"\nVertex "<<vtxIdx<<
" (customIndex="<<customIndex<<
"):";
229 for(
int component=0;component<dim;++component) std::cout<<
" "<<aCoords[dim*vtxIdx+component];
232 for(
int triIdx=0;triIdx<numTriangles;++triIdx)
235 getCornerIndices(
int(triIdx),v0,v1,v2);
236 std::cout<<
"\nTriangle "<<triIdx<<
": "<<v0<<
" "<<v1<<
" "<<v2;
239 std::vector<std::pair<int,int> > vNeighbors;
240 this->extractTriangleNeighborships(vNeighbors);
241 for(
size_t i=0;i<vNeighbors.size();++i)
243 std::cout<<
"\nTriangle "<<vNeighbors[i].first<<
" <-> Triangle "<<vNeighbors[i].second;
245 std::cout<<std::endl;
251 std::ofstream outFile(filename);
252 if(!outFile.is_open())
254 std::cout<<
"Can't write "<<filename<<std::endl;
257 std::cout<<
"writing "<<filename<<std::endl;
259 outFile<<
"# Written by Fade2D";
260 for(
int vtxIdx=0;vtxIdx<numPoints;++vtxIdx)
263 for(
int component=0;component<dim;++component) outFile<<
" "<<aCoords[dim*vtxIdx+component];
264 if(dim==2) outFile<<
" 0";
266 for(
int triIdx=0;triIdx<numTriangles;++triIdx)
269 for(
int corner=0;corner<3;++corner)
271 outFile<<
" "<<aTriangles[3*triIdx+corner]+1;
282 vNeigs.reserve(numTriangles*3/2);
283 std::vector<std::pair<std::pair<int,int>,
int> > vVtxPair2Tri;
284 vVtxPair2Tri.reserve(numTriangles*3);
286 for(
int tri=0;tri<numTriangles;++tri)
288 size_t vtxIdx(3*tri);
289 int vtx0(aTriangles[vtxIdx]);
290 int vtx1(aTriangles[vtxIdx+1]);
291 int vtx2(aTriangles[vtxIdx+2]);
292 if(vtx0>vtx1) std::swap(vtx0,vtx1);
295 std::swap(vtx1,vtx2);
296 if(vtx0>vtx1) std::swap(vtx0,vtx1);
298 vVtxPair2Tri.push_back(std::make_pair(std::make_pair(vtx0,vtx1),tri));
299 vVtxPair2Tri.push_back(std::make_pair(std::make_pair(vtx1,vtx2),tri));
300 vVtxPair2Tri.push_back(std::make_pair(std::make_pair(vtx0,vtx2),tri));
302 std::sort(vVtxPair2Tri.begin(),vVtxPair2Tri.end());
303 for(
size_t i=0;i<vVtxPair2Tri.size();++i)
305 int vtx0(vVtxPair2Tri[i].first.first);
306 int vtx1(vVtxPair2Tri[i].first.second);
307 int tri0(vVtxPair2Tri[i].second);
309 if( ++i<vVtxPair2Tri.size() &&
310 vVtxPair2Tri[i].first.first==vtx0 &&
311 vVtxPair2Tri[i].first.second==vtx1)
313 int tri1(vVtxPair2Tri[i].second);
314 vNeigs.push_back(std::pair<int,int>(tri0,tri1));
321 #if GEOM_PSEUDO3D==GEOM_TRUE
324 int base(dim*vtxIdx);
332 int base(dim*vtxIdx);
340 if(vtxIdx<numCustomIndices)
342 return aCustomIndices[vtxIdx];
FadeExport is a simple struct to export triangulation data.
Definition: FadeExport.h:43
void reset()
Reset the object.
Definition: FadeExport.h:100
void getNormal(int triIdx, double &x, double &y, double &z) const
Get the normal vector of a triangle.
int numTriangles
number of triangles
Definition: FadeExport.h:168
void print() const
Print data for demonstration purposes.
Definition: FadeExport.h:222
void lexiSort()
Sort the points lexicographically.
int * aCustomIndices
Custom indices of the points (only when exported)
Definition: FadeExport.h:171
void getCornerIndices(int triIdx, int &vtxIdx0, int &vtxIdx1, int &vtxIdx2) const
Get the corner indices of a certain triangle.
Definition: FadeExport.h:213
int getCustomIndex(int vtxIdx) const
Get the custom vertex index.
Definition: FadeExport.h:338
int dim
Dimension.
Definition: FadeExport.h:173
void extractTriangleNeighborships(std::vector< std::pair< int, int > > &vNeigs) const
Determine index-pairs of adjacent triangles.
Definition: FadeExport.h:280
int numPoints
number of points
Definition: FadeExport.h:169
int numCustomIndices
number of custom indices (same as numPoints when exported, otherwise 0)
Definition: FadeExport.h:167
bool writeObj(const char *filename) const
Write an *.obj file (supported by virtually any 3D viewer)
Definition: FadeExport.h:249
double * aCoords
Cartesian coordinates (dim*numPoints)
Definition: FadeExport.h:170
void getCoordinates(int vtxIdx, double &x, double &y, double &z) const
Get the coorinates for a certain vertex index.
Definition: FadeExport.h:322
int * aTriangles
3 counterclockwise oriented vertex-indices per triangle (3*numTriangles)
Definition: FadeExport.h:172