OpenWalnut  1.4.0
WROIManager.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 WROIMANAGER_H
26 #define WROIMANAGER_H
27 
28 #include <list>
29 #include <vector>
30 
31 #ifndef Q_MOC_RUN
32 #include <boost/enable_shared_from_this.hpp>
33 #endif
34 
35 #include "WRMBranch.h"
36 
37 
38 
39 /**
40  * Class to store and manage different ROI's for fiber selection
41  */
42 class WROIManager: public boost::enable_shared_from_this< WROIManager >
43 {
44 public:
45  /**
46  * standard constructor
47  */
48  WROIManager();
49 
50  /**
51  * destructor
52  */
53  ~WROIManager();
54 
55  /**
56  * Add a new branch.
57  *
58  * \return the new branch.
59  */
60  boost::shared_ptr< WRMBranch > addBranch();
61 
62  /**
63  * adds a new master ROI
64  *
65  * \param newRoi
66  * \return ROI representation which can be used to remove the ROI
67  */
68  void addRoi( osg::ref_ptr< WROI > newRoi );
69 
70  /**
71  * adds a new ROI below a master ROI
72  *
73  * \param newRoi
74  * \param parentRoi
75  * \return ROI representation which can be used to remove the ROI
76  */
77  void addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi );
78 
79  /**
80  * Add a ROI to a branch.
81  *
82  * \param newRoi the new ROI to add
83  * \param toBranch the branch to add the ROI to.
84  */
85  void addRoi( osg::ref_ptr< WROI > newRoi, boost::shared_ptr< WRMBranch > toBranch );
86 
87  /**
88  * removes a roi
89  *
90  * \param roi
91  */
92  void removeRoi( osg::ref_ptr< WROI > roi );
93 
94  /**
95  * removes a branch
96  *
97  * \param roi the first roi in the branch
98  */
99  void removeBranch( osg::ref_ptr< WROI > roi );
100 
101  /**
102  * getter
103  * returns the branch item the roi is in
104  * \param roi
105  * \return branch
106  */
107  boost::shared_ptr< WRMBranch> getBranch( osg::ref_ptr< WROI > roi );
108 
109  /**
110  * sets the dirty flag which will cause recalculation of the bit field
111  */
112  void setDirty();
113 
114  /**
115  * getter
116  * \param reset if true the dirty flag will be set to false
117  * \return the dirty flag
118  */
119  bool dirty( bool reset = false );
120 
121  /**
122  * Add a specified notifier to the list of default notifiers which get connected to each added roi.
123  *
124  * \param notifier the notifier function
125  */
126  void addAddNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier );
127 
128  /**
129  * Remove a specified notifier from the list of default notifiers which get connected to each added roi.
130  *
131  * \param notifier the notifier function
132  */
133  void removeAddNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier );
134 
135 
136  /**
137  * Add a specified notifier to the list of default notifiers which get connected to each removed roi.
138  *
139  * \param notifier the notifier function
140  */
141  void addRemoveNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier );
142 
143  /**
144  * Remove a specified notifier from the list of default notifiers which get connected to each removed roi.
145  *
146  * \param notifier the notifier function
147  */
148  void removeRemoveNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier );
149 
150  /**
151  * Add a specified notifier to the list of default notifiers which get connected to each removed branch.
152  *
153  * \param notifier the notifier function
154  */
155  void addRemoveBranchNotifier( boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > notifier );
156 
157  /**
158  * Remove a specified notifier from the list of default notifiers which get connected to each removed branch.
159  *
160  * \param notifier the notifier function
161  */
162  void removeRemoveBranchNotifier( boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > notifier );
163 
164  /**
165  * setter
166  * \param roi
167  */
168  void setSelectedRoi( osg::ref_ptr< WROI > roi );
169 
170  /**
171  * getter
172  *
173  * \return Pointer to the currently (in the ROI manager) selected ROI
174  */
175  osg::ref_ptr< WROI > getSelectedRoi();
176 
177  /**
178  * getter for the properties object
179  * \return the properties object
180  */
181  boost::shared_ptr< WProperties > getProperties();
182 
183  /**
184  * ROI list
185  */
186  typedef std::vector< osg::ref_ptr< WROI > > ROIs;
187 
188  /**
189  * getter
190  * \return all existing rois
191  */
192  ROIs getRois() const;
193 
194  /**
195  * Branches list
196  */
197  typedef std::vector< boost::shared_ptr< WRMBranch > > Branches;
198 
199  /**
200  * Get a copy of the current branch list. Please note that after getting the list, it might already have been changed by another thread.
201  *
202  * \return the list of current branches
203  */
204  Branches getBranches() const;
205 
206 protected:
207 private:
208  size_t m_size; //!< number of fibers in the dataset
209 
210  std::list< boost::shared_ptr< WRMBranch > > m_branches; //!< list of branches in the logical tree structure
211 
212  /**
213  * Lock for associated notifiers set.
214  */
215  boost::shared_mutex m_associatedNotifiersLock;
216 
217  /**
218  * The notifiers connected to added rois by default.
219  */
220  std::list< boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > > m_addNotifiers;
221 
222  /**
223  * The notifiers connected to removed rois by default.
224  */
225  std::list< boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > > m_removeNotifiers;
226 
227  /**
228  * The notifiers connected to removed rois by default.
229  */
230  std::list< boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > > m_removeBranchNotifiers;
231 
232 
233  osg::ref_ptr< WROI > m_selectedRoi; //!< stores a pointer to the currently selected roi
234 
235  /**
236  * The property object for the module.
237  */
238  boost::shared_ptr< WProperties > m_properties;
239 
240  /**
241  * dirty flag
242  */
243  WPropBool m_dirty;
244 };
245 
246 inline bool WROIManager::dirty( bool reset )
247 {
248  bool ret = m_dirty->get();
249  if( reset )
250  {
251  m_dirty->set( false );
252  }
253  return ret;
254 }
255 
256 inline boost::shared_ptr< WProperties > WROIManager::getProperties()
257 {
258  return m_properties;
259 }
260 
261 #endif // WROIMANAGER_H
void removeRemoveNotifier(boost::shared_ptr< boost::function< void(osg::ref_ptr< WROI >) > > notifier)
Remove a specified notifier from the list of default notifiers which get connected to each removed ro...
void addAddNotifier(boost::shared_ptr< boost::function< void(osg::ref_ptr< WROI >) > > notifier)
Add a specified notifier to the list of default notifiers which get connected to each added roi...
void addRemoveNotifier(boost::shared_ptr< boost::function< void(osg::ref_ptr< WROI >) > > notifier)
Add a specified notifier to the list of default notifiers which get connected to each removed roi...
std::list< boost::shared_ptr< boost::function< void(osg::ref_ptr< WROI >) > > > m_addNotifiers
The notifiers connected to added rois by default.
Definition: WROIManager.h:220
boost::shared_ptr< WProperties > m_properties
The property object for the module.
Definition: WROIManager.h:238
void removeRoi(osg::ref_ptr< WROI > roi)
removes a roi
Definition: WROIManager.cpp:93
void removeAddNotifier(boost::shared_ptr< boost::function< void(osg::ref_ptr< WROI >) > > notifier)
Remove a specified notifier from the list of default notifiers which get connected to each added roi...
osg::ref_ptr< WROI > getSelectedRoi()
getter
Branches getBranches() const
Get a copy of the current branch list.
void addRoi(osg::ref_ptr< WROI > newRoi)
adds a new master ROI
Definition: WROIManager.cpp:56
WPropBool m_dirty
dirty flag
Definition: WROIManager.h:243
void setDirty()
sets the dirty flag which will cause recalculation of the bit field
boost::shared_ptr< WRMBranch > getBranch(osg::ref_ptr< WROI > roi)
getter returns the branch item the roi is in
ROIs getRois() const
getter
osg::ref_ptr< WROI > m_selectedRoi
stores a pointer to the currently selected roi
Definition: WROIManager.h:233
~WROIManager()
destructor
Definition: WROIManager.cpp:40
void removeBranch(osg::ref_ptr< WROI > roi)
removes a branch
boost::shared_ptr< WProperties > getProperties()
getter for the properties object
Definition: WROIManager.h:256
std::list< boost::shared_ptr< WRMBranch > > m_branches
list of branches in the logical tree structure
Definition: WROIManager.h:210
void addRemoveBranchNotifier(boost::shared_ptr< boost::function< void(boost::shared_ptr< WRMBranch >) > > notifier)
Add a specified notifier to the list of default notifiers which get connected to each removed branch...
WROIManager()
standard constructor
Definition: WROIManager.cpp:34
Class to store and manage different ROI's for fiber selection.
Definition: WROIManager.h:42
std::vector< osg::ref_ptr< WROI > > ROIs
ROI list.
Definition: WROIManager.h:186
std::vector< boost::shared_ptr< WRMBranch > > Branches
Branches list.
Definition: WROIManager.h:197
size_t m_size
number of fibers in the dataset
Definition: WROIManager.h:208
boost::shared_mutex m_associatedNotifiersLock
Lock for associated notifiers set.
Definition: WROIManager.h:215
std::list< boost::shared_ptr< boost::function< void(osg::ref_ptr< WROI >) > > > m_removeNotifiers
The notifiers connected to removed rois by default.
Definition: WROIManager.h:225
bool dirty(bool reset=false)
getter
Definition: WROIManager.h:246
std::list< boost::shared_ptr< boost::function< void(boost::shared_ptr< WRMBranch >) > > > m_removeBranchNotifiers
The notifiers connected to removed rois by default.
Definition: WROIManager.h:230
void setSelectedRoi(osg::ref_ptr< WROI > roi)
setter
void removeRemoveBranchNotifier(boost::shared_ptr< boost::function< void(boost::shared_ptr< WRMBranch >) > > notifier)
Remove a specified notifier from the list of default notifiers which get connected to each removed br...
boost::shared_ptr< WRMBranch > addBranch()
Add a new branch.
Definition: WROIManager.cpp:61