OpenWalnut  1.5.0dev
WRMBranch.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WRMBRANCH_H
26 #define WRMBRANCH_H
27 
28 #include <algorithm>
29 #include <list>
30 #include <memory>
31 #include <shared_mutex>
32 #include <string>
33 #include <vector>
34 
35 #include "../common/WProperties.h"
36 #include "../graphicsEngine/WROI.h"
37 
38 class WROIManager;
39 
40 /**
41  * implements a branch in the tree like structure for rois
42  */
43 class WRMBranch : public std::enable_shared_from_this< WRMBranch >
44 {
45 public:
46  /**
47  * Convenience type for a shared pointer of this type
48  */
49  typedef std::shared_ptr< WRMBranch > SPtr;
50 
51  /**
52  * Convenience type for a const shared pointer of this type
53  */
54  typedef std::shared_ptr< const WRMBranch > ConstSPtr;
55 
56  /**
57  * construtor
58  * \param roiManager
59  */
60  explicit WRMBranch( std::shared_ptr< WROIManager > roiManager );
61 
62  /**
63  * destructor
64  */
65  ~WRMBranch();
66 
67  /**
68  * Get name property.
69  *
70  * \return name property
71  */
72  WPropString nameProperty();
73 
74  /**
75  * Get the "not" property.
76  *
77  * \return the property
78  */
79  WPropBool invertProperty();
80 
81  /**
82  * The branch color property.
83  *
84  * \return the color property
85  */
86  WPropColor colorProperty();
87 
88  /**
89  * Get the properties of this branch as group.
90  *
91  * \return branch property group
92  */
94 
95  /**
96  * adds a roi to the branch
97  *
98  * \param roi
99  */
100  void addRoi( osg::ref_ptr< WROI > roi );
101 
102  /**
103  * removes a roi from the branch
104  *
105  * \param roi
106  */
107  void removeRoi( osg::ref_ptr< WROI > roi );
108 
109  /**
110  * removes all rois from the branch
111  *
112  */
113  void removeAllRois();
114 
115  /**
116  * getter for dirty flag
117  *
118  * \param reset when true the dirty flag will be set to false
119  * \return the dirty flag
120  */
121  bool dirty( bool reset = false );
122 
123  /**
124  * sets dirty flag true and notifies the branch
125  */
126  void setDirty();
127 
128  /**
129  * returns whether the branch is empty.
130  *
131  * \return true if empty.
132  */
133  bool empty();
134 
135  /**
136  * checks wether a roi is in this branch
137  * \param roi
138  * \return true if the roi is in the branch, false otherwise
139  */
140  bool contains( osg::ref_ptr< WROI > roi );
141 
142  /**
143  * returns a pointer to the first roi in the branch
144  *
145  * \return the roi
146  */
147  osg::ref_ptr< WROI > getFirstRoi();
148 
149  /**
150  * getter for roi manager pointer
151  *
152  * \return the roi manager
153  */
154  std::shared_ptr< WROIManager > getRoiManager();
155 
156  /**
157  * returns the properties object.
158  *
159  * \return the properties of this branch
160  */
161  std::shared_ptr< WProperties > getProperties();
162 
163  /**
164  * getter for the NOT flag
165  * \return flag
166  */
167  bool isNot();
168 
169  /**
170  * add all the rois in this branch to a given vector
171  * \param roiVec the vector to fill
172  */
173  void getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ); //NOLINT
174 
175  /**
176  * Create a list of ROIs of the current point in time.
177  *
178  * \return the ROIs
179  */
180  std::vector< osg::ref_ptr< WROI > > getRois() const;
181 
182  /**
183  * Add a specified notifier to the list of default notifiers which get connected to each branch
184  *
185  * \param notifier the notifier function
186  */
187  void addChangeNotifier( std::shared_ptr< boost::function< void() > > notifier );
188 
189  /**
190  * Remove a specified notifier from the list of default notifiers which get connected to each branch
191  *
192  * \param notifier the notifier function
193  */
194  void removeChangeNotifier( std::shared_ptr< boost::function< void() > > notifier );
195 
196  /**
197  * Resorts the ROIs using the specified comparator from its begin to its end.
198  *
199  * \tparam Comparator the comparator type. Usually a boost::function or class providing the operator<().
200  *
201  * \param comp the comparator
202  */
203  template < typename Comparator >
204  void sort( Comparator comp );
205 
206 protected:
207  /**
208  * initializes properties
209  */
210  void properties();
211 
212  /**
213  * slot gets called when a property has changed
214  *
215  */
216  void propertyChanged();
217 private:
218  std::shared_ptr< WROIManager > m_roiManager; //!< stores a pointer to the roi manager
219 
220  std::vector< osg::ref_ptr< WROI > > m_rois; //!< list of rois in this this branch,
221  // first in the list is the main roi
222  /**
223  * the property object for the module
224  */
225  std::shared_ptr< WProperties > m_properties;
226 
227  WPropBool m_dirty; //!< dirty flag to indicate if anything has changed within the branch
228 
229  /**
230  * indicates if the branch is negated
231  */
232  WPropBool m_isNot;
233 
234  /**
235  * The color used when in isosurface mode for blending.
236  */
237  WPropColor m_bundleColor;
238 
239  /**
240  * Name property.
241  */
242  WPropString m_name;
243 
244  /**
245  * The notifiers connected to added rois by default.
246  */
247  std::list< std::shared_ptr< boost::function< void() > > > m_changeNotifiers;
248 
249  std::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the ROImanager branch
250 
251  /**
252  * Lock for associated notifiers set.
253  */
254  std::shared_mutex m_associatedNotifiersLock;
255 };
256 
257 inline bool WRMBranch::empty()
258 {
259  return m_rois.empty();
260 }
261 
262 inline bool WRMBranch::dirty( bool reset )
263 {
264  bool ret = m_dirty->get();
265  if( reset )
266  {
267  m_dirty->set( false );
268  }
269  return ret;
270 }
271 
272 inline bool WRMBranch::isNot()
273 {
274  return m_isNot->get();
275 }
276 
277 template < typename Comparator >
278 void WRMBranch::sort( Comparator comp )
279 {
280  // NOTE: technically, we need not setDirty here as the order of the ROIs has no influence
281  return std::sort( m_rois.begin(), m_rois.end(), comp );
282 }
283 
284 #endif // WRMBRANCH_H
std::shared_ptr< WPropertyGroup > SPtr
shared pointer to object of this type
implements a branch in the tree like structure for rois
Definition: WRMBranch.h:44
std::list< std::shared_ptr< boost::function< void() > > > m_changeNotifiers
The notifiers connected to added rois by default.
Definition: WRMBranch.h:247
void setDirty()
sets dirty flag true and notifies the branch
Definition: WRMBranch.cpp:145
WRMBranch(std::shared_ptr< WROIManager > roiManager)
construtor
Definition: WRMBranch.cpp:35
~WRMBranch()
destructor
Definition: WRMBranch.cpp:41
void addChangeNotifier(std::shared_ptr< boost::function< void() > > notifier)
Add a specified notifier to the list of default notifiers which get connected to each branch.
Definition: WRMBranch.cpp:172
std::shared_ptr< boost::function< void() > > m_changeRoiSignal
Signal that can be used to update the ROImanager branch.
Definition: WRMBranch.h:249
void removeChangeNotifier(std::shared_ptr< boost::function< void() > > notifier)
Remove a specified notifier from the list of default notifiers which get connected to each branch.
Definition: WRMBranch.cpp:180
std::vector< osg::ref_ptr< WROI > > m_rois
list of rois in this this branch,
Definition: WRMBranch.h:220
WPropertyGroup::SPtr getProperties() const
Get the properties of this branch as group.
Definition: WRMBranch.cpp:59
void addRoi(osg::ref_ptr< WROI > roi)
adds a roi to the branch
Definition: WRMBranch.cpp:84
std::shared_ptr< WProperties > m_properties
the property object for the module
Definition: WRMBranch.h:225
WPropBool invertProperty()
Get the "not" property.
Definition: WRMBranch.cpp:74
osg::ref_ptr< WROI > getFirstRoi()
returns a pointer to the first roi in the branch
Definition: WRMBranch.cpp:157
void removeAllRois()
removes all rois from the branch
Definition: WRMBranch.cpp:135
bool dirty(bool reset=false)
getter for dirty flag
Definition: WRMBranch.h:262
bool isNot()
getter for the NOT flag
Definition: WRMBranch.h:272
std::shared_ptr< WROIManager > m_roiManager
stores a pointer to the roi manager
Definition: WRMBranch.h:218
std::shared_ptr< const WRMBranch > ConstSPtr
Convenience type for a const shared pointer of this type.
Definition: WRMBranch.h:54
std::shared_ptr< WROIManager > getRoiManager()
getter for roi manager pointer
Definition: WRMBranch.cpp:162
WPropBool m_isNot
indicates if the branch is negated
Definition: WRMBranch.h:232
std::shared_mutex m_associatedNotifiersLock
Lock for associated notifiers set.
Definition: WRMBranch.h:254
void sort(Comparator comp)
Resorts the ROIs using the specified comparator from its begin to its end.
Definition: WRMBranch.h:278
std::shared_ptr< WRMBranch > SPtr
Convenience type for a shared pointer of this type.
Definition: WRMBranch.h:49
WPropBool m_dirty
dirty flag to indicate if anything has changed within the branch
Definition: WRMBranch.h:227
WPropString nameProperty()
Get name property.
Definition: WRMBranch.cpp:69
bool contains(osg::ref_ptr< WROI > roi)
checks wether a roi is in this branch
Definition: WRMBranch.cpp:91
WPropString m_name
Name property.
Definition: WRMBranch.h:242
void propertyChanged()
slot gets called when a property has changed
Definition: WRMBranch.cpp:64
WPropColor colorProperty()
The branch color property.
Definition: WRMBranch.cpp:79
WPropColor m_bundleColor
The color used when in isosurface mode for blending.
Definition: WRMBranch.h:237
void properties()
initializes properties
Definition: WRMBranch.cpp:45
std::vector< osg::ref_ptr< WROI > > getRois() const
Create a list of ROIs of the current point in time.
Definition: WRMBranch.cpp:125
void removeRoi(osg::ref_ptr< WROI > roi)
removes a roi from the branch
Definition: WRMBranch.cpp:103
bool empty()
returns whether the branch is empty.
Definition: WRMBranch.h:257
Class to store and manage different ROI's for fiber selection.
Definition: WROIManager.h:39