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