OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WSelectorBranch.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 WSELECTORBRANCH_H
26 #define WSELECTORBRANCH_H
27 
28 #include <list>
29 #include <vector>
30 
31 #include "WSelectorRoi.h"
32 #include "../kernel/WRMBranch.h"
33 
34 /**
35  * TODO(schurade): Document this!
36  */
38 {
39 public:
40  /**
41  * constructor
42  * \param fibers pointer to the fiber dataset to work on
43  * \param branch pointer to the branch object in the roi manager
44  */
45  WSelectorBranch( boost::shared_ptr< const WDataSetFibers > fibers, boost::shared_ptr< WRMBranch > branch );
46 
47  /**
48  * destructor
49  */
51 
52  /**
53  * getter
54  * \return the bitfield that is created from all rois in this branch
55  */
56  boost::shared_ptr< std::vector<bool> > getBitField();
57 
58  /**
59  * getter
60  * \return pointer to the branch object, mainly for deletion and update purposes
61  */
62  boost::shared_ptr<WRMBranch> getBranch();
63 
64  /**
65  * adds a roi to the branch
66  * \param roi
67  */
68  void addRoi( boost::shared_ptr< WSelectorRoi > roi );
69 
70 
71  /**
72  * Queries the ROIs.
73  *
74  * \return A copy of the list of WSelectorRois
75  */
76  std::list< boost::shared_ptr< WSelectorRoi > > getROIs();
77 
78  /**
79  * Removes a roi fromt he branch.
80  *
81  * \param roi
82  */
83  void removeRoi( osg::ref_ptr< WROI > roi );
84 
85  /**
86  * Checks if empty.
87  *
88  * \return true when this branch contains no rois
89  */
90  bool empty();
91 
92  /**
93  * Sets the dirty flag.
94  */
95  void setDirty();
96 
97  /**
98  * Checks if branch is dirty.
99  *
100  * \return true if dirty
101  */
102  bool dirty();
103 
104 protected:
105  /**
106  * function gets called when the color property of the roi branch has changed, it will write this color
107  * into the custom color array of the fiber dataset
108  */
109  void colorChanged();
110 private:
111  /**
112  * updates the output bitfield with the information from all rois in this branch
113  */
114  void recalculate();
115 
116  /**
117  * Pointer to the fiber data set
118  */
119  boost::shared_ptr< const WDataSetFibers > m_fibers;
120 
121  /**
122  * size of the fiber dataset, stored for convinience
123  */
124  size_t m_size;
125 
126  bool m_dirty; //!< dirty flag
127 
128  /**
129  * the bitfield given to the outside world
130  */
131  boost::shared_ptr< std::vector< bool > > m_bitField;
132 
133  /**
134  * the bitfield we work on
135  */
136  boost::shared_ptr< std::vector< bool > > m_workerBitfield;
137 
138  /**
139  * list of rois in this branch
140  */
141  std::list< boost::shared_ptr< WSelectorRoi > > m_rois;
142 
143  /**
144  * pointer to the branch object in the roi manager
145  */
146  boost::shared_ptr< WRMBranch > m_branch;
147 
148  boost::shared_ptr< boost::function< void() > > m_changeSignal; //!< Signal that can be used to update the selector branch
149  boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the selector branch
150 };
151 
152 inline boost::shared_ptr< std::vector<bool> > WSelectorBranch::getBitField()
153 {
154  if( m_dirty )
155  {
156  recalculate();
157  }
158  return m_bitField;
159 }
160 
161 inline boost::shared_ptr< WRMBranch > WSelectorBranch::getBranch()
162 {
163  return m_branch;
164 }
165 
167 {
168  return m_rois.empty();
169 }
170 
172 {
173  return m_dirty;
174 }
175 
176 #endif // WSELECTORBRANCH_H