Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_MESH_UTIL_MESH_REMOVE_REDUNDANT_VERTICES_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_MESH_UTIL_MESH_REMOVE_REDUNDANT_VERTICES_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace mesh
00015 {
00016
00028 template< typename mesh_type >
00029 void remove_redundant_vertices( mesh_type & input, mesh_type & output, double tolerance = 10e-7 )
00030 {
00031 typedef typename mesh_type::math_types math_types;
00032 typedef typename math_types::value_traits value_traits;
00033 typedef typename math_types::vector3_type vector3_type;
00034 typedef typename math_types::real_type real_type;
00035
00036 output.clear();
00037
00038 std::vector<typename mesh_type::vertex_handle> lut;
00039
00040 typename mesh_type::vertex_iterator vbegin = input.vertex_begin();
00041 typename mesh_type::vertex_iterator vend = input.vertex_end();
00042 typename mesh_type::vertex_iterator v = vbegin;
00043 unsigned int i=0;
00044 for(;v!=vend;++v,++i)
00045 {
00046 v->m_tag = i;
00047 typename mesh_type::vertex_iterator w = vbegin;
00048 bool redundant_vertex = false;
00049 unsigned int j = 0;
00050 for(;w!=v;++w,++j)
00051 {
00052 vector3_type diff = v->m_coord - w->m_coord;
00053 if(diff*diff<tolerance)
00054 {
00055 redundant_vertex = true;
00056 break;
00057 }
00058 }
00059 if(redundant_vertex)
00060 {
00061 #ifndef NDEBUG
00062 std::cout << "remove_redundant_vertices(): redundant vertex detected" << std::endl;
00063 #endif
00064 lut.push_back(lut[j]);
00065 }
00066 else
00067 {
00068 typename mesh_type::vertex_handle h = output.add_vertex( v->m_coord );
00069 lut.push_back(h);
00070 }
00071 }
00072
00073 typename mesh_type::face_iterator fbegin = input.face_begin();
00074 typename mesh_type::face_iterator fend = input.face_end();
00075 typename mesh_type::face_iterator f = fbegin;
00076 for(;f!=fend;++f)
00077 {
00078 std::list<typename mesh_type::vertex_handle> handles;
00079 typename mesh_type::face_vertex_circulator v(*f),vend;
00080 for(;v!=vend;++v)
00081 handles.push_back(lut[v->m_tag]);
00082
00083 typename mesh_type::face_handle fh = output.add_face(handles.begin(),handles.end());
00084
00085 if(fh.is_null())
00086 {
00087 std::cout << "remove_redundant_vertices(): could not create face" << std::endl;
00088 }
00089 }
00090
00091 }
00092
00093 }
00094 }
00095
00096
00097 #endif