Commit b5e50597 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

added ply binary export (boolean in function call)

parent a6d0a247
......@@ -40,6 +40,7 @@ namespace Export
* export the map into a PLY file
* @param the_map map to be exported
* @param filename filename of ply file
* @param binary write in binary mode
* @return true
*/
template <typename PFP>
......
......@@ -43,11 +43,13 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons
typedef typename PFP::MAP MAP;
typedef typename PFP::VEC3 VEC3;
// open file
std::ofstream out ;
//if (!binary)
if (!binary)
out.open(filename, std::ios::out) ;
//else
//out.open(filename, std::ios::out | std::ios::binary) ;
else
out.open(filename, std::ios::out | std::ios::binary) ;
if (!out.good())
{
CGoGNerr << "Unable to open file " << CGoGNendl ;
......@@ -64,6 +66,7 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons
std::vector<unsigned int> vertices ;
vertices.reserve(nbDarts/6) ;
// Go over all faces
CellMarker markV(map, VERTEX) ;
TraversorF<MAP> t(map, good) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
......@@ -88,8 +91,9 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons
facesIdx.push_back(fidx) ;
}
// Start writing the file
out << "ply" << std::endl ;
// ascii or binary
if (!binary)
out << "format ascii 1.0" << std::endl ;
else
......@@ -107,24 +111,28 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons
out << "comment File generated by the CGoGN library" << std::endl ;
out << "comment See : http://cgogn.unistra.fr/" << std::endl ;
out << "comment Or contact : cgogn@unistra.fr" << std::endl ;
out << "comment or contact : cgogn@unistra.fr" << std::endl ;
// Vertex elements
out << "element vertex " << vertices.size() << std::endl ;
// Position property
if (position.isValid())
{
out << "property float32 x" << std::endl ;
out << "property float32 y" << std::endl ;
out << "property float32 z" << std::endl ;
}
// Face element
out << "element face " << facesSize.size() << std::endl ;
out << "property list uint8 uint32 vertex_indices" << std::endl ;
out << "end_header" << std::endl ;
if (!binary)
if (!binary) // ascii
{
// ascii vertices
for(unsigned int i = 0; i < vertices.size(); ++i)
out << position[vertices[i]] << std::endl ;
// ascii faces
for(unsigned int i = 0; i < facesSize.size(); ++i)
{
out << facesSize[i] ;
......@@ -133,24 +141,21 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons
out << std::endl ;
}
}
else
else // binary
{
// binary vertices
for(unsigned int i = 0; i < vertices.size(); ++i)
{
Geom::Vec3f v = position[vertices[i]] ;
for (unsigned int c = 0 ; c < 3 ; ++c)
{
const float& floatofdouble = v[c] ;
out.write((char*)(&floatofdouble), sizeof(float)) ;
}
out.write((char*)(&(v[0])), 3 * sizeof(float)) ;
}
// binary faces
for(unsigned int i = 0; i < facesSize.size(); ++i)
{
unsigned char nbe = facesSize[i] ;
out.write((char*)(&nbe), sizeof(unsigned char)) ;
for(unsigned int j = 0 ; j < facesIdx[i].size() ; ++j)
out.write((char*)(&(facesIdx[i][j])), sizeof(unsigned int)) ;
out.write((char*)(&(facesIdx[i][0])), facesSize[i] * sizeof(float)) ;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment