63 #include "MeshInfoT.hh" 66 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh> 67 #include <OpenMesh/Core/Geometry/MathDefs.hh> 76 template <
typename MeshT >
78 int boundaryCount(MeshT* _mesh ) {
83 _mesh->add_property(visited);
85 typename MeshT::VertexHandle last;
86 const typename MeshT::VertexHandle begin;
89 for (
typename MeshT::HalfedgeIter he_it=_mesh->halfedges_begin(); he_it!=_mesh->halfedges_end() ; ++he_it )
90 _mesh->property(visited,*he_it) =
false;
92 for (
typename MeshT::HalfedgeIter he_it=_mesh->halfedges_begin(); he_it!=_mesh->halfedges_end() ; ++he_it ) {
93 if ( _mesh->property(visited,*he_it) )
96 if( !_mesh->is_boundary(*he_it ) )
99 _mesh->property(visited,*he_it) =
true;
100 typename MeshT::HalfedgeHandle he = _mesh->next_halfedge_handle(*he_it);
102 while( _mesh->is_boundary(*he_it) && ! _mesh->property(visited,he) ) {
103 _mesh->property(visited,he) =
true;
104 he = _mesh->next_halfedge_handle(he);
111 _mesh->remove_property(visited);
118 template <
typename MeshT >
120 int componentCount(MeshT* _mesh ) {
125 _mesh->add_property(visited);
127 typename MeshT::VertexIter v_it;
128 typename MeshT::VertexIter v_end = _mesh->vertices_end();
131 for (v_it = _mesh->vertices_begin(); v_it != v_end; ++v_it)
132 _mesh->property(visited, *v_it) =
false;
134 typename MeshT::VertexHandle vh;
135 typename MeshT::VertexIter current_pos = _mesh->vertices_begin();
140 for (v_it = current_pos ; v_it != v_end; ++v_it)
141 if ( !_mesh->property(visited, *v_it) ){
144 _mesh->property(visited, *v_it) =
true;
154 std::vector< typename MeshT::VertexHandle > handles;
155 handles.push_back( vh );
158 while( ! handles.empty() ){
159 typename MeshT::VertexHandle current = handles.back();
162 typename MeshT::VertexVertexIter vv_it;
164 for (vv_it=_mesh->vv_iter( current ); vv_it.is_valid(); ++vv_it)
165 if ( !_mesh->property(visited, *vv_it) ){
166 _mesh->property(visited, *vv_it) =
true;
167 handles.push_back( *vv_it );
172 _mesh->remove_property(visited);
179 template <
typename MeshT >
181 void getBoundingBox( MeshT* _mesh,
182 typename MeshT::Point& _min ,
183 typename MeshT::Point& _max) {
184 if ( _mesh->n_vertices() == 0 ) {
185 std::cerr <<
"Unable to compute Bounding Box: No points in Mesh!" << std::endl;
188 _min = _mesh->point(_mesh->vertex_handle(0));
189 _max = _mesh->point(_mesh->vertex_handle(0));
191 for (
typename MeshT::VertexIter v_it = _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it ) {
192 _min.minimize( _mesh->point(*v_it) );
193 _max.maximize( _mesh->point(*v_it) );
200 template <
typename MeshT >
202 typename MeshT::Point
203 cog (
const MeshT* _mesh ) {
204 typename MeshT::ConstVertexIter v_it, v_end=_mesh->vertices_end();
205 typename MeshT::Point cog(0.0,0.0,0.0);
207 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
208 cog += _mesh->point(*v_it);
209 cog = 1.0 / (
typename MeshT::Scalar)_mesh->n_vertices() * cog;