ug4
selector_interface.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
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__LIBGRID__SELECTOR_INTERFACE__
34 #define __H__LIBGRID__SELECTOR_INTERFACE__
35 
36 #include <cassert>
37 #include "lib_grid/grid/grid.h"
38 
39 #ifdef UG_PARALLEL
42 #endif
43 
44 
45 namespace ug
46 {
51 // SelectorElements
53 
57 {
58  SE_NONE = 0,
59  SE_VERTEX = 1,
60  SE_EDGE = 1<<1,
61  SE_FACE = 1<<2,
62  SE_VOLUME = 1 << 3,
64 };
65 
68 // ISelector
70 
126 {
127  public:
128  typedef byte status_t;
129 
130  enum{
131  DESELECTED = 0,
132  SELECTED = 1
133  };
134 
135  public:
136  ISelector(uint supportedElements = SE_ALL);
137  ISelector(Grid& grid, uint supportedElements = SE_ALL);
138  virtual ~ISelector();
139 
140  // virtual methods
141  virtual void clear() = 0;
142 
143  // selection
145 
153  inline void select(GridObject* elem, byte status);
154  inline void select(GridObject* elem)
155  {select(elem, 1);}
156 
157  template <class TElem>
158  inline void select(TElem* elem, byte status);
159  template <class TElem>
160  inline void select(TElem* elem)
161  {select(elem, 1);}
162 
163  template <class TIterator>
164  inline void select(TIterator iterBegin, TIterator iterEnd, byte status = 1);
168 
171  template <class TElem>
172  inline void mark(TElem* elem)
173  {select(elem);}
174 
175  template <class TElem>
176  inline void mark(TElem* elem, byte status)
177  {select(elem, status);}
181  // deselection
182  inline void deselect(GridObject* elem);
183 
184  template <class TElem>
185  inline void deselect(TElem* elem);
186 
187  template <class TIterator>
188  inline void deselect(TIterator iterBegin, TIterator iterEnd);
189 
191 
192  template <class TElem>
193  inline void unmark(TElem* elem)
194  {deselect(elem);}
195 
196  // selection status
198 
199  inline byte get_selection_status(GridObject* elem) const;
200  inline byte get_selection_status(Vertex* vrt) const {if(!elements_are_supported(SE_VERTEX)) return 0; return m_aaSelVRT[vrt];}
201  inline byte get_selection_status(Edge* edge) const {if(!elements_are_supported(SE_EDGE)) return 0; return m_aaSelEDGE[edge];}
202  inline byte get_selection_status(Face* face) const {if(!elements_are_supported(SE_FACE)) return 0; return m_aaSelFACE[face];}
203  inline byte get_selection_status(Volume* vol) const {if(!elements_are_supported(SE_VOLUME)) return 0; return m_aaSelVOL[vol];}
207 
209  template <class TElem>
210  inline byte get_mark(TElem* elem) const
211  {return get_selection_status(elem);}
212 
214  template <class TElem>
215  inline bool is_selected(TElem* elem) const {return get_selection_status(elem) != 0;}
216 
217  // non-virtual methods.
218  inline Grid* grid() const {return m_pGrid;}
219 
222 
224 
225  inline bool elements_are_supported(uint shElements) const;
226 
227  // if enabled, all new elements will be automatically enabled. Disabled by default.
228  void enable_autoselection(bool bEnable);
229  inline bool autoselection_enabled() {return m_bAutoselectionEnabled;}
230 
231  // if enabled, newly created elements derive their selection status from their parents. Enabled by default.
232  void enable_selection_inheritance(bool bEnable);
233  inline bool selection_inheritance_enabled() {return m_bSelectionInheritanceEnabled;}
234 
240  void enable_strict_inheritance(bool bEnable);
241  inline bool strict_inheritance_enabled() {return m_bStrictInheritanceEnabled;}
242  // grid callbacks
243  /*
244  virtual void registered_at_grid(Grid* grid);
245  virtual void unregistered_from_grid(Grid* grid);
246  */
247  virtual void grid_to_be_destroyed(Grid* grid);
248  virtual void elements_to_be_cleared(Grid* grid);
249 
250  // element callbacks
251  virtual void vertex_created(Grid* grid, Vertex* vrt,
252  GridObject* pParent = NULL,
253  bool replacesParent = false);
254 
255  virtual void edge_created(Grid* grid, Edge* e,
256  GridObject* pParent = NULL,
257  bool replacesParent = false);
258 
259  virtual void face_created(Grid* grid, Face* f,
260  GridObject* pParent = NULL,
261  bool replacesParent = false);
262 
263  virtual void volume_created(Grid* grid, Volume* vol,
264  GridObject* pParent = NULL,
265  bool replacesParent = false);
266 
267  virtual void vertex_to_be_erased(Grid* grid, Vertex* vrt,
268  Vertex* replacedBy = NULL);
269 
270  virtual void edge_to_be_erased(Grid* grid, Edge* e,
271  Edge* replacedBy = NULL);
272 
273  virtual void face_to_be_erased(Grid* grid, Face* f,
274  Face* replacedBy = NULL);
275 
276  virtual void volume_to_be_erased(Grid* grid, Volume* vol,
277  Volume* replacedBy = NULL);
278 
279  virtual void vertices_to_be_merged(Grid* grid, Vertex* target,
280  Vertex* elem1, Vertex* elem2);
281 
282  virtual void edges_to_be_merged(Grid* grid, Edge* target,
283  Edge* elem1, Edge* elem2);
284 
285  virtual void faces_to_be_merged(Grid* grid, Face* target,
286  Face* elem1, Face* elem2);
287 
288  virtual void volumes_to_be_merged(Grid* grid, Volume* target,
289  Volume* elem1, Volume* elem2);
290 
292  virtual bool contains_vertices() const = 0;
293 
295  virtual bool contains_edges() const = 0;
296 
298  virtual bool contains_faces() const = 0;
299 
301  virtual bool contains_volumes() const = 0;
302 
304 
314  virtual void broadcast_selection_states(bool deselect = false,
315  bool includeGhosts = false);
316 
317  protected:
322 
327 
328  protected:
329  virtual void add_to_list(Vertex* elem) = 0;
330  virtual void add_to_list(Edge* elem) = 0;
331  virtual void add_to_list(Face* elem) = 0;
332  virtual void add_to_list(Volume* elem) = 0;
333 
334  virtual void erase_from_list(Vertex* elem) = 0;
335  virtual void erase_from_list(Edge* elem) = 0;
336  virtual void erase_from_list(Face* elem) = 0;
337  virtual void erase_from_list(Volume* elem) = 0;
338 
339  protected:
341 
345  void set_grid(Grid* grid);
346 
348 
350  // Protected non-virtual to avoid virtual calls during construction
351  void set_supported_elements(uint shElements);
352 
354 
355  // Protected non-virtual to avoid virtual calls during construction
356  void enable_element_support(uint shElements);
357 
359 
360  // Protected non-virtual to avoid virtual calls during construction
361  void disable_element_support(uint shElements);
362 
363  inline void mark_selected(Vertex* elem, byte status) {assert(elements_are_supported(SE_VERTEX)); m_aaSelVRT[elem] = status;}
364  inline void mark_selected(Edge* elem, byte status) {assert(elements_are_supported(SE_EDGE)); m_aaSelEDGE[elem] = status;}
365  inline void mark_selected(Face* elem, byte status) {assert(elements_are_supported(SE_FACE)); m_aaSelFACE[elem] = status;}
366  inline void mark_selected(Volume* elem, byte status) {assert(elements_are_supported(SE_VOLUME)); m_aaSelVOL[elem] = status;}
367 
368  inline void mark_deselected(Vertex* elem) {assert(elements_are_supported(SE_VERTEX)); m_aaSelVRT[elem] = 0;}
369  inline void mark_deselected(Edge* elem) {assert(elements_are_supported(SE_EDGE)); m_aaSelEDGE[elem] = 0;}
370  inline void mark_deselected(Face* elem) {assert(elements_are_supported(SE_FACE)); m_aaSelFACE[elem] = 0;}
371  inline void mark_deselected(Volume* elem) {assert(elements_are_supported(SE_VOLUME)); m_aaSelVOL[elem] = 0;}
372 
374  template <class TElem>
375  void elems_to_be_merged(Grid* grid, TElem* target,
376  TElem* elem1, TElem* elem2);
377 
378  private:
379  ISelector(const ISelector& sel){};
380 
381  #ifdef UG_PARALLEL
382  template <class TIntfcCom>
383  void broadcast_selection_states(bool deselect, bool includeGhosts,
384  TIntfcCom& icom);
385  #endif
386 
387  protected:
393 
394  // will use a default constructor
397 
402 
403  #ifdef UG_PARALLEL
408  #endif
409 };
410 
412 
413 }// end of namespace
414 
416 // include implementation
418 
419 #endif
Performs communication between interfaces on different processes.
Definition: pcl_interface_communicator.h:68
A linked list of elements living in an attachment.
Definition: attached_list.h:182
Base-class for edges.
Definition: grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
the generic attachment-accessor for access to grids attachment pipes.
Definition: grid.h:182
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
a helper class that holds a collection of possibly unconnected geometric-objects.
Definition: grid_object_collection.h:96
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
Definition: grid_observer.h:80
base-implementation of a selector
Definition: selector_interface.h:126
pcl::InterfaceCommunicator< VolumeLayout > m_icomVOL
Definition: selector_interface.h:407
virtual GridObjectCollection get_grid_objects() const =0
returns a geometric object collection, containing all selected objects
AUChar m_aSelected
Definition: selector_interface.h:396
void unmark(TElem *elem)
deselects an element
Definition: selector_interface.h:193
bool is_selected(TElem *elem) const
returns true if an element is selected
Definition: selector_interface.h:215
Grid::traits< Face >::SectionContainer FaceSectionContainer
Definition: selector_interface.h:325
Grid::traits< Edge >::AttachedElementList AttachedEdgeList
Definition: selector_interface.h:319
bool m_bStrictInheritanceEnabled
Definition: selector_interface.h:392
void mark_selected(Face *elem, byte status)
Definition: selector_interface.h:365
virtual void add_to_list(Vertex *elem)=0
Grid::traits< Vertex >::AttachedElementList AttachedVertexList
Definition: selector_interface.h:318
pcl::InterfaceCommunicator< EdgeLayout > m_icomEDGE
Definition: selector_interface.h:405
virtual void add_to_list(Face *elem)=0
virtual void erase_from_list(Vertex *elem)=0
bool strict_inheritance_enabled()
Definition: selector_interface.h:241
Grid * grid() const
Definition: selector_interface.h:218
Grid::traits< Edge >::SectionContainer EdgeSectionContainer
Definition: selector_interface.h:324
ISelector(const ISelector &sel)
Definition: selector_interface.h:379
void mark_deselected(Volume *elem)
Definition: selector_interface.h:371
byte get_selection_status(Vertex *vrt) const
returns the selection state of the specified elelent
Definition: selector_interface.h:200
Grid::traits< Face >::AttachedElementList AttachedFaceList
Definition: selector_interface.h:320
byte get_mark(TElem *elem) const
returns the selection state of the specified elelent
Definition: selector_interface.h:210
void select(GridObject *elem)
selects an element
Definition: selector_interface.h:154
virtual bool contains_faces() const =0
returns true if the selector contains faces
Grid::traits< Vertex >::SectionContainer VertexSectionContainer
Definition: selector_interface.h:323
Grid::AttachmentAccessor< Face, AUChar > m_aaSelFACE
Definition: selector_interface.h:400
Attachment< unsigned char > AUChar
Definition: selector_interface.h:395
Grid::AttachmentAccessor< Vertex, AUChar > m_aaSelVRT
Definition: selector_interface.h:398
void select(TElem *elem)
selects an element
Definition: selector_interface.h:160
Grid::traits< Volume >::SectionContainer VolumeSectionContainer
Definition: selector_interface.h:326
virtual bool contains_edges() const =0
returns true if the selector contains edges
void mark(TElem *elem, byte status)
selects an element
Definition: selector_interface.h:176
void mark_deselected(Face *elem)
Definition: selector_interface.h:370
virtual void erase_from_list(Face *elem)=0
pcl::InterfaceCommunicator< FaceLayout > m_icomFACE
Definition: selector_interface.h:406
byte get_selection_status(Volume *vol) const
returns the selection state of the specified elelent
Definition: selector_interface.h:203
virtual void add_to_list(Volume *elem)=0
virtual void erase_from_list(Volume *elem)=0
bool selection_inheritance_enabled()
Definition: selector_interface.h:233
virtual void clear()=0
void mark_deselected(Vertex *elem)
Definition: selector_interface.h:368
void mark_selected(Vertex *elem, byte status)
Definition: selector_interface.h:363
bool autoselection_enabled()
Definition: selector_interface.h:229
void mark_selected(Edge *elem, byte status)
Definition: selector_interface.h:364
virtual void erase_from_list(Edge *elem)=0
byte get_selection_status(Edge *edge) const
returns the selection state of the specified elelent
Definition: selector_interface.h:201
uint m_supportedElements
Definition: selector_interface.h:389
bool m_bAutoselectionEnabled
Definition: selector_interface.h:390
byte get_selection_status(Face *face) const
returns the selection state of the specified elelent
Definition: selector_interface.h:202
virtual bool contains_vertices() const =0
returns true if the selector contains vertices
Grid * m_pGrid
Definition: selector_interface.h:388
Grid::AttachmentAccessor< Volume, AUChar > m_aaSelVOL
Definition: selector_interface.h:401
byte status_t
Definition: selector_interface.h:128
void mark(TElem *elem)
selects an element
Definition: selector_interface.h:172
void mark_deselected(Edge *elem)
Definition: selector_interface.h:369
virtual bool contains_volumes() const =0
returns true if the selector contains volumes
Grid::traits< Volume >::AttachedElementList AttachedVolumeList
Definition: selector_interface.h:321
bool m_bSelectionInheritanceEnabled
Definition: selector_interface.h:391
virtual void add_to_list(Edge *elem)=0
void mark_selected(Volume *elem, byte status)
Definition: selector_interface.h:366
pcl::InterfaceCommunicator< VertexLayout > m_icomVRT
Definition: selector_interface.h:404
Grid::AttachmentAccessor< Edge, AUChar > m_aaSelEDGE
Definition: selector_interface.h:399
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
SelectorElements
Use these constants to specify which elements shall be supported by a Selector.
Definition: selector_interface.h:57
@ SE_VOLUME
Definition: selector_interface.h:62
@ SE_ALL
Definition: selector_interface.h:63
@ SE_VERTEX
Definition: selector_interface.h:59
@ SE_NONE
Definition: selector_interface.h:58
@ SE_FACE
Definition: selector_interface.h:61
@ SE_EDGE
Definition: selector_interface.h:60
#define UG_API
Definition: ug_config.h:65
unsigned int uint
Definition: types.h:114
size_t target(SM_edge< typename T::value_type > const &e, ug::BidirectionalMatrix< T > const &m)
Definition: bidirectional_boost.h:100
the ug namespace