OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 <list>
29 #include <string>
30 #include <vector>
31 
32 #include <boost/enable_shared_from_this.hpp>
33 
34 #include "../common/WProperties.h"
35 
36 #include "../graphicsEngine/WROI.h"
37 
38 #include "WExportKernel.h"
39 
40 class WROIManager;
41 
42 /**
43  * implements a branch in the tree like structure for rois
44  */
45 class OWKERNEL_EXPORT WRMBranch : public boost::enable_shared_from_this< WRMBranch >
46 {
47 public:
48  /**
49  * construtor
50  * \param roiManager
51  */
52  explicit WRMBranch( boost::shared_ptr< WROIManager > roiManager );
53 
54  /**
55  * destructor
56  */
57  ~WRMBranch();
58 
59  /**
60  * adds a roi to the branch
61  *
62  * \param roi
63  */
64  void addRoi( osg::ref_ptr< WROI > roi );
65 
66  /**
67  * removes a roi from the branch
68  *
69  * \param roi
70  */
71  void removeRoi( osg::ref_ptr< WROI > roi );
72 
73  /**
74  * removes all rois from the branch
75  *
76  */
77  void removeAllRois();
78 
79  /**
80  * getter for dirty flag
81  *
82  * \param reset when true the dirty flag will be set to false
83  * \return the dirty flag
84  */
85  bool dirty( bool reset = false );
86 
87  /**
88  * sets dirty flag true and notifies the branch
89  */
90  void setDirty();
91 
92  /**
93  * returns whether the branch is empty.
94  *
95  * \return true if empty.
96  */
97  bool empty();
98 
99  /**
100  * checks wether a roi is in this branch
101  * \param roi
102  * \return true if the roi is in the branch, false otherwise
103  */
104  bool contains( osg::ref_ptr< WROI > roi );
105 
106  /**
107  * returns a pointer to the first roi in the branch
108  *
109  * \return the roi
110  */
111  osg::ref_ptr< WROI > getFirstRoi();
112 
113  /**
114  * getter for roi manager pointer
115  *
116  * \return the roi manager
117  */
118  boost::shared_ptr< WROIManager > getRoiManager();
119 
120  /**
121  * returns the properties object.
122  *
123  * \return the properties of this branch
124  */
125  boost::shared_ptr< WProperties > getProperties();
126 
127  /**
128  * getter for the NOT flag
129  * \return flag
130  */
131  bool isNot();
132 
133  /**
134  * add all the rois in this branch to a given vector
135  * \param roiVec the vector to fill
136  */
137  void getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ); //NOLINT
138 
139  /**
140  * Add a specified notifier to the list of default notifiers which get connected to each branch
141  *
142  * \param notifier the notifier function
143  */
144  void addChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier );
145 
146 
147  /**
148  * Remove a specified notifier from the list of default notifiers which get connected to each branch
149  *
150  * \param notifier the notifier function
151  */
152  void removeChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier );
153 
154 
155 protected:
156  /**
157  * initializes properties
158  */
159  void properties();
160 
161  /**
162  * slot gets called when a property has changed
163  *
164  */
165  void propertyChanged();
166 private:
167  boost::shared_ptr< WROIManager > m_roiManager; //!< stores a pointer to the roi manager
168 
169  std::list< osg::ref_ptr< WROI > > m_rois; //!< list of rois in this this branch,
170  // first in the list is the master roi
171  /**
172  * the property object for the module
173  */
174  boost::shared_ptr< WProperties > m_properties;
175 
176  WPropBool m_dirty; //!< dirty flag to indicate if anything has changed within the branch
177 
178  /**
179  * indicates if the branch is negated
180  */
181  WPropBool m_isNot;
182 
183  /**
184  * The color used when in isosurface mode for blending.
185  */
186  WPropColor m_bundleColor;
187 
188  /**
189  * The notifiers connected to added rois by default.
190  */
191  std::list< boost::shared_ptr< boost::function< void() > > > m_changeNotifiers;
192 
193  boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the ROImanager branch
194 
195  /**
196  * Lock for associated notifiers set.
197  */
198  boost::shared_mutex m_associatedNotifiersLock;
199 };
200 
201 inline bool WRMBranch::empty()
202 {
203  return m_rois.empty();
204 }
205 
206 inline bool WRMBranch::dirty( bool reset )
207 {
208  bool ret = m_dirty->get();
209  if( reset )
210  {
211  m_dirty->set( false );
212  }
213  return ret;
214 }
215 
216 inline bool WRMBranch::isNot()
217 {
218  return m_isNot->get();
219 }
220 #endif // WRMBRANCH_H