diff --git a/src/OpenMesh/Core/IO/exporter/BaseExporter.hh b/src/OpenMesh/Core/IO/exporter/BaseExporter.hh index 4b50943cd951c5013fc904b9b0f5a1136e0bdcea..5f4350bd2549b46d92ff8d3b6dee0e2eb8426f9f 100644 --- a/src/OpenMesh/Core/IO/exporter/BaseExporter.hh +++ b/src/OpenMesh/Core/IO/exporter/BaseExporter.hh @@ -93,6 +93,8 @@ public: virtual Vec4uc colorA(VertexHandle _vh) const = 0; virtual Vec3ui colori(VertexHandle _vh) const = 0; virtual Vec4ui colorAi(VertexHandle _vh) const = 0; + virtual Vec3f colorf(VertexHandle _vh) const = 0; + virtual Vec4f colorAf(VertexHandle _vh) const = 0; virtual Vec2f texcoord(VertexHandle _vh) const = 0; @@ -103,12 +105,18 @@ public: virtual Vec3f normal(FaceHandle _fh) const = 0; virtual Vec3uc color (FaceHandle _fh) const = 0; virtual Vec4uc colorA(FaceHandle _fh) const = 0; + virtual Vec3ui colori(FaceHandle _fh) const = 0; + virtual Vec4ui colorAi(FaceHandle _fh) const = 0; + virtual Vec3f colorf(FaceHandle _fh) const = 0; + virtual Vec4f colorAf(FaceHandle _fh) const = 0; // get edge data virtual Vec3uc color(EdgeHandle _eh) const = 0; virtual Vec4uc colorA(EdgeHandle _eh) const = 0; - virtual Vec3ui colori(EdgeHandle _vh) const = 0; - virtual Vec4ui colorAi(EdgeHandle _vh) const = 0; + virtual Vec3ui colori(EdgeHandle _eh) const = 0; + virtual Vec4ui colorAi(EdgeHandle _eh) const = 0; + virtual Vec3f colorf(EdgeHandle _eh) const = 0; + virtual Vec4f colorAf(EdgeHandle _eh) const = 0; // get reference to base kernel virtual const BaseKernel* kernel() { return 0; } diff --git a/src/OpenMesh/Core/IO/exporter/ExporterT.hh b/src/OpenMesh/Core/IO/exporter/ExporterT.hh index b221d7aa2e50ab964514ca64554e94bcbb640fc1..e14ee93c87b3fe36a85a34bd4314246bcf3d5de5 100644 --- a/src/OpenMesh/Core/IO/exporter/ExporterT.hh +++ b/src/OpenMesh/Core/IO/exporter/ExporterT.hh @@ -127,6 +127,20 @@ public: : Vec4ui(0, 0, 0, 0)); } + Vec3f colorf(VertexHandle _vh) const + { + return (mesh_.has_vertex_colors() + ? color_cast(mesh_.color(_vh)) + : Vec3f(0, 0, 0)); + } + + Vec4f colorAf(VertexHandle _vh) const + { + return (mesh_.has_vertex_colors() + ? color_cast(mesh_.color(_vh)) + : Vec4f(0, 0, 0, 0)); + } + Vec2f texcoord(VertexHandle _vh) const { #if defined(OM_CC_GCC) && (OM_CC_VERSION<30000) @@ -173,6 +187,20 @@ public: : Vec4ui(0, 0, 0, 0)); } + Vec3f colorf(EdgeHandle _eh) const + { + return (mesh_.has_vertex_colors() + ? color_cast(mesh_.color(_eh)) + : Vec3f(0, 0, 0)); + } + + Vec4f colorAf(EdgeHandle _eh) const + { + return (mesh_.has_vertex_colors() + ? color_cast(mesh_.color(_eh)) + : Vec4f(0, 0, 0, 0)); + } + // get face data unsigned int get_vhandles(FaceHandle _fh, @@ -223,6 +251,20 @@ public: : Vec4ui(0, 0, 0, 0)); } + Vec3f colorf(FaceHandle _fh) const + { + return (mesh_.has_vertex_colors() + ? color_cast(mesh_.color(_fh)) + : Vec3f(0, 0, 0)); + } + + Vec4f colorAf(FaceHandle _fh) const + { + return (mesh_.has_vertex_colors() + ? color_cast(mesh_.color(_fh)) + : Vec4f(0, 0, 0, 0)); + } + virtual const BaseKernel* kernel() { return &mesh_; } diff --git a/src/OpenMesh/Core/IO/reader/PLYReader.cc b/src/OpenMesh/Core/IO/reader/PLYReader.cc index 3970a29eff6cd970f748d66145cacf4b123f39de..bde7ef00529d6823ab570ca99d2055b4702c4b1d 100644 --- a/src/OpenMesh/Core/IO/reader/PLYReader.cc +++ b/src/OpenMesh/Core/IO/reader/PLYReader.cc @@ -153,6 +153,9 @@ bool _PLYReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt) { if (options_.is_binary()) { _opt += Options::Binary; } + if (options_.color_is_float()) { + _opt += Options::ColorFloat; + } // //force user-choice for the alpha value when reading binary // if ( options_.is_binary() && userOptions_.color_has_alpha() ) @@ -992,31 +995,45 @@ bool _PLYReader_::can_u_read(std::istream& _is) const { std::pair entry(COLORRED, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; options_ += Options::VertexColor; + if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) + options_ += Options::ColorFloat; } else if (propertyName == "green") { std::pair entry(COLORGREEN, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; options_ += Options::VertexColor; + if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) + options_ += Options::ColorFloat; } else if (propertyName == "blue") { std::pair entry(COLORBLUE, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; options_ += Options::VertexColor; + if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) + options_ += Options::ColorFloat; } else if (propertyName == "diffuse_red") { std::pair entry(COLORRED, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; options_ += Options::VertexColor; + if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) + options_ += Options::ColorFloat; } else if (propertyName == "diffuse_green") { std::pair entry(COLORGREEN, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; options_ += Options::VertexColor; + if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) + options_ += Options::ColorFloat; } else if (propertyName == "diffuse_blue") { std::pair entry(COLORBLUE, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; options_ += Options::VertexColor; + if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) + options_ += Options::ColorFloat; } else if (propertyName == "alpha") { std::pair entry(COLORALPHA, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; options_ += Options::VertexColor; options_ += Options::ColorAlpha; + if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) + options_ += Options::ColorFloat; } else { std::pair entry(UNSUPPORTED, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; diff --git a/src/OpenMesh/Core/IO/writer/PLYWriter.cc b/src/OpenMesh/Core/IO/writer/PLYWriter.cc index 989ec89a1af01d32c81c93131b80dc342a0ff1c8..d20468b06646aab3f9b63ac99c15ba3a5c308456 100644 --- a/src/OpenMesh/Core/IO/writer/PLYWriter.cc +++ b/src/OpenMesh/Core/IO/writer/PLYWriter.cc @@ -169,24 +169,20 @@ write(std::ostream& _os, BaseExporter& _be, Options _opt, std::streamsize _preci //----------------------------------------------------------------------------- -bool -_PLYWriter_:: -write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const -{ - omlog() << "[PLYWriter] : write ascii file\n"; - - - unsigned int i, j, nV, nF; - Vec3f v, n; - OpenMesh::Vec3ui c; - OpenMesh::Vec4ui cA; - OpenMesh::Vec2f t; - VertexHandle vh; - std::vector vhandles; - +void _PLYWriter_::write_header(std::ostream& _out, BaseExporter& _be, Options& _opt) const { //writing header _out << "ply" << std::endl; - _out << "format ascii 1.0" << std::endl; + + if (_opt.is_binary()) { + _out << "format "; + if ( options_.check(Options::MSB) ) + _out << "binary_big_endian "; + else + _out << "binary_little_endian "; + _out << "1.0" << std::endl; + } else + _out << "format ascii 1.0" << std::endl; + _out << "element vertex " << _be.n_vertices() << std::endl; _out << "property float x" << std::endl; @@ -205,17 +201,49 @@ write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const } if ( _opt.vertex_has_color() ){ - _out << "property uchar red" << std::endl; - _out << "property uchar green" << std::endl; - _out << "property uchar blue" << std::endl; - - if ( _opt.color_has_alpha() ) - _out << "property uchar alpha" << std::endl; + if ( _opt.color_is_float() ) { + _out << "property float red" << std::endl; + _out << "property float green" << std::endl; + _out << "property float blue" << std::endl; + + if ( _opt.color_has_alpha() ) + _out << "property float alpha" << std::endl; + } else { + _out << "property uchar red" << std::endl; + _out << "property uchar green" << std::endl; + _out << "property uchar blue" << std::endl; + + if ( _opt.color_has_alpha() ) + _out << "property uchar alpha" << std::endl; + } } _out << "element face " << _be.n_faces() << std::endl; _out << "property list uchar int vertex_indices" << std::endl; _out << "end_header" << std::endl; +} + + +//----------------------------------------------------------------------------- + + +bool +_PLYWriter_:: +write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const +{ + omlog() << "[PLYWriter] : write ascii file\n"; + + unsigned int i, j, nV, nF; + Vec3f v, n; + OpenMesh::Vec3ui c; + OpenMesh::Vec4ui cA; + OpenMesh::Vec3f cf; + OpenMesh::Vec4f cAf; + OpenMesh::Vec2f t; + VertexHandle vh; + std::vector vhandles; + + write_header(_out, _be, _opt); // vertex data (point, normals, colors, texcoords) for (i=0, nV=_be.n_vertices(); i vhandles; - //writing header - _out << "ply" << std::endl; - _out << "format "; - - if ( options_.check(Options::MSB) ) - _out << "binary_big_endian "; - else - _out << "binary_little_endian "; - - _out << "1.0" << std::endl; - - _out << "element vertex " << _be.n_vertices() << std::endl; - - _out << "property float x" << std::endl; - _out << "property float y" << std::endl; - _out << "property float z" << std::endl; - - if ( _opt.vertex_has_normal() ){ - _out << "property float nx" << std::endl; - _out << "property float ny" << std::endl; - _out << "property float nz" << std::endl; - } - - if ( _opt.vertex_has_texcoord() ){ - _out << "property float u" << std::endl; - _out << "property float v" << std::endl; - } - - if ( _opt.vertex_has_color() ){ - _out << "property uchar red" << std::endl; - _out << "property uchar green" << std::endl; - _out << "property uchar blue" << std::endl; - - if ( _opt.color_has_alpha() ) - _out << "property uchar alpha" << std::endl; - } - - _out << "element face " << _be.n_faces() << std::endl; - _out << "property list uchar int vertex_indices" << std::endl; - _out << "end_header" << std::endl; + write_header(_out, _be, _opt); // vertex data (point, normals, texcoords) for (i=0, nV=_be.n_vertices(); i