50 #define COMPONENTSPLUGIN_CC 52 #include "ComponentsPlugin.hh" 61 template<
class MeshT >
68 if ( !_mesh->get_property_handle(visited,
"visited") )
69 _mesh->add_property(visited,
"visited");
71 typename MeshT::FaceIter f_it;
72 typename MeshT::FaceIter f_end = _mesh->faces_end();
75 for (f_it = _mesh->faces_begin(); f_it != f_end; ++f_it)
76 _mesh->property(visited, *f_it) =
false;
78 typename MeshT::FaceHandle fh;
81 fh = *(_mesh->faces_begin());
82 _mesh->property(visited, fh) =
true;
86 if (!fh.is_valid() )
return;
88 std::vector< typename MeshT::FaceHandle > handles;
89 handles.push_back( fh );
92 while( handles.size() > 0 ){
94 typename MeshT::FaceHandle current = handles.back();
97 typename MeshT::FaceFaceIter ff_it;
99 for (ff_it=_mesh->ff_iter( current ); ff_it.is_valid(); ++ff_it)
100 if ( ! _mesh->property(visited, *ff_it) ){
101 _mesh->property(visited, *ff_it) =
true;
102 handles.push_back( *ff_it );
107 for (
typename MeshT::FaceIter f_it = _mesh->faces_begin(); f_it != f_end; ++f_it)
109 if ( _mesh->property(visited, *f_it) )
110 _mesh->delete_face( *f_it );
112 _copy->delete_face( *f_it );
116 _copy->garbage_collection();
117 _mesh->garbage_collection();
119 _mesh->remove_property(visited);
123 template<
class MeshT >
129 if ( !_mesh->get_property_handle(visited,
"visited") )
130 _mesh->add_property(visited,
"visited");
132 std::vector<typename MeshT::FaceHandle> facesInBiggest;
134 for (
typename MeshT::FaceIter fIter = _mesh->faces_begin(); fIter != _mesh->faces_end(); ++fIter)
136 if (_mesh->property(visited,*fIter))
140 std::vector<typename MeshT::FaceHandle> componentFaces;
141 componentFaces.push_back(*fIter);
143 for(std::size_t i = 0; i < componentFaces.size(); ++i )
146 for (
typename MeshT::FaceFaceIter ffIter = _mesh->ff_begin(componentFaces[i]); ffIter.is_valid() ;++ffIter)
148 if (!ffIter->is_valid())
149 std::cout <<
"handleId: " << *ffIter << std::endl;
150 if (ffIter->is_valid() && !_mesh->property(visited,*ffIter) )
152 _mesh->property(visited,*ffIter) =
true;
153 componentFaces.push_back(*ffIter);
159 if (facesInBiggest.size() < componentFaces.size())
161 std::swap(facesInBiggest,componentFaces);
164 _mesh->remove_property(visited);
167 for (
typename std::vector<typename MeshT::FaceHandle>::iterator iter = facesInBiggest.begin(); iter != facesInBiggest.end(); ++iter)
169 _mesh->status(*iter).set_selected(
true);
173 template<
class MeshT >
177 for (
typename MeshT::FaceIter fIter = _mesh->faces_begin(); fIter != _mesh->faces_end(); ++fIter)
179 if (!_mesh->status(*fIter).selected())
182 _mesh->delete_face(*fIter,
true);
186 _mesh->status(*fIter).set_selected(
false);
190 _mesh->garbage_collection();
void deleteUnselectedFaces(MeshT *_mesh)
Deletes all faces of a mesh that are not selected.
void splitComponent(MeshT *_mesh, MeshT *_copy)
Split mesh into components.
void selectBiggestComponent(MeshT *_mesh)
Select the biggest component of the mesh.