OpenWalnut 1.3.1
WROIManager.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 WROIMANAGER_H
00026 #define WROIMANAGER_H
00027 
00028 #include <list>
00029 #include <vector>
00030 
00031 #include <boost/enable_shared_from_this.hpp>
00032 
00033 #include "WRMBranch.h"
00034 
00035 
00036 
00037 /**
00038  * Class to store and manage different ROI's for fiber selection
00039  */
00040 class  WROIManager: public boost::enable_shared_from_this< WROIManager >
00041 {
00042 public:
00043     /**
00044      * standard constructor
00045      */
00046     WROIManager();
00047 
00048     /**
00049      * destructor
00050      */
00051     ~WROIManager();
00052 
00053     /**
00054      * adds a new master ROI
00055      *
00056      * \param newRoi
00057      * \return ROI representation which can be used to remove the ROI
00058      */
00059     void addRoi( osg::ref_ptr< WROI > newRoi );
00060 
00061     /**
00062      * adds a new ROI below a master ROI
00063      *
00064      * \param newRoi
00065      * \param parentRoi
00066      * \return ROI representation which can be used to remove the ROI
00067      */
00068     void addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi );
00069 
00070     /**
00071      * removes a roi
00072      *
00073      * \param roi
00074      */
00075     void removeRoi( osg::ref_ptr< WROI > roi );
00076 
00077     /**
00078      * removes a branch
00079      *
00080      * \param roi the first roi in the branch
00081      */
00082     void removeBranch( osg::ref_ptr< WROI > roi );
00083 
00084     /**
00085      * getter
00086      * returns the branch item the roi is in
00087      * \param roi
00088      * \return branch
00089      */
00090     boost::shared_ptr< WRMBranch> getBranch( osg::ref_ptr< WROI > roi );
00091 
00092     /**
00093      * sets the dirty flag which will cause recalculation of the bit field
00094      */
00095     void setDirty();
00096 
00097     /**
00098      *  getter
00099      *   \param reset if true the dirty flag will be set to false
00100      *  \return the dirty flag
00101      */
00102     bool dirty( bool reset = false );
00103 
00104     /**
00105      * Add a specified notifier to the list of default notifiers which get connected to each added roi.
00106      *
00107      * \param notifier  the notifier function
00108      */
00109     void addAddNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier );
00110 
00111     /**
00112      * Remove a specified notifier from the list of default notifiers which get connected to each added roi.
00113      *
00114      * \param notifier  the notifier function
00115      */
00116     void removeAddNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier );
00117 
00118 
00119     /**
00120      * Add a specified notifier to the list of default notifiers which get connected to each removed roi.
00121      *
00122      * \param notifier  the notifier function
00123      */
00124     void addRemoveNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier );
00125 
00126     /**
00127      * Remove a specified notifier from the list of default notifiers which get connected to each removed roi.
00128      *
00129      * \param notifier  the notifier function
00130      */
00131     void removeRemoveNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier );
00132 
00133     /**
00134      * Add a specified notifier to the list of default notifiers which get connected to each removed branch.
00135      *
00136      * \param notifier  the notifier function
00137      */
00138     void addRemoveBranchNotifier( boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > notifier );
00139 
00140     /**
00141      * Remove a specified notifier from the list of default notifiers which get connected to each removed branch.
00142      *
00143      * \param notifier  the notifier function
00144      */
00145     void removeRemoveBranchNotifier(  boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > notifier );
00146 
00147     /**
00148      * setter
00149      * \param roi
00150      */
00151     void setSelectedRoi( osg::ref_ptr< WROI > roi );
00152 
00153     /**
00154      * getter
00155      *
00156      * \return Pointer to the currently (in the ROI manager) selected ROI
00157      */
00158     osg::ref_ptr< WROI > getSelectedRoi();
00159 
00160     /**
00161      * getter for the properties object
00162      * \return the properties object
00163      */
00164     boost::shared_ptr< WProperties > getProperties();
00165 
00166     /**
00167      * getter
00168      * \return all existing rois
00169      */
00170     std::vector< osg::ref_ptr< WROI > > getRois();
00171 
00172 protected:
00173 private:
00174     size_t m_size; //!< number of fibers in the dataset
00175 
00176     std::list< boost::shared_ptr< WRMBranch > > m_branches; //!< list of branches in the logical tree structure
00177 
00178     /**
00179      * Lock for associated notifiers set.
00180      */
00181     boost::shared_mutex m_associatedNotifiersLock;
00182 
00183     /**
00184      * The notifiers connected to added rois by default.
00185      */
00186     std::list<  boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > > m_addNotifiers;
00187 
00188     /**
00189      * The notifiers connected to removed rois by default.
00190      */
00191     std::list<  boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > > m_removeNotifiers;
00192 
00193     /**
00194      * The notifiers connected to removed rois by default.
00195      */
00196     std::list<  boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > > m_removeBranchNotifiers;
00197 
00198 
00199     osg::ref_ptr< WROI > m_selectedRoi; //!< stores a pointer to the currently selected roi
00200 
00201     /**
00202      * The property object for the module.
00203      */
00204     boost::shared_ptr< WProperties > m_properties;
00205 
00206     /**
00207      * dirty flag
00208      */
00209     WPropBool m_dirty;
00210 };
00211 
00212 inline bool WROIManager::dirty( bool reset )
00213 {
00214     bool ret = m_dirty->get();
00215     if( reset )
00216     {
00217         m_dirty->set( false );
00218     }
00219     return ret;
00220 }
00221 
00222 inline boost::shared_ptr< WProperties > WROIManager::getProperties()
00223 {
00224     return m_properties;
00225 }
00226 
00227 #endif  // WROIMANAGER_H