My Project
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__
44# define EXPORT_MESH __attribute__((visibility("default")))
45# else
46# define EXPORT_MESH
47# endif
48
49#endif
50
51
53
62{
63
64public:
67 static const char *data_descr;
68
70
71
72 typedef std::shared_ptr<CTriangleMesh> Pointer;
73
75 enum EData {ed_none = 0,
76 ed_vertex = 1,
77 ed_normal = 2,
78 ed_color = 4,
79 ed_scale = 8
80 };
81
83 typedef std::vector<T3DVector<unsigned int>> CTrianglefield;
84 typedef std::vector<C3DFVector> CVertexfield;
85 typedef std::vector<C3DFVector> CNormalfield;
86 typedef std::vector<C3DFVector> CColorfield;
87 typedef std::vector<float> CScalefield;
88
89 typedef std::shared_ptr<CTrianglefield > PTrianglefield;
90 typedef std::shared_ptr<CVertexfield > PVertexfield;
91 typedef std::shared_ptr<CNormalfield > PNormalfield;
92 typedef std::shared_ptr<CColorfield > PColorfield;
93 typedef std::shared_ptr<CScalefield > PScalefield;
94
95 typedef CTrianglefield::value_type triangle_type;
96 typedef CVertexfield::value_type vertex_type;
97 typedef CNormalfield::value_type normal_type;
98 typedef CColorfield::value_type color_type;
99 typedef CScalefield::value_type scale_type;
100
101 typedef CVertexfield::const_iterator const_vertex_iterator;
102 typedef CVertexfield::iterator vertex_iterator;
103
104 typedef CTrianglefield::const_iterator const_triangle_iterator;
105 typedef CTrianglefield::iterator triangle_iterator;
106
107 typedef CNormalfield::const_iterator const_normal_iterator;
108 typedef CNormalfield::iterator normal_iterator;
109
110 typedef CScalefield::const_iterator const_scale_iterator;
111 typedef CScalefield::iterator scale_iterator;
112
113 typedef CColorfield::const_iterator const_color_iterator;
114 typedef CColorfield::iterator color_iterator;
116
119
126
131 CTriangleMesh(int n_triangles, int n_vertices);
132
140 CTriangleMesh(PTrianglefield triangles,
141 PVertexfield vertices,
142 PNormalfield normals,
143 PColorfield colors,
144 PScalefield scales);
145
150 CTriangleMesh(PTrianglefield triangles, PVertexfield vertices);
151
152
154 CTriangleMesh *clone() const __attribute__((warn_unused_result));
155
158 CTriangleMesh clone_connectivity()const;
159
162
166 static const std::string get_type_description();
167
171 int get_available_data() const;
172
176 const void *get_vertex_pointer()const;
177
181 const void *get_normal_pointer()const;
182
183
187 const void *get_triangle_pointer()const;
188
192 const void *get_color_pointer()const;
193
194
198 unsigned int triangle_size()const;
199
203 unsigned int vertices_size()const;
204
208 const triangle_type& triangle_at(unsigned int i)const;
209
213 const vertex_type& vertex_at(unsigned int i)const;
214
218 const normal_type& normal_at(unsigned int i)const;
219
223 const scale_type& scale_at(unsigned int i)const;
224
229 const color_type& color_at(unsigned int i)const;
230
231
232 const CVertexfield& get_vertices() const;
233 const CTrianglefield& get_triangles() const;
234
236 const_triangle_iterator triangles_begin() const;
237 triangle_iterator triangles_begin();
238 const_triangle_iterator triangles_end() const;
239 triangle_iterator triangles_end();
240
241 const_vertex_iterator vertices_begin()const;
242 const_vertex_iterator vertices_end()const;
243 vertex_iterator vertices_begin();
244 vertex_iterator vertices_end();
245
246 const_normal_iterator normals_begin()const;
247 const_normal_iterator normals_end()const;
248 normal_iterator normals_begin();
249 normal_iterator normals_end();
250
251 const_scale_iterator scale_begin()const;
252 const_scale_iterator scale_end()const;
253 scale_iterator scale_begin();
254 scale_iterator scale_end();
255
256 const_color_iterator color_begin()const;
257 const_color_iterator color_end()const;
258 color_iterator color_begin();
259 color_iterator color_end();
261
263 const std::string& get_sourceformat()const
264 {
265 return m_sourceformat;
266 }
267
269 void set_sourceformat(const std::string& fmt)
270 {
271 m_sourceformat = fmt;
272 }
273
280
281private:
282 std::string m_sourceformat;
283 struct CTriangleMeshData *data;
284};
285
288
289
290PTriangleMesh EXPORT_MESH get_sub_mesh(const CTriangleMesh& mesh, const std::vector<unsigned>& triangle_indices);
291
292
300template <class Deformation>
301void colorize_mesh(CTriangleMesh *mesh, const Deformation& deform)
302{
304 mesh->evaluate_normals();
305
306 // make sure we use the const versions of some iterators to keep the sharing of
307 // vertex (and evl. normal) data
308 const CTriangleMesh& cmesh = *mesh;
309 CTriangleMesh::scale_iterator sb = mesh->scale_begin();
310 CTriangleMesh::scale_iterator se = mesh->scale_end();
311 CTriangleMesh::const_vertex_iterator vb = cmesh.vertices_begin();
312 CTriangleMesh::const_normal_iterator nb = cmesh.normals_begin();
313
314 while (sb != se)
315 *sb++ = dot(*nb++, deform.apply(*vb++));
316}
317
318
327template <class Deformation>
328CTriangleMesh 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
347extern template class EXPORT_MESH TIOPlugin<CTriangleMesh>;
348
351
352
354
355#endif // __TRIANGULARMESH_HH
T dot(const T2DVector< T > &a, const T2DVector< T > &b)
Definition 2d/vector.hh:437
helper class to derive from for data that can be loaded and stored to a disk.
Definition iodata.hh:37
A class to deine a triangle mesh with some attributes.
CTriangleMesh * clone() const __attribute__((warn_unused_result))
EData
these are some flags to indicate, which data is actually available
CTriangleMesh()
Standart constructor creates an empty mesh.
CTriangleMesh type
CTriangleMesh(const CTriangleMesh &orig)
CTriangleMesh(int n_triangles, int n_vertices)
int get_available_data() const
std::shared_ptr< CTriangleMesh > Pointer
void evaluate_normals()
CTriangleMesh(PTrianglefield triangles, PVertexfield vertices)
void set_sourceformat(const std::string &fmt)
CTriangleMesh(PTrianglefield triangles, PVertexfield vertices, PNormalfield normals, PColorfield colors, PScalefield scales)
static const char * data_descr
the singleton that a plug-in handler really is
Definition handler.hh:159
The templatex basis class of all IO plug-ins.
Definition ioplugin.hh:58
The generic base for all plug-ins.
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
THandlerSingleton< TIOPluginHandler< CMeshIOPlugin > > CMeshIOPluginHandler
Plug-in handler for triangulat mesh IO.
PTriangleMesh EXPORT_MESH get_sub_mesh(const CTriangleMesh &mesh, const std::vector< unsigned > &triangle_indices)
#define EXPORT_MESH
define visibility for proper export
void colorize_mesh(CTriangleMesh *mesh, const Deformation &deform)
TIOPlugin< CTriangleMesh > CMeshIOPlugin
IO plugin for triangular meshes.
CTriangleMesh::Pointer PTriangleMesh
Pointer type of the CTriangle mesh class.