OpenWalnut  1.4.0
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 <string>
31 #include <vector>
32 
33 #ifndef Q_MOC_RUN
34 #include <boost/enable_shared_from_this.hpp>
35 #endif
36 
37 #include "../common/WProperties.h"
38 
39 #include "../graphicsEngine/WROI.h"
40 
41 class WROIManager;
42 
43 /**
44  * implements a branch in the tree like structure for rois
45  */
46 class WRMBranch : public boost::enable_shared_from_this< WRMBranch >
47 {
48 public:
49  /**
50  * Convenience type for a shared pointer of this type
51  */
52  typedef boost::shared_ptr< WRMBranch > SPtr;
53 
54  /**
55  * Convenience type for a const shared pointer of this type
56  */
57  typedef boost::shared_ptr< const WRMBranch > ConstSPtr;
58 
59  /**
60  * construtor
61  * \param roiManager
62  */
63  explicit WRMBranch( boost::shared_ptr< WROIManager > roiManager );
64 
65  /**
66  * destructor
67  */
68  ~WRMBranch();
69 
70  /**
71  * Get name property.
72  *
73  * \return name property
74  */
75  WPropString nameProperty();
76 
77  /**
78  * Get the "not" property.
79  *
80  * \return the property
81  */
82  WPropBool invertProperty();
83 
84  /**
85  * The branch color property.
86  *
87  * \return the color property
88  */
89  WPropColor colorProperty();
90 
91  /**
92  * Get the properties of this branch as group.
93  *
94  * \return branch property group
95  */
97 
98  /**
99  * adds a roi to the branch
100  *
101  * \param roi
102  */
103  void addRoi( osg::ref_ptr< WROI > roi );
104 
105  /**
106  * removes a roi from the branch
107  *
108  * \param roi
109  */
110  void removeRoi( osg::ref_ptr< WROI > roi );
111 
112  /**
113  * removes all rois from the branch
114  *
115  */
116  void removeAllRois();
117 
118  /**
119  * getter for dirty flag
120  *
121  * \param reset when true the dirty flag will be set to false
122  * \return the dirty flag
123  */
124  bool dirty( bool reset = false );
125 
126  /**
127  * sets dirty flag true and notifies the branch
128  */
129  void setDirty();
130 
131  /**
132  * returns whether the branch is empty.
133  *
134  * \return true if empty.
135  */
136  bool empty();
137 
138  /**
139  * checks wether a roi is in this branch
140  * \param roi
141  * \return true if the roi is in the branch, false otherwise
142  */
143  bool contains( osg::ref_ptr< WROI > roi );
144 
145  /**
146  * returns a pointer to the first roi in the branch
147  *
148  * \return the roi
149  */
150  osg::ref_ptr< WROI > getFirstRoi();
151 
152  /**
153  * getter for roi manager pointer
154  *
155  * \return the roi manager
156  */
157  boost::shared_ptr< WROIManager > getRoiManager();
158 
159  /**
160  * returns the properties object.
161  *
162  * \return the properties of this branch
163  */
164  boost::shared_ptr< WProperties > getProperties();
165 
166  /**
167  * getter for the NOT flag
168  * \return flag
169  */
170  bool isNot();
171 
172  /**
173  * add all the rois in this branch to a given vector
174  * \param roiVec the vector to fill
175  */
176  void getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ); //NOLINT
177 
178  /**
179  * Create a list of ROIs of the current point in time.
180  *
181  * \return the ROIs
182  */
183  std::vector< osg::ref_ptr< WROI > > getRois() const;
184 
185  /**
186  * Add a specified notifier to the list of default notifiers which get connected to each branch
187  *
188  * \param notifier the notifier function
189  */
190  void addChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier );
191 
192  /**
193  * Remove a specified notifier from the list of default notifiers which get connected to each branch
194  *
195  * \param notifier the notifier function
196  */
197  void removeChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier );
198 
199  /**
200  * Resorts the ROIs using the specified comparator from its begin to its end.
201  *
202  * \tparam Comparator the comparator type. Usually a boost::function or class providing the operator<().
203  *
204  * \param comp the comparator
205  */
206  template < typename Comparator >
207  void sort( Comparator comp );
208 
209 protected:
210  /**
211  * initializes properties
212  */
213  void properties();
214 
215  /**
216  * slot gets called when a property has changed
217  *
218  */
219  void propertyChanged();
220 private:
221  boost::shared_ptr< WROIManager > m_roiManager; //!< stores a pointer to the roi manager
222 
223  std::vector< osg::ref_ptr< WROI > > m_rois; //!< list of rois in this this branch,
224  // first in the list is the master roi
225  /**
226  * the property object for the module
227  */
228  boost::shared_ptr< WProperties > m_properties;
229 
230  WPropBool m_dirty; //!< dirty flag to indicate if anything has changed within the branch
231 
232  /**
233  * indicates if the branch is negated
234  */
235  WPropBool m_isNot;
236 
237  /**
238  * The color used when in isosurface mode for blending.
239  */
240  WPropColor m_bundleColor;
241 
242  /**
243  * Name property.
244  */
245  WPropString m_name;
246 
247  /**
248  * The notifiers connected to added rois by default.
249  */
250  std::list< boost::shared_ptr< boost::function< void() > > > m_changeNotifiers;
251 
252  boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the ROImanager branch
253 
254  /**
255  * Lock for associated notifiers set.
256  */
257  boost::shared_mutex m_associatedNotifiersLock;
258 };
259 
260 inline bool WRMBranch::empty()
261 {
262  return m_rois.empty();
263 }
264 
265 inline bool WRMBranch::dirty( bool reset )
266 {
267  bool ret = m_dirty->get();
268  if( reset )
269  {
270  m_dirty->set( false );
271  }
272  return ret;
273 }
274 
275 inline bool WRMBranch::isNot()
276 {
277  return m_isNot->get();
278 }
279 
280 template < typename Comparator >
281 void WRMBranch::sort( Comparator comp )
282 {
283  // NOTE: technically, we need not setDirty here as the order of the ROIs has no influence
284  return std::sort( m_rois.begin(), m_rois.end(), comp );
285 }
286 
287 #endif // WRMBRANCH_H
std::vector< osg::ref_ptr< WROI > > getRois() const
Create a list of ROIs of the current point in time.
Definition: WRMBranch.cpp:125
WPropBool m_isNot
indicates if the branch is negated
Definition: WRMBranch.h:235
void addChangeNotifier(boost::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
WPropColor m_bundleColor
The color used when in isosurface mode for blending.
Definition: WRMBranch.h:240
boost::shared_ptr< const WRMBranch > ConstSPtr
Convenience type for a const shared pointer of this type.
Definition: WRMBranch.h:57
std::vector< osg::ref_ptr< WROI > > m_rois
list of rois in this this branch,
Definition: WRMBranch.h:223
implements a branch in the tree like structure for rois
Definition: WRMBranch.h:46
osg::ref_ptr< WROI > getFirstRoi()
returns a pointer to the first roi in the branch
Definition: WRMBranch.cpp:157
void setDirty()
sets dirty flag true and notifies the branch
Definition: WRMBranch.cpp:145
void properties()
initializes properties
Definition: WRMBranch.cpp:45
boost::shared_ptr< boost::function< void() > > m_changeRoiSignal
Signal that can be used to update the ROImanager branch.
Definition: WRMBranch.h:252
bool isNot()
getter for the NOT flag
Definition: WRMBranch.h:275
bool contains(osg::ref_ptr< WROI > roi)
checks wether a roi is in this branch
Definition: WRMBranch.cpp:91
~WRMBranch()
destructor
Definition: WRMBranch.cpp:41
void sort(Comparator comp)
Resorts the ROIs using the specified comparator from its begin to its end.
Definition: WRMBranch.h:281
boost::shared_ptr< WRMBranch > SPtr
Convenience type for a shared pointer of this type.
Definition: WRMBranch.h:52
WPropertyGroup::SPtr getProperties() const
Get the properties of this branch as group.
Definition: WRMBranch.cpp:59
boost::shared_mutex m_associatedNotifiersLock
Lock for associated notifiers set.
Definition: WRMBranch.h:257
boost::shared_ptr< WROIManager > getRoiManager()
getter for roi manager pointer
Definition: WRMBranch.cpp:162
Class to store and manage different ROI's for fiber selection.
Definition: WROIManager.h:42
void removeChangeNotifier(boost::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
boost::shared_ptr< WROIManager > m_roiManager
stores a pointer to the roi manager
Definition: WRMBranch.h:221
WPropColor colorProperty()
The branch color property.
Definition: WRMBranch.cpp:79
boost::shared_ptr< WPropertyGroup > SPtr
shared pointer to object of this type
std::list< boost::shared_ptr< boost::function< void() > > > m_changeNotifiers
The notifiers connected to added rois by default.
Definition: WRMBranch.h:250
bool empty()
returns whether the branch is empty.
Definition: WRMBranch.h:260
void propertyChanged()
slot gets called when a property has changed
Definition: WRMBranch.cpp:64
WRMBranch(boost::shared_ptr< WROIManager > roiManager)
construtor
Definition: WRMBranch.cpp:35
void removeRoi(osg::ref_ptr< WROI > roi)
removes a roi from the branch
Definition: WRMBranch.cpp:103
boost::shared_ptr< WProperties > m_properties
the property object for the module
Definition: WRMBranch.h:228
WPropBool m_dirty
dirty flag to indicate if anything has changed within the branch
Definition: WRMBranch.h:230
WPropString m_name
Name property.
Definition: WRMBranch.h:245
WPropString nameProperty()
Get name property.
Definition: WRMBranch.cpp:69
void removeAllRois()
removes all rois from the branch
Definition: WRMBranch.cpp:135
void addRoi(osg::ref_ptr< WROI > roi)
adds a roi to the branch
Definition: WRMBranch.cpp:84
bool dirty(bool reset=false)
getter for dirty flag
Definition: WRMBranch.h:265
WPropBool invertProperty()
Get the "not" property.
Definition: WRMBranch.cpp:74