PolygonalMesh Debugging: Added direct loading of quad mesh into polygonal meshes (without need of having a trimesh to support)

This commit is contained in:
Paolo Cignoni 2014-02-18 10:58:57 +00:00
parent 1a4c5ef80d
commit d2f164d90c
1 changed files with 663 additions and 636 deletions

View File

@ -25,25 +25,23 @@
#include <fstream> #include <fstream>
#include<vcg/complex/algorithms/bitquad_support.h> #include<vcg/complex/algorithms/bitquad_support.h>
#include <wrap/callback.h>
#include <wrap/io_trimesh/io_mask.h> #include <wrap/io_trimesh/io_mask.h>
#include <wrap/io_trimesh/io_fan_tessellator.h> #include <wrap/io_trimesh/io_fan_tessellator.h>
namespace vcg
{ namespace vcg {
namespace tri namespace tri {
{ namespace io {
namespace io
{ // /** \addtogroup */
// /** \addtogroup */ // /* @{ */
// /* @{ */ /**
/**
This class encapsulate a filter for importing OFF meshes. This class encapsulate a filter for importing OFF meshes.
A basic description of the OFF file format can be found at http://www.geomview.org/docs/html/geomview_41.html A basic description of the OFF file format can be found at http://www.geomview.org/docs/html/geomview_41.html
*/ */
template<class MESH_TYPE> template<class MESH_TYPE>
class ImporterOFF class ImporterOFF
{ {
public: public:
typedef typename MESH_TYPE::VertexType VertexType; typedef typename MESH_TYPE::VertexType VertexType;
typedef typename MESH_TYPE::VertexIterator VertexIterator; typedef typename MESH_TYPE::VertexIterator VertexIterator;
@ -364,7 +362,36 @@ namespace vcg
// READ FACES // READ FACES
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
if(FaceType::HasPolyInfo())
{
for (unsigned int f=0; f < nFaces; f++)
{
if(cb && (f%1000)==0) cb(50+f*50/nFaces,"Face Loading");
TokenizeNextLine(stream, tokens);
int vert_per_face = atoi(tokens[0].c_str());
std::vector<int> vInd(vert_per_face);
k = 1;
for (int j=0; j < vert_per_face; j++)
{
if (k == tokens.size()) // if EOL // Go to next line when needed
{
TokenizeNextLine(stream, tokens);
if (tokens.size() == 0) return InvalidFile; // if EOF
k = 0;
}
vInd[j] = atoi(tokens[k].c_str());
k++;
}
if(vert_per_face==3)
Allocator<MESH_TYPE>::AddFace(mesh, &mesh.vert[ vInd[0] ], &mesh.vert[ vInd[1] ], &mesh.vert[ vInd[2] ]);
if(vert_per_face==4)
Allocator<MESH_TYPE>::AddQuadFace(mesh, &mesh.vert[ vInd[0] ], &mesh.vert[ vInd[1] ], &mesh.vert[ vInd[2] ],&mesh.vert[ vInd[3] ]);
}
}
else // Standard Triangular Mesh Loading
{
Allocator<MESH_TYPE>::AddFaces(mesh, nFaces); Allocator<MESH_TYPE>::AddFaces(mesh, nFaces);
unsigned int f0=0; unsigned int f0=0;
@ -553,12 +580,12 @@ namespace vcg
} //end switch } //end switch
} // end if (isColorDefined) } // end if (isColorDefined)
} // end of for f=... } // end of for f=...
}
return NoError; return NoError;
} // end Open } // end Open
protected: protected:
/*! /*!
* Read the next valid line and parses it into "tokens", allowing the tokens to be read one at a time. * Read the next valid line and parses it into "tokens", allowing the tokens to be read one at a time.
@ -752,10 +779,10 @@ namespace vcg
}; };
return Color4f(colorMap[i][0], colorMap[i][1], colorMap[i][2], colorMap[i][3]); return Color4f(colorMap[i][0], colorMap[i][1], colorMap[i][2], colorMap[i][3]);
} }
}; };
// /*! @} */ // /*! @} */
} //namespace io } //namespace io
}//namespace tri }//namespace tri
} // namespace vcg } // namespace vcg
#endif //__VCGLIB_IMPORT_OFF #endif //__VCGLIB_IMPORT_OFF