Corrected triangulation bug in off file.

This commit is contained in:
Paolo Cignoni 2012-11-06 21:54:13 +00:00
parent c72396e6f7
commit 45b736926a
1 changed files with 89 additions and 67 deletions

View File

@ -404,11 +404,12 @@ namespace vcg
}
else
{
// The face must be triangulate
// The face must be triangulated
unsigned int trigs = vert_per_face-3; // number of extra faces to add
nFaces += trigs;
Allocator<MESH_TYPE>::AddFaces(mesh, trigs);
std::vector<int> vertIndices(vert_per_face);
std::vector<vcg::Point3f > polygonVect(vert_per_face); // vec of polygon loops used for the triangulation of polygonal face
for (int j=0; j < vert_per_face; j++)
{
if (k == tokens.size()) // if EOL // Go to next line when needed
@ -418,6 +419,7 @@ namespace vcg
k = 0;
}
vertIndices[j] = atoi(tokens[k].c_str());
polygonVect[j] = mesh.vert[ vertIndices[j] ].P();
k++;
}
if(vert_per_face==4)
@ -428,9 +430,8 @@ namespace vcg
BitQuad<MESH_TYPE>::QuadTriangulate(q);
for(int qqi=0;qqi<4;++qqi)
vertIndices[qqi] = q[qqi]- & mesh.vert[0];
}
// standard fan triangulation (we hope the polygon is convex...)
for (int j=0; j<=vert_per_face-3; j++)
// build a two face fan
for (int j=0; j<2; j++)
{
mesh.face[f+j].V(0) = &(mesh.vert[ vertIndices[0 ] ]);
mesh.face[f+j].V(1) = &(mesh.vert[ vertIndices[1+j] ]);
@ -442,6 +443,27 @@ namespace vcg
loadmask |= Mask::IOM_BITPOLYGONAL;
}
}
}
else // standard fan triangulation (we hope the polygon is convex...)
{
std::vector<int> indexTriangulatedVect;
// TessellatePlanarPolygon3(polygonVect,indexTriangulatedVect);
std::vector< std::vector<Point3f> > loopVect;
loopVect.push_back(polygonVect);
#ifdef __gl_h_
//qDebug("OK: using opengl tessellation for a polygon of %i vertices",vertexesPerFace);
vcg::glu_tesselator::tesselate<vcg::Point3f>(loopVect, indexTriangulatedVect);
#else
//qDebug("Warning: using fan tessellation for a polygon of %i vertices",vertexesPerFace);
InternalFanTessellator(loopVect, indexTriangulatedVect);
#endif
for (int j=0; j<indexTriangulatedVect.size(); j+=3)
{
mesh.face[f+j/3].V(0) = &(mesh.vert[ vertIndices[ indexTriangulatedVect[j+0] ] ]);
mesh.face[f+j/3].V(1) = &(mesh.vert[ vertIndices[ indexTriangulatedVect[j+1] ] ]);
mesh.face[f+j/3].V(2) = &(mesh.vert[ vertIndices[ indexTriangulatedVect[j+2] ] ]);
}
}
f+=trigs;
}
@ -540,7 +562,7 @@ namespace vcg
std::string line;
do
std::getline(stream, line, '\n');
while (line[0] == '#' || line.length()==0);
while (line[0] == '#' || line.length()==0 || line[0]=='\r');
size_t from = 0;
size_t to = 0;