59 #define MESHSELECTION_C 64 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh> 78 template<
typename MeshT >
80 void selectVertices(MeshT* _mesh,
const std::vector< int >& _vertices) {
81 const int n_vertices = (int)_mesh->n_vertices();
83 for ( uint i = 0 ; i < _vertices.size() ; ++i )
84 if ( (_vertices[i] >= 0) && ( _vertices[i] < n_vertices ) ) {
85 typename MeshT::VertexHandle vh(_vertices[i]);
86 _mesh->status(vh).set_selected(
true);
92 template<
typename MeshT >
94 void unselectVertices(MeshT* _mesh,
const std::vector< int >& _vertices) {
95 const int n_vertices = (int)_mesh->n_vertices();
97 for ( uint i = 0 ; i < _vertices.size() ; ++i )
98 if ( (_vertices[i] >= 0) && ( _vertices[i] < n_vertices ) ) {
99 typename MeshT::VertexHandle vh(_vertices[i]);
100 _mesh->status(vh).set_selected(
false);
106 template<
typename MeshT >
108 void selectAllVertices(MeshT* _mesh) {
109 typename MeshT::VertexIter v_it, v_end=_mesh->vertices_end();
111 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
112 _mesh->status(*v_it).set_selected(
true);
118 template<
typename MeshT >
120 void clearVertexSelection(MeshT* _mesh) {
121 typename MeshT::VertexIter v_it, v_end=_mesh->vertices_end();
123 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
124 _mesh->status(*v_it).set_selected(
false);
129 template<
typename MeshT >
131 void invertVertexSelection(MeshT* _mesh) {
132 typename MeshT::VertexIter v_it, v_end=_mesh->vertices_end();
134 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
135 _mesh->status(*v_it).set_selected( ! _mesh->status(*v_it).selected());
141 template<
typename MeshT >
143 void selectBoundaryVertices(MeshT* _mesh) {
144 typename MeshT::HalfedgeIter he_it, he_end=_mesh->halfedges_end();
146 for (he_it = _mesh->halfedges_begin(); he_it != he_end ; ++he_it)
147 if (_mesh->is_boundary(*he_it) ) {
148 _mesh->status(_mesh->to_vertex_handle(*he_it)).set_selected(
true);
149 _mesh->status(_mesh->from_vertex_handle(*he_it)).set_selected(
true);
155 template<
typename MeshT >
157 void shrinkVertexSelection(MeshT* _mesh) {
160 _mesh->add_property( temp_shrink,
"Temp property for Vertex selection shrinking" );
162 typename MeshT::VertexIter v_it, v_end=_mesh->vertices_end();
165 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
166 _mesh->property(temp_shrink,*v_it) = _mesh->status(*v_it).selected();
169 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
170 if ( _mesh->property(temp_shrink,*v_it) ) {
171 _mesh->status(*v_it).set_selected(
true );
173 for (
typename MeshT::VertexVertexIter vv_it(*_mesh,*v_it); vv_it.is_valid(); ++vv_it)
174 if ( ! _mesh->property(temp_shrink,*vv_it) ){
175 _mesh->status(*v_it).set_selected(
false );
180 _mesh->remove_property(temp_shrink);
185 template<
typename MeshT >
187 void growVertexSelection(MeshT* _mesh) {
190 _mesh->add_property( temp_grow,
"Temp property for Vertex selection growing" );
193 typename MeshT::VertexIter v_it, v_end=_mesh->vertices_end();
194 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
195 _mesh->property(temp_grow,*v_it) = _mesh->status(*v_it).selected();
198 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
199 if ( _mesh->property(temp_grow,*v_it) )
200 for (
typename MeshT::VertexVertexIter vv_it(*_mesh,*v_it); vv_it.is_valid(); ++vv_it)
201 _mesh->status(*vv_it).set_selected(
true );
203 _mesh->remove_property(temp_grow);
208 template<
typename MeshT >
210 std::vector< int > getVertexSelection(MeshT* _mesh) {
211 std::vector< int > selection;
213 for (
typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
214 if ( _mesh->status(*v_it).selected() )
215 selection.push_back( v_it->idx() );
222 template<
typename MeshT >
224 std::vector< int > getVertexSelection(MeshT* _mesh,
bool& _invert) {
225 std::vector< int > selection;
229 for (
typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
230 if ( _mesh->status(*v_it).selected() )
233 if ( count > (
int)( _mesh->n_vertices() / 2) )
238 for (
typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
239 if ( _mesh->status(*v_it).selected() ^ _invert )
240 selection.push_back( v_it->idx() );
246 template<
typename MeshT >
248 void selectBoundaryVertices(MeshT* _mesh,
const typename MeshT::VertexHandle& _vh){
251 _mesh->add_property(visited,
"Visited Vertices");
253 typename MeshT::VertexIter v_it, v_end = _mesh->vertices_end();
254 for (v_it = _mesh->vertices_begin(); v_it != v_end; ++v_it)
255 _mesh->property(visited, *v_it) =
false;
257 std::stack< typename MeshT::VertexHandle > stack;
260 while (!stack.empty()){
262 typename MeshT::VertexHandle vh = stack.top();
265 if (_mesh->property(visited,vh))
269 for (
typename MeshT::VertexOHalfedgeIter voh_it(*_mesh,vh); voh_it.is_valid(); ++voh_it)
270 if ( _mesh->is_boundary( _mesh->edge_handle( *voh_it ) ) )
271 stack.push( _mesh->to_vertex_handle(*voh_it) );
274 _mesh->property(visited,vh) =
true;
275 _mesh->status( vh ).set_selected(
true);
277 _mesh->remove_property(visited);
280 template<
typename MeshT >
282 void convertVertexToEdgeSelection(MeshT* _mesh,
const std::vector< int >& _vertices) {
284 for ( std::vector<int>::const_iterator v = _vertices.begin(); v != _vertices.end(); ++v) {
286 typename MeshT::VertexHandle vh(*v);
287 typename MeshT::VertexOHalfedgeIter ohe_iter = _mesh->voh_iter(vh);
289 for (; ohe_iter.is_valid(); ++ohe_iter) {
291 typename MeshT::VertexHandle ovh = _mesh->to_vertex_handle(*ohe_iter);
293 for(std::vector<int>::const_iterator it = _vertices.begin(); it != _vertices.end(); ++it) {
294 if((*it) == ovh.idx()) {
295 _mesh->status(_mesh->edge_handle(*ohe_iter)).set_selected(
true);
303 template<
typename MeshT >
305 void convertVertexToEdgeSelection(MeshT* _mesh) {
307 typename MeshT::VertexIter v_it, v_end = _mesh->vertices_end();
308 for (v_it = _mesh->vertices_begin(); v_it != v_end; ++v_it) {
310 if ( _mesh->status( *v_it ).selected() ) {
311 typename MeshT::VertexOHalfedgeIter ohe_iter = _mesh->voh_iter(*v_it);
313 for (; ohe_iter.is_valid(); ++ohe_iter) {
315 typename MeshT::VertexHandle ovh = _mesh->to_vertex_handle(*ohe_iter);
316 if (_mesh->status(ovh).selected())
317 _mesh->status(_mesh->edge_handle(*ohe_iter)).set_selected(
true);
323 template<
typename MeshT >
325 void convertVertexToHalfedgeSelection(MeshT* _mesh,
const std::vector< int >& _vertices) {
327 for (std::vector<int>::const_iterator v = _vertices.begin(); v != _vertices.end(); ++v) {
329 typename MeshT::VertexHandle vh(*v);
330 typename MeshT::VertexOHalfedgeIter ohe_iter = _mesh->voh_iter(vh);
332 for (; ohe_iter.is_valid(); ++ohe_iter) {
334 typename MeshT::VertexHandle ovh = _mesh->to_vertex_handle(*ohe_iter);
336 for(std::vector<int>::const_iterator it = _vertices.begin(); it != _vertices.end(); ++it) {
337 if((*it) == ovh.idx()) {
338 _mesh->status(*ohe_iter).set_selected(
true);
339 _mesh->status(_mesh->opposite_halfedge_handle(*ohe_iter)).set_selected(
true);
347 template<
typename MeshT >
349 void convertVertexToHalfedgeSelection(MeshT* _mesh) {
351 typename MeshT::VertexIter v_it, v_end = _mesh->vertices_end();
353 for (v_it = _mesh->vertices_begin(); v_it != v_end; ++v_it) {
355 if ( _mesh->status( *v_it ).selected() ) {
357 typename MeshT::VertexOHalfedgeIter ohe_iter = _mesh->voh_iter(*v_it);
359 for (; ohe_iter.is_valid(); ++ohe_iter) {
361 typename MeshT::VertexHandle ovh = _mesh->to_vertex_handle(*ohe_iter);
362 if (_mesh->status(ovh).selected()) {
363 _mesh->status(*ohe_iter).set_selected(
true);
364 _mesh->status(_mesh->opposite_halfedge_handle(*ohe_iter)).set_selected(
true);
371 template<
typename MeshT >
373 void convertVertexToFaceSelection(MeshT* _mesh,
const std::vector< int >& _vertices) {
375 for(
typename MeshT::FaceIter f_it = _mesh->faces_begin(); f_it != _mesh->faces_end(); ++f_it) {
376 typename MeshT::FaceVertexIter fv_it = _mesh->fv_iter(*f_it);
378 bool allfound =
true;
379 for(; fv_it.is_valid(); ++fv_it) {
381 bool onefound =
false;
382 for(std::vector<int>::const_iterator it = _vertices.begin(); it != _vertices.end(); ++it) {
383 if((*it) == fv_it->idx()) { onefound =
true;
break; }
392 _mesh->status(*f_it).set_selected(
true);
397 template<
typename MeshT >
399 void convertVertexToFaceSelection(MeshT* _mesh) {
401 typename MeshT::FaceIter f_it, f_end = _mesh->faces_end();
403 for (f_it = _mesh->faces_begin(); f_it != f_end; ++f_it) {
405 typename MeshT::FaceVertexIter fv_it = _mesh->fv_iter(*f_it);
407 bool allfound =
true;
408 for(; fv_it.is_valid(); ++fv_it) {
409 if(!_mesh->status(*fv_it).selected()) {
415 _mesh->status(*f_it).set_selected(
true);
419 template<
typename MeshT >
421 void convertVertexSelectionToFeatureVertices(MeshT* _mesh) {
423 for (
typename MeshT::VertexIter v_it = _mesh->vertices_begin(); v_it != _mesh->vertices_end(); ++v_it) {
425 if (_mesh->status(*v_it).selected()) {
427 _mesh->status(*v_it).set_feature(
true);
429 _mesh->status(*v_it).set_feature(
false);
434 template<
typename MeshT >
436 void convertFeatureVerticesToVertexSelection(MeshT* _mesh) {
438 for (
typename MeshT::VertexIter v_it = _mesh->vertices_begin(); v_it != _mesh->vertices_end(); ++v_it) {
440 if (_mesh->status(*v_it).feature()) {
442 _mesh->status(*v_it).set_selected(
true);
444 _mesh->status(*v_it).set_selected(
false);
449 template<
typename MeshT >
451 void clearFeatureVertices(MeshT* _mesh) {
453 for (
typename MeshT::VertexIter v_it = _mesh->vertices_begin(); v_it != _mesh->vertices_end(); ++v_it) {
455 _mesh->status(*v_it).set_feature(
false);
463 template<
typename MeshT >
465 void setArea(MeshT* _mesh,
const std::vector< int >& _vertices ,
unsigned int _type,
bool _state) {
466 for ( uint i = 0 ; i < _vertices.size() ; ++i ) {
467 if ( _vertices[i] > (
int)_mesh->n_vertices() )
470 typename MeshT::VertexHandle vh(_vertices[i]);
471 _mesh->status(vh).change_bit(_type, _state);
475 template<
typename MeshT >
477 void setArea(MeshT* _mesh ,
unsigned int _type,
bool _state) {
478 for (
typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
479 _mesh->status(*v_it).change_bit(_type, _state);
482 template<
typename MeshT >
484 std::vector< int > getArea(MeshT* _mesh,
unsigned int _type) {
485 std::vector< int > selection;
487 for (
typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
488 if ( _mesh->status(*v_it).is_bit_set( _type ) )
489 selection.push_back( v_it->idx() );
494 template<
typename MeshT >
496 std::vector< int > getArea(MeshT* _mesh,
unsigned int _type ,
bool& _invert) {
497 std::vector< int > selection;
501 for (
typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
502 if ( _mesh->status(*v_it).is_bit_set( _type ) )
505 if ( count > (
int)( _mesh->n_vertices() / 2) )
510 for (
typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
511 if ( _mesh->status(*v_it).is_bit_set( _type ) ^ _invert )
512 selection.push_back( v_it->idx() );
522 template<
typename MeshT >
524 void selectEdges(MeshT* _mesh,
const std::vector< int >& _edges) {
525 const int n_edges = (int)_mesh->n_edges();
527 for ( uint i = 0 ; i < _edges.size() ; ++i )
528 if ( (_edges[i] >= 0) && ( _edges[i] < n_edges ) ) {
529 typename MeshT::EdgeHandle eh(_edges[i]);
530 _mesh->status(eh).set_selected(
true);
536 template<
typename MeshT >
538 void unselectEdges(MeshT* _mesh,
const std::vector< int >& _edges) {
539 const int n_edges = (int)_mesh->n_edges();
541 for ( uint i = 0 ; i < _edges.size() ; ++i )
542 if ( (_edges[i] >= 0) && ( _edges[i] < n_edges ) ) {
543 typename MeshT::EdgeHandle eh(_edges[i]);
544 _mesh->status(eh).set_selected(
false);
550 template<
typename MeshT >
552 void selectAllEdges(MeshT* _mesh) {
553 typename MeshT::EdgeIter e_it, e_end=_mesh->edges_end();
555 for (e_it = _mesh->edges_begin(); e_it != e_end ; ++e_it)
556 _mesh->status(*e_it).set_selected(
true);
561 template<
typename MeshT >
563 void clearEdgeSelection(MeshT* _mesh) {
564 typename MeshT::EdgeIter e_it, e_end=_mesh->edges_end();
566 for (e_it = _mesh->edges_begin(); e_it != e_end ; ++e_it)
567 _mesh->status(*e_it).set_selected(
false);
572 template<
typename MeshT >
574 void invertEdgeSelection(MeshT* _mesh) {
575 typename MeshT::EdgeIter e_it, e_end=_mesh->edges_end();
577 for (e_it = _mesh->edges_begin(); e_it != e_end ; ++e_it)
578 _mesh->status(*e_it).set_selected( ! _mesh->status(*e_it).selected());
583 template<
typename MeshT>
585 void growEdgeSelection(MeshT* _mesh) {
586 std::set<typename MeshT::EdgeHandle> selectedEhs;
587 for (
typename MeshT::EdgeIter e_it = _mesh->edges_begin(), e_end = _mesh->edges_end();
588 e_it != e_end; ++e_it) {
590 if (!_mesh->status(*e_it).selected())
continue;
592 const typename MeshT::HalfedgeHandle he = _mesh->halfedge_handle(*e_it, 0);
593 const typename MeshT::VertexHandle vhs[] = { _mesh->from_vertex_handle(he),
594 _mesh->to_vertex_handle(he) };
596 for (
int i = 0; i < 2; ++i) {
597 for (
typename MeshT::VertexEdgeIter ve_it = _mesh->ve_begin(vhs[i]), ve_end = _mesh->ve_end(vhs[i]);
598 ve_it != ve_end; ++ve_it) {
600 selectedEhs.insert(*ve_it);
606 for (
typename std::set<typename MeshT::EdgeHandle>::const_iterator it = selectedEhs.begin(); it != selectedEhs.end(); ++it)
607 _mesh->status(*it).set_selected(
true);
613 template<
typename MeshT >
615 void selectBoundaryEdges(MeshT* _mesh) {
616 typename MeshT::EdgeIter e_it, e_end=_mesh->edges_end();
618 for (e_it = _mesh->edges_begin(); e_it != e_end ; ++e_it)
619 if ( _mesh->is_boundary( _mesh->halfedge_handle(*e_it,0) ) ||
620 _mesh->is_boundary( _mesh->halfedge_handle(*e_it,1) ) )
621 _mesh->status(*e_it).set_selected(
true );
626 template<
typename MeshT >
628 std::vector< int > getEdgeSelection(MeshT* _mesh) {
629 std::vector< int > selection;
631 for (
typename MeshT::EdgeIter e_it= _mesh->edges_begin() ; e_it != _mesh->edges_end() ; ++e_it )
632 if ( _mesh->status(*e_it).selected() )
633 selection.push_back( e_it->idx() );
640 template<
typename MeshT >
642 std::vector< int > getEdgeSelection(MeshT* _mesh,
bool& _invert) {
643 std::vector< int > selection;
647 for (
typename MeshT::VertexIter e_it= _mesh->edges_begin() ; e_it != _mesh->edges_end() ; ++e_it )
648 if ( _mesh->status(*e_it).selected() )
651 if ( count > (
int)( _mesh->n_vertices() / 2) )
656 for (
typename MeshT::VertexIter e_it= _mesh->edges_begin() ; e_it != _mesh->edges_end() ; ++e_it )
657 if ( _mesh->status(*e_it).selected() ^ _invert )
658 selection.push_back( e_it->idx() );
663 template<
typename MeshT >
665 void convertEdgeToVertexSelection(MeshT* _mesh,
const std::vector< int >& _edges) {
667 for (std::vector<int>::const_iterator e = _edges.begin(); e != _edges.end(); ++e) {
669 typename MeshT::EdgeHandle eh(*e);
670 typename MeshT::HalfedgeHandle heh0 = _mesh->halfedge_handle(eh, 0);
672 typename MeshT::VertexHandle vh0 = _mesh->to_vertex_handle(heh0);
673 typename MeshT::VertexHandle vh1 = _mesh->from_vertex_handle(heh0);
675 _mesh->status(vh0).set_selected(
true);
676 _mesh->status(vh1).set_selected(
true);
680 template<
typename MeshT >
682 void convertEdgeToVertexSelection(MeshT* _mesh) {
684 for (
typename MeshT::EdgeIter e_it= _mesh->edges_begin() ; e_it != _mesh->edges_end() ; ++e_it )
686 if ( _mesh->status(*e_it).selected() ){
688 typename MeshT::HalfedgeHandle heh0 = _mesh->halfedge_handle(*e_it, 0);
690 typename MeshT::VertexHandle vh0 = _mesh->to_vertex_handle(heh0);
691 typename MeshT::VertexHandle vh1 = _mesh->from_vertex_handle(heh0);
693 _mesh->status(vh0).set_selected(
true);
694 _mesh->status(vh1).set_selected(
true);
698 template<
typename MeshT >
700 void convertEdgeToFaceSelection(MeshT* _mesh,
const std::vector< int >& _edges) {
702 for(
typename MeshT::FaceIter f_it = _mesh->faces_begin(); f_it != _mesh->faces_end(); ++f_it) {
703 typename MeshT::FaceEdgeIter fe_it = _mesh->fe_iter(*f_it);
705 bool allfound =
true;
706 for(; fe_it.is_valid(); ++fe_it) {
708 bool onefound =
false;
709 for(std::vector<int>::const_iterator it = _edges.begin(); it != _edges.end(); ++it) {
710 if((*it) == fe_it->idx()) { onefound =
true;
break; }
719 _mesh->status(*f_it).set_selected(
true);
724 template<
typename MeshT >
726 void convertEdgeToFaceSelection(MeshT* _mesh) {
728 typename MeshT::FaceIter f_it, f_end = _mesh->faces_end();
730 for (f_it = _mesh->faces_begin(); f_it != f_end; ++f_it) {
732 typename MeshT::FaceEdgeIter fe_it = _mesh->fe_iter(*f_it);
734 bool allfound =
true;
735 for(; fe_it.is_valid(); ++fe_it) {
736 if(!_mesh->status(*fe_it).selected()) {
742 _mesh->status(*f_it).set_selected(
true);
746 template<
typename MeshT >
748 void convertEdgeToHalfedgeSelection(MeshT* _mesh) {
750 for (
typename MeshT::EdgeIter e_it= _mesh->edges_begin() ; e_it != _mesh->edges_end() ; ++e_it )
752 if ( _mesh->status(*e_it).selected() ){
754 _mesh->status(_mesh->halfedge_handle(*e_it, 0)).set_selected(
true);
755 _mesh->status(_mesh->halfedge_handle(*e_it, 1)).set_selected(
true);
759 template<
typename MeshT >
761 void convertEdgeSelectionToFeatureEdges(MeshT* _mesh) {
763 for (
typename MeshT::EdgeIter e_it = _mesh->edges_begin(); e_it != _mesh->edges_end(); ++e_it) {
765 if (_mesh->status(*e_it).selected()) {
767 _mesh->status(*e_it).set_feature(
true);
769 _mesh->status(*e_it).set_feature(
false);
774 template<
typename MeshT >
776 void convertFeatureEdgesToEdgeSelection(MeshT* _mesh) {
778 for (
typename MeshT::EdgeIter e_it = _mesh->edges_begin(); e_it != _mesh->edges_end(); ++e_it) {
780 if (_mesh->status(*e_it).feature()) {
782 _mesh->status(*e_it).set_selected(
true);
784 _mesh->status(*e_it).set_selected(
false);
789 template<
typename MeshT >
791 void clearFeatureEdges(MeshT* _mesh) {
793 for (
typename MeshT::EdgeIter e_it = _mesh->edges_begin(); e_it != _mesh->edges_end(); ++e_it) {
795 _mesh->status(*e_it).set_feature(
false);
803 template<
typename MeshT >
805 void selectHalfedges(MeshT* _mesh,
const std::vector< int >& _halfedges) {
806 const int n_halfedges = (int)_mesh->n_halfedges();
808 for ( uint i = 0 ; i < _halfedges.size() ; ++i )
809 if ( (_halfedges[i] >= 0) && ( _halfedges[i] < n_halfedges ) ) {
810 typename MeshT::HalfedgeHandle heh(_halfedges[i]);
811 _mesh->status(heh).set_selected(
true);
817 template<
typename MeshT >
819 void unselectHalfedges(MeshT* _mesh,
const std::vector< int >& _halfedges) {
820 const int n_halfedges = (int)_mesh->n_halfedges();
822 for ( uint i = 0 ; i < _halfedges.size() ; ++i )
823 if ( (_halfedges[i] >= 0) && ( _halfedges[i] < n_halfedges ) ) {
824 typename MeshT::HalfedgeHandle heh(_halfedges[i]);
825 _mesh->status(heh).set_selected(
false);
831 template<
typename MeshT >
833 void selectAllHalfedges(MeshT* _mesh) {
834 typename MeshT::HalfedgeIter he_it, he_end=_mesh->halfedges_end();
836 for (he_it = _mesh->halfedges_begin(); he_it != he_end ; ++he_it)
837 _mesh->status(*he_it).set_selected(
true);
842 template<
typename MeshT >
844 void clearHalfedgeSelection(MeshT* _mesh) {
845 typename MeshT::HalfedgeIter he_it, he_end=_mesh->halfedges_end();
847 for (he_it = _mesh->halfedges_begin(); he_it != he_end ; ++he_it)
848 _mesh->status(*he_it).set_selected(
false);
853 template<
typename MeshT >
855 void invertHalfedgeSelection(MeshT* _mesh) {
856 typename MeshT::HalfedgeIter he_it, he_end=_mesh->halfedges_end();
858 for (he_it = _mesh->halfedges_begin(); he_it != he_end ; ++he_it)
859 _mesh->status(*he_it).set_selected( ! _mesh->status(*he_it).selected());
865 template<
typename MeshT >
867 void selectBoundaryHalfedges(MeshT* _mesh) {
868 typename MeshT::HalfedgeIter he_it, he_end=_mesh->halfedges_end();
870 for (he_it = _mesh->halfedges_begin(); he_it != he_end ; ++he_it)
871 if ( _mesh->is_boundary( *he_it))
872 _mesh->status(*he_it).set_selected(
true );
877 template<
typename MeshT >
879 std::vector< int > getHalfedgeSelection(MeshT* _mesh) {
880 std::vector< int > selection;
882 for (
typename MeshT::HalfedgeIter he_it= _mesh->halfedges_begin() ; he_it != _mesh->halfedges_end() ; ++he_it )
883 if ( _mesh->status(*he_it).selected() )
884 selection.push_back( he_it->idx() );
889 template<
typename MeshT >
891 void convertHalfedgeToVertexSelection(MeshT* _mesh) {
893 for (
typename MeshT::HalfedgeIter he_it= _mesh->halfedges_begin() ; he_it != _mesh->halfedges_end() ; ++he_it ) {
895 if(_mesh->status(*he_it).selected()) {
896 _mesh->status(_mesh->to_vertex_handle(*he_it)).set_selected(
true);
897 _mesh->status(_mesh->from_vertex_handle(*he_it)).set_selected(
true);
902 template<
typename MeshT >
904 void convertHalfedgeToEdgeSelection(MeshT* _mesh) {
906 for (
typename MeshT::HalfedgeIter he_it= _mesh->halfedges_begin() ; he_it != _mesh->halfedges_end() ; ++he_it ) {
908 if(_mesh->status(*he_it).selected()) {
909 _mesh->status(_mesh->edge_handle(*he_it)).set_selected(
true);
914 template<
typename MeshT >
916 void convertHalfedgeToFaceSelection(MeshT* _mesh) {
921 for (
typename MeshT::HalfedgeIter he_it= _mesh->halfedges_begin() ; he_it != _mesh->halfedges_end() ; ++he_it ) {
923 if(_mesh->status(*he_it).selected()) {
924 _mesh->status(_mesh->face_handle(*he_it)).set_selected(
true);
933 template<
typename MeshT >
935 void selectFaces(MeshT* _mesh,
const std::vector< int >& _faces) {
936 const int n_faces = (int)_mesh->n_faces();
938 for ( uint i = 0 ; i < _faces.size() ; ++i )
939 if ( (_faces[i] >= 0) && ( _faces[i] < n_faces ) ) {
940 typename MeshT::FaceHandle fh(_faces[i]);
941 _mesh->status(fh).set_selected(
true);
947 template<
typename MeshT >
949 void unselectFaces(MeshT* _mesh,
const std::vector< int >& _faces) {
950 const int n_faces = (int)_mesh->n_faces();
952 for ( uint i = 0 ; i < _faces.size() ; ++i )
953 if ( (_faces[i] >= 0) && ( _faces[i] < n_faces ) ) {
954 typename MeshT::FaceHandle fh(_faces[i]);
955 _mesh->status(fh).set_selected(
false);
961 template<
typename MeshT >
963 void selectAllFaces(MeshT* _mesh) {
964 typename MeshT::FaceIter f_it, f_end=_mesh->faces_end();
966 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
967 _mesh->status(*f_it).set_selected(
true);
973 template<
typename MeshT >
975 void clearFaceSelection(MeshT* _mesh) {
976 typename MeshT::FaceIter f_it, f_end=_mesh->faces_end();
978 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
979 _mesh->status(*f_it).set_selected(
false);
985 template<
typename MeshT >
987 void invertFaceSelection(MeshT* _mesh) {
988 typename MeshT::FaceIter f_it, f_end=_mesh->faces_end();
990 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
991 _mesh->status(*f_it).set_selected( ! _mesh->status(*f_it).selected());
996 template<
typename MeshT >
998 void selectBoundaryFaces(MeshT* _mesh) {
999 typename MeshT::HalfedgeIter he_it, he_end=_mesh->halfedges_end();
1001 for (he_it = _mesh->halfedges_begin(); he_it != he_end ; ++he_it)
1002 if (_mesh->is_boundary(*he_it) ) {
1003 for (
typename MeshT::VertexFaceIter vf_it(*_mesh ,_mesh->to_vertex_handle(*he_it) ) ; vf_it.is_valid() ; ++vf_it)
1004 _mesh->status(*vf_it).set_selected(
true);
1005 for (
typename MeshT::VertexFaceIter vf_it(*_mesh ,_mesh->from_vertex_handle(*he_it) ) ; vf_it.is_valid() ; ++vf_it)
1006 _mesh->status(*vf_it).set_selected(
true);
1013 template<
typename MeshT >
1015 void shrinkFaceSelection(MeshT* _mesh) {
1018 _mesh->add_property( temp_shrink,
"Temp property for Face selection shrinking" );
1020 typename MeshT::FaceIter f_it, f_end=_mesh->faces_end();
1023 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
1024 _mesh->property(temp_shrink,*f_it) = _mesh->status(*f_it).selected();
1027 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
1028 if ( _mesh->property(temp_shrink,*f_it) ) {
1029 bool boundary =
false;
1030 for (
typename MeshT::FaceVertexIter fv_it(*_mesh,*f_it); fv_it.is_valid() ; ++fv_it) {
1031 for (
typename MeshT::VertexFaceIter vf_it(*_mesh,*fv_it); vf_it.is_valid() ; ++vf_it) {
1032 if ( ! _mesh->property(temp_shrink,*vf_it) ) {
1040 _mesh->status(*f_it).set_selected( !boundary );
1043 _mesh->remove_property(temp_shrink);
1048 template<
typename MeshT >
1050 void growFaceSelection(MeshT* _mesh) {
1053 _mesh->add_property( temp_grow,
"Temp property for Face selection growing" );
1055 typename MeshT::FaceIter f_it, f_end=_mesh->faces_end();
1058 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
1059 _mesh->property(temp_grow,*f_it) = _mesh->status(*f_it).selected();
1062 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
1063 if ( _mesh->property(temp_grow,*f_it) )
1064 for (
typename MeshT::FaceVertexIter fv_it(*_mesh,*f_it); fv_it.is_valid() ; ++fv_it)
1065 for (
typename MeshT::VertexFaceIter vf_it(*_mesh,*fv_it); vf_it.is_valid() ; ++vf_it)
1066 _mesh->status(*vf_it).set_selected(
true );
1068 _mesh->remove_property(temp_grow);
1073 template<
typename MeshT >
1075 std::vector< int > getFaceSelection(MeshT* _mesh) {
1076 std::vector< int > selection;
1078 for (
typename MeshT::FaceIter f_it= _mesh->faces_begin() ; f_it != _mesh->faces_end() ; ++f_it )
1079 if ( _mesh->status(*f_it).selected() )
1080 selection.push_back( f_it->idx() );
1087 template<
typename MeshT >
1089 std::vector< int > getFaceSelection(MeshT* _mesh,
bool& _invert) {
1090 std::vector< int > selection;
1094 for (
typename MeshT::FaceIter f_it= _mesh->faces_begin() ; f_it != _mesh->faces_end() ; ++f_it )
1095 if ( _mesh->status(*f_it).selected() )
1098 if ( count > (
int)( _mesh->n_vertices() / 2) )
1103 for (
typename MeshT::FaceIter f_it= _mesh->faces_begin() ; f_it != _mesh->faces_end() ; ++f_it )
1104 if ( _mesh->status(*f_it).selected() ^ _invert )
1105 selection.push_back( f_it->idx() );
1110 template<
typename MeshT >
1112 void convertFaceToVertexSelection(MeshT* _mesh,
const std::vector< int >& _faces) {
1114 for (std::vector<int>::const_iterator f = _faces.begin(); f != _faces.end(); ++f) {
1116 typename MeshT::FaceHandle fh(*f);
1118 typename MeshT::FaceVertexIter v_iter = _mesh->fv_iter(fh);
1120 for (; v_iter.is_valid(); ++v_iter) {
1121 _mesh->status(*v_iter).set_selected(
true);
1126 template<
typename MeshT >
1128 void convertFaceToVertexSelection(MeshT* _mesh) {
1130 for (
typename MeshT::FaceIter f_it= _mesh->faces_begin() ; f_it != _mesh->faces_end() ; ++f_it )
1132 if ( _mesh->status(*f_it).selected() ){
1134 typename MeshT::FaceVertexIter v_iter = _mesh->fv_iter(*f_it);
1136 for (; v_iter.is_valid(); ++v_iter)
1137 _mesh->status(*v_iter).set_selected(
true);
1141 template<
typename MeshT >
1143 void convertFaceToEdgeSelection(MeshT* _mesh,
const std::vector< int >& _faces) {
1145 for (std::vector<int>::const_iterator f = _faces.begin(); f != _faces.end(); ++f) {
1147 typename MeshT::FaceHandle fh(*f);
1149 typename MeshT::FaceEdgeIter e_iter = _mesh->fe_iter(fh);
1151 for (; e_iter.is_valid(); ++e_iter) {
1152 _mesh->status(*e_iter).set_selected(
true);
1157 template<
typename MeshT >
1159 void convertFaceToEdgeSelection(MeshT* _mesh) {
1161 for (
typename MeshT::FaceIter f_it= _mesh->faces_begin() ; f_it != _mesh->faces_end() ; ++f_it )
1163 if ( _mesh->status(*f_it).selected() ){
1165 typename MeshT::FaceEdgeIter e_iter = _mesh->fe_iter(*f_it);
1167 for (; e_iter.is_valid(); ++e_iter)
1168 _mesh->status(*e_iter).set_selected(
true);
1172 template<
typename MeshT >
1174 void convertFaceToHalfedgeSelection(MeshT* _mesh) {
1176 for (
typename MeshT::FaceIter f_it= _mesh->faces_begin() ; f_it != _mesh->faces_end() ; ++f_it )
1178 if ( _mesh->status(*f_it).selected() ){
1180 typename MeshT::FaceHalfedgeIter fh_iter = _mesh->fh_iter(*f_it);
1182 for (; fh_iter.is_valid(); ++fh_iter)
1183 _mesh->status(*fh_iter).set_selected(
true);
1187 template<
typename MeshT >
1189 void convertFaceSelectionToFeatureFaces(MeshT* _mesh) {
1191 for (
typename MeshT::FaceIter f_it = _mesh->faces_begin(); f_it != _mesh->faces_end(); ++f_it) {
1193 if (_mesh->status(*f_it).selected()) {
1195 _mesh->status(*f_it).set_feature(
true);
1197 _mesh->status(*f_it).set_feature(
false);
1202 template<
typename MeshT >
1204 void convertFeatureFacesToFaceSelection(MeshT* _mesh) {
1206 for (
typename MeshT::FaceIter f_it = _mesh->faces_begin(); f_it != _mesh->faces_end(); ++f_it) {
1208 if (_mesh->status(*f_it).feature()) {
1210 _mesh->status(*f_it).set_selected(
true);
1212 _mesh->status(*f_it).set_selected(
false);
1217 template<
typename MeshT >
1219 void clearFeatureFaces(MeshT* _mesh) {
1221 for (
typename MeshT::FaceIter f_it = _mesh->faces_begin(); f_it != _mesh->faces_end(); ++f_it) {
1223 _mesh->status(*f_it).set_feature(
false);
Functions for selection on a mesh.