OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExporterT.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2014 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: 990 $ *
38  * $Date: 2014-02-05 10:01:07 +0100 (Mi, 05 Feb 2014) $ *
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  Vec3ui colori(VertexHandle _vh) const
117  {
118  return (mesh_.has_vertex_colors()
119  ? color_cast<Vec3ui>(mesh_.color(_vh))
120  : Vec3ui(0, 0, 0));
121  }
122 
123  Vec4ui colorAi(VertexHandle _vh) const
124  {
125  return (mesh_.has_vertex_colors()
126  ? color_cast<Vec4ui>(mesh_.color(_vh))
127  : Vec4ui(0, 0, 0, 0));
128  }
129 
130  Vec3f colorf(VertexHandle _vh) const
131  {
132  return (mesh_.has_vertex_colors()
133  ? color_cast<Vec3f>(mesh_.color(_vh))
134  : Vec3f(0, 0, 0));
135  }
136 
137  Vec4f colorAf(VertexHandle _vh) const
138  {
139  return (mesh_.has_vertex_colors()
140  ? color_cast<Vec4f>(mesh_.color(_vh))
141  : Vec4f(0, 0, 0, 0));
142  }
143 
144  Vec2f texcoord(VertexHandle _vh) const
145  {
146 #if defined(OM_CC_GCC) && (OM_CC_VERSION<30000)
147  // Workaround!
148  // gcc 2.95.3 exits with internal compiler error at the
149  // code below!??? **)
150  if (mesh_.has_vertex_texcoords2D())
151  return vector_cast<Vec2f>(mesh_.texcoord2D(_vh));
152  return Vec2f(0.0f, 0.0f);
153 #else // **)
154  return (mesh_.has_vertex_texcoords2D()
155  ? vector_cast<Vec2f>(mesh_.texcoord2D(_vh))
156  : Vec2f(0.0f, 0.0f));
157 #endif
158  }
159 
160  // get edge data
161 
162  Vec3uc color(EdgeHandle _eh) const
163  {
164  return (mesh_.has_edge_colors()
165  ? color_cast<Vec3uc>(mesh_.color(_eh))
166  : Vec3uc(0, 0, 0));
167  }
168 
169  Vec4uc colorA(EdgeHandle _eh) const
170  {
171  return (mesh_.has_edge_colors()
172  ? color_cast<Vec4uc>(mesh_.color(_eh))
173  : Vec4uc(0, 0, 0, 0));
174  }
175 
176  Vec3ui colori(EdgeHandle _eh) const
177  {
178  return (mesh_.has_edge_colors()
179  ? color_cast<Vec3ui>(mesh_.color(_eh))
180  : Vec3ui(0, 0, 0));
181  }
182 
183  Vec4ui colorAi(EdgeHandle _eh) const
184  {
185  return (mesh_.has_edge_colors()
186  ? color_cast<Vec4ui>(mesh_.color(_eh))
187  : Vec4ui(0, 0, 0, 0));
188  }
189 
190  Vec3f colorf(EdgeHandle _eh) const
191  {
192  return (mesh_.has_vertex_colors()
193  ? color_cast<Vec3f>(mesh_.color(_eh))
194  : Vec3f(0, 0, 0));
195  }
196 
197  Vec4f colorAf(EdgeHandle _eh) const
198  {
199  return (mesh_.has_vertex_colors()
200  ? color_cast<Vec4f>(mesh_.color(_eh))
201  : Vec4f(0, 0, 0, 0));
202  }
203 
204  // get face data
205 
206  unsigned int get_vhandles(FaceHandle _fh,
207  std::vector<VertexHandle>& _vhandles) const
208  {
209  unsigned int count(0);
210  _vhandles.clear();
211  for (typename Mesh::CFVIter fv_it=mesh_.cfv_iter(_fh); fv_it.is_valid(); ++fv_it)
212  {
213  _vhandles.push_back(*fv_it);
214  ++count;
215  }
216  return count;
217  }
218 
219  Vec3f normal(FaceHandle _fh) const
220  {
221  return (mesh_.has_face_normals()
222  ? vector_cast<Vec3f>(mesh_.normal(_fh))
223  : Vec3f(0.0f, 0.0f, 0.0f));
224  }
225 
226  Vec3uc color(FaceHandle _fh) const
227  {
228  return (mesh_.has_face_colors()
229  ? color_cast<Vec3uc>(mesh_.color(_fh))
230  : Vec3uc(0, 0, 0));
231  }
232 
233  Vec4uc colorA(FaceHandle _fh) const
234  {
235  return (mesh_.has_face_colors()
236  ? color_cast<Vec4uc>(mesh_.color(_fh))
237  : Vec4uc(0, 0, 0, 0));
238  }
239 
240  Vec3ui colori(FaceHandle _fh) const
241  {
242  return (mesh_.has_face_colors()
243  ? color_cast<Vec3ui>(mesh_.color(_fh))
244  : Vec3ui(0, 0, 0));
245  }
246 
247  Vec4ui colorAi(FaceHandle _fh) const
248  {
249  return (mesh_.has_face_colors()
250  ? color_cast<Vec4ui>(mesh_.color(_fh))
251  : Vec4ui(0, 0, 0, 0));
252  }
253 
254  Vec3f colorf(FaceHandle _fh) const
255  {
256  return (mesh_.has_vertex_colors()
257  ? color_cast<Vec3f>(mesh_.color(_fh))
258  : Vec3f(0, 0, 0));
259  }
260 
261  Vec4f colorAf(FaceHandle _fh) const
262  {
263  return (mesh_.has_vertex_colors()
264  ? color_cast<Vec4f>(mesh_.color(_fh))
265  : Vec4f(0, 0, 0, 0));
266  }
267 
268  virtual const BaseKernel* kernel() { return &mesh_; }
269 
270 
271  // query number of faces, vertices, normals, texcoords
272  size_t n_vertices() const { return mesh_.n_vertices(); }
273  size_t n_faces() const { return mesh_.n_faces(); }
274  size_t n_edges() const { return mesh_.n_edges(); }
275 
276 
277  // property information
278  bool is_triangle_mesh() const
279  { return Mesh::is_triangles(); }
280 
281  bool has_vertex_normals() const { return mesh_.has_vertex_normals(); }
282  bool has_vertex_colors() const { return mesh_.has_vertex_colors(); }
283  bool has_vertex_texcoords() const { return mesh_.has_vertex_texcoords2D(); }
284  bool has_edge_colors() const { return mesh_.has_edge_colors(); }
285  bool has_face_normals() const { return mesh_.has_face_normals(); }
286  bool has_face_colors() const { return mesh_.has_face_colors(); }
287 
288 private:
289 
290  const Mesh& mesh_;
291 };
292 
293 
294 //=============================================================================
295 } // namespace IO
296 } // namespace OpenMesh
297 //=============================================================================
298 #endif
299 //=============================================================================
vector_caster< dst_t, src_t >::return_type vector_cast(const src_t &_src)
Cast vector type to another vector type by copying the vector elements.
Definition: vector_cast.hh:170
This class template provides an exporter module for OpenMesh meshes.
Definition: ExporterT.hh:80
Handle for a edge entity.
Definition: Handles.hh:128
Handle for a face entity.
Definition: Handles.hh:135
Base class for exporter modules.
Definition: BaseExporter.hh:82
This class provides the basic property management like adding/removing properties and access to prope...
Definition: BaseKernel.hh:91
Handle for a vertex entity.
Definition: Handles.hh:114

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