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