OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ExporterT.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5  * www.openmesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenMesh. *
9  * *
10  * OpenMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 736 $ *
38  * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08 Okt 2012) $ *
39  * *
40 \*===========================================================================*/
41 
42 
43 //=============================================================================
44 //
45 // Implements an exporter module for arbitrary OpenMesh meshes
46 //
47 //=============================================================================
48 
49 
50 #ifndef __EXPORTERT_HH__
51 #define __EXPORTERT_HH__
52 
53 
54 //=== INCLUDES ================================================================
55 
56 // C++
57 #include <vector>
58 
59 // OpenMesh
60 #include <OpenMesh/Core/System/config.h>
61 #include <OpenMesh/Core/Geometry/VectorT.hh>
62 #include <OpenMesh/Core/Utils/GenProg.hh>
63 #include <OpenMesh/Core/Utils/vector_cast.hh>
64 #include <OpenMesh/Core/Utils/color_cast.hh>
65 #include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
66 
67 
68 //=== NAMESPACES ==============================================================
69 
70 namespace OpenMesh {
71 namespace IO {
72 
73 
74 //=== EXPORTER CLASS ==========================================================
75 
79 template <class Mesh>
80 class ExporterT : public BaseExporter
81 {
82 public:
83 
84  // Constructor
85  ExporterT(const Mesh& _mesh) : mesh_(_mesh) {}
86 
87 
88  // get vertex data
89 
90  Vec3f point(VertexHandle _vh) const
91  {
92  return vector_cast<Vec3f>(mesh_.point(_vh));
93  }
94 
95  Vec3f normal(VertexHandle _vh) const
96  {
97  return (mesh_.has_vertex_normals()
98  ? vector_cast<Vec3f>(mesh_.normal(_vh))
99  : Vec3f(0.0f, 0.0f, 0.0f));
100  }
101 
102  Vec3uc color(VertexHandle _vh) const
103  {
104  return (mesh_.has_vertex_colors()
105  ? color_cast<Vec3uc>(mesh_.color(_vh))
106  : Vec3uc(0, 0, 0));
107  }
108 
109  Vec4uc colorA(VertexHandle _vh) const
110  {
111  return (mesh_.has_vertex_colors()
112  ? color_cast<Vec4uc>(mesh_.color(_vh))
113  : Vec4uc(0, 0, 0, 0));
114  }
115 
116  Vec2f texcoord(VertexHandle _vh) const
117  {
118 #if defined(OM_CC_GCC) && (OM_CC_VERSION<30000)
119  // Workaround!
120  // gcc 2.95.3 exits with internal compiler error at the
121  // code below!??? **)
122  if (mesh_.has_vertex_texcoords2D())
123  return vector_cast<Vec2f>(mesh_.texcoord2D(_vh));
124  return Vec2f(0.0f, 0.0f);
125 #else // **)
126  return (mesh_.has_vertex_texcoords2D()
127  ? vector_cast<Vec2f>(mesh_.texcoord2D(_vh))
128  : Vec2f(0.0f, 0.0f));
129 #endif
130  }
131 
132  // get edge data
133 
134  Vec3uc color(EdgeHandle _eh) const
135  {
136  return (mesh_.has_edge_colors()
137  ? color_cast<Vec3uc>(mesh_.color(_eh))
138  : Vec3uc(0, 0, 0));
139  }
140 
141  Vec4uc colorA(EdgeHandle _eh) const
142  {
143  return (mesh_.has_edge_colors()
144  ? color_cast<Vec4uc>(mesh_.color(_eh))
145  : Vec4uc(0, 0, 0, 0));
146  }
147 
148 
149  // get face data
150 
151  unsigned int get_vhandles(FaceHandle _fh,
152  std::vector<VertexHandle>& _vhandles) const
153  {
154  unsigned int count(0);
155  _vhandles.clear();
156  for (typename Mesh::CFVIter fv_it=mesh_.cfv_iter(_fh); fv_it; ++fv_it)
157  {
158  _vhandles.push_back(fv_it.handle());
159  ++count;
160  }
161  return count;
162  }
163 
164  Vec3f normal(FaceHandle _fh) const
165  {
166  return (mesh_.has_face_normals()
167  ? vector_cast<Vec3f>(mesh_.normal(_fh))
168  : Vec3f(0.0f, 0.0f, 0.0f));
169  }
170 
171  Vec3uc color(FaceHandle _fh) const
172  {
173  return (mesh_.has_face_colors()
174  ? color_cast<Vec3uc>(mesh_.color(_fh))
175  : Vec3uc(0, 0, 0));
176  }
177 
178  Vec4uc colorA(FaceHandle _fh) const
179  {
180  return (mesh_.has_face_colors()
181  ? color_cast<Vec4uc>(mesh_.color(_fh))
182  : Vec4uc(0, 0, 0, 0));
183  }
184 
185  virtual const BaseKernel* kernel() { return &mesh_; }
186 
187 
188  // query number of faces, vertices, normals, texcoords
189  size_t n_vertices() const { return mesh_.n_vertices(); }
190  size_t n_faces() const { return mesh_.n_faces(); }
191  size_t n_edges() const { return mesh_.n_edges(); }
192 
193 
194  // property information
195  bool is_triangle_mesh() const
196  { return Mesh::is_triangles(); }
197 
198  bool has_vertex_normals() const { return mesh_.has_vertex_normals(); }
199  bool has_vertex_colors() const { return mesh_.has_vertex_colors(); }
200  bool has_vertex_texcoords() const { return mesh_.has_vertex_texcoords2D(); }
201  bool has_edge_colors() const { return mesh_.has_edge_colors(); }
202  bool has_face_normals() const { return mesh_.has_face_normals(); }
203  bool has_face_colors() const { return mesh_.has_face_colors(); }
204 
205 private:
206 
207  const Mesh& mesh_;
208 };
209 
210 
211 //=============================================================================
212 } // namespace IO
213 } // namespace OpenMesh
214 //=============================================================================
215 #endif
216 //=============================================================================

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .