OpenWalnut  1.3.1
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 
33 #include "WSelectorRoi.h"
34 #include "WSelectorBranch.h"
35 
36 #include "WKdTree.h"
37 
38 
39 
40 /**
41  * Adaptor class between the roi manager and the fiber display
42  */
43 class WFiberSelector // NOLINT
44 {
45 public:
46  /**
47  * constructor
48  * \param fibers pointer to the datset this selector works on
49  */
50  explicit WFiberSelector( boost::shared_ptr< const WDataSetFibers > fibers );
51 
52  /**
53  * destructor
54  */
56 
57  /**
58  * Return the number of fibers in the dataset.
59  *
60  * \return number of fibers
61  */
62  size_t size();
63 
64  /**
65  * getter
66  * \return the bitfield calculated from all active rois
67  */
68  boost::shared_ptr< std::vector< bool > > getBitfield();
69 
70  /**
71  * getter for the line start index array
72  * \return line starts
73  */
74  boost::shared_ptr< std::vector< size_t > > getStarts();
75 
76  /**
77  * getter for the line length array
78  * \return line lengths
79  */
80  boost::shared_ptr< std::vector< size_t > > getLengths();
81 
82  /**
83  * setter
84  * sets the dirty flag
85  */
86  void setDirty();
87 
88 protected:
89  /**
90  * listener function for inserting rois
91  * \param roi new roi inserted into the roi structure
92  */
93  void slotAddRoi( osg::ref_ptr< WROI > roi );
94 
95  /**
96  * listener function for removing rois
97  * \param roi roi that is being removed
98  */
99  void slotRemoveRoi( osg::ref_ptr< WROI > roi );
100 
101  /**
102  * listener function for removing rois
103  * \param branch branch that is being removed
104  */
105  void slotRemoveBranch( boost::shared_ptr< WRMBranch > branch );
106 
107 private:
108  /**
109  * update the bitfield when there was a change in the roi structure
110  */
111  void recalculate();
112 
113  /**
114  * Pointer to the fiber data set
115  */
116  boost::shared_ptr< const WDataSetFibers > m_fibers;
117 
118  size_t m_size; //!< number of fibers in the dataset
119 
120  bool m_dirty; //!< dirty flag
121 
122  /**
123  * Stores a pointer to the kdTree used for fiber selection
124  */
125  boost::shared_ptr< WKdTree > m_kdTree;
126 
127  boost::shared_ptr< std::vector< bool > >m_outputBitfield; //!< bit field of activated fibers
128 
129  boost::shared_ptr< std::vector< bool > >m_workerBitfield; //!< bit field of activated fibers
130 
131  std::list< boost::shared_ptr<WSelectorBranch> >m_branches; //!< list of branches int he roi structure
132 
133  boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > m_assocRoiSignal; //!< Signal that can be used to update the selector
134  boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > m_removeRoiSignal; //!< Signal that can be used to update the selector
135  boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > m_removeBranchSignal; //!< Signal for updating the selector
136  boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the selector
137 };
138 
139 inline size_t WFiberSelector::size()
140 {
141  return m_size;
142 }
143 
144 inline boost::shared_ptr< std::vector< size_t > > WFiberSelector::getStarts()
145 {
146  return m_fibers->getLineStartIndexes();
147 }
148 
149 inline boost::shared_ptr< std::vector< size_t > > WFiberSelector::getLengths()
150 {
151  return m_fibers->getLineLengths();
152 }
153 
154 #endif // WFIBERSELECTOR_H