Commit a6d0a247 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

added ply binary export (boolean in function call)

parent 0edf4e04
...@@ -234,7 +234,7 @@ void Viewer::exportMesh(std::string& filename) ...@@ -234,7 +234,7 @@ void Viewer::exportMesh(std::string& filename)
if (extension == std::string(".off")) if (extension == std::string(".off"))
Algo::Export::exportOFF<PFP>(myMap, position, filename.c_str(), allDarts) ; Algo::Export::exportOFF<PFP>(myMap, position, filename.c_str(), allDarts) ;
else if (extension.compare(0, 4, std::string(".ply")) == 0) else if (extension.compare(0, 4, std::string(".ply")) == 0)
Algo::Export::exportPLY<PFP>(myMap, position, filename.c_str(), allDarts) ; Algo::Export::exportPLY<PFP>(myMap, position, filename.c_str(), true, allDarts) ;
else if (extension == std::string(".map")) else if (extension == std::string(".map"))
myMap.saveMapBin(filename) ; myMap.saveMapBin(filename) ;
else else
......
...@@ -43,7 +43,7 @@ namespace Export ...@@ -43,7 +43,7 @@ namespace Export
* @return true * @return true
*/ */
template <typename PFP> template <typename PFP>
bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const FunctorSelect& good = allDarts) ; bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const bool binary, const FunctorSelect& good = allDarts) ;
/** /**
* export the map into a OFF file * export the map into a OFF file
......
...@@ -38,12 +38,16 @@ namespace Export ...@@ -38,12 +38,16 @@ namespace Export
{ {
template <typename PFP> template <typename PFP>
bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const FunctorSelect& good) bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, bool binary, const FunctorSelect& good)
{ {
typedef typename PFP::MAP MAP; typedef typename PFP::MAP MAP;
typedef typename PFP::VEC3 VEC3; typedef typename PFP::VEC3 VEC3;
std::ofstream out(filename, std::ios::out) ; std::ofstream out ;
//if (!binary)
out.open(filename, std::ios::out) ;
//else
//out.open(filename, std::ios::out | std::ios::binary) ;
if (!out.good()) if (!out.good())
{ {
CGoGNerr << "Unable to open file " << CGoGNendl ; CGoGNerr << "Unable to open file " << CGoGNendl ;
...@@ -85,30 +89,73 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons ...@@ -85,30 +89,73 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons
} }
out << "ply" << std::endl ; out << "ply" << std::endl ;
out << "format ascii 1.0" << std::endl ;
out << "comment no comment" << std::endl ; if (!binary)
out << "format ascii 1.0" << std::endl ;
else
{ // test endianness
union
{
uint32_t i ;
char c[4] ;
} bint = {0x01020304} ;
if (bint.c[0] == 1) // big endian
out << "format binary_big_endian 1.0" << std::endl ;
else
out << "format binary_little_endian 1.0" << std::endl ;
}
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 << "element vertex " << vertices.size() << std::endl ; out << "element vertex " << vertices.size() << std::endl ;
out << "property float x" << std::endl ; if (position.isValid())
out << "property float y" << std::endl ; {
out << "property float z" << std::endl ; out << "property float32 x" << std::endl ;
out << "property float32 y" << std::endl ;
out << "property float32 z" << std::endl ;
}
out << "element face " << facesSize.size() << std::endl ; out << "element face " << facesSize.size() << std::endl ;
out << "property list uchar int vertex_indices" << std::endl ; out << "property list uint8 uint32 vertex_indices" << std::endl ;
out << "end_header" << std::endl ; out << "end_header" << std::endl ;
for(unsigned int i = 0; i < vertices.size(); ++i) if (!binary)
{ {
const VEC3& v = position[vertices[i]] ; for(unsigned int i = 0; i < vertices.size(); ++i)
out << v[0] << " " << v[1] << " " << v[2] << std::endl ; out << position[vertices[i]] << std::endl ;
for(unsigned int i = 0; i < facesSize.size(); ++i)
{
out << facesSize[i] ;
for(unsigned int j = 0; j < facesIdx[i].size(); ++j)
out << " " << facesIdx[i][j] ;
out << std::endl ;
}
} }
for(unsigned int i = 0; i < facesSize.size(); ++i) else
{ {
out << facesSize[i] ; for(unsigned int i = 0; i < vertices.size(); ++i)
for(unsigned int j = 0; j < facesIdx[i].size(); ++j) {
out << " " << facesIdx[i][j] ; Geom::Vec3f v = position[vertices[i]] ;
out << std::endl ; for (unsigned int c = 0 ; c < 3 ; ++c)
{
const float& floatofdouble = v[c] ;
out.write((char*)(&floatofdouble), sizeof(float)) ;
}
}
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.close() ; out.close() ;
return true ; return true ;
} }
......
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