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