OpenWalnut  1.3.1
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  * adds a new master ROI
55  *
56  * \param newRoi
57  * \return ROI representation which can be used to remove the ROI
58  */
59  void addRoi( osg::ref_ptr< WROI > newRoi );
60 
61  /**
62  * adds a new ROI below a master ROI
63  *
64  * \param newRoi
65  * \param parentRoi
66  * \return ROI representation which can be used to remove the ROI
67  */
68  void addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi );
69 
70  /**
71  * removes a roi
72  *
73  * \param roi
74  */
75  void removeRoi( osg::ref_ptr< WROI > roi );
76 
77  /**
78  * removes a branch
79  *
80  * \param roi the first roi in the branch
81  */
82  void removeBranch( osg::ref_ptr< WROI > roi );
83 
84  /**
85  * getter
86  * returns the branch item the roi is in
87  * \param roi
88  * \return branch
89  */
90  boost::shared_ptr< WRMBranch> getBranch( osg::ref_ptr< WROI > roi );
91 
92  /**
93  * sets the dirty flag which will cause recalculation of the bit field
94  */
95  void setDirty();
96 
97  /**
98  * getter
99  * \param reset if true the dirty flag will be set to false
100  * \return the dirty flag
101  */
102  bool dirty( bool reset = false );
103 
104  /**
105  * Add a specified notifier to the list of default notifiers which get connected to each added roi.
106  *
107  * \param notifier the notifier function
108  */
109  void addAddNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier );
110 
111  /**
112  * Remove a specified notifier from the list of default notifiers which get connected to each added roi.
113  *
114  * \param notifier the notifier function
115  */
116  void removeAddNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier );
117 
118 
119  /**
120  * Add a specified notifier to the list of default notifiers which get connected to each removed roi.
121  *
122  * \param notifier the notifier function
123  */
124  void addRemoveNotifier( 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 removed roi.
128  *
129  * \param notifier the notifier function
130  */
131  void removeRemoveNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier );
132 
133  /**
134  * Add a specified notifier to the list of default notifiers which get connected to each removed branch.
135  *
136  * \param notifier the notifier function
137  */
138  void addRemoveBranchNotifier( boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > notifier );
139 
140  /**
141  * Remove a specified notifier from the list of default notifiers which get connected to each removed branch.
142  *
143  * \param notifier the notifier function
144  */
145  void removeRemoveBranchNotifier( boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > notifier );
146 
147  /**
148  * setter
149  * \param roi
150  */
151  void setSelectedRoi( osg::ref_ptr< WROI > roi );
152 
153  /**
154  * getter
155  *
156  * \return Pointer to the currently (in the ROI manager) selected ROI
157  */
158  osg::ref_ptr< WROI > getSelectedRoi();
159 
160  /**
161  * getter for the properties object
162  * \return the properties object
163  */
164  boost::shared_ptr< WProperties > getProperties();
165 
166  /**
167  * getter
168  * \return all existing rois
169  */
170  std::vector< osg::ref_ptr< WROI > > getRois();
171 
172 protected:
173 private:
174  size_t m_size; //!< number of fibers in the dataset
175 
176  std::list< boost::shared_ptr< WRMBranch > > m_branches; //!< list of branches in the logical tree structure
177 
178  /**
179  * Lock for associated notifiers set.
180  */
181  boost::shared_mutex m_associatedNotifiersLock;
182 
183  /**
184  * The notifiers connected to added rois by default.
185  */
186  std::list< boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > > m_addNotifiers;
187 
188  /**
189  * The notifiers connected to removed rois by default.
190  */
191  std::list< boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > > m_removeNotifiers;
192 
193  /**
194  * The notifiers connected to removed rois by default.
195  */
196  std::list< boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > > m_removeBranchNotifiers;
197 
198 
199  osg::ref_ptr< WROI > m_selectedRoi; //!< stores a pointer to the currently selected roi
200 
201  /**
202  * The property object for the module.
203  */
204  boost::shared_ptr< WProperties > m_properties;
205 
206  /**
207  * dirty flag
208  */
209  WPropBool m_dirty;
210 };
211 
212 inline bool WROIManager::dirty( bool reset )
213 {
214  bool ret = m_dirty->get();
215  if( reset )
216  {
217  m_dirty->set( false );
218  }
219  return ret;
220 }
221 
222 inline boost::shared_ptr< WProperties > WROIManager::getProperties()
223 {
224  return m_properties;
225 }
226 
227 #endif // WROIMANAGER_H