From 66f26c13f71a8427c999be81706806d1da4b7213 Mon Sep 17 00:00:00 2001 From: Kenneth Vanhoey Date: Wed, 18 Apr 2012 11:27:39 +0200 Subject: [PATCH] exportPly is now generic for PFP::REAL --- include/Algo/Export/export.hpp | 12 ++++++------ include/Utils/nameTypes.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/include/Algo/Export/export.hpp b/include/Algo/Export/export.hpp index fcbb823e..5816aa4a 100644 --- a/include/Algo/Export/export.hpp +++ b/include/Algo/Export/export.hpp @@ -117,13 +117,13 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons // Position property if (position.isValid()) { - out << "property float32 x" << std::endl ; - out << "property float32 y" << std::endl ; - out << "property float32 z" << std::endl ; + out << "property " << nameOfTypePly(position[0][0]) << 8 * sizeof(position[0][0]) <<" x" << std::endl ; + out << "property " << nameOfTypePly(position[0][1]) << 8 * sizeof(position[0][1]) <<" y" << std::endl ; + out << "property " << nameOfTypePly(position[0][2]) << 8 * sizeof(position[0][2]) <<" z" << std::endl ; } // Face element out << "element face " << facesSize.size() << std::endl ; - out << "property list uint8 uint32 vertex_indices" << std::endl ; + out << "property list uint8 uint" << 8 * sizeof(facesIdx[0][0]) << " vertex_indices" << std::endl ; out << "end_header" << std::endl ; if (!binary) // ascii @@ -147,7 +147,7 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons for(unsigned int i = 0; i < vertices.size(); ++i) { Geom::Vec3f v = position[vertices[i]] ; - out.write((char*)(&(v[0])), 3 * sizeof(float)) ; + out.write((char*)(&(v[0])), sizeof(v)) ; } // binary faces @@ -155,7 +155,7 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons { unsigned char nbe = facesSize[i] ; out.write((char*)(&nbe), sizeof(unsigned char)) ; - out.write((char*)(&(facesIdx[i][0])), facesSize[i] * sizeof(float)) ; + out.write((char*)(&(facesIdx[i][0])), facesSize[i] * sizeof(facesIdx[i][0])) ; } } diff --git a/include/Utils/nameTypes.h b/include/Utils/nameTypes.h index 5963e317..140c2758 100644 --- a/include/Utils/nameTypes.h +++ b/include/Utils/nameTypes.h @@ -60,6 +60,35 @@ template <> inline std::string nameOfType(const double& v) { return "double"; } template <> inline std::string nameOfType(const std::string& v) { return "std::string"; } +// Ply compatibility +template +std::string nameOfTypePly(const T& v) +{ + return v.CGoGNnameOfType(); +} + +template <> inline std::string nameOfTypePly(const char& v) { return "int8"; } + +template <> inline std::string nameOfTypePly(const short int& v) { return "int16"; } + +template <> inline std::string nameOfTypePly(const int& v) { return "int32"; } + +template <> inline std::string nameOfTypePly(const long int& v) { return "invalid"; } + +template <> inline std::string nameOfTypePly(const unsigned char& v) { return "uint8"; } + +template <> inline std::string nameOfType(const unsigned short int& v) { return "uint16"; } + +template <> inline std::string nameOfTypePly(const unsigned int& v) { return "uint32"; } + +template <> inline std::string nameOfTypePly(const unsigned long int& v) { return "invalid"; } + +template <> inline std::string nameOfTypePly(const float& v) { return "float32"; } + +template <> inline std::string nameOfTypePly(const double& v) { return "float64"; } + +template <> inline std::string nameOfTypePly(const std::string& v) { return "invalid"; } + } #endif /* NAMETYPES_H_ */ -- GitLab