42 #define COMPONENTSPLUGIN_CC 44 #include "ComponentsPlugin.hh" 53 template<
class MeshT >
60 if ( !_mesh->get_property_handle(visited,
"visited") )
61 _mesh->add_property(visited,
"visited");
63 typename MeshT::FaceIter f_it;
64 typename MeshT::FaceIter f_end = _mesh->faces_end();
67 for (f_it = _mesh->faces_begin(); f_it != f_end; ++f_it)
68 _mesh->property(visited, *f_it) =
false;
70 typename MeshT::FaceHandle fh;
73 fh = *(_mesh->faces_begin());
74 _mesh->property(visited, fh) =
true;
78 if (!fh.is_valid() )
return;
80 std::vector< typename MeshT::FaceHandle > handles;
81 handles.push_back( fh );
84 while( handles.size() > 0 ){
86 typename MeshT::FaceHandle current = handles.back();
89 typename MeshT::FaceFaceIter ff_it;
91 for (ff_it=_mesh->ff_iter( current ); ff_it.is_valid(); ++ff_it)
92 if ( ! _mesh->property(visited, *ff_it) ){
93 _mesh->property(visited, *ff_it) =
true;
94 handles.push_back( *ff_it );
99 for (
typename MeshT::FaceIter f_it = _mesh->faces_begin(); f_it != f_end; ++f_it)
101 if ( _mesh->property(visited, *f_it) )
102 _mesh->delete_face( *f_it );
104 _copy->delete_face( *f_it );
108 _copy->garbage_collection();
109 _mesh->garbage_collection();
111 _mesh->remove_property(visited);
115 template<
class MeshT >
121 if ( !_mesh->get_property_handle(visited,
"visited") )
122 _mesh->add_property(visited,
"visited");
124 std::vector<typename MeshT::FaceHandle> facesInBiggest;
126 for (
typename MeshT::FaceIter fIter = _mesh->faces_begin(); fIter != _mesh->faces_end(); ++fIter)
128 if (_mesh->property(visited,*fIter))
132 std::vector<typename MeshT::FaceHandle> componentFaces;
133 componentFaces.push_back(*fIter);
135 for(std::size_t i = 0; i < componentFaces.size(); ++i )
138 for (
typename MeshT::FaceFaceIter ffIter = _mesh->ff_begin(componentFaces[i]); ffIter.is_valid() ;++ffIter)
140 if (!ffIter->is_valid())
141 std::cout <<
"handleId: " << *ffIter << std::endl;
142 if (ffIter->is_valid() && !_mesh->property(visited,*ffIter) )
144 _mesh->property(visited,*ffIter) =
true;
145 componentFaces.push_back(*ffIter);
151 if (facesInBiggest.size() < componentFaces.size())
153 std::swap(facesInBiggest,componentFaces);
156 _mesh->remove_property(visited);
159 for (
typename std::vector<typename MeshT::FaceHandle>::iterator iter = facesInBiggest.begin(); iter != facesInBiggest.end(); ++iter)
161 _mesh->status(*iter).set_selected(
true);
165 template<
class MeshT >
169 for (
typename MeshT::FaceIter fIter = _mesh->faces_begin(); fIter != _mesh->faces_end(); ++fIter)
171 if (!_mesh->status(*fIter).selected())
174 _mesh->delete_face(*fIter,
true);
178 _mesh->status(*fIter).set_selected(
false);
182 _mesh->garbage_collection();
void splitComponent(MeshT *_mesh, MeshT *_copy)
Split mesh into components.
void selectBiggestComponent(MeshT *_mesh)
Select the biggest component of the mesh.
void deleteUnselectedFaces(MeshT *_mesh)
Deletes all faces of a mesh that are not selected.