OpenWalnut  1.4.0
WFiberSelector.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 WFIBERSELECTOR_H
26 #define WFIBERSELECTOR_H
27 
28 #include <list>
29 #include <vector>
30 
31 #include "../dataHandler/WDataSetFibers.h"
32 #include "../common/WCondition.h"
33 
34 #include "WSelectorRoi.h"
35 #include "WSelectorBranch.h"
36 
37 #include "WKdTree.h"
38 
39 /**
40  * Adaptor class between the roi manager and the fiber display
41  */
42 class WFiberSelector // NOLINT
43 {
44 public:
45  /**
46  * Fiber selector pointer
47  */
48  typedef boost::shared_ptr< WFiberSelector > SPtr;
49 
50  /**
51  * Const fiber selector pointer.
52  */
53  typedef boost::shared_ptr< const WFiberSelector > ConstSPtr;
54 
55  /**
56  * constructor
57  * \param fibers pointer to the datset this selector works on
58  */
59  explicit WFiberSelector( boost::shared_ptr< const WDataSetFibers > fibers );
60 
61  /**
62  * destructor
63  */
65 
66  /**
67  * Return the number of fibers in the dataset.
68  *
69  * \return number of fibers
70  */
71  size_t size();
72 
73  /**
74  * getter
75  * \return the bitfield calculated from all active rois
76  */
77  boost::shared_ptr< std::vector< bool > > getBitfield();
78 
79  /**
80  * Get color for fiber with given index.
81  *
82  * \param fidx the index. Returns white for invalid index.
83  *
84  * \return color.
85  */
86  WColor getFiberColor( size_t fidx ) const;
87 
88  /**
89  * getter for the line start index array
90  * \return line starts
91  */
92  boost::shared_ptr< std::vector< size_t > > getStarts();
93 
94  /**
95  * getter for the line length array
96  * \return line lengths
97  */
98  boost::shared_ptr< std::vector< size_t > > getLengths();
99 
100  /**
101  * setter
102  * sets the dirty flag
103  */
104  void setDirty();
105 
106  /**
107  * Get the current dirty-state.
108  *
109  * \return the dirty flag
110  */
111  bool getDirty();
112 
113  /**
114  * Condition that fires upon a recalculation of the fiber selection.
115  *
116  * \return the condition
117  */
119 
120  /**
121  * Returns true if no fiber gets filtered out because there is no branch in the ROI tree.
122  *
123  * \return true if all fibers should be shown
124  */
125  bool isNothingFiltered() const;
126 
127 protected:
128  /**
129  * listener function for inserting rois
130  * \param roi new roi inserted into the roi structure
131  */
132  void slotAddRoi( osg::ref_ptr< WROI > roi );
133 
134  /**
135  * listener function for removing rois
136  * \param roi roi that is being removed
137  */
138  void slotRemoveRoi( osg::ref_ptr< WROI > roi );
139 
140  /**
141  * listener function for removing rois
142  * \param branch branch that is being removed
143  */
144  void slotRemoveBranch( boost::shared_ptr< WRMBranch > branch );
145 
146 private:
147  /**
148  * update the bitfield when there was a change in the roi structure
149  */
150  void recalculate();
151 
152  /**
153  * Pointer to the fiber data set
154  */
155  boost::shared_ptr< const WDataSetFibers > m_fibers;
156 
157  size_t m_size; //!< number of fibers in the dataset
158 
159  bool m_dirty; //!< dirty flag
160 
161  /**
162  * Stores a pointer to the kdTree used for fiber selection
163  */
164  boost::shared_ptr< WKdTree > m_kdTree;
165 
166  boost::shared_ptr< std::vector< bool > >m_outputBitfield; //!< bit field of activated fibers
167 
168  boost::shared_ptr< std::vector< float > >m_outputColorMap; //!< Map each fiber to a color
169 
170  std::list< boost::shared_ptr<WSelectorBranch> >m_branches; //!< list of branches int he roi structure
171 
172  boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > m_assocRoiSignal; //!< Signal that can be used to update the selector
173  boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > m_removeRoiSignal; //!< Signal that can be used to update the selector
174  boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > m_removeBranchSignal; //!< Signal for updating the selector
175  boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the selector
176 
177  /**
178  * Condition that fires on setDirty.
179  */
181 };
182 
183 inline size_t WFiberSelector::size()
184 {
185  return m_size;
186 }
187 
188 inline boost::shared_ptr< std::vector< size_t > > WFiberSelector::getStarts()
189 {
190  return m_fibers->getLineStartIndexes();
191 }
192 
193 inline boost::shared_ptr< std::vector< size_t > > WFiberSelector::getLengths()
194 {
195  return m_fibers->getLineLengths();
196 }
197 
198 #endif // WFIBERSELECTOR_H