diff --git a/src/OpenMesh/Core/IO/importer/BaseImporter.hh b/src/OpenMesh/Core/IO/importer/BaseImporter.hh
index 5f40f311..a1195c58 100644
--- a/src/OpenMesh/Core/IO/importer/BaseImporter.hh
+++ b/src/OpenMesh/Core/IO/importer/BaseImporter.hh
@@ -4,10 +4,10 @@
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
* www.openmesh.org *
* *
- *---------------------------------------------------------------------------*
+ *---------------------------------------------------------------------------*
* This file is part of OpenMesh. *
* *
- * OpenMesh is free software: you can redistribute it and/or modify *
+ * OpenMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
@@ -30,10 +30,10 @@
* License along with OpenMesh. If not, *
* see . *
* *
-\*===========================================================================*/
+\*===========================================================================*/
/*===========================================================================*\
- * *
+ * *
* $Revision$ *
* $Date$ *
* *
@@ -108,6 +108,12 @@ public:
// set vertex color
virtual void set_color(VertexHandle _vh, const Vec4uc& _color) = 0;
+ // set vertex color
+ virtual void set_color(VertexHandle _vh, const Vec3f& _color) = 0;
+
+ // set vertex color
+ virtual void set_color(VertexHandle _vh, const Vec4f& _color) = 0;
+
// set vertex texture coordinate
virtual void set_texcoord(VertexHandle _vh, const Vec2f& _texcoord) = 0;
@@ -116,10 +122,16 @@ public:
// set edge color
virtual void set_color(EdgeHandle _eh, const Vec3uc& _color) = 0;
-
+
// set edge color
virtual void set_color(EdgeHandle _eh, const Vec4uc& _color) = 0;
-
+
+ // set edge color
+ virtual void set_color(EdgeHandle _eh, const Vec3f& _color) = 0;
+
+ // set edge color
+ virtual void set_color(EdgeHandle _eh, const Vec4f& _color) = 0;
+
// set face normal
virtual void set_normal(FaceHandle _fh, const Vec3f& _normal) = 0;
@@ -129,6 +141,12 @@ public:
// set face color
virtual void set_color(FaceHandle _fh, const Vec4uc& _color) = 0;
+ // set face color
+ virtual void set_color(FaceHandle _fh, const Vec3f& _color) = 0;
+
+ // set face color
+ virtual void set_color(FaceHandle _fh, const Vec4f& _color) = 0;
+
// Store a property in the mesh mapping from an int to a texture file
// Use set_face_texindex to set the index for each face
virtual void add_texture_information( int _id , std::string _name ) = 0;
diff --git a/src/OpenMesh/Core/IO/importer/ImporterT.hh b/src/OpenMesh/Core/IO/importer/ImporterT.hh
index 1bc90d42..23ee4c37 100644
--- a/src/OpenMesh/Core/IO/importer/ImporterT.hh
+++ b/src/OpenMesh/Core/IO/importer/ImporterT.hh
@@ -4,10 +4,10 @@
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
* www.openmesh.org *
* *
- *---------------------------------------------------------------------------*
+ *---------------------------------------------------------------------------*
* This file is part of OpenMesh. *
* *
- * OpenMesh is free software: you can redistribute it and/or modify *
+ * OpenMesh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
@@ -30,10 +30,10 @@
* License along with OpenMesh. If not, *
* see . *
* *
-\*===========================================================================*/
+\*===========================================================================*/
/*===========================================================================*\
- * *
+ * *
* $Revision$ *
* $Date$ *
* *
@@ -103,7 +103,7 @@ public:
{
VHandles::const_iterator it, it2, end(_indices.end());
-
+
// test for valid vertex indices
for (it=_indices.begin(); it!=end; ++it)
if (! mesh_.is_valid_handle(*it))
@@ -177,6 +177,17 @@ public:
mesh_.set_color(_vh, color_cast(_color));
}
+ virtual void set_color(VertexHandle _vh, const Vec4f& _color)
+ {
+ if (mesh_.has_vertex_colors())
+ mesh_.set_color(_vh, color_cast(_color));
+ }
+
+ virtual void set_color(VertexHandle _vh, const Vec3f& _color)
+ {
+ if (mesh_.has_vertex_colors())
+ mesh_.set_color(_vh, color_cast(_color));
+ }
virtual void set_texcoord(VertexHandle _vh, const Vec2f& _texcoord)
{
@@ -191,19 +202,31 @@ public:
}
// edge attributes
-
+
virtual void set_color(EdgeHandle _eh, const Vec4uc& _color)
{
if (mesh_.has_edge_colors())
mesh_.set_color(_eh, color_cast(_color));
}
-
+
virtual void set_color(EdgeHandle _eh, const Vec3uc& _color)
{
if (mesh_.has_edge_colors())
mesh_.set_color(_eh, color_cast(_color));
}
+ virtual void set_color(EdgeHandle _eh, const Vec4f& _color)
+ {
+ if (mesh_.has_edge_colors())
+ mesh_.set_color(_eh, color_cast(_color));
+ }
+
+ virtual void set_color(EdgeHandle _eh, const Vec3f& _color)
+ {
+ if (mesh_.has_edge_colors())
+ mesh_.set_color(_eh, color_cast(_color));
+ }
+
// face attributes
virtual void set_normal(FaceHandle _fh, const Vec3f& _normal)
@@ -224,6 +247,18 @@ public:
mesh_.set_color(_fh, color_cast(_color));
}
+ virtual void set_color(FaceHandle _fh, const Vec3f& _color)
+ {
+ if (mesh_.has_face_colors())
+ mesh_.set_color(_fh, color_cast(_color));
+ }
+
+ virtual void set_color(FaceHandle _fh, const Vec4f& _color)
+ {
+ if (mesh_.has_face_colors())
+ mesh_.set_color(_fh, color_cast(_color));
+ }
+
virtual void add_face_texcoords( FaceHandle _fh, VertexHandle _vh, const std::vector& _face_texcoords)
{
// get first halfedge handle
@@ -297,7 +332,7 @@ public:
vhandles[j] = mesh_.add_vertex(p);
// DO STORE p, reference may not work since vertex array
// may be relocated after adding a new vertex !
-
+
// Mark vertices of failed face as non-manifold
if (mesh_.has_vertex_status()) {
mesh_.status(vhandles[j]).set_fixed_nonmanifold(true);
@@ -306,11 +341,11 @@ public:
// add face
FaceHandle fh = mesh_.add_face(vhandles);
-
+
// Mark failed face as non-manifold
if (mesh_.has_face_status())
mesh_.status(fh).set_fixed_nonmanifold(true);
-
+
// Mark edges of failed face as non-two-manifold
if (mesh_.has_edge_status()) {
typename Mesh::FaceEdgeIter fe_it = mesh_.fe_iter(fh);
diff --git a/src/OpenMesh/Core/IO/reader/OFFReader.cc b/src/OpenMesh/Core/IO/reader/OFFReader.cc
index a01837cf..9f9494fc 100644
--- a/src/OpenMesh/Core/IO/reader/OFFReader.cc
+++ b/src/OpenMesh/Core/IO/reader/OFFReader.cc
@@ -162,8 +162,8 @@ _OFFReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt )
options_ += Options::ColorAlpha;
return (options_.is_binary() ?
- read_binary(_in, _bi, swap) :
- read_ascii(_in, _bi));
+ read_binary(_in, _bi, _opt, swap) :
+ read_ascii(_in, _bi, _opt));
}
@@ -172,7 +172,7 @@ _OFFReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt )
//-----------------------------------------------------------------------------
bool
-_OFFReader_::read_ascii(std::istream& _in, BaseImporter& _bi) const
+_OFFReader_::read_ascii(std::istream& _in, BaseImporter& _bi, Options& _opt) const
{
@@ -246,13 +246,17 @@ omlog() << "[OFFReader] : read ascii file\n";
break;
// rgb floats
case 5 : stream >> c3f[0]; stream >> c3f[1]; stream >> c3f[2];
- if ( userOptions_.vertex_has_color() )
- _bi.set_color( vh, color_cast(c3f) );
+ if ( userOptions_.vertex_has_color() ) {
+ _bi.set_color( vh, c3f );
+ _opt += Options::ColorFloat;
+ }
break;
// rgba floats
case 6 : stream >> c4f[0]; stream >> c4f[1]; stream >> c4f[2]; stream >> c4f[3];
- if ( userOptions_.vertex_has_color() )
- _bi.set_color( vh, color_cast(c4f) );
+ if ( userOptions_.vertex_has_color() ) {
+ _bi.set_color( vh, c4f );
+ _opt += Options::ColorFloat;
+ }
break;
default:
@@ -327,13 +331,17 @@ omlog() << "[OFFReader] : read ascii file\n";
break;
// rgb floats
case 5 : stream >> c3f[0]; stream >> c3f[1]; stream >> c3f[2];
- if ( userOptions_.face_has_color() )
- _bi.set_color( fh, color_cast(c3f) );
+ if ( userOptions_.face_has_color() ) {
+ _bi.set_color( fh, c3f );
+ _opt += Options::ColorFloat;
+ }
break;
// rgba floats
case 6 : stream >> c4f[0]; stream >> c4f[1]; stream >> c4f[2]; stream >> c4f[3];
- if ( userOptions_.face_has_color() )
- _bi.set_color( fh, color_cast(c4f) );
+ if ( userOptions_.face_has_color() ) {
+ _bi.set_color( fh, c4f );
+ _opt += Options::ColorFloat;
+ }
break;
default:
@@ -423,7 +431,7 @@ void _OFFReader_::readValue(std::istream& _in, unsigned int& _value) const{
}
bool
-_OFFReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap*/) const
+_OFFReader_::read_binary(std::istream& _in, BaseImporter& _bi, Options& _opt, bool /*_swap*/) const
{
omlog() << "[OFFReader] : read binary file\n";
@@ -432,6 +440,8 @@ _OFFReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap*/) c
OpenMesh::Vec3f v, n;
OpenMesh::Vec3i c;
OpenMesh::Vec4i cA;
+ OpenMesh::Vec3f cf;
+ OpenMesh::Vec4f cAf;
OpenMesh::Vec2f t;
BaseImporter::VHandles vhandles;
VertexHandle vh;
@@ -467,23 +477,46 @@ _OFFReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap*/) c
}
if ( options_.vertex_has_color() ) {
- //with alpha
- if ( options_.color_has_alpha() ){
- readValue(_in, cA[0]);
- readValue(_in, cA[1]);
- readValue(_in, cA[2]);
- readValue(_in, cA[3]);
+ if ( userOptions_.color_is_float() ) {
+ _opt += Options::ColorFloat;
+ //with alpha
+ if ( options_.color_has_alpha() ){
+ readValue(_in, cAf[0]);
+ readValue(_in, cAf[1]);
+ readValue(_in, cAf[2]);
+ readValue(_in, cAf[3]);
- if ( userOptions_.vertex_has_color() )
- _bi.set_color( vh, Vec4uc( cA ) );
- }else{
- //without alpha
- readValue(_in, c[0]);
- readValue(_in, c[1]);
- readValue(_in, c[2]);
+ if ( userOptions_.vertex_has_color() )
+ _bi.set_color( vh, cAf );
+ }else{
- if ( userOptions_.vertex_has_color() )
- _bi.set_color( vh, Vec3uc( c ) );
+ //without alpha
+ readValue(_in, cf[0]);
+ readValue(_in, cf[1]);
+ readValue(_in, cf[2]);
+
+ if ( userOptions_.vertex_has_color() )
+ _bi.set_color( vh, cf );
+ }
+ } else {
+ //with alpha
+ if ( options_.color_has_alpha() ){
+ readValue(_in, cA[0]);
+ readValue(_in, cA[1]);
+ readValue(_in, cA[2]);
+ readValue(_in, cA[3]);
+
+ if ( userOptions_.vertex_has_color() )
+ _bi.set_color( vh, Vec4uc( cA ) );
+ }else{
+ //without alpha
+ readValue(_in, c[0]);
+ readValue(_in, c[1]);
+ readValue(_in, c[2]);
+
+ if ( userOptions_.vertex_has_color() )
+ _bi.set_color( vh, Vec3uc( c ) );
+ }
}
}
@@ -503,7 +536,6 @@ _OFFReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap*/) c
{
readValue(_in, nV);
-
if (nV == 3)
{
vhandles.resize(3);
@@ -514,9 +546,7 @@ _OFFReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap*/) c
vhandles[0] = VertexHandle(j);
vhandles[1] = VertexHandle(k);
vhandles[2] = VertexHandle(l);
- }
- else
- {
+ } else {
vhandles.clear();
for (j=0; j= 4 )
remainingChars -= 4;
- else
+ else
remainingChars = 0;
if ( ( remainingChars >= 6 ) && ( strncmp(p, "BINARY", 6) == 0 ) )
diff --git a/src/OpenMesh/Core/IO/reader/OFFReader.hh b/src/OpenMesh/Core/IO/reader/OFFReader.hh
index cf059c27..89158feb 100644
--- a/src/OpenMesh/Core/IO/reader/OFFReader.hh
+++ b/src/OpenMesh/Core/IO/reader/OFFReader.hh
@@ -136,8 +136,8 @@ private:
bool can_u_read(std::istream& _is) const;
- bool read_ascii(std::istream& _in, BaseImporter& _bi) const;
- bool read_binary(std::istream& _in, BaseImporter& _bi, bool swap) const;
+ bool read_ascii(std::istream& _in, BaseImporter& _bi, Options& _opt) const;
+ bool read_binary(std::istream& _in, BaseImporter& _bi, Options& _opt, bool swap) const;
void readValue(std::istream& _in, float& _value) const;
void readValue(std::istream& _in, int& _value) const;
diff --git a/src/OpenMesh/Core/IO/writer/OFFWriter.cc b/src/OpenMesh/Core/IO/writer/OFFWriter.cc
index ba7edd03..d6af8114 100644
--- a/src/OpenMesh/Core/IO/writer/OFFWriter.cc
+++ b/src/OpenMesh/Core/IO/writer/OFFWriter.cc
@@ -183,6 +183,8 @@ write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const
Vec2f t;
OpenMesh::Vec3i c;
OpenMesh::Vec4i cA;
+ OpenMesh::Vec3f cf;
+ OpenMesh::Vec4f cAf;
VertexHandle vh;
std::vector vhandles;
@@ -192,6 +194,9 @@ write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const
_out << _be.n_faces() << " ";
_out << 0 << "\n";
+ if (_opt.color_is_float())
+ _out << std::fixed;
+
// vertex data (point, normals, colors, texcoords)
for (i=0, nV=_be.n_vertices(); i vhandles;
-
// #vertices, #faces
writeValue(_out, (uint)_be.n_vertices() );
writeValue(_out, (uint) _be.n_faces() );
writeValue(_out, 0 );
-
// vertex data (point, normals, texcoords)
for (i=0, nV=_be.n_vertices(); i