triangularMesh.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __TRIANGULARMESH_HH
#define __TRIANGULARMESH_HH 1
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string>
#include <mia/core/iodata.hh>
#include <mia/core/ioplugin.hh>
#include <mia/core/iohandler.hh>
#include <mia/3d/vector.hh>
#ifdef WIN32
# ifdef miamesh_EXPORTS
# define EXPORT_MESH __declspec(dllexport)
# else
# define EXPORT_MESH __declspec(dllimport)
# endif
#else
# ifdef __GNUC__
# define EXPORT_MESH __attribute__((visibility("default")))
# else
# define EXPORT_MESH
# endif
#endif
NS_MIA_BEGIN
class EXPORT_MESH CTriangleMesh: public CIOData
{
public:
static const char *data_descr;
typedef CTriangleMesh type;
typedef std::shared_ptr<CTriangleMesh> Pointer;
enum EData {ed_none = 0,
ed_vertex = 1,
ed_normal = 2,
ed_color = 4,
ed_scale = 8
};
typedef std::vector<T3DVector<unsigned int>> CTrianglefield;
typedef std::vector<C3DFVector> CVertexfield;
typedef std::vector<C3DFVector> CNormalfield;
typedef std::vector<C3DFVector> CColorfield;
typedef std::vector<float> CScalefield;
typedef std::shared_ptr<CTrianglefield > PTrianglefield;
typedef std::shared_ptr<CVertexfield > PVertexfield;
typedef std::shared_ptr<CNormalfield > PNormalfield;
typedef std::shared_ptr<CColorfield > PColorfield;
typedef std::shared_ptr<CScalefield > PScalefield;
typedef CTrianglefield::value_type triangle_type;
typedef CVertexfield::value_type vertex_type;
typedef CNormalfield::value_type normal_type;
typedef CColorfield::value_type color_type;
typedef CScalefield::value_type scale_type;
typedef CVertexfield::const_iterator const_vertex_iterator;
typedef CVertexfield::iterator vertex_iterator;
typedef CTrianglefield::const_iterator const_triangle_iterator;
typedef CTrianglefield::iterator triangle_iterator;
typedef CNormalfield::const_iterator const_normal_iterator;
typedef CNormalfield::iterator normal_iterator;
typedef CScalefield::const_iterator const_scale_iterator;
typedef CScalefield::iterator scale_iterator;
typedef CColorfield::const_iterator const_color_iterator;
typedef CColorfield::iterator color_iterator;
CTriangleMesh();
CTriangleMesh(const CTriangleMesh& orig);
CTriangleMesh(int n_triangles, int n_vertices);
CTriangleMesh(PTrianglefield triangles,
PVertexfield vertices,
PNormalfield normals,
PColorfield colors,
PScalefield scales);
CTriangleMesh(PTrianglefield triangles, PVertexfield vertices);
CTriangleMesh *clone() const __attribute__((warn_unused_result));
CTriangleMesh clone_connectivity()const;
~CTriangleMesh();
static const std::string get_type_description();
int get_available_data() const;
const void *get_vertex_pointer()const;
const void *get_normal_pointer()const;
const void *get_triangle_pointer()const;
const void *get_color_pointer()const;
unsigned int triangle_size()const;
unsigned int vertices_size()const;
const triangle_type& triangle_at(unsigned int i)const;
const vertex_type& vertex_at(unsigned int i)const;
const normal_type& normal_at(unsigned int i)const;
const scale_type& scale_at(unsigned int i)const;
const color_type& color_at(unsigned int i)const;
const CVertexfield& get_vertices() const;
const CTrianglefield& get_triangles() const;
const_triangle_iterator triangles_begin() const;
triangle_iterator triangles_begin();
const_triangle_iterator triangles_end() const;
triangle_iterator triangles_end();
const_vertex_iterator vertices_begin()const;
const_vertex_iterator vertices_end()const;
vertex_iterator vertices_begin();
vertex_iterator vertices_end();
const_normal_iterator normals_begin()const;
const_normal_iterator normals_end()const;
normal_iterator normals_begin();
normal_iterator normals_end();
const_scale_iterator scale_begin()const;
const_scale_iterator scale_end()const;
scale_iterator scale_begin();
scale_iterator scale_end();
const_color_iterator color_begin()const;
const_color_iterator color_end()const;
color_iterator color_begin();
color_iterator color_end();
const std::string& get_sourceformat()const
{
return m_sourceformat;
}
void set_sourceformat(const std::string& fmt)
{
m_sourceformat = fmt;
}
void evaluate_normals();
private:
std::string m_sourceformat;
struct CTriangleMeshData *data;
};
typedef CTriangleMesh::Pointer PTriangleMesh;
PTriangleMesh EXPORT_MESH get_sub_mesh(const CTriangleMesh& mesh, const std::vector<unsigned>& triangle_indices);
template <class Deformation>
void colorize_mesh(CTriangleMesh *mesh, const Deformation& deform)
{
if (! (mesh->get_available_data() & CTriangleMesh::ed_normal))
mesh->evaluate_normals();
// make sure we use the const versions of some iterators to keep the sharing of
// vertex (and evl. normal) data
const CTriangleMesh& cmesh = *mesh;
CTriangleMesh::scale_iterator sb = mesh->scale_begin();
CTriangleMesh::scale_iterator se = mesh->scale_end();
CTriangleMesh::const_vertex_iterator vb = cmesh.vertices_begin();
CTriangleMesh::const_normal_iterator nb = cmesh.normals_begin();
while (sb != se)
*sb++ = dot(*nb++, deform.apply(*vb++));
}
template <class Deformation>
CTriangleMesh colorize_mesh(const CTriangleMesh& mesh, const Deformation& deform)
{
CTriangleMesh result(mesh);
colorize_mesh(&result, deform);
return result;
}
/* evaluate the distance between two meshes, and set the scale accordingly
\param mesh this mesh will get the per vertex distance values in its scale
\param reference the mesh we want to know the distance from
void distance_transform(CTriangleMesh *mesh, const CTriangleMesh& reference);
*/
typedef TIOPlugin<CTriangleMesh> CMeshIOPlugin;
extern template class EXPORT_MESH TPlugin<CTriangleMesh, io_plugin_type>;
extern template class EXPORT_MESH TIOPlugin<CTriangleMesh>;
typedef THandlerSingleton<TIOPluginHandler<CMeshIOPlugin>> CMeshIOPluginHandler;
NS_MIA_END
#endif // __TRIANGULARMESH_HH
dot
T dot(const T2DVector< T > &a, const T2DVector< T > &b)
Definition 2d/vector.hh:437
vector.hh
CIOData
helper class to derive from for data that can be loaded and stored to a disk.
Definition iodata.hh:37
CTriangleMesh
A class to deine a triangle mesh with some attributes.
Definition triangularMesh.hh:62
CTriangleMesh::scale_at
const scale_type & scale_at(unsigned int i) const
CTriangleMesh::clone
CTriangleMesh * clone() const __attribute__((warn_unused_result))
CTriangleMesh::vertices_size
unsigned int vertices_size() const
CTriangleMesh::normal_at
const normal_type & normal_at(unsigned int i) const
CTriangleMesh::EData
EData
these are some flags to indicate, which data is actually available
Definition triangularMesh.hh:75
CTriangleMesh::ed_color
@ ed_color
Definition triangularMesh.hh:78
CTriangleMesh::ed_normal
@ ed_normal
Definition triangularMesh.hh:77
CTriangleMesh::ed_scale
@ ed_scale
Definition triangularMesh.hh:79
CTriangleMesh::ed_none
@ ed_none
Definition triangularMesh.hh:75
CTriangleMesh::ed_vertex
@ ed_vertex
Definition triangularMesh.hh:76
CTriangleMesh::get_triangle_pointer
const void * get_triangle_pointer() const
CTriangleMesh::triangle_at
const triangle_type & triangle_at(unsigned int i) const
CTriangleMesh::CTriangleMesh
CTriangleMesh()
Standart constructor creates an empty mesh.
CTriangleMesh::type
CTriangleMesh type
Definition triangularMesh.hh:69
CTriangleMesh::triangle_size
unsigned int triangle_size() const
CTriangleMesh::get_normal_pointer
const void * get_normal_pointer() const
CTriangleMesh::clone_connectivity
CTriangleMesh clone_connectivity() const
CTriangleMesh::CTriangleMesh
CTriangleMesh(const CTriangleMesh &orig)
CTriangleMesh::get_vertices
const CVertexfield & get_vertices() const
CTriangleMesh::CTriangleMesh
CTriangleMesh(int n_triangles, int n_vertices)
CTriangleMesh::get_available_data
int get_available_data() const
CTriangleMesh::color_at
const color_type & color_at(unsigned int i) const
CTriangleMesh::get_sourceformat
const std::string & get_sourceformat() const
Definition triangularMesh.hh:263
CTriangleMesh::Pointer
std::shared_ptr< CTriangleMesh > Pointer
Definition triangularMesh.hh:72
CTriangleMesh::get_vertex_pointer
const void * get_vertex_pointer() const
CTriangleMesh::vertex_at
const vertex_type & vertex_at(unsigned int i) const
CTriangleMesh::evaluate_normals
void evaluate_normals()
CTriangleMesh::CTriangleMesh
CTriangleMesh(PTrianglefield triangles, PVertexfield vertices)
CTriangleMesh::get_type_description
static const std::string get_type_description()
CTriangleMesh::set_sourceformat
void set_sourceformat(const std::string &fmt)
Definition triangularMesh.hh:269
CTriangleMesh::get_triangles
const CTrianglefield & get_triangles() const
CTriangleMesh::CTriangleMesh
CTriangleMesh(PTrianglefield triangles, PVertexfield vertices, PNormalfield normals, PColorfield colors, PScalefield scales)
CTriangleMesh::get_color_pointer
const void * get_color_pointer() const
CTriangleMesh::data_descr
static const char * data_descr
Definition triangularMesh.hh:67
THandlerSingleton
the singleton that a plug-in handler really is
Definition handler.hh:159
TIOPlugin
The templatex basis class of all IO plug-ins.
Definition ioplugin.hh:58
TPlugin
The generic base for all plug-ins.
Definition plugin_base.hh:172
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
iodata.hh
iohandler.hh
ioplugin.hh
std
Definition gsl_iterator.hh:324
CMeshIOPluginHandler
THandlerSingleton< TIOPluginHandler< CMeshIOPlugin > > CMeshIOPluginHandler
Plug-in handler for triangulat mesh IO.
Definition triangularMesh.hh:350
get_sub_mesh
PTriangleMesh EXPORT_MESH get_sub_mesh(const CTriangleMesh &mesh, const std::vector< unsigned > &triangle_indices)
EXPORT_MESH
#define EXPORT_MESH
define visibility for proper export
Definition triangularMesh.hh:44
colorize_mesh
void colorize_mesh(CTriangleMesh *mesh, const Deformation &deform)
Definition triangularMesh.hh:301
CMeshIOPlugin
TIOPlugin< CTriangleMesh > CMeshIOPlugin
IO plugin for triangular meshes.
Definition triangularMesh.hh:344
PTriangleMesh
CTriangleMesh::Pointer PTriangleMesh
Pointer type of the CTriangle mesh class.
Definition triangularMesh.hh:287