triangularMesh.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef __TRIANGULARMESH_HH
22 #define __TRIANGULARMESH_HH 1
23 
24 
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28 
29 #include <string>
30 #include <mia/core/iodata.hh>
31 #include <mia/core/ioplugin.hh>
32 #include <mia/core/iohandler.hh>
33 #include <mia/3d/vector.hh>
34 
35 #ifdef WIN32
36 # ifdef miamesh_EXPORTS
37 # define EXPORT_MESH __declspec(dllexport)
38 # else
39 # define EXPORT_MESH __declspec(dllimport)
40 # endif
41 #else
42 # ifdef __GNUC__
43 # define EXPORT_MESH __attribute__((visibility("default")))
45 # else
46 # define EXPORT_MESH
47 # endif
48 
49 #endif
50 
51 
53 
62 
63 public:
66  static const char *data_descr;
67 
68  typedef CTriangleMesh type;
69 
70 
71  typedef std::shared_ptr<CTriangleMesh> Pointer;
72 
74  enum EData {ed_none = 0,
75  ed_vertex = 1,
76  ed_normal = 2,
77  ed_color = 4,
78  ed_scale = 8};
79 
81  typedef std::vector<T3DVector<unsigned int> > CTrianglefield;
82  typedef std::vector<C3DFVector> CVertexfield;
83  typedef std::vector<C3DFVector> CNormalfield;
84  typedef std::vector<C3DFVector> CColorfield;
85  typedef std::vector<float> CScalefield;
86 
87  typedef std::shared_ptr<CTrianglefield > PTrianglefield;
88  typedef std::shared_ptr<CVertexfield > PVertexfield;
89  typedef std::shared_ptr<CNormalfield > PNormalfield;
90  typedef std::shared_ptr<CColorfield > PColorfield;
91  typedef std::shared_ptr<CScalefield > PScalefield;
92 
93  typedef CTrianglefield::value_type triangle_type;
94  typedef CVertexfield::value_type vertex_type;
95  typedef CNormalfield::value_type normal_type;
96  typedef CColorfield::value_type color_type;
97  typedef CScalefield::value_type scale_type;
98 
99  typedef CVertexfield::const_iterator const_vertex_iterator;
100  typedef CVertexfield::iterator vertex_iterator;
101 
102  typedef CTrianglefield::const_iterator const_triangle_iterator;
103  typedef CTrianglefield::iterator triangle_iterator;
104 
105  typedef CNormalfield::const_iterator const_normal_iterator;
106  typedef CNormalfield::iterator normal_iterator;
107 
108  typedef CScalefield::const_iterator const_scale_iterator;
109  typedef CScalefield::iterator scale_iterator;
110 
111  typedef CColorfield::const_iterator const_color_iterator;
112  typedef CColorfield::iterator color_iterator;
114 
116  CTriangleMesh();
117 
123  CTriangleMesh(const CTriangleMesh& orig);
124 
129  CTriangleMesh(int n_triangles, int n_vertices);
130 
138  CTriangleMesh(PTrianglefield triangles,
139  PVertexfield vertices,
140  PNormalfield normals,
141  PColorfield colors,
142  PScalefield scales);
143 
148  CTriangleMesh(PTrianglefield triangles, PVertexfield vertices);
149 
150 
152  CTriangleMesh *clone() const __attribute__((warn_unused_result));
153 
156  CTriangleMesh clone_connectivity()const;
157 
159  ~CTriangleMesh();
160 
164  static const std::string get_type_description();
165 
169  int get_available_data() const;
170 
174  const void *get_vertex_pointer()const;
175 
179  const void *get_normal_pointer()const;
180 
181 
185  const void *get_triangle_pointer()const;
186 
190  const void *get_color_pointer()const;
191 
192 
196  unsigned int triangle_size()const;
197 
201  unsigned int vertices_size()const;
202 
206  const triangle_type& triangle_at(unsigned int i)const;
207 
211  const vertex_type& vertex_at(unsigned int i)const;
212 
216  const normal_type& normal_at(unsigned int i)const;
217 
221  const scale_type& scale_at(unsigned int i)const;
222 
227  const color_type& color_at(unsigned int i)const;
228 
229 
230  const CVertexfield& get_vertices() const;
231  const CTrianglefield& get_triangles() const;
232 
234  const_triangle_iterator triangles_begin() const;
235  triangle_iterator triangles_begin();
236  const_triangle_iterator triangles_end() const;
237  triangle_iterator triangles_end();
238 
239  const_vertex_iterator vertices_begin()const;
240  const_vertex_iterator vertices_end()const;
241  vertex_iterator vertices_begin();
242  vertex_iterator vertices_end();
243 
244  const_normal_iterator normals_begin()const;
245  const_normal_iterator normals_end()const;
246  normal_iterator normals_begin();
247  normal_iterator normals_end();
248 
249  const_scale_iterator scale_begin()const;
250  const_scale_iterator scale_end()const;
251  scale_iterator scale_begin();
252  scale_iterator scale_end();
253 
254  const_color_iterator color_begin()const;
255  const_color_iterator color_end()const;
256  color_iterator color_begin();
257  color_iterator color_end();
259 
261  const std::string& get_sourceformat()const {
262  return m_sourceformat;
263  }
264 
266  void set_sourceformat(const std::string& fmt){
267  m_sourceformat = fmt;
268  }
269 
275  void evaluate_normals();
276 
277 private:
278  std::string m_sourceformat;
279  struct CTriangleMeshData * data;
280 };
281 
284 
285 
286 PTriangleMesh EXPORT_MESH get_sub_mesh(const CTriangleMesh& mesh, const std::vector<unsigned>& triangle_indices);
287 
288 
296 template <class Deformation>
297 void colorize_mesh(CTriangleMesh *mesh, const Deformation& deform)
298 {
300  mesh->evaluate_normals();
301 
302  // make sure we use the const versions of some iterators to keep the sharing of
303  // vertex (and evl. normal) data
304  const CTriangleMesh& cmesh = *mesh;
305 
306 
307  CTriangleMesh::scale_iterator sb = mesh->scale_begin();
308  CTriangleMesh::scale_iterator se = mesh->scale_end();
309 
310  CTriangleMesh::const_vertex_iterator vb = cmesh.vertices_begin();
311  CTriangleMesh::const_normal_iterator nb = cmesh.normals_begin();
312 
313  while (sb != se)
314  *sb++ = dot(*nb++, deform.apply(*vb++));
315 
316 }
317 
318 
327 template <class Deformation>
328 CTriangleMesh colorize_mesh(const CTriangleMesh& mesh, const Deformation& deform)
329 {
330  CTriangleMesh result(mesh);
331  colorize_mesh(&result,deform);
332  return result;
333 }
334 
335 
336 /* evaluate the distance between two meshes, and set the scale accordingly
337  \param mesh this mesh will get the per vertex distance values in its scale
338  \param reference the mesh we want to know the distance from
339  void distance_transform(CTriangleMesh *mesh, const CTriangleMesh& reference);
340 */
341 
342 
345 
347 extern template class EXPORT_MESH TIOPlugin<CTriangleMesh>;
348 
351 
352 
354 
355 #endif // __TRIANGULARMESH_HH
the singleton that a plug-in handler really is
Definition: handler.hh:157
PTriangleMesh EXPORT_MESH get_sub_mesh(const CTriangleMesh &mesh, const std::vector< unsigned > &triangle_indices)
CTriangleMesh type
EData
these are some flags to indicate, which data is actually available
void set_sourceformat(const std::string &fmt)
The templatex basis class of all IO plug-ins.
Definition: ioplugin.hh:57
#define EXPORT_MESH
define visibility for proper export
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
void evaluate_normals()
THandlerSingleton< TIOPluginHandler< CMeshIOPlugin > > CMeshIOPluginHandler
Plug-in handler for triangulat mesh IO.
helper class to derive from for data that can be loaded and stored to a disk.
Definition: iodata.hh:36
A class to deine a triangle mesh with some attributes.
double EXPORT_GSL dot(const gsl_vector *lhs, const gsl_vector *rhs)
CTriangleMesh::Pointer PTriangleMesh
Pointer type of the CTriangle mesh class.
void colorize_mesh(CTriangleMesh *mesh, const Deformation &deform)
static const char * data_descr
TIOPlugin< CTriangleMesh > CMeshIOPlugin
IO plugin for triangular meshes.
std::shared_ptr< CTriangleMesh > Pointer
int get_available_data() const
The generic base for all plug-ins.
Definition: plugin_base.hh:170
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36