OpenWalnut 1.3.1
WRMBranch.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 WRMBRANCH_H
00026 #define WRMBRANCH_H
00027 
00028 #include <list>
00029 #include <string>
00030 #include <vector>
00031 
00032 #include <boost/enable_shared_from_this.hpp>
00033 
00034 #include "../common/WProperties.h"
00035 
00036 #include "../graphicsEngine/WROI.h"
00037 
00038 
00039 
00040 class WROIManager;
00041 
00042 /**
00043  * implements a branch in the tree like structure for rois
00044  */
00045 class  WRMBranch : public boost::enable_shared_from_this< WRMBranch >
00046 {
00047 public:
00048     /**
00049      * construtor
00050      * \param roiManager
00051      */
00052     explicit WRMBranch( boost::shared_ptr< WROIManager > roiManager );
00053 
00054     /**
00055      * destructor
00056      */
00057     ~WRMBranch();
00058 
00059     /**
00060      * adds a roi to the branch
00061      *
00062      * \param roi
00063      */
00064     void addRoi( osg::ref_ptr< WROI > roi );
00065 
00066     /**
00067      * removes a roi from the branch
00068      *
00069      * \param roi
00070      */
00071     void removeRoi( osg::ref_ptr< WROI > roi );
00072 
00073     /**
00074      * removes all rois from the branch
00075      *
00076      */
00077     void removeAllRois();
00078 
00079     /**
00080      * getter for dirty flag
00081      *
00082      * \param reset when true the dirty flag will be set to false
00083      * \return the dirty flag
00084      */
00085     bool dirty( bool reset = false );
00086 
00087     /**
00088      * sets dirty flag true and notifies the branch
00089      */
00090     void setDirty();
00091 
00092     /**
00093      * returns whether the branch is empty.
00094      *
00095      * \return true if empty.
00096      */
00097     bool empty();
00098 
00099     /**
00100      * checks wether a roi is in this branch
00101      * \param roi
00102      * \return true if the roi is in the branch, false otherwise
00103      */
00104     bool contains( osg::ref_ptr< WROI > roi );
00105 
00106     /**
00107      * returns a pointer to the first roi in the branch
00108      *
00109      * \return the roi
00110      */
00111     osg::ref_ptr< WROI > getFirstRoi();
00112 
00113     /**
00114      * getter for roi manager pointer
00115      *
00116      * \return the roi manager
00117      */
00118     boost::shared_ptr< WROIManager > getRoiManager();
00119 
00120     /**
00121      * returns the properties object.
00122      *
00123      * \return the properties of this branch
00124      */
00125     boost::shared_ptr< WProperties > getProperties();
00126 
00127     /**
00128      * getter for the NOT flag
00129      * \return flag
00130      */
00131     bool isNot();
00132 
00133     /**
00134      * add all the rois in this branch to a given vector
00135      * \param roiVec the vector to fill
00136      */
00137     void getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ); //NOLINT
00138 
00139     /**
00140      * Add a specified notifier to the list of default notifiers which get connected to each branch
00141      *
00142      * \param notifier  the notifier function
00143      */
00144     void addChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier );
00145 
00146 
00147     /**
00148      * Remove a specified notifier from the list of default notifiers which get connected to each branch
00149      *
00150      * \param notifier  the notifier function
00151      */
00152     void removeChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier );
00153 
00154 
00155 protected:
00156     /**
00157      * initializes properties
00158      */
00159     void properties();
00160 
00161     /**
00162      * slot gets called when a property has changed
00163      *
00164      */
00165     void propertyChanged();
00166 private:
00167     boost::shared_ptr< WROIManager > m_roiManager; //!< stores a pointer to the roi manager
00168 
00169     std::list< osg::ref_ptr< WROI > > m_rois; //!< list of rois in this this branch,
00170                                                                   // first in the list is the master roi
00171     /**
00172      * the property object for the module
00173      */
00174     boost::shared_ptr< WProperties > m_properties;
00175 
00176     WPropBool m_dirty; //!< dirty flag to indicate if anything has changed within the branch
00177 
00178     /**
00179      * indicates if the branch is negated
00180      */
00181     WPropBool m_isNot;
00182 
00183     /**
00184      * The color used when in isosurface mode for blending.
00185      */
00186     WPropColor m_bundleColor;
00187 
00188     /**
00189      * The notifiers connected to added rois by default.
00190      */
00191     std::list< boost::shared_ptr< boost::function< void() > > > m_changeNotifiers;
00192 
00193     boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the ROImanager branch
00194 
00195     /**
00196      * Lock for associated notifiers set.
00197      */
00198     boost::shared_mutex m_associatedNotifiersLock;
00199 };
00200 
00201 inline bool WRMBranch::empty()
00202 {
00203     return m_rois.empty();
00204 }
00205 
00206 inline bool WRMBranch::dirty( bool reset )
00207 {
00208     bool ret = m_dirty->get();
00209     if( reset )
00210     {
00211         m_dirty->set( false );
00212     }
00213     return ret;
00214 }
00215 
00216 inline bool WRMBranch::isNot()
00217 {
00218     return m_isNot->get();
00219 }
00220 #endif  // WRMBRANCH_H