- added color_cast from Vec4f to Vec4i and Vec4ui

- added colori and colorAi functions to BaseExporter which return Vec3i and Vec4i respectively
- adjusted the PLYWriter to use colori and colorAi for writing ascii files

refs #1405

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@815 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Isaak Lim
2013-02-27 13:25:42 +00:00
parent 7460c8ac82
commit 951aa17bd9
4 changed files with 134 additions and 61 deletions

View File

@@ -4,10 +4,10 @@
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen * * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
* www.openmesh.org * * www.openmesh.org *
* * * *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* This file is part of OpenMesh. * * 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 * * it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of * * published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the * * the License, or (at your option) any later version with the *
@@ -30,10 +30,10 @@
* License along with OpenMesh. If not, * * License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. * * see <http://www.gnu.org/licenses/>. *
* * * *
\*===========================================================================*/ \*===========================================================================*/
/*===========================================================================*\ /*===========================================================================*\
* * * *
* $Revision$ * * $Revision$ *
* $Date$ * * $Date$ *
* * * *
@@ -76,7 +76,7 @@ namespace IO {
/** /**
Base class for exporter modules. Base class for exporter modules.
The exporter modules provide an interface between the writer modules and The exporter modules provide an interface between the writer modules and
the target data structure. the target data structure.
*/ */
class OPENMESHDLLEXPORT BaseExporter class OPENMESHDLLEXPORT BaseExporter
@@ -84,27 +84,31 @@ class OPENMESHDLLEXPORT BaseExporter
public: public:
virtual ~BaseExporter() { } virtual ~BaseExporter() { }
// get vertex data // get vertex data
virtual Vec3f point(VertexHandle _vh) const = 0; virtual Vec3f point(VertexHandle _vh) const = 0;
virtual Vec3f normal(VertexHandle _vh) const = 0; virtual Vec3f normal(VertexHandle _vh) const = 0;
virtual Vec3uc color(VertexHandle _vh) const = 0; virtual Vec3uc color(VertexHandle _vh) const = 0;
virtual Vec4uc colorA(VertexHandle _vh) const = 0; virtual Vec4uc colorA(VertexHandle _vh) const = 0;
virtual Vec3ui colori(VertexHandle _vh) const = 0;
virtual Vec4ui colorAi(VertexHandle _vh) const = 0;
virtual Vec2f texcoord(VertexHandle _vh) const = 0; virtual Vec2f texcoord(VertexHandle _vh) const = 0;
// get face data // get face data
virtual unsigned int virtual unsigned int
get_vhandles(FaceHandle _fh, get_vhandles(FaceHandle _fh,
std::vector<VertexHandle>& _vhandles) const=0; std::vector<VertexHandle>& _vhandles) const=0;
virtual Vec3f normal(FaceHandle _fh) const = 0; virtual Vec3f normal(FaceHandle _fh) const = 0;
virtual Vec3uc color (FaceHandle _fh) const = 0; virtual Vec3uc color (FaceHandle _fh) const = 0;
virtual Vec4uc colorA(FaceHandle _fh) const = 0; virtual Vec4uc colorA(FaceHandle _fh) const = 0;
// get edge data // get edge data
virtual Vec3uc color(EdgeHandle _eh) const = 0; virtual Vec3uc color(EdgeHandle _eh) const = 0;
virtual Vec4uc colorA(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;
// get reference to base kernel // get reference to base kernel
virtual const BaseKernel* kernel() { return 0; } virtual const BaseKernel* kernel() { return 0; }
@@ -121,7 +125,7 @@ public:
virtual bool has_vertex_normals() const { return false; } virtual bool has_vertex_normals() const { return false; }
virtual bool has_vertex_colors() const { return false; } virtual bool has_vertex_colors() const { return false; }
virtual bool has_vertex_texcoords() const { return false; } virtual bool has_vertex_texcoords() const { return false; }
virtual bool has_edge_colors() const { return false; } virtual bool has_edge_colors() const { return false; }
virtual bool has_face_normals() const { return false; } virtual bool has_face_normals() const { return false; }
virtual bool has_face_colors() const { return false; } virtual bool has_face_colors() const { return false; }
}; };

View File

@@ -4,10 +4,10 @@
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen * * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
* www.openmesh.org * * www.openmesh.org *
* * * *
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* This file is part of OpenMesh. * * 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 * * it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of * * published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the * * the License, or (at your option) any later version with the *
@@ -30,10 +30,10 @@
* License along with OpenMesh. If not, * * License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. * * see <http://www.gnu.org/licenses/>. *
* * * *
\*===========================================================================*/ \*===========================================================================*/
/*===========================================================================*\ /*===========================================================================*\
* * * *
* $Revision$ * * $Revision$ *
* $Date$ * * $Date$ *
* * * *
@@ -83,72 +83,99 @@ public:
// Constructor // Constructor
ExporterT(const Mesh& _mesh) : mesh_(_mesh) {} ExporterT(const Mesh& _mesh) : mesh_(_mesh) {}
// get vertex data // get vertex data
Vec3f point(VertexHandle _vh) const Vec3f point(VertexHandle _vh) const
{ {
return vector_cast<Vec3f>(mesh_.point(_vh)); return vector_cast<Vec3f>(mesh_.point(_vh));
} }
Vec3f normal(VertexHandle _vh) const Vec3f normal(VertexHandle _vh) const
{ {
return (mesh_.has_vertex_normals() return (mesh_.has_vertex_normals()
? vector_cast<Vec3f>(mesh_.normal(_vh)) ? vector_cast<Vec3f>(mesh_.normal(_vh))
: Vec3f(0.0f, 0.0f, 0.0f)); : Vec3f(0.0f, 0.0f, 0.0f));
} }
Vec3uc color(VertexHandle _vh) const Vec3uc color(VertexHandle _vh) const
{ {
return (mesh_.has_vertex_colors() return (mesh_.has_vertex_colors()
? color_cast<Vec3uc>(mesh_.color(_vh)) ? color_cast<Vec3uc>(mesh_.color(_vh))
: Vec3uc(0, 0, 0)); : Vec3uc(0, 0, 0));
} }
Vec4uc colorA(VertexHandle _vh) const Vec4uc colorA(VertexHandle _vh) const
{ {
return (mesh_.has_vertex_colors() return (mesh_.has_vertex_colors()
? color_cast<Vec4uc>(mesh_.color(_vh)) ? color_cast<Vec4uc>(mesh_.color(_vh))
: Vec4uc(0, 0, 0, 0)); : Vec4uc(0, 0, 0, 0));
} }
Vec3ui colori(VertexHandle _vh) const
{
return (mesh_.has_vertex_colors()
? color_cast<Vec3ui>(mesh_.color(_vh))
: Vec3ui(0, 0, 0));
}
Vec4ui colorAi(VertexHandle _vh) const
{
return (mesh_.has_vertex_colors()
? color_cast<Vec4ui>(mesh_.color(_vh))
: Vec4ui(0, 0, 0, 0));
}
Vec2f texcoord(VertexHandle _vh) const Vec2f texcoord(VertexHandle _vh) const
{ {
#if defined(OM_CC_GCC) && (OM_CC_VERSION<30000) #if defined(OM_CC_GCC) && (OM_CC_VERSION<30000)
// Workaround! // Workaround!
// gcc 2.95.3 exits with internal compiler error at the // gcc 2.95.3 exits with internal compiler error at the
// code below!??? **) // code below!??? **)
if (mesh_.has_vertex_texcoords2D()) if (mesh_.has_vertex_texcoords2D())
return vector_cast<Vec2f>(mesh_.texcoord2D(_vh)); return vector_cast<Vec2f>(mesh_.texcoord2D(_vh));
return Vec2f(0.0f, 0.0f); return Vec2f(0.0f, 0.0f);
#else // **) #else // **)
return (mesh_.has_vertex_texcoords2D() return (mesh_.has_vertex_texcoords2D()
? vector_cast<Vec2f>(mesh_.texcoord2D(_vh)) ? vector_cast<Vec2f>(mesh_.texcoord2D(_vh))
: Vec2f(0.0f, 0.0f)); : Vec2f(0.0f, 0.0f));
#endif #endif
} }
// get edge data // get edge data
Vec3uc color(EdgeHandle _eh) const Vec3uc color(EdgeHandle _eh) const
{ {
return (mesh_.has_edge_colors() return (mesh_.has_edge_colors()
? color_cast<Vec3uc>(mesh_.color(_eh)) ? color_cast<Vec3uc>(mesh_.color(_eh))
: Vec3uc(0, 0, 0)); : Vec3uc(0, 0, 0));
} }
Vec4uc colorA(EdgeHandle _eh) const Vec4uc colorA(EdgeHandle _eh) const
{ {
return (mesh_.has_edge_colors() return (mesh_.has_edge_colors()
? color_cast<Vec4uc>(mesh_.color(_eh)) ? color_cast<Vec4uc>(mesh_.color(_eh))
: Vec4uc(0, 0, 0, 0)); : Vec4uc(0, 0, 0, 0));
} }
Vec3ui colori(EdgeHandle _eh) const
{
return (mesh_.has_edge_colors()
? color_cast<Vec3ui>(mesh_.color(_eh))
: Vec3ui(0, 0, 0));
}
Vec4ui colorAi(EdgeHandle _eh) const
{
return (mesh_.has_edge_colors()
? color_cast<Vec4ui>(mesh_.color(_eh))
: Vec4ui(0, 0, 0, 0));
}
// get face data // get face data
unsigned int get_vhandles(FaceHandle _fh, unsigned int get_vhandles(FaceHandle _fh,
std::vector<VertexHandle>& _vhandles) const std::vector<VertexHandle>& _vhandles) const
{ {
unsigned int count(0); unsigned int count(0);
@@ -161,32 +188,46 @@ public:
return count; return count;
} }
Vec3f normal(FaceHandle _fh) const Vec3f normal(FaceHandle _fh) const
{ {
return (mesh_.has_face_normals() return (mesh_.has_face_normals()
? vector_cast<Vec3f>(mesh_.normal(_fh)) ? vector_cast<Vec3f>(mesh_.normal(_fh))
: Vec3f(0.0f, 0.0f, 0.0f)); : Vec3f(0.0f, 0.0f, 0.0f));
} }
Vec3uc color(FaceHandle _fh) const Vec3uc color(FaceHandle _fh) const
{ {
return (mesh_.has_face_colors() return (mesh_.has_face_colors()
? color_cast<Vec3uc>(mesh_.color(_fh)) ? color_cast<Vec3uc>(mesh_.color(_fh))
: Vec3uc(0, 0, 0)); : Vec3uc(0, 0, 0));
} }
Vec4uc colorA(FaceHandle _fh) const Vec4uc colorA(FaceHandle _fh) const
{ {
return (mesh_.has_face_colors() return (mesh_.has_face_colors()
? color_cast<Vec4uc>(mesh_.color(_fh)) ? color_cast<Vec4uc>(mesh_.color(_fh))
: Vec4uc(0, 0, 0, 0)); : Vec4uc(0, 0, 0, 0));
} }
Vec3ui colori(FaceHandle _fh) const
{
return (mesh_.has_face_colors()
? color_cast<Vec3ui>(mesh_.color(_fh))
: Vec3ui(0, 0, 0));
}
Vec4ui colorAi(FaceHandle _fh) const
{
return (mesh_.has_face_colors()
? color_cast<Vec4ui>(mesh_.color(_fh))
: Vec4ui(0, 0, 0, 0));
}
virtual const BaseKernel* kernel() { return &mesh_; } virtual const BaseKernel* kernel() { return &mesh_; }
// query number of faces, vertices, normals, texcoords // query number of faces, vertices, normals, texcoords
size_t n_vertices() const { return mesh_.n_vertices(); } size_t n_vertices() const { return mesh_.n_vertices(); }
size_t n_faces() const { return mesh_.n_faces(); } size_t n_faces() const { return mesh_.n_faces(); }
size_t n_edges() const { return mesh_.n_edges(); } size_t n_edges() const { return mesh_.n_edges(); }
@@ -194,7 +235,7 @@ public:
// property information // property information
bool is_triangle_mesh() const bool is_triangle_mesh() const
{ return Mesh::is_triangles(); } { return Mesh::is_triangles(); }
bool has_vertex_normals() const { return mesh_.has_vertex_normals(); } bool has_vertex_normals() const { return mesh_.has_vertex_normals(); }
bool has_vertex_colors() const { return mesh_.has_vertex_colors(); } bool has_vertex_colors() const { return mesh_.has_vertex_colors(); }
bool has_vertex_texcoords() const { return mesh_.has_vertex_texcoords2D(); } bool has_vertex_texcoords() const { return mesh_.has_vertex_texcoords2D(); }
@@ -203,7 +244,7 @@ public:
bool has_face_colors() const { return mesh_.has_face_colors(); } bool has_face_colors() const { return mesh_.has_face_colors(); }
private: private:
const Mesh& mesh_; const Mesh& mesh_;
}; };

View File

@@ -178,8 +178,8 @@ write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const
unsigned int i, j, nV, nF; unsigned int i, j, nV, nF;
Vec3f v, n; Vec3f v, n;
OpenMesh::Vec3uc c; OpenMesh::Vec3ui c;
OpenMesh::Vec4uc cA; OpenMesh::Vec4ui cA;
OpenMesh::Vec2f t; OpenMesh::Vec2f t;
VertexHandle vh; VertexHandle vh;
std::vector<VertexHandle> vhandles; std::vector<VertexHandle> vhandles;
@@ -242,12 +242,12 @@ write_ascii(std::ostream& _out, BaseExporter& _be, Options _opt) const
if ( _opt.vertex_has_color() ) { if ( _opt.vertex_has_color() ) {
//with alpha //with alpha
if ( _opt.color_has_alpha() ){ if ( _opt.color_has_alpha() ){
cA = _be.colorA(vh); cA = _be.colorAi(vh);
_out << " " << (unsigned int)cA[0] << " " << (unsigned int)cA[1] << " " << (unsigned int)cA[2] << " " << (unsigned int)cA[3]; _out << " " << cA;
}else{ }else{
//without alpha //without alpha
c = _be.color(vh); c = _be.colori(vh);
_out << " " << (unsigned int)c[0] << " " << (unsigned int)c[1] << " " << (unsigned int)c[2]; _out << " " << c;
} }
} }

View File

@@ -140,6 +140,20 @@ struct color_caster<Vec3i,Vec4f>
} }
}; };
template <>
struct color_caster<Vec4i,Vec4f>
{
typedef Vec4i return_type;
inline static return_type cast(const Vec4f& _src)
{
return Vec4i( (int)(_src[0]* 255.0f + 0.5f),
(int)(_src[1]* 255.0f + 0.5f),
(int)(_src[2]* 255.0f + 0.5f),
(int)(_src[3]* 255.0f + 0.5f) );
}
};
template <> template <>
struct color_caster<Vec3ui,Vec3f> struct color_caster<Vec3ui,Vec3f>
{ {
@@ -166,6 +180,20 @@ struct color_caster<Vec3ui,Vec4f>
} }
}; };
template <>
struct color_caster<Vec4ui,Vec4f>
{
typedef Vec4ui return_type;
inline static return_type cast(const Vec4f& _src)
{
return Vec4ui( (unsigned int)(_src[0]* 255.0f + 0.5f),
(unsigned int)(_src[1]* 255.0f + 0.5f),
(unsigned int)(_src[2]* 255.0f + 0.5f),
(unsigned int)(_src[3]* 255.0f + 0.5f) );
}
};
template <> template <>
struct color_caster<Vec4uc,Vec3f> struct color_caster<Vec4uc,Vec3f>
{ {