ug4
selection_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2015: G-CSC, Goethe University FrankfurtG
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__LIB_GRID__SELECTION_UTIL__
34 #define __H__LIB_GRID__SELECTION_UTIL__
35 
36 #include <stack>
37 #include "lib_grid/lg_base.h"
38 #include "common/ug_config.h"
41 
42 namespace ug
43 {
44 
47 // selection util methods
48 
57 // CalculateCenter
59 
63 template <class TAAPosVRT>
64 bool CalculateCenter(typename TAAPosVRT::ValueType& centerOut,
65  Selector& sel, TAAPosVRT& aaPos);
66 
69 
71 template <class TAAPosVRT>
72 void TranslateSelection(Selector& sel, const typename TAAPosVRT::ValueType& offset,
73  TAAPosVRT& aaPos);
74 
75 
77 // CollectVerticesTouchingSelection
79 
82 UG_API
83 size_t CollectVerticesTouchingSelection(std::vector<Vertex*>& vrtsOut,
84  ISelector& sel);
85 
87 // EraseSelectedObjects
89 
92 template <class TSelector>
93 void EraseSelectedObjects(TSelector& sel);
94 
95 
97 // InvertSelection
99 
102 template <class TSelector, class TIterator>
103 void InvertSelection(TSelector& sel, TIterator begin, TIterator end);
104 
106 // InvertSelection
108 
111 template <class TSelector>
112 void InvertSelection(TSelector& sel);
113 
114 
117 
122 template <class TElem, class TIterator>
123 void
124 SelectAssociated(ISelector& sel, TIterator begin, TIterator end,
126 
128 // SelectAssociatedVertices
130 
145 template <class TSelector, class TElemIterator>
146 void SelectAssociatedVertices(TSelector& sel, TElemIterator elemsBegin,
147  TElemIterator elemsEnd,
149 
151 // SelectAssociatedEdges
153 
165 template <class TSelector, class TElemIterator>
166 void SelectAssociatedEdges(TSelector& sel, TElemIterator elemsBegin,
167  TElemIterator elemsEnd,
169 
171 // SelectAssociatedFaces
173 
185 template <class TSelector, class TElemIterator>
186 void SelectAssociatedFaces(TSelector& sel, TElemIterator elemsBegin,
187  TElemIterator elemsEnd,
189 
191 // SelectAssociatedVolumes
193 
205 template <class TSelector, class TElemIterator>
206 void SelectAssociatedVolumes(TSelector& sel, TElemIterator elemsBegin,
207  TElemIterator elemsEnd,
209 
210 
213 //UG_API
214 //void SelectAssociatedGridObjects(Selector& sel,
215 // ISelector::status_t status = ISelector::SELECTED);
216 
219 template <class TSelector>
220 UG_API
221 void SelectAssociatedGridObjects(TSelector& sel,
223 
224 
227 template <class TSelector>
228 UG_API
229 void CloseSelection (TSelector& sel);
230 
231 
234 
242 template <class TElem, class TSelector>
243 void AssignSelectionStateToSides(TSelector& sel, bool recursive);
244 
247 template <class TElemIterator>
248 void SelectBoundaryElements(ISelector& sel, TElemIterator elemsBegin,
249  TElemIterator elemsEnd);
250 
253 template <class TElemIterator>
254 void SelectInnerElements(ISelector& sel, TElemIterator elemsBegin,
255  TElemIterator elemsEnd);
256 
259 template <class TEdgeIterator>
260 void SelectCreaseEdges(ISelector& sel, TEdgeIterator edgesBegin, TEdgeIterator edgesEnd,
261  number minAngle, APosition aVrtPos,
262  bool ignoreBoundaryEdges = true,
264 
267 
277 template <class TIter>
278 void SelectAreaBoundary(ISelector& sel, const TIter begin, const TIter end);
279 
282 
285 template <class TIter>
286 void SelectInterfaceElements(ISelector& sel, ISubsetHandler& sh,
287  const TIter begin, const TIter end,
288  bool regardSelectedNbrsOnly = false);
289 
292 
294 template <class TElem>
295 void SelectSubsetElements(ISelector& sel, ISubsetHandler& sh, int subsetIndex,
297 
300 
307 template <class TSelector>
308 UG_API
309 void ExtendSelection(TSelector& sel, size_t extSize,
311 
312 
315 
331 template <class TSelector, class TAAPos>
332 UG_API
334  TSelector& sel,
335  size_t extSize,
336  const typename TAAPos::ValueType& dir,
337  number minAngle,
338  number maxAngle,
339  const TAAPos& aaPos,
341 
342 
345 
357 template <class TGeomObj>
358 void SelectionFill(Selector& sel,
359  typename Grid::traits<typename TGeomObj::side>::callback cbRegionBoundary);
360 
363 
381 template <class TGeomObj, class TAAPos>
382 bool SelectRegion(Selector& sel, const typename TAAPos::ValueType& p, TAAPos& aaPos,
383  typename Grid::traits<typename TGeomObj::side>::callback cbRegionBoundary);
384 
386 // SelectAssociatedGenealogy
388 
401 UG_API
402 void SelectAssociatedGenealogy(MGSelector& msel, bool selectAssociatedElements);
403 
406 template <class TAAPos>
408  Selector& sel,
409  TAAPos& aaPos,
410  const vector3& dir,
411  number minDeviationAngle,
412  number maxDeviationAngle,
413  bool selectFlipped);
414 
417 template <class TAAPos>
419  Selector& sel,
420  SubsetHandler& sh,
421  int subsetIndex,
422  TAAPos& aaPos,
423  const vector3& dir,
424  number minDeviationAngle,
425  number maxDeviationAngle,
426  bool selectFlipped);
427 
428 
430 // SelectSmoothEdgePath
432 
445 UG_API
446 void SelectSmoothEdgePath(Selector& sel, number thresholdDegree,
447  number normalWeight,
448  bool stopAtSelVrts = true,
449  APosition& aPos = aPosition);
450 
451 
453 // SelectShortPolychains
455 template <class TAAPos>
456 void SelectShortPolychains(ISelector& sel, number maxLength, bool closedChainsOnly,
457  TAAPos aaPos);
458 
461 // SelectInnerSelectionVertices
463 
469 template <class TSelector>
470 void SelectInnerSelectionVertices(TSelector& sel);
471 
473 // SelectInnerSelectionEdges
475 
481 template <class TSelector>
482 void SelectInnerSelectionEdges(TSelector& sel);
483 
485 // SelectInnerSelectionFaces
487 
493 template <class TSelector>
494 void SelectInnerSelectionFaces(TSelector& sel);
495 
496 
499 // DeselectBoundarySelectionVertices
501 
505 template <class TSelector>
506 void DeselectBoundarySelectionVertices(TSelector& sel);
507 
509 // DeselectBoundarySelectionEdges
511 
515 template <class TSelector>
516 void DeselectBoundarySelectionEdges(TSelector& sel);
517 
519 // DeselectBoundarySelectionFaces
521 
525 template <class TSelector>
526 void DeselectBoundarySelectionFaces(TSelector& sel);
527 
528 
530 // SelectLinkedElements
532 
540 template <class TElem>
541 void SelectLinkedElements(ISelector& sel,
543  cbIsSelectable = ConsiderAll(),
545  cbIsTraversable = ConsiderAll());
546 
547 
549 // SelectLinkedFlatFaces
551 
558 UG_API
559 void SelectLinkedFlatFaces(Selector& sel, number maxDeviationAngle,
560  bool ignoreOrientation = false,
561  bool stopAtSelectedEdges = false,
562  APosition& aPos = aPosition);
563 
565 // SelectLinkedFlatFaces
567 
577 UG_API
578 void SelectLinkedFlatAndDegeneratedFaces(Selector& sel,
579  number maxDeviationAngle,
580  bool ignoreOrientation = false,
581  bool stopAtSelectedEdges = false,
582  number degThreshold = SMALL,
583  APosition& aPos = aPosition);
584 
586 // FaceArea
595 template <class TAAPosVRT>
596 UG_API
597 number FaceArea(ISelector& sel, TAAPosVRT& aaPos);
598 
599 
601 
605 template <class elem_t>
606 void GetSelectedElementIndices (const ISelector& sel, std::vector<int>& indsOut);
607 
608 void GetSelectedElementIndices (const ISelector& sel,
609  std::vector<size_t>& vrtIndsOut,
610  std::vector<size_t>& edgeIndsOut,
611  std::vector<size_t>& faceIndsOut,
612  std::vector<size_t>& volIndsOut);
617 
621 template <class elem_t>
622 void SelectElementsByIndex (ISelector& sel, const std::vector<size_t>& inds);
623 
625  const std::vector<size_t>& vrtInds,
626  const std::vector<size_t>& edgeInds,
627  const std::vector<size_t>& faceInds,
628  const std::vector<size_t>& volInds);
629 
639 void SelectSubset(ISelector& sel,
640  const ISubsetHandler& sh,
641  int si,
642  ISelector::status_t status);
643  // end of doxygen defgroup command
645 }// end of namespace
646 
647 
649 // include implementation
650 #include "selection_util_impl.hpp"
651 
652 #endif
base-implementation of a selector
Definition: selector_interface.h:126
@ SELECTED
Definition: selector_interface.h:132
byte status_t
Definition: selector_interface.h:128
Definition: subset_handler_interface.h:223
static number FaceArea(TDomain &dom, ISubsetHandler &sh, int si, size_t lvl)
Definition: domain_bridge.cpp:262
void DeselectBoundarySelectionVertices(TSelector &sel)
deselects all vertices that are connected to unselected elements.
Definition: selection_util.cpp:885
void SelectCreaseEdges(ISelector &sel, TEdgeIterator edgesBegin, TEdgeIterator edgesEnd, number minAngle, APosition aVrtPos, bool ignoreBoundaryEdges=true, ISelector::status_t state=ISelector::SELECTED)
Selects edges which at which triangles meet in a large angle.
Definition: selection_util_impl.hpp:499
void SelectAssociatedGenealogy(MGSelector &msel, bool selectAssociatedElements)
Selects the complete genealogy of all selected elements.
Definition: selection_util.cpp:422
void SelectLinkedElements(ISelector &sel, typename Grid::traits< TElem >::callback cbIsSelectable=ConsiderAll(), typename Grid::traits< typename TElem::side >::callback cbIsTraversable=ConsiderAll())
Repeatedly traverses sides of selected elements and selects associated elements.
Definition: selection_util_impl.hpp:762
void EraseSelectedObjects(TSelector &sel)
Erases selected objects from the associated grid.
Definition: selection_util.cpp:145
void SelectSubsetEdgesByDirection(Selector &sel, SubsetHandler &sh, int subsetIndex, TAAPos &aaPos, const vector3 &dir, number minDeviationAngle, number maxDeviationAngle, bool selectFlipped)
Selects all subset edges that face a given direction.
Definition: selection_util_impl.hpp:464
void SelectAssociated(ISelector &sel, TIterator begin, TIterator end, ISelector::status_t status=ISelector::SELECTED)
Selects all elements of type TElem, which touch an element between begin and end.
Definition: selection_util_impl.hpp:209
void InvertSelection(TSelector &sel)
Inverts the selection.
Definition: selection_util.cpp:167
void SelectAreaBoundary(ISelector &sel, const TIter begin, const TIter end)
selects sides that are only adjacent to one of the given inner elements
Definition: selection_util_impl.hpp:549
void SelectInnerSelectionVertices(TSelector &sel)
selects all vertices that are only connected to selected elements.
Definition: selection_util.cpp:641
bool SelectRegion(Selector &sel, const typename TAAPos::ValueType &p, TAAPos &aaPos, typename Grid::traits< typename TGeomObj::side >::callback cbRegionBoundary)
Selects the region which contains the given point.
Definition: selection_util_impl.hpp:643
void SelectAssociatedVertices(TSelector &sel, TElemIterator elemsBegin, TElemIterator elemsEnd, ISelector::status_t status=ISelector::SELECTED)
selects all associated vertices of the elements between elemsBegin and elemsEnd
Definition: selection_util_impl.hpp:229
void SelectAssociatedGridObjects(TSelector &sel, ISelector::status_t status)
selects associated geometric objects of selected ones on each level.
Definition: selection_util.cpp:221
void SelectInnerSelectionEdges(TSelector &sel)
selects all edges that are only connected to selected elements.
Definition: selection_util.cpp:748
void SelectElementsByIndex(ISelector &sel, const std::vector< size_t > &inds)
Selects elements with the specified indices.
Definition: selection_util.cpp:1253
void DeselectBoundarySelectionEdges(TSelector &sel)
deselects all edges that are connected to unselected elements.
Definition: selection_util.cpp:948
void DeselectBoundarySelectionFaces(TSelector &sel)
deselects all faces that are connected to unselected elements.
Definition: selection_util.cpp:1003
void AssignSelectionStateToSides(TSelector &sel, bool recursive)
Assigns the selection state of selected elements to associated sides.
Definition: selection_util_impl.hpp:294
void SelectInnerElements(ISelector &sel, TElemIterator elemsBegin, TElemIterator elemsEnd)
selects elements that do not lie on the associated grid's boundary
Definition: selection_util_impl.hpp:341
void SelectInterfaceElements(ISelector &sel, ISubsetHandler &sh, const TIter begin, const TIter end, bool regardSelectedNbrsOnly=false)
Selects elements which are adjacent to higher dimensional elements of different subsets.
Definition: selection_util_impl.hpp:588
void SelectSubset(ISelector &sel, const ISubsetHandler &sh, int si, ISelector::status_t status)
Select all elements specified by a subset index ans selection status.
Definition: selection_util.cpp:1297
void CloseSelection(TSelector &sel)
Selects all associated elements of lower dimensions.
Definition: selection_util.cpp:262
void ExtendSelection(TSelector &sel, size_t extSize, ISelector::status_t status)
extends the selection to neighbours of selected elements.
Definition: selection_util.cpp:294
void SelectLinkedFlatFaces(Selector &sel, number maxDeviationAngle, bool ignoreOrientation, bool stopAtSelectedEdges, APosition &aPos)
Extends the selection of faces to all neighbouring faces that have a similar normal.
Definition: selection_util.cpp:1036
UG_API void ExtendSelectionInDirection(TSelector &sel, size_t extSize, const typename TAAPos::ValueType &dir, number minAngle, number maxAngle, const TAAPos &aaPos, ISelector::status_t status=ISelector::SELECTED)
extends the selection to neighbours of selected elements in the given direction.
Definition: selection_util_impl.hpp:358
void SelectBoundaryElements(ISelector &sel, TElemIterator elemsBegin, TElemIterator elemsEnd)
selects elements that lie on the associated grid's boundary
Definition: selection_util_impl.hpp:326
void SelectAssociatedVolumes(TSelector &sel, TElemIterator elemsBegin, TElemIterator elemsEnd, ISelector::status_t status=ISelector::SELECTED)
selects all associated faces of the elements between elemsBegin and elemsEnd
Definition: selection_util_impl.hpp:286
void SelectAssociatedFaces(TSelector &sel, TElemIterator elemsBegin, TElemIterator elemsEnd, ISelector::status_t status=ISelector::SELECTED)
selects all associated faces of the elements between elemsBegin and elemsEnd
Definition: selection_util_impl.hpp:265
void SelectSubsetElements(ISelector &sel, ISubsetHandler &sh, int subsetIndex, ISelector::status_t status=ISelector::SELECTED)
selects all elements of the given type in the given subset
Definition: selection_util_impl.hpp:629
void SelectInnerSelectionFaces(TSelector &sel)
selects all faces that are only connected to selected elements.
Definition: selection_util.cpp:835
void SelectLinkedFlatAndDegeneratedFaces(Selector &sel, number maxDeviationAngle, bool ignoreOrientation, bool stopAtSelectedEdges, number degThreshold, APosition &aPos)
Extends the selection of faces to all neighbouring faces that have a similar normal.
Definition: selection_util.cpp:1111
void TranslateSelection(Selector &sel, const typename TAAPosVRT::ValueType &offset, TAAPosVRT &aaPos)
moves all vertices touching the selection by the specified offset.
Definition: selection_util_impl.hpp:128
void SelectAssociatedEdges(TSelector &sel, TElemIterator elemsBegin, TElemIterator elemsEnd, ISelector::status_t status=ISelector::SELECTED)
selects all associated edges of the elements between elemsBegin and elemsEnd
Definition: selection_util_impl.hpp:244
size_t CollectVerticesTouchingSelection(std::vector< Vertex * > &vrtsOut, ISelector &sel)
Collects all vertices which are selected or which touch a selected element.
Definition: selection_util.cpp:77
void SelectSmoothEdgePath(Selector &sel, number thresholdDegree, number normalWeight, bool stopAtSelVrts, APosition &aPos)
selects for each selected edge all edges that can be reached by a smooth path.
Definition: selection_util.cpp:457
void SelectShortPolychains(ISelector &sel, number maxLength, bool closedChainsOnly, TAAPos aaPos)
Selects regular polygonal chains which are shorter than a given threshold.
Definition: selection_util_impl.hpp:673
void SelectEdgesByDirection(Selector &sel, TAAPos &aaPos, const vector3 &dir, number minDeviationAngle, number maxDeviationAngle, bool selectFlipped)
Selects all edges that face a given direction.
Definition: selection_util_impl.hpp:431
void SelectionFill(Selector &sel, typename Grid::traits< typename TGeomObj::side >::callback cbRegionBoundary)
Extends the selection around selected objects until selected sides are reached.
Definition: selection_util.cpp:363
#define UG_API
Definition: ug_config.h:65
double number
Definition: types.h:124
void CalculateCenter(vector_t &centerOut, const vector_t *pointSet, size_t numPoints)
calculates the center of a point-set
Definition: math_util_impl.hpp:98
MathVector< 3, number > vector3
a 3d vector
Definition: ugmath_types.h:72
the ug namespace
const number SMALL
Definition: math_constants.h:41
GridSubsetHandler SubsetHandler
Definition: subset_handler_grid.h:376
APosition3 APosition
Definition: common_attachments.h:76
APosition aPosition("position", true)
The standard 3d position type.
Definition: common_attachments.h:84
void GetSelectedElementIndices(const ISelector &sel, std::vector< size_t > &indsOut)
Definition: selection_util.cpp:1213
boost::function< bool(base_object *)> callback
callback type for the elements base type.
Definition: grid.h:150