OpenWalnut  1.4.0
WFiberSelector.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 WFIBERSELECTOR_H
00026 #define WFIBERSELECTOR_H
00027 
00028 #include <list>
00029 #include <vector>
00030 
00031 #include "../dataHandler/WDataSetFibers.h"
00032 #include "../common/WCondition.h"
00033 
00034 #include "WSelectorRoi.h"
00035 #include "WSelectorBranch.h"
00036 
00037 #include "WKdTree.h"
00038 
00039 /**
00040  * Adaptor class between the roi manager and the fiber display
00041  */
00042 class  WFiberSelector // NOLINT
00043 {
00044 public:
00045     /**
00046      * Fiber selector pointer
00047      */
00048     typedef boost::shared_ptr< WFiberSelector > SPtr;
00049 
00050     /**
00051      * Const fiber selector pointer.
00052      */
00053     typedef boost::shared_ptr< const WFiberSelector > ConstSPtr;
00054 
00055     /**
00056      * constructor
00057      * \param fibers pointer to the datset this selector works on
00058      */
00059     explicit WFiberSelector( boost::shared_ptr< const WDataSetFibers > fibers );
00060 
00061     /**
00062      * destructor
00063      */
00064     ~WFiberSelector();
00065 
00066     /**
00067      * Return the number of fibers in the dataset.
00068      *
00069      * \return number of fibers
00070      */
00071     size_t size();
00072 
00073     /**
00074      * getter
00075      * \return the bitfield calculated from all active rois
00076      */
00077     boost::shared_ptr< std::vector< bool > > getBitfield();
00078 
00079     /**
00080      * Get color for fiber with given index.
00081      *
00082      * \param fidx the index. Returns white for invalid index.
00083      *
00084      * \return color.
00085      */
00086     WColor getFiberColor( size_t fidx ) const;
00087 
00088     /**
00089      * getter for the line start index array
00090      * \return line starts
00091      */
00092     boost::shared_ptr< std::vector< size_t > > getStarts();
00093 
00094     /**
00095      * getter for the line length array
00096      * \return line lengths
00097      */
00098     boost::shared_ptr< std::vector< size_t > > getLengths();
00099 
00100     /**
00101      * setter
00102      * sets the dirty flag
00103      */
00104     void setDirty();
00105 
00106     /**
00107      * Get the current dirty-state.
00108      *
00109      * \return the dirty flag
00110      */
00111     bool getDirty();
00112 
00113     /**
00114      * Condition that fires upon a recalculation of the fiber selection.
00115      *
00116      * \return the condition
00117      */
00118     WCondition::SPtr getDirtyCondition();
00119 
00120     /**
00121      * Returns true if no fiber gets filtered out because there is no branch in the ROI tree.
00122      *
00123      * \return true if all fibers should be shown
00124      */
00125     bool isNothingFiltered() const;
00126 
00127 protected:
00128     /**
00129      * listener function for inserting rois
00130      * \param roi new roi inserted into the roi structure
00131      */
00132     void slotAddRoi( osg::ref_ptr< WROI > roi );
00133 
00134     /**
00135      * listener function for removing rois
00136      * \param roi roi that is being removed
00137      */
00138     void slotRemoveRoi( osg::ref_ptr< WROI > roi );
00139 
00140     /**
00141      * listener function for removing rois
00142      * \param branch branch that is being removed
00143      */
00144     void slotRemoveBranch( boost::shared_ptr< WRMBranch > branch );
00145 
00146 private:
00147     /**
00148      * update the bitfield when there was a change in the roi structure
00149      */
00150     void recalculate();
00151 
00152     /**
00153      * Pointer to the fiber data set
00154      */
00155     boost::shared_ptr< const WDataSetFibers > m_fibers;
00156 
00157     size_t m_size; //!< number of fibers in the dataset
00158 
00159     bool m_dirty; //!< dirty flag
00160 
00161     /**
00162      * Stores a pointer to the kdTree used for fiber selection
00163      */
00164     boost::shared_ptr< WKdTree > m_kdTree;
00165 
00166     boost::shared_ptr< std::vector< bool > >m_outputBitfield; //!< bit field of activated fibers
00167 
00168     boost::shared_ptr< std::vector< float > >m_outputColorMap; //!< Map each fiber to a color
00169 
00170     std::list< boost::shared_ptr<WSelectorBranch> >m_branches; //!< list of branches int he roi structure
00171 
00172     boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > m_assocRoiSignal; //!< Signal that can be used to update the selector
00173     boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > m_removeRoiSignal; //!< Signal that can be used to update the selector
00174     boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > m_removeBranchSignal; //!< Signal for updating the selector
00175     boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the selector
00176 
00177     /**
00178      * Condition that fires on setDirty.
00179      */
00180     WCondition::SPtr m_dirtyCondition;
00181 };
00182 
00183 inline size_t WFiberSelector::size()
00184 {
00185     return m_size;
00186 }
00187 
00188 inline boost::shared_ptr< std::vector< size_t > > WFiberSelector::getStarts()
00189 {
00190     return m_fibers->getLineStartIndexes();
00191 }
00192 
00193 inline boost::shared_ptr< std::vector< size_t > > WFiberSelector::getLengths()
00194 {
00195     return m_fibers->getLineLengths();
00196 }
00197 
00198 #endif  // WFIBERSELECTOR_H