33 #ifndef __H__LIB_GRID__SELECTION_UTIL_IMPL__
34 #define __H__LIB_GRID__SELECTION_UTIL_IMPL__
50 template <
class TAAPosVRT>
55 throw(
UGError(
"No grid assigned to selector"));
74 VecAdd(centerOut, centerOut, aaPos[*iter]);
83 for(
size_t i = 0; i < (*iter)->num_vertices(); ++i){
86 VecAdd(centerOut, centerOut, aaPos[vrts[i]]);
96 for(
size_t i = 0; i < (*iter)->num_vertices(); ++i){
99 VecAdd(centerOut, centerOut, aaPos[vrts[i]]);
109 for(
size_t i = 0; i < (*iter)->num_vertices(); ++i){
112 VecAdd(centerOut, centerOut, aaPos[vrts[i]]);
127 template <
class TAAPosVRT>
132 throw(
UGError(
"No grid assigned to selector"));
145 VecAdd(aaPos[*iter], aaPos[*iter], offset);
153 for(
size_t i = 0; i < (*iter)->num_vertices(); ++i){
156 VecAdd(aaPos[vrts[i]], aaPos[vrts[i]], offset);
165 for(
size_t i = 0; i < (*iter)->num_vertices(); ++i){
168 VecAdd(aaPos[vrts[i]], aaPos[vrts[i]], offset);
177 for(
size_t i = 0; i < (*iter)->num_vertices(); ++i){
180 VecAdd(aaPos[vrts[i]], aaPos[vrts[i]], offset);
190 template <
class TSelector,
class TIterator>
193 for(TIterator iter = begin; iter != end;){
199 if(sel.is_selected(v))
207 template <
class TElem,
class TIterator>
217 std::vector<TElem*> elems;
218 for(TIterator iter = begin; iter != end; ++iter){
220 for(
size_t i = 0; i < elems.size(); ++i){
221 sel.
select(elems[i], status);
228 template <
class TSelector,
class TElemIterator>
232 while(elemsBegin != elemsEnd)
234 uint numVrts = (*elemsBegin)->num_vertices();
235 for(
uint i = 0; i < numVrts; ++i)
236 sel.select((*elemsBegin)->vertex(i), status);
243 template <
class TSelector,
class TElemIterator>
247 Grid* pGrid = sel.grid();
251 std::vector<Edge*> vEdges;
252 while(elemsBegin != elemsEnd)
255 for(
uint i = 0; i < vEdges.size(); ++i)
256 sel.select(vEdges[i], status);
264 template <
class TSelector,
class TElemIterator>
268 Grid* pGrid = sel.grid();
272 std::vector<Face*> vFaces;
273 while(elemsBegin != elemsEnd)
276 for(
uint i = 0; i < vFaces.size(); ++i)
277 sel.select(vFaces[i], status);
285 template <
class TSelector,
class TElemIterator>
289 SelectAssociated<Volume>(sel, elemsBegin, elemsEnd, status);
293 template <
class TElem,
class TSelector>
296 typedef typename TSelector::template traits<TElem>::level_iterator TIter;
297 typedef typename TElem::side TSide;
299 UG_ASSERT(sel.grid(),
"A selector has to operate on a grid");
301 Grid& g = *sel.grid();
304 for(
size_t lvl = 0; lvl < sel.num_levels(); ++lvl){
305 for(TIter iter = sel.template begin<TElem>(lvl);
306 iter != sel.template end<TElem>(lvl); ++iter)
312 for(
size_t i = 0; i < sides.
size(); ++i){
314 sel.select(sides[i], elemStatus | sideStatus);
319 if(recursive && TSide::HAS_SIDES){
320 AssignSelectionStateToSides<TSide>(sel, recursive);
325 template <
class TElemIterator>
327 TElemIterator elemsEnd)
329 UG_ASSERT(sel.
grid(),
"A grid has to be associated with the selector");
332 for(TElemIterator iter = elemsBegin; iter != elemsEnd; ++iter){
340 template <
class TElemIterator>
342 TElemIterator elemsEnd)
344 UG_ASSERT(sel.
grid(),
"A grid has to be associated with the selector");
347 for(TElemIterator iter = elemsBegin; iter != elemsEnd; ++iter){
357 template <
class TSelector,
class TAAPos>
361 const typename TAAPos::ValueType& dir,
368 UG_LOG(
"ERROR in ExtendSelection: Selector has to be assigned to a grid.\n");
372 Grid& grid = *sel.grid();
382 for(
size_t extIters = 0; extIters < extSize; ++extIters)
391 for(
size_t lvl = 0; lvl < sel.num_levels(); ++lvl){
393 iter != sel.template end<Vertex>(lvl); ++iter)
405 sel.select(*asIter, status);
412 sel.select(*asIter, status);
419 sel.select(*asIter, status);
430 template <
class TAAPos>
451 VecSubtract(dir, aaPos[e->vertex(1)], aaPos[e->vertex(0)]);
454 if((d >= minDot -
SMALL && d <= maxDot +
SMALL) ||
455 (selectFlipped && (-d >= minDot -
SMALL && -d <= maxDot +
SMALL)))
463 template <
class TAAPos>
485 VecSubtract(dir, aaPos[e->vertex(1)], aaPos[e->vertex(0)]);
488 if((d >= minDot -
SMALL && d <= maxDot +
SMALL) ||
489 (selectFlipped && (-d >= minDot -
SMALL && -d <= maxDot +
SMALL)))
498 template <
class TEdgeIterator>
521 number minDot = cos(minAngle * 3.14159265 / 180.f);
524 for(TEdgeIterator iter = edgesBegin; iter != edgesEnd; ++iter)
536 if(
VecDot(n[0], n[1]) < minDot)
548 template <
class TIter>
552 typedef typename TElem::side TSide;
561 std::vector<TSide*> sides;
567 for(
size_t i = 0; i < sides.size(); ++i){
568 TSide* side = sides[i];
587 template <
class TIter>
589 const TIter begin,
const TIter end,
590 bool regardSelectedNbrsOnly)
593 typedef typename TElem::sideof TNbr;
595 if(!TElem::CAN_BE_SIDE)
603 std::vector<TNbr*> nbrs;
605 for(TIter iter = begin; iter != end;){
612 for(
size_t i = 0; i < nbrs.size(); ++i){
613 if(!regardSelectedNbrsOnly || sel.
is_selected(nbrs[i])){
628 template <
class TElem>
635 for(
size_t lvl = 0; lvl < goc.
num_levels(); ++lvl){
636 for(TIter iter = goc.
begin<TElem>(lvl); iter != goc.
end<TElem>(lvl); ++iter)
637 sel.
select(*iter, status);
642 template <
class TGeomObj,
class TAAPos>
654 TGeomObj* startElem = NULL;
655 for(TIter iter = g.
begin<TGeomObj>(); iter != g.
end<TGeomObj>(); ++iter){
665 sel.
clear<TGeomObj>();
667 SelectionFill<TGeomObj>(sel, cbRegionBoundary);
672 template <
class TAAPos>
683 std::vector<Edge*> curChain;
684 std::queue<Edge*> nextEdges;
687 std::vector<Vertex*> junctionPoints;
695 bool curChainIsClosed =
true;
696 number curChainLength = 0;
699 junctionPoints.clear();
701 nextEdges.push(*eiter);
704 while(!nextEdges.empty()){
705 Edge* e = nextEdges.front();
709 if(curChainLength <= maxLength)
710 curChain.push_back(e);
712 for(
size_t ivrt = 0; ivrt < 2; ++ivrt){
716 curChainIsClosed =
false;
717 else if(edges.
size() == 2){
718 for(
size_t iedge = 0; iedge < 2; ++iedge){
719 Edge* nextEdge = edges[iedge];
722 nextEdges.push(nextEdge);
727 junctionPoints.push_back(vrt);
732 if((curChainLength <= maxLength)){
733 if(closedChainsOnly && curChainIsClosed && !junctionPoints.empty()){
737 for(
size_t ivrt = 0; ivrt < junctionPoints.size(); ++ivrt){
738 Vertex* vrt = junctionPoints[ivrt];
739 size_t numConnectedEdges = 0;
740 for(
size_t iedge = 0; iedge < curChain.size(); ++iedge){
745 if(numConnectedEdges != 2){
746 curChainIsClosed =
false;
753 if(curChainIsClosed || !closedChainsOnly)
754 sel.
select(curChain.begin(), curChain.end());
761 template <
class TElem>
768 typedef typename TElem::side Side;
774 queue<TElem*> qElems;
779 for(ElemIter iter = goc.
begin<TElem>(i); iter != goc.
end<TElem>(i); ++iter)
786 while(!qElems.empty()){
787 TElem* e = qElems.front();
792 for(
size_t i_side = 0; i_side < sides.
size(); ++i_side){
793 Side* side = sides[i_side];
796 if(!cbIsTraversable(side))
804 for(
size_t i_nbr = 0; i_nbr < nbrs.
size(); ++i_nbr){
805 TElem* nbr = nbrs[i_nbr];
808 if(!cbIsSelectable(nbr))
819 template <
class TAAPosVRT>
826 UG_WARNING(
"A grid has to be associated with the selector!");
A generic specialization of IAttachment.
Definition: attachment_pipe.h:263
Base-class for edges.
Definition: grid_base_objects.h:397
virtual Vertex * vertex(size_t index) const
Definition: grid_base_objects.h:366
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
EdgeContainer::iterator AssociatedEdgeIterator
used to iterate over associated edges of vertices, faces and volumes
Definition: grid.h:249
void end_marking()
ends a marking sequence. Call this method when you're done with marking.
Definition: grid.cpp:1285
AssociatedFaceIterator associated_faces_begin(Vertex *vrt)
DO NOT INVOKE! Subject to change.
Definition: grid.cpp:944
AssociatedEdgeIterator associated_edges_begin(Vertex *vrt)
DO NOT INVOKE! Subject to change.
Definition: grid.cpp:882
bool is_marked(GridObject *obj) const
returns true if the object is marked, false if not.
Definition: grid_impl.hpp:843
AssociatedEdgeIterator associated_edges_end(Vertex *vrt)
DO NOT INVOKE! Subject to change.
Definition: grid.cpp:892
VolumeContainer::iterator AssociatedVolumeIterator
used to iterate over associated volumes of vertices, edges and faces
Definition: grid.h:253
void mark(GridObject *obj)
marks the object. Calls are only valid between calls to Grid::begin_marking and Grid::end_marking.
Definition: grid_impl.hpp:773
AssociatedVolumeIterator associated_volumes_begin(Vertex *vrt)
DO NOT INVOKE! Subject to change.
Definition: grid.cpp:1006
void begin_marking()
begin marking.
Definition: grid.cpp:1262
AssociatedFaceIterator associated_faces_end(Vertex *vrt)
DO NOT INVOKE! Subject to change.
Definition: grid.cpp:954
geometry_traits< TGeomObj >::iterator begin()
Definition: grid_impl.hpp:164
bool has_vertex_attachment(IAttachment &attachment)
Definition: grid.h:798
void associated_elements(traits< Vertex >::secure_container &elemsOut, TElem *e)
Puts all elements of type TAss which are contained in 'e' or which contain 'e' into elemsOut.
Definition: grid_impl.hpp:466
AssociatedVolumeIterator associated_volumes_end(Vertex *vrt)
DO NOT INVOKE! Subject to change.
Definition: grid.cpp:1016
FaceContainer::iterator AssociatedFaceIterator
used to iterate over associated faces of vertices, edges and volumes
Definition: grid.h:251
geometry_traits< TGeomObj >::iterator end()
Definition: grid_impl.hpp:175
a helper class that holds a collection of possibly unconnected geometric-objects.
Definition: grid_object_collection.h:96
geometry_traits< TGeomObj >::iterator begin(size_t level=0)
Definition: grid_object_collection_impl.hpp:95
geometry_traits< TGeomObj >::iterator end(size_t level=0)
Definition: grid_object_collection_impl.hpp:106
size_t num_levels() const
returns the number of levels
Definition: grid_object_collection.h:128
Partitions elements of a grid into several subsets.
Definition: subset_handler_grid.h:53
base-implementation of a selector
Definition: selector_interface.h:126
virtual GridObjectCollection get_grid_objects() const =0
returns a geometric object collection, containing all selected objects
bool is_selected(TElem *elem) const
returns true if an element is selected
Definition: selector_interface.h:215
Grid * grid() const
Definition: selector_interface.h:218
void select(GridObject *elem, byte status)
selects an element
Definition: selector_interface_impl.hpp:56
void deselect(GridObject *elem)
Definition: selector_interface_impl.hpp:96
byte status_t
Definition: selector_interface.h:128
Definition: subset_handler_interface.h:223
int get_subset_index(GridObject *elem) const
Definition: subset_handler_interface.cpp:560
virtual GridObjectCollection get_grid_objects_in_subset(int subsetInd) const =0
Returns the geometric object collection for the given subset.
Vertex *const * ConstVertexArray
Definition: grid_base_objects.h:319
Container which holds an array of pointers.
Definition: pointer_const_array.h:84
size_t size() const
returns the size of the associated array.
Definition: pointer_const_array_impl.hpp:106
specialization of ISelector for a grid of class Grid.
Definition: selector_grid.h:96
VertexIterator vertices_end()
Definition: selector_grid.h:173
virtual void clear()
Definition: selector_grid.cpp:155
VolumeIterator volumes_end()
Definition: selector_grid.h:179
VolumeIterator volumes_begin()
Definition: selector_grid.h:178
VertexIterator vertices_begin()
Definition: selector_grid.h:172
EdgeIterator edges_end()
Definition: selector_grid.h:175
EdgeIterator edges_begin()
Definition: selector_grid.h:174
FaceIterator faces_end()
Definition: selector_grid.h:177
FaceIterator faces_begin()
Definition: selector_grid.h:176
Instances of this class or of derived classes are thrown if errors arise.
Definition: error.h:104
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
static number FaceArea(TDomain &dom, ISubsetHandler &sh, int si, size_t lvl)
Definition: domain_bridge.cpp:262
bool EdgeContains(EdgeVertices *e, Vertex *vrt)
Definition: grid_util_impl.hpp:45
bool LiesOnBoundary(Grid &grid, Edge *e)
returns true, if the edge lies on a 2d or 3d boundary
Definition: edge_util.cpp:169
int CalculateNormal(vector3 &vNormOut, Grid &grid, Edge *e, Grid::AttachmentAccessor< Vertex, APosition > &aaPos, Grid::AttachmentAccessor< Face, ANormal > *paaNormFACE)
Calculates the normal of the given edge.
Definition: edge_util.cpp:314
bool IsBoundaryEdge2D(Grid &grid, Edge *e)
returns whether an edge lies on the boundary of a 2D grid.
Definition: edge_util.cpp:112
int GetAssociatedFaces(Face **facesOut, Grid &grid, Edge *e, int maxNumFaces)
writes associated faces of e to facesOut.
Definition: edge_util.cpp:186
UG_API number EdgeLength(const EdgeVertices *e, TAAPosVRT &aaPos)
Calculates the length of the given edge.
Definition: edge_util_impl.hpp:80
UG_API bool ContainsPoint(const EdgeVertices *e, const vector_t &p, TAAPos aaPos)
Returns true if the given point lies on the given edge.
Definition: edge_util_impl.hpp:513
bool CheckDirection(TElem1 *e1, TElem2 *e2, const TAAPos &aaPos, const typename TAAPos::ValueType &dir, number minAngle, number maxAngle)
Checks whether the center of e2 can be reached from the center of e1 in the given direction.
Definition: misc_util_impl.hpp:338
void CollectEdges(std::vector< Edge * > &vEdgesOut, Grid &grid, Vertex *vrt, bool clearContainer)
Collects all edges which exist in the given grid and which are part of the given vertex.
Definition: grid_util.cpp:295
void CollectFaces(std::vector< Face * > &vFacesOut, Grid &grid, Vertex *vrt, bool clearContainer)
Collects all faces that exist in the given grid which contain the given vertex.
Definition: grid_util.cpp:458
UG_API void CollectAssociated(std::vector< Vertex * > &vVertexOut, Grid &grid, GridObject *obj, bool clearContainer=true)
Definition: grid_util_impl.hpp:169
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 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 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
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 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
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 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
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
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_API
Definition: ug_config.h:65
#define UG_LOG(msg)
Definition: log.h:367
unsigned int uint
Definition: types.h:114
#define UG_WARNING(msg)
Definition: log.h:328
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
double number
Definition: types.h:124
void CalculateCenter(vector_t ¢erOut, const vector_t *pointSet, size_t numPoints)
calculates the center of a point-set
Definition: math_util_impl.hpp:98
TNumber deg_to_rad(TNumber deg)
Definition: math_util_impl.hpp:49
void VecSet(vector_t &vInOut, typename vector_t::value_type s)
Set each vector component to scalar (componentwise)
Definition: math_vector_functions_common_impl.hpp:539
void VecNormalize(vector_t &vOut, const vector_t &v)
scales a vector_t to unit length
Definition: math_vector_functions_common_impl.hpp:501
void VecSubtract(vector_t &vOut, const vector_t &v1, const vector_t &v2)
subtracts v2 from v1 and stores the result in a vOut
Definition: math_vector_functions_common_impl.hpp:226
void VecAdd(vector_t &vOut, const vector_t &v1, const vector_t &v2)
adds two MathVector<N>s and stores the result in a third one
Definition: math_vector_functions_common_impl.hpp:185
void VecScale(vector_t &vOut, const vector_t &v, typename vector_t::value_type s)
scales a MathVector<N>
Definition: math_vector_functions_common_impl.hpp:252
vector_t::value_type VecDot(const vector_t &v1, const vector_t &v2)
returns the dot-product of two vector_ts
Definition: math_vector_functions_common_impl.hpp:385
#define lg_for_each_in_subset(_feType, _feVar, _feCon, _feSubset)
Definition: lg_for_each.h:64
#define lg_for_each(_feType, _feVar, _feCon)
Definition: lg_for_each.h:38
#define lg_end_for
Definition: lg_for_each.h:88
Definition: smart_pointer.h:814
ElementStorage< Vertex >::SectionContainer::iterator VertexIterator
This Iterator will be used as base-class for iterators of specialized geometric objects.
Definition: grid_base_object_traits.h:73
ElementStorage< Face >::SectionContainer::iterator FaceIterator
Definition: grid_base_object_traits.h:79
const number SMALL
Definition: math_constants.h:41
ElementStorage< Edge >::SectionContainer::iterator EdgeIterator
Definition: grid_base_object_traits.h:76
ElementStorage< Volume >::SectionContainer::iterator VolumeIterator
Definition: grid_base_object_traits.h:82
T value_type
Definition: sparsematrix_interface.h:2
boost::function< bool(base_object *)> callback
callback type for the elements base type.
Definition: grid.h:150
geometry_traits< TElem >::const_iterator const_iterator
Definition: grid.h:144
geometry_traits< TElem >::iterator iterator
Definition: grid.h:143
geometry_traits< TElem >::iterator iterator
Definition: grid_object_collection.h:101
Definition: metaprogramming_util.h:48