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
35 #pragma warning(disable : 4996)
50 numCustomIndices(0),numTriangles(0),numPoints(0),
51 aCoords(NULL),aCustomIndices(NULL),aTriangles(NULL)
53 #if GEOM_PSEUDO3D==GEOM_TRUE
84 size_t siz(3*numTriangles);
85 aTriangles=
new int[siz];
90 size_t siz(dim*numPoints);
91 aCoords=
new double[siz];
96 aCustomIndices=
new int[numCustomIndices];
107 if(aCoords!=NULL)
delete [] aCoords;
108 if(aCustomIndices!=NULL)
delete [] aCustomIndices;
109 if(aTriangles!=NULL)
delete [] aTriangles;
130 bool writeObj(
const char* filename)
const;
133 void extractTriangleNeighborships(std::vector<std::pair<int,int> >& vNeigs)
const;
140 void getCornerIndices(
int triIdx,
int& vtxIdx0,
int& vtxIdx1,
int& vtxIdx2)
const;
148 int getCustomIndex(
int vtxIdx)
const;
150 #if GEOM_PSEUDO3D==GEOM_TRUE
152 void getNormal(
int triIdx,
double& x,
double& y,
double& z)
const;
155 #if GEOM_PSEUDO3D==GEOM_TRUE
161 void getCoordinates(
int vtxIdx,
double& x,
double& y,
double& z)
const;
168 void getCoordinates(
int vtxIdx,
double& x,
double& y)
const;
170 bool operator==(
const FadeExport& other)
const;
181 inline FadeExport::~FadeExport()
183 if(aCoords!=NULL)
delete [] aCoords;
184 if(aCustomIndices!=NULL)
delete [] aCustomIndices;
185 if(aTriangles!=NULL)
delete [] aTriangles;
191 inline bool FadeExport::operator==(
const FadeExport& other)
const
193 if(numTriangles != other.numTriangles)
return false;
194 if(numPoints != other.numPoints)
return false;
196 for(
int vtxIdx=0;vtxIdx<numPoints;++vtxIdx)
198 for(
int component=0;component<dim;++component)
200 size_t addr(dim*vtxIdx+component);
201 if(aCoords[addr]!=other.aCoords[addr])
return false;
205 for(
int triIdx=0;triIdx<numTriangles;++triIdx)
208 getCornerIndices(
int(triIdx),v0,v1,v2);
210 other.getCornerIndices(
int(triIdx),va,vb,vc);
211 if(v0!=va || v1!=vb || v2!=vc)
return false;
218 inline void FadeExport::getCornerIndices(
int triIdx,
int& vtxIdx0,
int& vtxIdx1,
int& vtxIdx2)
const
221 vtxIdx0=aTriangles[base];
222 vtxIdx1=aTriangles[base+1];
223 vtxIdx2=aTriangles[base+2];
227 inline void FadeExport::print()
const
229 for(
int vtxIdx=0;vtxIdx<numPoints;++vtxIdx)
232 if(numCustomIndices>0) customIndex=aCustomIndices[vtxIdx];
233 std::cout<<
"\nVertex "<<vtxIdx<<
" (customIndex="<<customIndex<<
"):";
234 for(
int component=0;component<dim;++component) std::cout<<
" "<<aCoords[dim*vtxIdx+component];
237 for(
int triIdx=0;triIdx<numTriangles;++triIdx)
240 getCornerIndices(
int(triIdx),v0,v1,v2);
241 std::cout<<
"\nTriangle "<<triIdx<<
": "<<v0<<
" "<<v1<<
" "<<v2;
244 std::vector<std::pair<int,int> > vNeighbors;
245 this->extractTriangleNeighborships(vNeighbors);
246 for(
size_t i=0;i<vNeighbors.size();++i)
248 std::cout<<
"\nTriangle "<<vNeighbors[i].first<<
" <-> Triangle "<<vNeighbors[i].second;
250 std::cout<<std::endl;
254 inline bool FadeExport::writeObj(
const char* filename)
const
256 std::ofstream outFile(filename);
257 if(!outFile.is_open())
259 std::cout<<
"Can't write "<<filename<<std::endl;
262 std::cout<<
"writing "<<filename<<std::endl;
264 outFile<<
"# Written by Fade2D";
265 for(
int vtxIdx=0;vtxIdx<numPoints;++vtxIdx)
268 for(
int component=0;component<dim;++component) outFile<<
" "<<aCoords[dim*vtxIdx+component];
269 if(dim==2) outFile<<
" 0";
271 for(
int triIdx=0;triIdx<numTriangles;++triIdx)
274 for(
int corner=0;corner<3;++corner)
276 outFile<<
" "<<aTriangles[3*triIdx+corner]+1;
285 inline void FadeExport::extractTriangleNeighborships(std::vector<std::pair<int,int> >& vNeigs)
const
287 vNeigs.reserve(numTriangles*3/2);
288 std::vector<std::pair<std::pair<int,int>,
int> > vVtxPair2Tri;
289 vVtxPair2Tri.reserve(numTriangles*3);
291 for(
int tri=0;tri<numTriangles;++tri)
293 size_t vtxIdx(3*tri);
294 int vtx0(aTriangles[vtxIdx]);
295 int vtx1(aTriangles[vtxIdx+1]);
296 int vtx2(aTriangles[vtxIdx+2]);
297 if(vtx0>vtx1) std::swap(vtx0,vtx1);
300 std::swap(vtx1,vtx2);
301 if(vtx0>vtx1) std::swap(vtx0,vtx1);
303 vVtxPair2Tri.push_back(std::make_pair(std::make_pair(vtx0,vtx1),tri));
304 vVtxPair2Tri.push_back(std::make_pair(std::make_pair(vtx1,vtx2),tri));
305 vVtxPair2Tri.push_back(std::make_pair(std::make_pair(vtx0,vtx2),tri));
307 std::sort(vVtxPair2Tri.begin(),vVtxPair2Tri.end());
308 for(
size_t i=0;i<vVtxPair2Tri.size();++i)
310 int vtx0(vVtxPair2Tri[i].first.first);
311 int vtx1(vVtxPair2Tri[i].first.second);
312 int tri0(vVtxPair2Tri[i].second);
314 if( ++i<vVtxPair2Tri.size() &&
315 vVtxPair2Tri[i].first.first==vtx0 &&
316 vVtxPair2Tri[i].first.second==vtx1)
318 int tri1(vVtxPair2Tri[i].second);
319 vNeigs.push_back(std::pair<int,int>(tri0,tri1));
326 #if GEOM_PSEUDO3D==GEOM_TRUE
327 inline void FadeExport::getCoordinates(
int vtxIdx,
double& x,
double& y,
double& z)
const
329 int base(dim*vtxIdx);
335 inline void FadeExport::getCoordinates(
int vtxIdx,
double& x,
double& y)
const
337 int base(dim*vtxIdx);
343 inline int FadeExport::getCustomIndex(
int vtxIdx)
const
345 if(vtxIdx<numCustomIndices)
347 return aCustomIndices[vtxIdx];
FadeExport is a simple struct to export triangulation data.
Definition: FadeExport.h:48
void reset()
Reset the object.
Definition: FadeExport.h:105
void lexiSort()
Sort the points lexicographically.
double * aCoords
Cartesian coordinates (dim*numPoints)
Definition: FadeExport.h:175
int * aCustomIndices
Custom indices of the points (only when exported)
Definition: FadeExport.h:176
int numTriangles
number of triangles
Definition: FadeExport.h:173
int * aTriangles
3 counterclockwise oriented vertex-indices per triangle (3*numTriangles)
Definition: FadeExport.h:177
int dim
Dimension.
Definition: FadeExport.h:178
int numCustomIndices
number of custom indices (same as numPoints when exported, otherwise 0)
Definition: FadeExport.h:172
int numPoints
number of points
Definition: FadeExport.h:174