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