OpenWalnut 1.2.5

WSelectorRoi.h

00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WSELECTORROI_H
00026 #define WSELECTORROI_H
00027 
00028 #include <vector>
00029 
00030 #include "../dataHandler/WDataSetFibers.h"
00031 
00032 #include "../graphicsEngine/WROI.h"
00033 
00034 #include "WKdTree.h"
00035 /**
00036  * class implements the updating of a bitfield for a roi
00037  */
00038 class WSelectorRoi
00039 {
00040 public:
00041     /**
00042      * constructor
00043      * \param roi the roi representation
00044      * \param fibers the fiber dataset to work on
00045      * \param kdTree kd tree for fast intersection checks
00046      */
00047     WSelectorRoi( osg::ref_ptr< WROI > roi, boost::shared_ptr< const WDataSetFibers > fibers, boost::shared_ptr< WKdTree> kdTree );
00048 
00049     /**
00050      * destructor
00051      */
00052     ~WSelectorRoi();
00053 
00054     /**
00055      * getter
00056      * \return the bitfield for this ROI
00057      */
00058     boost::shared_ptr< std::vector<bool> >getBitField();
00059 
00060     /**
00061      * getter
00062      * access to the ROI representation, mainly for delete and update functions
00063      *
00064      * \return Pointer to the ROI representation
00065      */
00066     osg::ref_ptr< WROI > getRoi();
00067 
00068     /**
00069      * setter
00070      * sets the dirty flag
00071      */
00072     void setDirty();
00073 
00074 protected:
00075 private:
00076     /**
00077      * updates the output bitfiel when something with the rois has changed
00078      */
00079     void recalculate();
00080 
00081     /**
00082      * recursive function to check for intersections with the roi
00083      * \param left
00084      * \param right
00085      * \param axis
00086      */
00087     void boxTest( int left, int right, int axis );
00088 
00089     /**
00090      * getter
00091      * \param point point to check
00092      * \return the index of the line the point is part of
00093      *
00094      */
00095     size_t getLineForPoint( size_t point );
00096 
00097     /**
00098      * pointer to the roi
00099      */
00100     osg::ref_ptr< WROI > m_roi;
00101 
00102     /**
00103      * Pointer to the fiber data set
00104      */
00105     boost::shared_ptr< const WDataSetFibers > m_fibers;
00106 
00107     /**
00108      * Stores a pointer to the kdTree used for fiber selection
00109      */
00110     boost::shared_ptr< WKdTree > m_kdTree;
00111 
00112     /**
00113      * size of the fiber dataset, stored for convinience
00114      */
00115     size_t m_size;
00116 
00117     /**
00118      * dirty flag
00119      */
00120     bool m_dirty;
00121 
00122     /**
00123      * the bitfield that is given to the outside world
00124      */
00125     boost::shared_ptr< std::vector<bool> >m_bitField;
00126 
00127     /**
00128      * the bitfield we work on
00129      */
00130     boost::shared_ptr< std::vector<bool> >m_workerBitfield;
00131 
00132     /**
00133      * pointer to the array that is used for updating
00134      * this is used for the recurse update function, to reduce the amount of function parameters
00135      */
00136     boost::shared_ptr< std::vector< float > > m_currentArray;
00137 
00138     /**
00139      * pointer to the reverse array that is used for updating
00140      * this is used for the recurse update function, to reduce the amount of function parameters
00141      */
00142     boost::shared_ptr< std::vector< size_t > > m_currentReverse;
00143 
00144     std::vector<float> m_boxMin; //!< lower boundary of the box, used for boxtest
00145     std::vector<float> m_boxMax; //!< upper boundary of the box, used for boxtest
00146 
00147     boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the selector ROI
00148 };
00149 
00150 inline boost::shared_ptr< std::vector<bool> > WSelectorRoi::getBitField()
00151 {
00152     if( m_dirty )
00153     {
00154         recalculate();
00155     }
00156     return m_bitField;
00157 }
00158 
00159 inline size_t WSelectorRoi::getLineForPoint( size_t point )
00160 {
00161     return ( *m_currentReverse )[point];
00162 }
00163 
00164 inline osg::ref_ptr< WROI > WSelectorRoi::getRoi()
00165 {
00166     return m_roi;
00167 }
00168 
00169 #endif  // WSELECTORROI_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends