OpenWalnut  1.4.0
WSelectorBranch.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 WSELECTORBRANCH_H
00026 #define WSELECTORBRANCH_H
00027 
00028 #include <list>
00029 #include <vector>
00030 
00031 #include "WSelectorRoi.h"
00032 #include "../kernel/WRMBranch.h"
00033 
00034 /**
00035  * TODO(schurade): Document this!
00036  */
00037 class WSelectorBranch
00038 {
00039 public:
00040     /**
00041      * constructor
00042      * \param fibers pointer to the fiber dataset to work on
00043      * \param branch pointer to the branch object in the roi manager
00044      */
00045     WSelectorBranch( boost::shared_ptr< const WDataSetFibers > fibers, boost::shared_ptr< WRMBranch > branch );
00046 
00047     /**
00048      * destructor
00049      */
00050     ~WSelectorBranch();
00051 
00052     /**
00053      * getter
00054      * \return the bitfield that is created from all rois in this branch
00055      */
00056     boost::shared_ptr< std::vector<bool> > getBitField();
00057 
00058     /**
00059      * getter
00060      * \return pointer to the branch object, mainly for deletion and update purposes
00061      */
00062     boost::shared_ptr<WRMBranch> getBranch();
00063 
00064     /**
00065      * adds a roi to the branch
00066      * \param roi
00067      */
00068     void addRoi( boost::shared_ptr< WSelectorRoi > roi );
00069 
00070 
00071     /**
00072      * Queries the ROIs.
00073      *
00074      * \return A copy of the list of WSelectorRois
00075      */
00076     std::list< boost::shared_ptr< WSelectorRoi > > getROIs();
00077 
00078     /**
00079      * Removes a roi fromt he branch.
00080      *
00081      * \param roi
00082      */
00083     void removeRoi( osg::ref_ptr< WROI > roi );
00084 
00085     /**
00086      * Checks if empty.
00087      *
00088      * \return true when this branch contains no rois
00089      */
00090     bool empty();
00091 
00092     /**
00093      * Sets the dirty flag.
00094      */
00095     void setDirty();
00096 
00097     /**
00098      * Checks if branch is dirty.
00099      *
00100      * \return true if dirty
00101      */
00102     bool dirty();
00103 
00104     /**
00105      * Return the current branch color.
00106      *
00107      * \return  the color
00108      */
00109     WColor getBranchColor() const;
00110 protected:
00111 private:
00112     /**
00113      * updates the output bitfield with the information from all rois in this branch
00114      */
00115     void recalculate();
00116 
00117     /**
00118      * Pointer to the fiber data set
00119      */
00120     boost::shared_ptr< const WDataSetFibers > m_fibers;
00121 
00122     /**
00123      * size of the fiber dataset, stored for convinience
00124      */
00125     size_t m_size;
00126 
00127     bool m_dirty; //!< dirty flag
00128 
00129     /**
00130      * the bitfield given to the outside world
00131      */
00132     boost::shared_ptr< std::vector< bool > > m_bitField;
00133 
00134     /**
00135      * the bitfield we work on
00136      */
00137     boost::shared_ptr< std::vector< bool > > m_workerBitfield;
00138 
00139     /**
00140      * list of rois in this branch
00141      */
00142     std::list< boost::shared_ptr< WSelectorRoi > > m_rois;
00143 
00144     /**
00145      * pointer to the branch object in the roi manager
00146      */
00147     boost::shared_ptr< WRMBranch > m_branch;
00148 
00149     boost::shared_ptr< boost::function< void() > > m_changeSignal; //!< Signal that can be used to update the selector branch
00150     boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the selector branch
00151 };
00152 
00153 inline boost::shared_ptr< std::vector<bool> > WSelectorBranch::getBitField()
00154 {
00155     if( m_dirty )
00156     {
00157         recalculate();
00158     }
00159     return m_bitField;
00160 }
00161 
00162 inline boost::shared_ptr< WRMBranch > WSelectorBranch::getBranch()
00163 {
00164     return m_branch;
00165 }
00166 
00167 inline bool WSelectorBranch::empty()
00168 {
00169     return m_rois.empty();
00170 }
00171 
00172 inline bool WSelectorBranch::dirty()
00173 {
00174     return m_dirty;
00175 }
00176 
00177 #endif  // WSELECTORBRANCH_H