Developer Documentation
MeshSelectionT_impl.hh
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42
43
44
45
46
47//=============================================================================
48//
49// IMPLEMENTATION
50//
51//=============================================================================
52
53#define MESHSELECTION_C
54
55//== INCLUDES =================================================================
56
57#include "MeshSelectionT.hh"
58#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
59
60#include <stack>
61#include <set>
62//== NAMESPACES ===============================================================
63
64namespace MeshSelection {
65
66//== IMPLEMENTATION ==========================================================
67
68//=========================================================
69//== Vertex Selection =====================================
70//=========================================================
71
72template< typename MeshT >
73inline
74void selectVertices(MeshT* _mesh, const std::vector< int >& _vertices) {
75 const int n_vertices = (int)_mesh->n_vertices();
76
77 for ( uint i = 0 ; i < _vertices.size() ; ++i )
78 if ( (_vertices[i] >= 0) && ( _vertices[i] < n_vertices ) ) {
79 typename MeshT::VertexHandle vh(_vertices[i]);
80 _mesh->status(vh).set_selected(true);
81 }
82}
83
84//=========================================================
85
86template< typename MeshT >
87inline
88void unselectVertices(MeshT* _mesh, const std::vector< int >& _vertices) {
89 const int n_vertices = (int)_mesh->n_vertices();
90
91 for ( uint i = 0 ; i < _vertices.size() ; ++i )
92 if ( (_vertices[i] >= 0) && ( _vertices[i] < n_vertices ) ) {
93 typename MeshT::VertexHandle vh(_vertices[i]);
94 _mesh->status(vh).set_selected(false);
95 }
96}
97
98//=========================================================
99
100template< typename MeshT >
101inline
103 typename MeshT::VertexIter v_it, v_end=_mesh->vertices_end();
104
105 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
106 _mesh->status(*v_it).set_selected(true);
107
108}
109
110//=========================================================
111
112template< typename MeshT >
113inline
115 typename MeshT::VertexIter v_it, v_end=_mesh->vertices_end();
116
117 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
118 _mesh->status(*v_it).set_selected(false);
119}
120
121//=========================================================
122
123template< typename MeshT >
124inline
126 typename MeshT::VertexIter v_it, v_end=_mesh->vertices_end();
127
128 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
129 _mesh->status(*v_it).set_selected( ! _mesh->status(*v_it).selected());
130}
131
132//=========================================================
133
134
135template< typename MeshT >
136inline
138 typename MeshT::HalfedgeIter he_it, he_end=_mesh->halfedges_end();
139
140 for (he_it = _mesh->halfedges_begin(); he_it != he_end ; ++he_it)
141 if (_mesh->is_boundary(*he_it) ) {
142 _mesh->status(_mesh->to_vertex_handle(*he_it)).set_selected(true);
143 _mesh->status(_mesh->from_vertex_handle(*he_it)).set_selected(true);
144 }
145}
146
147//-----------------------------------------------------------------------------
148
149template< typename MeshT >
150inline
153
154 _mesh->add_property( temp_shrink, "Temp property for Vertex selection shrinking" );
155
156 typename MeshT::VertexIter v_it, v_end=_mesh->vertices_end();
157
158 // initialize property ( copy status to new property )
159 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
160 _mesh->property(temp_shrink,*v_it) = _mesh->status(*v_it).selected();
161
162 // update selection
163 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
164 if ( _mesh->property(temp_shrink,*v_it) ) {
165 _mesh->status(*v_it).set_selected( true );
166
167 for ( typename MeshT::VertexVertexIter vv_it(*_mesh,*v_it); vv_it.is_valid(); ++vv_it)
168 if ( ! _mesh->property(temp_shrink,*vv_it) ){
169 _mesh->status(*v_it).set_selected( false );
170 break;
171 }
172 }
173
174 _mesh->remove_property(temp_shrink);
175}
176
177//=========================================================
178
179template< typename MeshT >
180inline
183
184 _mesh->add_property( temp_grow, "Temp property for Vertex selection growing" );
185
186 // initialize property ( copy status to new property )
187 typename MeshT::VertexIter v_it, v_end=_mesh->vertices_end();
188 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
189 _mesh->property(temp_grow,*v_it) = _mesh->status(*v_it).selected();
190
191 // update selection
192 for (v_it = _mesh->vertices_begin(); v_it != v_end ; ++v_it)
193 if ( _mesh->property(temp_grow,*v_it) )
194 for ( typename MeshT::VertexVertexIter vv_it(*_mesh,*v_it); vv_it.is_valid(); ++vv_it)
195 _mesh->status(*vv_it).set_selected( true );
196
197 _mesh->remove_property(temp_grow);
198}
199
200//=========================================================
201
202template< typename MeshT >
203inline
204std::vector< int > getVertexSelection(MeshT* _mesh) {
205 std::vector< int > selection;
206
207 for ( typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
208 if ( _mesh->status(*v_it).selected() )
209 selection.push_back( v_it->idx() );
210
211 return selection;
212}
213
214//=========================================================
215
216template< typename MeshT >
217inline
218std::vector< int > getVertexSelection(MeshT* _mesh, bool& _invert) {
219 std::vector< int > selection;
220
221 int count = 0;
222
223 for ( typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
224 if ( _mesh->status(*v_it).selected() )
225 ++count;
226
227 if ( count > (int)( _mesh->n_vertices() / 2) )
228 _invert = true;
229 else
230 _invert = false;
231
232 for ( typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
233 if ( _mesh->status(*v_it).selected() ^ _invert )
234 selection.push_back( v_it->idx() );
235
236 return selection;
237}
238
239
240template< typename MeshT >
241inline
242void selectBoundaryVertices(MeshT* _mesh, const typename MeshT::VertexHandle& _vh){
243
245 _mesh->add_property(visited, "Visited Vertices");
246
247 typename MeshT::VertexIter v_it, v_end = _mesh->vertices_end();
248 for (v_it = _mesh->vertices_begin(); v_it != v_end; ++v_it)
249 _mesh->property(visited, *v_it) = false;
250
251 std::stack< typename MeshT::VertexHandle > stack;
252 stack.push( _vh );
253
254 while (!stack.empty()){
255
256 typename MeshT::VertexHandle vh = stack.top();
257 stack.pop();
258
259 if (_mesh->property(visited,vh))
260 continue;
261
262 //find outgoing boundary-edges
263 for (typename MeshT::VertexOHalfedgeIter voh_it(*_mesh,vh); voh_it.is_valid(); ++voh_it)
264 if ( _mesh->is_boundary( _mesh->edge_handle( *voh_it ) ) )
265 stack.push( _mesh->to_vertex_handle(*voh_it) );
266
267 //select vertex
268 _mesh->property(visited,vh) = true;
269 _mesh->status( vh ).set_selected(true);
270 }
271 _mesh->remove_property(visited);
272}
273
274template< typename MeshT >
275inline
276void convertVertexToEdgeSelection(MeshT* _mesh, const std::vector< int >& _vertices) {
277
278 for ( std::vector<int>::const_iterator v = _vertices.begin(); v != _vertices.end(); ++v) {
279
280 typename MeshT::VertexHandle vh(*v);
281 typename MeshT::VertexOHalfedgeIter ohe_iter = _mesh->voh_iter(vh);
282
283 for (; ohe_iter.is_valid(); ++ohe_iter) {
284 // test if both incident vertices are in _vertices
285 typename MeshT::VertexHandle ovh = _mesh->to_vertex_handle(*ohe_iter);
286 // search for ovh in _vertices
287 for(std::vector<int>::const_iterator it = _vertices.begin(); it != _vertices.end(); ++it) {
288 if((*it) == ovh.idx()) {
289 _mesh->status(_mesh->edge_handle(*ohe_iter)).set_selected(true);
290 break;
291 }
292 }
293 }
294 }
295}
296
297template< typename MeshT >
298inline
300
301 typename MeshT::VertexIter v_it, v_end = _mesh->vertices_end();
302 for (v_it = _mesh->vertices_begin(); v_it != v_end; ++v_it) {
303
304 if ( _mesh->status( *v_it ).selected() ) {
305 typename MeshT::VertexOHalfedgeIter ohe_iter = _mesh->voh_iter(*v_it);
306
307 for (; ohe_iter.is_valid(); ++ohe_iter) {
308 // test if both incident vertices are in _vertices
309 typename MeshT::VertexHandle ovh = _mesh->to_vertex_handle(*ohe_iter);
310 if (_mesh->status(ovh).selected())
311 _mesh->status(_mesh->edge_handle(*ohe_iter)).set_selected(true);
312 }
313 }
314 }
315}
316
317template< typename MeshT >
318inline
319void convertVertexToHalfedgeSelection(MeshT* _mesh, const std::vector< int >& _vertices) {
320
321 for (std::vector<int>::const_iterator v = _vertices.begin(); v != _vertices.end(); ++v) {
322
323 typename MeshT::VertexHandle vh(*v);
324 typename MeshT::VertexOHalfedgeIter ohe_iter = _mesh->voh_iter(vh);
325
326 for (; ohe_iter.is_valid(); ++ohe_iter) {
327 // test if both incident vertices are in _vertices
328 typename MeshT::VertexHandle ovh = _mesh->to_vertex_handle(*ohe_iter);
329 // search for ovh in _vertices
330 for(std::vector<int>::const_iterator it = _vertices.begin(); it != _vertices.end(); ++it) {
331 if((*it) == ovh.idx()) {
332 _mesh->status(*ohe_iter).set_selected(true);
333 _mesh->status(_mesh->opposite_halfedge_handle(*ohe_iter)).set_selected(true);
334 break;
335 }
336 }
337 }
338 }
339}
340
341template< typename MeshT >
342inline
344
345 typename MeshT::VertexIter v_it, v_end = _mesh->vertices_end();
346
347 for (v_it = _mesh->vertices_begin(); v_it != v_end; ++v_it) {
348
349 if ( _mesh->status( *v_it ).selected() ) {
350
351 typename MeshT::VertexOHalfedgeIter ohe_iter = _mesh->voh_iter(*v_it);
352
353 for (; ohe_iter.is_valid(); ++ohe_iter) {
354 // test if both incident vertices are in _vertices
355 typename MeshT::VertexHandle ovh = _mesh->to_vertex_handle(*ohe_iter);
356 if (_mesh->status(ovh).selected()) {
357 _mesh->status(*ohe_iter).set_selected(true);
358 _mesh->status(_mesh->opposite_halfedge_handle(*ohe_iter)).set_selected(true);
359 }
360 }
361 }
362 }
363}
364
365template< typename MeshT >
366inline
367void convertVertexToFaceSelection(MeshT* _mesh, const std::vector< int >& _vertices) {
368
369 for(typename MeshT::FaceIter f_it = _mesh->faces_begin(); f_it != _mesh->faces_end(); ++f_it) {
370 typename MeshT::FaceVertexIter fv_it = _mesh->fv_iter(*f_it);
371 // go over each vertex of each face and test if it's selected
372 bool allfound = true;
373 for(; fv_it.is_valid(); ++fv_it) {
374 // search fv_it in _vertices
375 bool onefound = false;
376 for(std::vector<int>::const_iterator it = _vertices.begin(); it != _vertices.end(); ++it) {
377 if((*it) == fv_it->idx()) { onefound = true; break; }
378 }
379 if(!onefound) {
380 allfound = false;
381 break;
382 }
383 }
384 if(allfound) {
385 // all incident vertices are selected -> select face
386 _mesh->status(*f_it).set_selected(true);
387 }
388 }
389}
390
391template< typename MeshT >
392inline
394
395 typename MeshT::FaceIter f_it, f_end = _mesh->faces_end();
396
397 for (f_it = _mesh->faces_begin(); f_it != f_end; ++f_it) {
398
399 typename MeshT::FaceVertexIter fv_it = _mesh->fv_iter(*f_it);
400 // test if all incident vertices are selected
401 bool allfound = true;
402 for(; fv_it.is_valid(); ++fv_it) {
403 if(!_mesh->status(*fv_it).selected()) {
404 allfound = false;
405 break;
406 }
407 }
408 if(allfound)
409 _mesh->status(*f_it).set_selected(true);
410 }
411}
412
413template< typename MeshT >
414inline
416
417 for (typename MeshT::VertexIter v_it = _mesh->vertices_begin(); v_it != _mesh->vertices_end(); ++v_it) {
418
419 if (_mesh->status(*v_it).selected()) {
420
421 _mesh->status(*v_it).set_feature(true);
422 } else {
423 _mesh->status(*v_it).set_feature(false);
424 }
425 }
426}
427
428template< typename MeshT >
429inline
431
432 for (typename MeshT::VertexIter v_it = _mesh->vertices_begin(); v_it != _mesh->vertices_end(); ++v_it) {
433
434 if (_mesh->status(*v_it).feature()) {
435
436 _mesh->status(*v_it).set_selected(true);
437 } else {
438 _mesh->status(*v_it).set_selected(false);
439 }
440 }
441}
442
443template< typename MeshT >
444inline
446
447 for (typename MeshT::VertexIter v_it = _mesh->vertices_begin(); v_it != _mesh->vertices_end(); ++v_it) {
448
449 _mesh->status(*v_it).set_feature(false);
450 }
451}
452
453//=========================================================
454//== Modeling Regions =====================================
455//=========================================================
456
457template< typename MeshT >
458inline
459void setArea(MeshT* _mesh, const std::vector< int >& _vertices , unsigned int _type, bool _state) {
460 for ( uint i = 0 ; i < _vertices.size() ; ++i ) {
461 if ( _vertices[i] > (int)_mesh->n_vertices() )
462 continue;
463
464 typename MeshT::VertexHandle vh(_vertices[i]);
465 _mesh->status(vh).change_bit(_type, _state);
466 }
467}
468
469template< typename MeshT >
470inline
471void setArea(MeshT* _mesh , unsigned int _type, bool _state) {
472 for ( typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
473 _mesh->status(*v_it).change_bit(_type, _state);
474}
475
476template< typename MeshT >
477inline
478std::vector< int > getArea(MeshT* _mesh, unsigned int _type) {
479 std::vector< int > selection;
480
481 for ( typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
482 if ( _mesh->status(*v_it).is_bit_set( _type ) )
483 selection.push_back( v_it->idx() );
484
485 return selection;
486}
487
488template< typename MeshT >
489inline
490std::vector< int > getArea(MeshT* _mesh, unsigned int _type , bool& _invert) {
491 std::vector< int > selection;
492
493 int count = 0;
494
495 for ( typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
496 if ( _mesh->status(*v_it).is_bit_set( _type ) )
497 ++count;
498
499 if ( count > (int)( _mesh->n_vertices() / 2) )
500 _invert = true;
501 else
502 _invert = false;
503
504 for ( typename MeshT::VertexIter v_it= _mesh->vertices_begin() ; v_it != _mesh->vertices_end() ; ++v_it )
505 if ( _mesh->status(*v_it).is_bit_set( _type ) ^ _invert )
506 selection.push_back( v_it->idx() );
507
508 return selection;
509}
510
511
512//=========================================================
513//== Edge Selection =====================================
514//=========================================================
515
516template< typename MeshT >
517inline
518void selectEdges(MeshT* _mesh, const std::vector< int >& _edges, const double _dihedral_angle_threshold) {
519 const int n_edges = (int)_mesh->n_edges();
520
521 for ( uint i = 0 ; i < _edges.size() ; ++i )
522 if ( (_edges[i] >= 0) && ( _edges[i] < n_edges ) ) {
523 typename MeshT::EdgeHandle eh(_edges[i]);
524 if(!_mesh->has_face_normals() || std::abs(_mesh->calc_dihedral_angle_fast(eh)) >= _dihedral_angle_threshold)
525 _mesh->status(eh).set_selected(true);
526 }
527}
528
529//=========================================================
530
531template< typename MeshT >
532inline
533void unselectEdges(MeshT* _mesh, const std::vector< int >& _edges) {
534 const int n_edges = (int)_mesh->n_edges();
535
536 for ( uint i = 0 ; i < _edges.size() ; ++i )
537 if ( (_edges[i] >= 0) && ( _edges[i] < n_edges ) ) {
538 typename MeshT::EdgeHandle eh(_edges[i]);
539 _mesh->status(eh).set_selected(false);
540 }
541}
542
543//=========================================================
544
545template< typename MeshT >
546inline
547void selectAllEdges(MeshT* _mesh) {
548 typename MeshT::EdgeIter e_it, e_end=_mesh->edges_end();
549
550 for (e_it = _mesh->edges_begin(); e_it != e_end ; ++e_it)
551 _mesh->status(*e_it).set_selected(true);
552}
553
554//=========================================================
555
556template< typename MeshT >
557inline
559 typename MeshT::EdgeIter e_it, e_end=_mesh->edges_end();
560
561 for (e_it = _mesh->edges_begin(); e_it != e_end ; ++e_it)
562 _mesh->status(*e_it).set_selected(false);
563}
564
565//=========================================================
566
567template< typename MeshT >
568inline
570 typename MeshT::EdgeIter e_it, e_end=_mesh->edges_end();
571
572 for (e_it = _mesh->edges_begin(); e_it != e_end ; ++e_it)
573 _mesh->status(*e_it).set_selected( ! _mesh->status(*e_it).selected());
574}
575
576//=========================================================
577
578template<typename MeshT>
579inline
581 std::set<typename MeshT::EdgeHandle> selectedEhs;
582 for (typename MeshT::EdgeIter e_it = _mesh->edges_begin(), e_end = _mesh->edges_end();
583 e_it != e_end; ++e_it) {
584
585 if (!_mesh->status(*e_it).selected()) continue;
586
587 const typename MeshT::HalfedgeHandle he = _mesh->halfedge_handle(*e_it, 0);
588 const typename MeshT::VertexHandle vhs[] = { _mesh->from_vertex_handle(he),
589 _mesh->to_vertex_handle(he) };
590
591 for (int i = 0; i < 2; ++i) {
592 for (typename MeshT::VertexEdgeIter ve_it = _mesh->ve_begin(vhs[i]), ve_end = _mesh->ve_end(vhs[i]);
593 ve_it != ve_end; ++ve_it) {
594
595 selectedEhs.insert(*ve_it);
596 }
597 }
598
599 }
600
601 for (typename std::set<typename MeshT::EdgeHandle>::const_iterator it = selectedEhs.begin(); it != selectedEhs.end(); ++it)
602 _mesh->status(*it).set_selected(true);
603}
604
605//=========================================================
606
607
608template< typename MeshT >
609inline
611 typename MeshT::EdgeIter e_it, e_end=_mesh->edges_end();
612
613 for (e_it = _mesh->edges_begin(); e_it != e_end ; ++e_it)
614 if ( _mesh->is_boundary( _mesh->halfedge_handle(*e_it,0) ) ||
615 _mesh->is_boundary( _mesh->halfedge_handle(*e_it,1) ) )
616 _mesh->status(*e_it).set_selected( true );
617}
618
619//=========================================================
620
621template< typename MeshT >
622inline
623std::vector< int > getEdgeSelection(MeshT* _mesh) {
624 std::vector< int > selection;
625
626 for ( typename MeshT::EdgeIter e_it= _mesh->edges_begin() ; e_it != _mesh->edges_end() ; ++e_it )
627 if ( _mesh->status(*e_it).selected() )
628 selection.push_back( e_it->idx() );
629
630 return selection;
631}
632
633//=========================================================
634
635template< typename MeshT >
636inline
637std::vector< int > getEdgeSelection(MeshT* _mesh, bool& _invert) {
638 std::vector< int > selection;
639
640 int count = 0;
641
642 for ( typename MeshT::VertexIter e_it= _mesh->edges_begin() ; e_it != _mesh->edges_end() ; ++e_it )
643 if ( _mesh->status(*e_it).selected() )
644 ++count;
645
646 if ( count > (int)( _mesh->n_vertices() / 2) )
647 _invert = true;
648 else
649 _invert = false;
650
651 for ( typename MeshT::VertexIter e_it= _mesh->edges_begin() ; e_it != _mesh->edges_end() ; ++e_it )
652 if ( _mesh->status(*e_it).selected() ^ _invert )
653 selection.push_back( e_it->idx() );
654
655 return selection;
656}
657
658template< typename MeshT >
659inline
660void convertEdgeToVertexSelection(MeshT* _mesh, const std::vector< int >& _edges) {
661
662 for (std::vector<int>::const_iterator e = _edges.begin(); e != _edges.end(); ++e) {
663
664 typename MeshT::EdgeHandle eh(*e);
665 typename MeshT::HalfedgeHandle heh0 = _mesh->halfedge_handle(eh, 0);
666
667 typename MeshT::VertexHandle vh0 = _mesh->to_vertex_handle(heh0);
668 typename MeshT::VertexHandle vh1 = _mesh->from_vertex_handle(heh0);
669
670 _mesh->status(vh0).set_selected(true);
671 _mesh->status(vh1).set_selected(true);
672 }
673}
674
675template< typename MeshT >
676inline
678
679 for ( typename MeshT::EdgeIter e_it= _mesh->edges_begin() ; e_it != _mesh->edges_end() ; ++e_it )
680
681 if ( _mesh->status(*e_it).selected() ){
682
683 typename MeshT::HalfedgeHandle heh0 = _mesh->halfedge_handle(*e_it, 0);
684
685 typename MeshT::VertexHandle vh0 = _mesh->to_vertex_handle(heh0);
686 typename MeshT::VertexHandle vh1 = _mesh->from_vertex_handle(heh0);
687
688 _mesh->status(vh0).set_selected(true);
689 _mesh->status(vh1).set_selected(true);
690 }
691}
692
693template< typename MeshT >
694inline
695void convertEdgeToFaceSelection(MeshT* _mesh, const std::vector< int >& _edges) {
696
697 for(typename MeshT::FaceIter f_it = _mesh->faces_begin(); f_it != _mesh->faces_end(); ++f_it) {
698 typename MeshT::FaceEdgeIter fe_it = _mesh->fe_iter(*f_it);
699 // go over each edge of each face and test if it's selected
700 bool allfound = true;
701 for(; fe_it.is_valid(); ++fe_it) {
702 // search fe_it in _edges
703 bool onefound = false;
704 for(std::vector<int>::const_iterator it = _edges.begin(); it != _edges.end(); ++it) {
705 if((*it) == fe_it->idx()) { onefound = true; break; }
706 }
707 if(!onefound) {
708 allfound = false;
709 break;
710 }
711 }
712 if(allfound) {
713 // all incident vertices are selected -> select face
714 _mesh->status(*f_it).set_selected(true);
715 }
716 }
717}
718
719template< typename MeshT >
720inline
722
723 typename MeshT::FaceIter f_it, f_end = _mesh->faces_end();
724
725 for (f_it = _mesh->faces_begin(); f_it != f_end; ++f_it) {
726
727 typename MeshT::FaceEdgeIter fe_it = _mesh->fe_iter(*f_it);
728 // test if all incident edges are selected
729 bool allfound = true;
730 for(; fe_it.is_valid(); ++fe_it) {
731 if(!_mesh->status(*fe_it).selected()) {
732 allfound = false;
733 break;
734 }
735 }
736 if(allfound)
737 _mesh->status(*f_it).set_selected(true);
738 }
739}
740
741template< typename MeshT >
742inline
744
745 for ( typename MeshT::EdgeIter e_it= _mesh->edges_begin() ; e_it != _mesh->edges_end() ; ++e_it )
746
747 if ( _mesh->status(*e_it).selected() ){
748
749 _mesh->status(_mesh->halfedge_handle(*e_it, 0)).set_selected(true);
750 _mesh->status(_mesh->halfedge_handle(*e_it, 1)).set_selected(true);
751 }
752}
753
754template< typename MeshT >
755inline
757
758 for (typename MeshT::EdgeIter e_it = _mesh->edges_begin(); e_it != _mesh->edges_end(); ++e_it) {
759
760 if (_mesh->status(*e_it).selected()) {
761
762 _mesh->status(*e_it).set_feature(true);
763 } else {
764 _mesh->status(*e_it).set_feature(false);
765 }
766 }
767}
768
769template< typename MeshT >
770inline
772
773 for (typename MeshT::EdgeIter e_it = _mesh->edges_begin(); e_it != _mesh->edges_end(); ++e_it) {
774
775 if (_mesh->status(*e_it).feature()) {
776
777 _mesh->status(*e_it).set_selected(true);
778 } else {
779 _mesh->status(*e_it).set_selected(false);
780 }
781 }
782}
783
784template< typename MeshT >
785inline
787
788 for (typename MeshT::EdgeIter e_it = _mesh->edges_begin(); e_it != _mesh->edges_end(); ++e_it) {
789
790 _mesh->status(*e_it).set_feature(false);
791 }
792}
793
794//=========================================================
795//== Halfedge Selection =====================================
796//=========================================================
797
798template< typename MeshT >
799inline
800void selectHalfedges(MeshT* _mesh, const std::vector< int >& _halfedges) {
801 const int n_halfedges = (int)_mesh->n_halfedges();
802
803 for ( uint i = 0 ; i < _halfedges.size() ; ++i )
804 if ( (_halfedges[i] >= 0) && ( _halfedges[i] < n_halfedges ) ) {
805 typename MeshT::HalfedgeHandle heh(_halfedges[i]);
806 _mesh->status(heh).set_selected(true);
807 }
808}
809
810//=========================================================
811
812template< typename MeshT >
813inline
814void unselectHalfedges(MeshT* _mesh, const std::vector< int >& _halfedges) {
815 const int n_halfedges = (int)_mesh->n_halfedges();
816
817 for ( uint i = 0 ; i < _halfedges.size() ; ++i )
818 if ( (_halfedges[i] >= 0) && ( _halfedges[i] < n_halfedges ) ) {
819 typename MeshT::HalfedgeHandle heh(_halfedges[i]);
820 _mesh->status(heh).set_selected(false);
821 }
822}
823
824//=========================================================
825
826template< typename MeshT >
827inline
829 typename MeshT::HalfedgeIter he_it, he_end=_mesh->halfedges_end();
830
831 for (he_it = _mesh->halfedges_begin(); he_it != he_end ; ++he_it)
832 _mesh->status(*he_it).set_selected(true);
833}
834
835//=========================================================
836
837template< typename MeshT >
838inline
840 typename MeshT::HalfedgeIter he_it, he_end=_mesh->halfedges_end();
841
842 for (he_it = _mesh->halfedges_begin(); he_it != he_end ; ++he_it)
843 _mesh->status(*he_it).set_selected(false);
844}
845
846//=========================================================
847
848template< typename MeshT >
849inline
851 typename MeshT::HalfedgeIter he_it, he_end=_mesh->halfedges_end();
852
853 for (he_it = _mesh->halfedges_begin(); he_it != he_end ; ++he_it)
854 _mesh->status(*he_it).set_selected( ! _mesh->status(*he_it).selected());
855}
856
857//=========================================================
858
859
860template< typename MeshT >
861inline
863 typename MeshT::HalfedgeIter he_it, he_end=_mesh->halfedges_end();
864
865 for (he_it = _mesh->halfedges_begin(); he_it != he_end ; ++he_it)
866 if ( _mesh->is_boundary( *he_it))
867 _mesh->status(*he_it).set_selected( true );
868}
869
870//=========================================================
871
872template< typename MeshT >
873inline
874std::vector< int > getHalfedgeSelection(MeshT* _mesh) {
875 std::vector< int > selection;
876
877 for ( typename MeshT::HalfedgeIter he_it= _mesh->halfedges_begin() ; he_it != _mesh->halfedges_end() ; ++he_it )
878 if ( _mesh->status(*he_it).selected() )
879 selection.push_back( he_it->idx() );
880
881 return selection;
882}
883
884template< typename MeshT >
885inline
887
888 for ( typename MeshT::HalfedgeIter he_it= _mesh->halfedges_begin() ; he_it != _mesh->halfedges_end() ; ++he_it ) {
889
890 if(_mesh->status(*he_it).selected()) {
891 _mesh->status(_mesh->to_vertex_handle(*he_it)).set_selected(true);
892 _mesh->status(_mesh->from_vertex_handle(*he_it)).set_selected(true);
893 }
894 }
895}
896
897template< typename MeshT >
898inline
900
901 for ( typename MeshT::HalfedgeIter he_it= _mesh->halfedges_begin() ; he_it != _mesh->halfedges_end() ; ++he_it ) {
902
903 if(_mesh->status(*he_it).selected()) {
904 _mesh->status(_mesh->edge_handle(*he_it)).set_selected(true);
905 }
906 }
907}
908
909template< typename MeshT >
910inline
912 // Note: A face is not only selected
913 // iff all incident halfedges are selected but
914 // at least one of them. This is, however,
915 // desired in some cases.
916 for ( typename MeshT::HalfedgeIter he_it= _mesh->halfedges_begin() ; he_it != _mesh->halfedges_end() ; ++he_it ) {
917
918 if(_mesh->status(*he_it).selected()) {
919 _mesh->status(_mesh->face_handle(*he_it)).set_selected(true);
920 }
921 }
922}
923
924//=========================================================
925//== Face Selection =======================================
926//=========================================================
927
928template< typename MeshT >
929inline
930void selectFaces(MeshT* _mesh, const std::vector< int >& _faces) {
931 const int n_faces = (int)_mesh->n_faces();
932
933 for ( uint i = 0 ; i < _faces.size() ; ++i )
934 if ( (_faces[i] >= 0) && ( _faces[i] < n_faces ) ) {
935 typename MeshT::FaceHandle fh(_faces[i]);
936 _mesh->status(fh).set_selected(true);
937 }
938}
939
940//=========================================================
941
942template< typename MeshT >
943inline
944void unselectFaces(MeshT* _mesh, const std::vector< int >& _faces) {
945 const int n_faces = (int)_mesh->n_faces();
946
947 for ( uint i = 0 ; i < _faces.size() ; ++i )
948 if ( (_faces[i] >= 0) && ( _faces[i] < n_faces ) ) {
949 typename MeshT::FaceHandle fh(_faces[i]);
950 _mesh->status(fh).set_selected(false);
951 }
952}
953
954//=========================================================
955
956template< typename MeshT >
957inline
958void selectAllFaces(MeshT* _mesh) {
959 typename MeshT::FaceIter f_it, f_end=_mesh->faces_end();
960
961 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
962 _mesh->status(*f_it).set_selected(true);
963}
964
965//=========================================================
966
967
968template< typename MeshT >
969inline
971 typename MeshT::FaceIter f_it, f_end=_mesh->faces_end();
972
973 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
974 _mesh->status(*f_it).set_selected(false);
975}
976
977//-----------------------------------------------------------------------------
978
979
980template< typename MeshT >
981inline
983 typename MeshT::FaceIter f_it, f_end=_mesh->faces_end();
984
985 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
986 _mesh->status(*f_it).set_selected( ! _mesh->status(*f_it).selected());
987}
988
989//=========================================================
990
991template< typename MeshT >
992inline
994 typename MeshT::HalfedgeIter he_it, he_end=_mesh->halfedges_end();
995
996 for (he_it = _mesh->halfedges_begin(); he_it != he_end ; ++he_it)
997 if (_mesh->is_boundary(*he_it) ) {
998 for (typename MeshT::VertexFaceIter vf_it(*_mesh ,_mesh->to_vertex_handle(*he_it) ) ; vf_it.is_valid() ; ++vf_it)
999 _mesh->status(*vf_it).set_selected(true);
1000 for (typename MeshT::VertexFaceIter vf_it(*_mesh ,_mesh->from_vertex_handle(*he_it) ) ; vf_it.is_valid() ; ++vf_it)
1001 _mesh->status(*vf_it).set_selected(true);
1002 }
1003}
1004
1005//=========================================================
1006
1007
1008template< typename MeshT >
1009inline
1012
1013 _mesh->add_property( temp_shrink, "Temp property for Face selection shrinking" );
1014
1015 typename MeshT::FaceIter f_it, f_end=_mesh->faces_end();
1016
1017 // initialize property ( copy status to new property )
1018 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
1019 _mesh->property(temp_shrink,*f_it) = _mesh->status(*f_it).selected();
1020
1021 // Shrink selection ( deselects all faces which are adjacent to a boundary vertex of the original selection)
1022 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
1023 if ( _mesh->property(temp_shrink,*f_it) ) {
1024 bool boundary = false;
1025 for ( typename MeshT::FaceVertexIter fv_it(*_mesh,*f_it); fv_it.is_valid() ; ++fv_it) {
1026 for ( typename MeshT::VertexFaceIter vf_it(*_mesh,*fv_it); vf_it.is_valid() ; ++vf_it) {
1027 if ( ! _mesh->property(temp_shrink,*vf_it) ) {
1028 boundary = true;
1029 }
1030 }
1031 if ( boundary )
1032 break;
1033 }
1034
1035 _mesh->status(*f_it).set_selected( !boundary );
1036 }
1037
1038 _mesh->remove_property(temp_shrink);
1039}
1040
1041//=========================================================
1042
1043template< typename MeshT >
1044inline
1047
1048 _mesh->add_property( temp_grow, "Temp property for Face selection growing" );
1049
1050 typename MeshT::FaceIter f_it, f_end=_mesh->faces_end();
1051
1052 // initialize property ( copy status to new property )
1053 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
1054 _mesh->property(temp_grow,*f_it) = _mesh->status(*f_it).selected();
1055
1056 // Grow selection ( selects all faces which are adjacent to a vertex of a already selected face)
1057 for (f_it = _mesh->faces_begin(); f_it != f_end ; ++f_it)
1058 if ( _mesh->property(temp_grow,*f_it) )
1059 for ( typename MeshT::FaceVertexIter fv_it(*_mesh,*f_it); fv_it.is_valid() ; ++fv_it)
1060 for ( typename MeshT::VertexFaceIter vf_it(*_mesh,*fv_it); vf_it.is_valid() ; ++vf_it)
1061 _mesh->status(*vf_it).set_selected( true );
1062
1063 _mesh->remove_property(temp_grow);
1064}
1065
1066//=========================================================
1067
1068template< typename MeshT >
1069inline
1070std::vector< int > getFaceSelection(MeshT* _mesh) {
1071 std::vector< int > selection;
1072
1073 for ( typename MeshT::FaceIter f_it= _mesh->faces_begin() ; f_it != _mesh->faces_end() ; ++f_it )
1074 if ( _mesh->status(*f_it).selected() )
1075 selection.push_back( f_it->idx() );
1076
1077 return selection;
1078}
1079
1080//=========================================================
1081
1082template< typename MeshT >
1083inline
1084std::vector< int > getFaceSelection(MeshT* _mesh, bool& _invert) {
1085 std::vector< int > selection;
1086
1087 int count = 0;
1088
1089 for ( typename MeshT::FaceIter f_it= _mesh->faces_begin() ; f_it != _mesh->faces_end() ; ++f_it )
1090 if ( _mesh->status(*f_it).selected() )
1091 ++count;
1092
1093 if ( count > (int)( _mesh->n_vertices() / 2) )
1094 _invert = true;
1095 else
1096 _invert = false;
1097
1098 for ( typename MeshT::FaceIter f_it= _mesh->faces_begin() ; f_it != _mesh->faces_end() ; ++f_it )
1099 if ( _mesh->status(*f_it).selected() ^ _invert )
1100 selection.push_back( f_it->idx() );
1101
1102 return selection;
1103}
1104
1105template< typename MeshT >
1106inline
1107void convertFaceToVertexSelection(MeshT* _mesh, const std::vector< int >& _faces) {
1108
1109 for (std::vector<int>::const_iterator f = _faces.begin(); f != _faces.end(); ++f) {
1110
1111 typename MeshT::FaceHandle fh(*f);
1112
1113 typename MeshT::FaceVertexIter v_iter = _mesh->fv_iter(fh);
1114
1115 for (; v_iter.is_valid(); ++v_iter) {
1116 _mesh->status(*v_iter).set_selected(true);
1117 }
1118 }
1119}
1120
1121template< typename MeshT >
1122inline
1124
1125 for ( typename MeshT::FaceIter f_it= _mesh->faces_begin() ; f_it != _mesh->faces_end() ; ++f_it )
1126
1127 if ( _mesh->status(*f_it).selected() ){
1128
1129 typename MeshT::FaceVertexIter v_iter = _mesh->fv_iter(*f_it);
1130
1131 for (; v_iter.is_valid(); ++v_iter)
1132 _mesh->status(*v_iter).set_selected(true);
1133 }
1134}
1135
1136template< typename MeshT >
1137inline
1138void convertFaceToEdgeSelection(MeshT* _mesh, const std::vector< int >& _faces) {
1139
1140 for (std::vector<int>::const_iterator f = _faces.begin(); f != _faces.end(); ++f) {
1141
1142 typename MeshT::FaceHandle fh(*f);
1143
1144 typename MeshT::FaceEdgeIter e_iter = _mesh->fe_iter(fh);
1145
1146 for (; e_iter.is_valid(); ++e_iter) {
1147 _mesh->status(*e_iter).set_selected(true);
1148 }
1149 }
1150}
1151
1152template< typename MeshT >
1153inline
1155
1156 for ( typename MeshT::FaceIter f_it= _mesh->faces_begin() ; f_it != _mesh->faces_end() ; ++f_it )
1157
1158 if ( _mesh->status(*f_it).selected() ){
1159
1160 typename MeshT::FaceEdgeIter e_iter = _mesh->fe_iter(*f_it);
1161
1162 for (; e_iter.is_valid(); ++e_iter)
1163 _mesh->status(*e_iter).set_selected(true);
1164 }
1165}
1166
1167template< typename MeshT >
1168inline
1170
1171 for ( typename MeshT::FaceIter f_it= _mesh->faces_begin() ; f_it != _mesh->faces_end() ; ++f_it )
1172
1173 if ( _mesh->status(*f_it).selected() ){
1174
1175 typename MeshT::FaceHalfedgeIter fh_iter = _mesh->fh_iter(*f_it);
1176
1177 for (; fh_iter.is_valid(); ++fh_iter)
1178 _mesh->status(*fh_iter).set_selected(true);
1179 }
1180}
1181
1182template< typename MeshT >
1183inline
1185
1186 for (typename MeshT::FaceIter f_it = _mesh->faces_begin(); f_it != _mesh->faces_end(); ++f_it) {
1187
1188 if (_mesh->status(*f_it).selected()) {
1189
1190 _mesh->status(*f_it).set_feature(true);
1191 } else {
1192 _mesh->status(*f_it).set_feature(false);
1193 }
1194 }
1195}
1196
1197template< typename MeshT >
1198inline
1200
1201 for (typename MeshT::FaceIter f_it = _mesh->faces_begin(); f_it != _mesh->faces_end(); ++f_it) {
1202
1203 if (_mesh->status(*f_it).feature()) {
1204
1205 _mesh->status(*f_it).set_selected(true);
1206 } else {
1207 _mesh->status(*f_it).set_selected(false);
1208 }
1209 }
1210}
1211
1212template< typename MeshT >
1213inline
1215
1216 for (typename MeshT::FaceIter f_it = _mesh->faces_begin(); f_it != _mesh->faces_end(); ++f_it) {
1217
1218 _mesh->status(*f_it).set_feature(false);
1219 }
1220}
1221
1222//=============================================================================
1223} // MeshSelection Namespace
1224//=============================================================================
Functions for selection on a mesh.
void shrinkVertexSelection(MeshT *_mesh)
Shrink vertex selection.
void convertEdgeSelectionToFeatureEdges(MeshT *_mesh)
void invertFaceSelection(MeshT *_mesh)
Invert face selection.
void selectHalfedges(MeshT *_mesh, const std::vector< int > &_halfedges)
Select given halfedges of a mesh.
void invertHalfedgeSelection(MeshT *_mesh)
Invert Edge selection.
void convertFeatureEdgesToEdgeSelection(MeshT *_mesh)
std::vector< int > getFaceSelection(MeshT *_mesh)
std::vector< int > getHalfedgeSelection(MeshT *_mesh)
void selectBoundaryEdges(MeshT *_mesh)
Select all boundary edges of a mesh.
void clearHalfedgeSelection(MeshT *_mesh)
Set all edges to unselected.
void selectAllHalfedges(MeshT *_mesh)
Select all edges of a mesh.
std::vector< int > getArea(MeshT *_mesh, unsigned int _type)
void convertVertexToEdgeSelection(MeshT *_mesh, const std::vector< int > &_vertices)
Select for each vertex in _vertices all incident edges.
void growEdgeSelection(MeshT *_mesh)
Invert Edge selection.
void invertEdgeSelection(MeshT *_mesh)
Invert Edge selection.
void growFaceSelection(MeshT *_mesh)
Grow Face selection.
void clearFaceSelection(MeshT *_mesh)
Set all faces to unselected.
void clearEdgeSelection(MeshT *_mesh)
Set all edges to unselected.
void clearFeatureFaces(MeshT *_mesh)
void convertFeatureFacesToFaceSelection(MeshT *_mesh)
void unselectEdges(MeshT *_mesh, const std::vector< int > &_edges)
Unselect given edges of a mesh.
void invertVertexSelection(MeshT *_mesh)
invert vertex selection
void convertFaceToVertexSelection(MeshT *_mesh, const std::vector< int > &_faces)
void selectVertices(MeshT *_mesh, const std::vector< int > &_vertices)
Select given vertices of a mesh.
void growVertexSelection(MeshT *_mesh)
Grow vertex selection.
void convertHalfedgeToFaceSelection(MeshT *_mesh)
std::vector< int > getVertexSelection(MeshT *_mesh)
Get the current vertex selection.
void selectBoundaryVertices(MeshT *_mesh)
Select all vertices of the mesh which are boundary vertices.
void shrinkFaceSelection(MeshT *_mesh)
Shrink Face selection.
void selectAllFaces(MeshT *_mesh)
Select all faces of a mesh.
void convertFaceToHalfedgeSelection(MeshT *_mesh)
void selectAllEdges(MeshT *_mesh)
Select all edges of a mesh.
void convertFaceSelectionToFeatureFaces(MeshT *_mesh)
void selectBoundaryHalfedges(MeshT *_mesh)
Select all boundary edges of a mesh.
void unselectVertices(MeshT *_mesh, const std::vector< int > &_vertices)
Unselect given vertices of a mesh.
void selectAllVertices(MeshT *_mesh)
Select all vertices of a mesh.
void convertVertexToHalfedgeSelection(MeshT *_mesh, const std::vector< int > &_vertices)
Select for each vertex in _vertices all incident halfedges.
void setArea(MeshT *_mesh, const std::vector< int > &_vertices, unsigned int _type, bool _state)
Set the area bit for all defined vertices.
void clearFeatureVertices(MeshT *_mesh)
Clear all features.
void selectFaces(MeshT *_mesh, const std::vector< int > &_faces)
Select given faces of a mesh.
void convertFaceToEdgeSelection(MeshT *_mesh)
void convertHalfedgeToVertexSelection(MeshT *_mesh)
void unselectFaces(MeshT *_mesh, const std::vector< int > &_faces)
Unselect given faces of a mesh.
void convertEdgeToHalfedgeSelection(MeshT *_mesh)
void selectBoundaryFaces(MeshT *_mesh)
Select all boundary faces of a mesh.
void selectEdges(MeshT *_mesh, const std::vector< int > &_edges, const double _dihedral_angle_threshold=0.0)
Select given edges of a mesh.
std::vector< int > getEdgeSelection(MeshT *_mesh)
void convertEdgeToVertexSelection(MeshT *_mesh, const std::vector< int > &_edges)
void convertVertexSelectionToFeatureVertices(MeshT *_mesh)
Convert vertex selection to feature selection.
void unselectHalfedges(MeshT *_mesh, const std::vector< int > &_halfedges)
Unselect given edges of a mesh.
void clearVertexSelection(MeshT *_mesh)
Set all vertices to unselected.
void convertEdgeToFaceSelection(MeshT *_mesh, const std::vector< int > &_edges)
void convertFeatureVerticesToVertexSelection(MeshT *_mesh)
Convert feature selection to vertex selection.
void convertVertexToFaceSelection(MeshT *_mesh, const std::vector< int > &_vertices)
Select for each vertex in _vertices all adjacent faces.
void clearFeatureEdges(MeshT *_mesh)
void convertHalfedgeToEdgeSelection(MeshT *_mesh)
size_t n_halfedges() const override
Get number of halfedges in mesh.
static HalfEdgeHandle halfedge_handle(EdgeHandle _h, const unsigned char _subIdx)
Conversion function.
static EdgeHandle edge_handle(HalfEdgeHandle _h)
Handle conversion.
size_t n_vertices() const override
Get number of vertices in mesh.
size_t n_faces() const override
Get number of faces in mesh.
size_t n_edges() const override
Get number of edges in mesh.
VertexHandle from_vertex_handle(HalfEdgeHandle _h) const
Get the vertex the halfedge starts from.
VertexHandle to_vertex_handle(HalfEdgeHandle _h) const
Get the vertex the halfedge points to.