57 #include "MeshInfoT.hh" 60 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh> 61 #include <OpenMesh/Core/Geometry/MathDefs.hh> 70 template <
typename MeshT >
72 int boundaryCount(MeshT* _mesh ) {
77 _mesh->add_property(visited);
79 typename MeshT::VertexHandle last;
80 const typename MeshT::VertexHandle begin;
83 for (
typename MeshT::HalfedgeIter he_it=_mesh->halfedges_begin(); he_it!=_mesh->halfedges_end() ; ++he_it )
84 _mesh->property(visited,*he_it) =
false;
86 for (
typename MeshT::HalfedgeIter he_it=_mesh->halfedges_begin(); he_it!=_mesh->halfedges_end() ; ++he_it ) {
87 if ( _mesh->property(visited,*he_it) )
90 if( !_mesh->is_boundary(*he_it ) )
93 _mesh->property(visited,*he_it) =
true;
94 typename MeshT::HalfedgeHandle he = _mesh->next_halfedge_handle(*he_it);
96 while( _mesh->is_boundary(*he_it) && ! _mesh->property(visited,he) ) {
97 _mesh->property(visited,he) =
true;
98 he = _mesh->next_halfedge_handle(he);
105 _mesh->remove_property(visited);
112 template <
typename MeshT >
114 int componentCount(MeshT* _mesh ) {
119 _mesh->add_property(visited);
121 typename MeshT::VertexIter v_it;
122 typename MeshT::VertexIter v_end = _mesh->vertices_end();
125 for (v_it = _mesh->vertices_begin(); v_it != v_end; ++v_it)
126 _mesh->property(visited, *v_it) =
false;
128 typename MeshT::VertexHandle vh;
129 typename MeshT::VertexIter current_pos = _mesh->vertices_begin();
134 for (v_it = current_pos ; v_it != v_end; ++v_it)
135 if ( !_mesh->property(visited, *v_it) ){
138 _mesh->property(visited, *v_it) =
true;
148 std::vector< typename MeshT::VertexHandle > handles;
149 handles.push_back( vh );
152 while( ! handles.empty() ){
153 typename MeshT::VertexHandle current = handles.back();
156 typename MeshT::VertexVertexIter vv_it;
158 for (vv_it=_mesh->vv_iter( current ); vv_it.is_valid(); ++vv_it)
159 if ( !_mesh->property(visited, *vv_it) ){
160 _mesh->property(visited, *vv_it) =
true;
161 handles.push_back( *vv_it );
166 _mesh->remove_property(visited);
173 template <
typename MeshT >
175 void getBoundingBox( MeshT* _mesh,
176 typename MeshT::Point& _min ,
177 typename MeshT::Point& _max) {
178 if ( _mesh->n_vertices() == 0 ) {
179 std::cerr <<
"Unable to compute Bounding Box: No points in Mesh!" << std::endl;
182 _min = _mesh->point(_mesh->vertex_handle(0));
183 _max = _mesh->point(_mesh->vertex_handle(0));
185 for (
typename MeshT::VertexIter v_it = _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it ) {
186 _min.minimize( _mesh->point(*v_it) );
187 _max.maximize( _mesh->point(*v_it) );
194 template <
typename MeshT >
196 typename MeshT::Point
197 cog (
const MeshT* _mesh ) {
198 typename MeshT::ConstVertexIter v_it, v_end=_mesh->vertices_end();
199 typename MeshT::Point cog(0.0,0.0,0.0);
201 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
202 cog += _mesh->point(*v_it);
203 cog = 1.0 / (
typename MeshT::Scalar)_mesh->n_vertices() * cog;