Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_GL_GL_DRAW_T4MESH_H
00002 #define OPENTISSUE_UTILITY_GL_GL_DRAW_T4MESH_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_basic_types.h>
00013 #include <OpenTissue/core/geometry/geometry_tetrahedron.h>
00014
00015 namespace OpenTissue
00016 {
00017
00018 namespace gl
00019 {
00020
00030 template <typename t4mesh>
00031 inline void DrawT4Mesh(t4mesh const& mesh, double scale = 0.95, bool wireframe = false)
00032 {
00033 typedef typename t4mesh::const_node_iterator const_node_iterator;
00034 typedef typename t4mesh::const_tetrahedron_iterator const_tetrahedron_iterator;
00035
00036 geometry::Tetrahedron<math::default_math_types> T;
00037
00038 for (const_tetrahedron_iterator tetrahedron = mesh.tetrahedron_begin();tetrahedron != mesh.tetrahedron_end(); ++tetrahedron)
00039 {
00040 const_node_iterator i = tetrahedron->i();
00041 const_node_iterator j = tetrahedron->j();
00042 const_node_iterator k = tetrahedron->k();
00043 const_node_iterator m = tetrahedron->m();
00044 T.p0() = i->m_coord ;
00045 T.p1() = j->m_coord ;
00046 T.p2() = k->m_coord ;
00047 T.p3() = m->m_coord ;
00048 T.scale( scale );
00049 DrawTetrahedron( T, wireframe );
00050 }
00051 };
00052
00053
00061 template <typename point_container, typename t4mesh >
00062 inline void DrawPointsT4Mesh( point_container const& points, t4mesh const& mesh, double const& scale = 0.95, bool wireframe = false)
00063 {
00064 typedef typename t4mesh::const_node_iterator const_node_iterator;
00065 typedef typename t4mesh::const_tetrahedron_iterator const_tetrahedron_iterator;
00066
00067
00068 geometry::Tetrahedron<math::default_math_types> T;
00069
00070 for (const_tetrahedron_iterator tetrahedron = mesh.tetrahedron_begin();tetrahedron != mesh.tetrahedron_end(); ++tetrahedron)
00071 {
00072 const_node_iterator i = tetrahedron->i();
00073 const_node_iterator j = tetrahedron->j();
00074 const_node_iterator k = tetrahedron->k();
00075 const_node_iterator m = tetrahedron->m();
00076 T.p0() = points[i->idx()] ;
00077 T.p1() = points[j->idx()] ;
00078 T.p2() = points[k->idx()] ;
00079 T.p3() = points[m->idx()] ;
00080 T.scale( scale );
00081 DrawTetrahedron( T, wireframe );
00082 }
00083 };
00084
00085
00096 template <typename t4mesh_type, typename plane_type >
00097 inline void DrawT4MeshCutThrough(t4mesh_type const& mesh, plane_type const& plane, double scale = 1.0, bool wireframe = false)
00098 {
00099 typedef typename t4mesh_type::const_node_iterator const_node_iterator;
00100 typedef typename t4mesh_type::const_tetrahedron_iterator const_tetrahedron_iterator;
00101
00102 geometry::Tetrahedron<math::default_math_types> T;
00103
00104 const_tetrahedron_iterator tend = mesh.tetrahedron_end();
00105 for (const_tetrahedron_iterator tetrahedron = mesh.tetrahedron_begin(); tetrahedron != tend; ++tetrahedron)
00106 {
00107 const_node_iterator i = tetrahedron->i();
00108 const_node_iterator j = tetrahedron->j();
00109 const_node_iterator k = tetrahedron->k();
00110 const_node_iterator m = tetrahedron->m();
00111 if (plane.signed_distance(i->m_coord) <= 0 ||
00112 plane.signed_distance(j->m_coord) <= 0 ||
00113 plane.signed_distance(k->m_coord) <= 0 ||
00114 plane.signed_distance(m->m_coord) <= 0) continue;
00115 T.p0() = i->m_coord ;
00116 T.p1() = j->m_coord ;
00117 T.p2() = k->m_coord ;
00118 T.p3() = m->m_coord ;
00119 T.scale( scale );
00120 DrawTetrahedron( T, wireframe );
00121 }
00122 }
00123
00124
00136 template <typename point_container,typename t4mesh_type, typename plane_type >
00137 inline void DrawPointsT4MeshCutThrough( point_container const& points, t4mesh_type const& mesh, plane_type const& plane, double scale = 1.0, bool wireframe = false)
00138 {
00139 typedef typename t4mesh_type::const_node_iterator const_node_iterator;
00140 typedef typename t4mesh_type::const_tetrahedron_iterator const_tetrahedron_iterator;
00141
00142 geometry::Tetrahedron<math::default_math_types> T;
00143
00144 const_tetrahedron_iterator tend = mesh.tetrahedron_end();
00145 for (const_tetrahedron_iterator tetrahedron = mesh.tetrahedron_begin(); tetrahedron != tend; ++tetrahedron)
00146 {
00147 const_node_iterator i = tetrahedron->i();
00148 const_node_iterator j = tetrahedron->j();
00149 const_node_iterator k = tetrahedron->k();
00150 const_node_iterator m = tetrahedron->m();
00151 if (plane.signed_distance( points[i->idx()] ) <= 0 ||
00152 plane.signed_distance( points[j->idx()] ) <= 0 ||
00153 plane.signed_distance( points[k->idx()] ) <= 0 ||
00154 plane.signed_distance( points[m->idx()] ) <= 0) continue;
00155 T.p0() = points[i->idx()] ;
00156 T.p1() = points[j->idx()] ;
00157 T.p2() = points[k->idx()] ;
00158 T.p3() = points[m->idx()] ;
00159 T.scale( scale );
00160 DrawTetrahedron( T, wireframe );
00161 }
00162 }
00163
00164 }
00165
00166 }
00167
00168
00169 #endif