Improved management of fauxbit for quad and polygonal meshes in OBJ (did not set the high level polygonal bit) and OFF (wrong faux bits for polygonal faces with more than 4 sides)

This commit is contained in:
Paolo Cignoni 2013-04-12 09:49:51 +00:00
parent 371ff46282
commit e77e13a8fe
2 changed files with 70 additions and 60 deletions

View File

@ -416,6 +416,8 @@ namespace vcg {
GoodObjIndex(indexTVect[pi],oi.numTexCoords);
polygonVect[0][pi].Import(m.vert[indexVVect[pi]].cP());
}
if(vertexesPerFace>3)
oi.mask |= Mask::IOM_BITPOLYGONAL;
if(vertexesPerFace<5)
InternalFanTessellator(polygonVect, indexTriangulatedVect);

View File

@ -58,7 +58,7 @@ namespace vcg
// OFF codes
enum OFFCodes {NoError=0, CantOpen, InvalidFile,
InvalidFile_MissingOFF,
UnsupportedFormat, ErrorNotTriangularFace,ErrorHighDimension,ErrorDegenerateFace};
UnsupportedFormat, ErrorNotTriangularFace,ErrorHighDimension,ErrorDegenerateFace};
/*!
* Standard call for knowing the meaning of an error code
@ -71,9 +71,9 @@ namespace vcg
{
"No errors", "Can't open file", "Invalid file",
"Invalid file: OFF file should have in the first line the OFF keyword as a first token",
"Unsupported format", "Face with more than 3 vertices","File with high dimensional vertexes are not supported", "Error Degenerate Face with less than 3 vertices" };
"Unsupported format", "Face with more than 3 vertices","File with high dimensional vertexes are not supported", "Error Degenerate Face with less than 3 vertices" };
if(message_code>6 || message_code<0)
if(message_code>6 || message_code<0)
return "Unknown error";
else
return error_msg[message_code];
@ -90,9 +90,9 @@ namespace vcg
{
// To obtain the loading mask all the file must be parsed
// to distinguish between per-vertex and per-face color attribute.
loadmask=0;
loadmask=0;
MESH_TYPE dummyMesh;
return (Open(dummyMesh, filename, loadmask)==NoError);
return (Open(dummyMesh, filename, loadmask)==NoError);
}
static int Open(MESH_TYPE &mesh, const char *filename,CallBackPos *cb=0)
@ -109,7 +109,7 @@ namespace vcg
* \return the operation result
*/
static int Open(MESH_TYPE &mesh, const char *filename, int &loadmask,
CallBackPos *cb=0)
CallBackPos *cb=0)
{
std::ifstream stream(filename);
if (stream.fail())
@ -163,7 +163,7 @@ namespace vcg
}
else return InvalidFile_MissingOFF;
// If the file is slightly malformed and it has nvert and nface AFTER the OFF string instead of in the next line
// If the file is slightly malformed and it has nvert and nface AFTER the OFF string instead of in the next line
// we manage it here...
if(tokens.size()==1) TokenizeNextLine(stream, tokens);
else tokens.erase(tokens.begin(),tokens.begin()+1);
@ -178,7 +178,7 @@ namespace vcg
if (isColorDefined) { loadmask |= Mask::IOM_VERTCOLOR;loadmask |= Mask::IOM_FACECOLOR;}
//if(onlyMaskFlag) return NoError;
//if(onlyMaskFlag) return NoError;
mesh.Clear();
@ -410,7 +410,7 @@ namespace vcg
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
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
@ -420,7 +420,7 @@ namespace vcg
k = 0;
}
vertIndices[j] = atoi(tokens[k].c_str());
polygonVect[j].Import<ScalarType> (mesh.vert[ vertIndices[j] ].P());
polygonVect[j].Import<ScalarType> (mesh.vert[ vertIndices[j] ].P());
k++;
}
if(vert_per_face==4)
@ -449,7 +449,7 @@ namespace vcg
{
std::vector<int> indexTriangulatedVect;
// TessellatePlanarPolygon3(polygonVect,indexTriangulatedVect);
std::vector< std::vector<Point3f> > loopVect;
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);
@ -463,6 +463,14 @@ namespace vcg
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] ] ]);
// To correctly set Faux edges we have to clear the faux bit for all the edges that do not correspond to consecutive vertices
// Consecutivity is in the space of the index of the polygon.
for(int qq=0;qq<3;++qq)
{
if( (indexTriangulatedVect[j+qq]+1)%indexTriangulatedVect.size() == indexTriangulatedVect[j+(qq+1)%3])
mesh.face[f+j/3].ClearF(qq);
else mesh.face[f+j/3].SetF(qq);
}
}
}
f+=trigs;
@ -471,11 +479,11 @@ namespace vcg
// NOTE: It is assumed that colored face takes exactly one text line
// (otherwise it is impossible to parse color information since
// color components can vary)
size_t color_elements = tokens.size() - vert_per_face-1;
isColorDefined |= (color_elements>0);
if(isColorDefined) loadmask |= Mask::IOM_FACECOLOR;
size_t color_elements = tokens.size() - vert_per_face-1;
isColorDefined |= (color_elements>0);
if(isColorDefined) loadmask |= Mask::IOM_FACECOLOR;
if( (color_elements>0) && tri::HasPerFaceColor(mesh) )
if( (color_elements>0) && tri::HasPerFaceColor(mesh) )
{
@ -551,14 +559,14 @@ namespace vcg
} // end Open
protected:
protected:
/*!
* Read the next valid line and parses it into "tokens", allowing the tokens to be read one at a time.
* \param stream The object providing the input stream
* \param tokens The "tokens" in the next line
*/
inline static void TokenizeNextLine(std::ifstream &stream, std::vector< std::string > &tokens)
inline static void TokenizeNextLine(std::ifstream &stream, std::vector< std::string > &tokens)
{
std::string line;
do