OpenWalnut  1.4.0
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  /**
105  * Return the current branch color.
106  *
107  * \return the color
108  */
109  WColor getBranchColor() const;
110 protected:
111 private:
112  /**
113  * updates the output bitfield with the information from all rois in this branch
114  */
115  void recalculate();
116 
117  /**
118  * Pointer to the fiber data set
119  */
120  boost::shared_ptr< const WDataSetFibers > m_fibers;
121 
122  /**
123  * size of the fiber dataset, stored for convinience
124  */
125  size_t m_size;
126 
127  bool m_dirty; //!< dirty flag
128 
129  /**
130  * the bitfield given to the outside world
131  */
132  boost::shared_ptr< std::vector< bool > > m_bitField;
133 
134  /**
135  * the bitfield we work on
136  */
137  boost::shared_ptr< std::vector< bool > > m_workerBitfield;
138 
139  /**
140  * list of rois in this branch
141  */
142  std::list< boost::shared_ptr< WSelectorRoi > > m_rois;
143 
144  /**
145  * pointer to the branch object in the roi manager
146  */
147  boost::shared_ptr< WRMBranch > m_branch;
148 
149  boost::shared_ptr< boost::function< void() > > m_changeSignal; //!< Signal that can be used to update the selector branch
150  boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the selector branch
151 };
152 
153 inline boost::shared_ptr< std::vector<bool> > WSelectorBranch::getBitField()
154 {
155  if( m_dirty )
156  {
157  recalculate();
158  }
159  return m_bitField;
160 }
161 
162 inline boost::shared_ptr< WRMBranch > WSelectorBranch::getBranch()
163 {
164  return m_branch;
165 }
166 
168 {
169  return m_rois.empty();
170 }
171 
173 {
174  return m_dirty;
175 }
176 
177 #endif // WSELECTORBRANCH_H