OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WSelectorRoi.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 WSELECTORROI_H
26 #define WSELECTORROI_H
27 
28 #include <vector>
29 
30 #include "../dataHandler/WDataSetFibers.h"
31 
32 #include "../graphicsEngine/WROI.h"
33 
34 #include "WKdTree.h"
35 /**
36  * class implements the updating of a bitfield for a roi
37  */
39 {
40 public:
41  /**
42  * constructor
43  * \param roi the roi representation
44  * \param fibers the fiber dataset to work on
45  * \param kdTree kd tree for fast intersection checks
46  */
47  WSelectorRoi( osg::ref_ptr< WROI > roi, boost::shared_ptr< const WDataSetFibers > fibers, boost::shared_ptr< WKdTree> kdTree );
48 
49  /**
50  * destructor
51  */
52  ~WSelectorRoi();
53 
54  /**
55  * getter
56  * \return the bitfield for this ROI
57  */
58  boost::shared_ptr< std::vector<bool> >getBitField();
59 
60  /**
61  * getter
62  * access to the ROI representation, mainly for delete and update functions
63  *
64  * \return Pointer to the ROI representation
65  */
66  osg::ref_ptr< WROI > getRoi();
67 
68  /**
69  * setter
70  * sets the dirty flag
71  */
72  void setDirty();
73 
74 protected:
75 private:
76  /**
77  * updates the output bitfiel when something with the rois has changed
78  */
79  void recalculate();
80 
81  /**
82  * recursive function to check for intersections with the roi
83  * \param left
84  * \param right
85  * \param axis
86  */
87  void boxTest( int left, int right, int axis );
88 
89  /**
90  * getter
91  * \param point point to check
92  * \return the index of the line the point is part of
93  *
94  */
95  size_t getLineForPoint( size_t point );
96 
97  /**
98  * pointer to the roi
99  */
100  osg::ref_ptr< WROI > m_roi;
101 
102  /**
103  * Pointer to the fiber data set
104  */
105  boost::shared_ptr< const WDataSetFibers > m_fibers;
106 
107  /**
108  * Stores a pointer to the kdTree used for fiber selection
109  */
110  boost::shared_ptr< WKdTree > m_kdTree;
111 
112  /**
113  * size of the fiber dataset, stored for convinience
114  */
115  size_t m_size;
116 
117  /**
118  * dirty flag
119  */
120  bool m_dirty;
121 
122  /**
123  * the bitfield that is given to the outside world
124  */
125  boost::shared_ptr< std::vector<bool> >m_bitField;
126 
127  /**
128  * the bitfield we work on
129  */
130  boost::shared_ptr< std::vector<bool> >m_workerBitfield;
131 
132  /**
133  * pointer to the array that is used for updating
134  * this is used for the recurse update function, to reduce the amount of function parameters
135  */
136  boost::shared_ptr< std::vector< float > > m_currentArray;
137 
138  /**
139  * pointer to the reverse array that is used for updating
140  * this is used for the recurse update function, to reduce the amount of function parameters
141  */
142  boost::shared_ptr< std::vector< size_t > > m_currentReverse;
143 
144  std::vector<float> m_boxMin; //!< lower boundary of the box, used for boxtest
145  std::vector<float> m_boxMax; //!< upper boundary of the box, used for boxtest
146 
147  boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the selector ROI
148 };
149 
150 inline boost::shared_ptr< std::vector<bool> > WSelectorRoi::getBitField()
151 {
152  if( m_dirty )
153  {
154  recalculate();
155  }
156  return m_bitField;
157 }
158 
159 inline size_t WSelectorRoi::getLineForPoint( size_t point )
160 {
161  return ( *m_currentReverse )[point];
162 }
163 
164 inline osg::ref_ptr< WROI > WSelectorRoi::getRoi()
165 {
166  return m_roi;
167 }
168 
169 #endif // WSELECTORROI_H