OpenWalnut
1.4.0
|
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 * Add a new branch. 00055 * 00056 * \return the new branch. 00057 */ 00058 boost::shared_ptr< WRMBranch > addBranch(); 00059 00060 /** 00061 * adds a new master ROI 00062 * 00063 * \param newRoi 00064 * \return ROI representation which can be used to remove the ROI 00065 */ 00066 void addRoi( osg::ref_ptr< WROI > newRoi ); 00067 00068 /** 00069 * adds a new ROI below a master ROI 00070 * 00071 * \param newRoi 00072 * \param parentRoi 00073 * \return ROI representation which can be used to remove the ROI 00074 */ 00075 void addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi ); 00076 00077 /** 00078 * Add a ROI to a branch. 00079 * 00080 * \param newRoi the new ROI to add 00081 * \param toBranch the branch to add the ROI to. 00082 */ 00083 void addRoi( osg::ref_ptr< WROI > newRoi, boost::shared_ptr< WRMBranch > toBranch ); 00084 00085 /** 00086 * removes a roi 00087 * 00088 * \param roi 00089 */ 00090 void removeRoi( osg::ref_ptr< WROI > roi ); 00091 00092 /** 00093 * removes a branch 00094 * 00095 * \param roi the first roi in the branch 00096 */ 00097 void removeBranch( osg::ref_ptr< WROI > roi ); 00098 00099 /** 00100 * getter 00101 * returns the branch item the roi is in 00102 * \param roi 00103 * \return branch 00104 */ 00105 boost::shared_ptr< WRMBranch> getBranch( osg::ref_ptr< WROI > roi ); 00106 00107 /** 00108 * sets the dirty flag which will cause recalculation of the bit field 00109 */ 00110 void setDirty(); 00111 00112 /** 00113 * getter 00114 * \param reset if true the dirty flag will be set to false 00115 * \return the dirty flag 00116 */ 00117 bool dirty( bool reset = false ); 00118 00119 /** 00120 * Add a specified notifier to the list of default notifiers which get connected to each added roi. 00121 * 00122 * \param notifier the notifier function 00123 */ 00124 void addAddNotifier( 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 added roi. 00128 * 00129 * \param notifier the notifier function 00130 */ 00131 void removeAddNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier ); 00132 00133 00134 /** 00135 * Add a specified notifier to the list of default notifiers which get connected to each removed roi. 00136 * 00137 * \param notifier the notifier function 00138 */ 00139 void addRemoveNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier ); 00140 00141 /** 00142 * Remove a specified notifier from the list of default notifiers which get connected to each removed roi. 00143 * 00144 * \param notifier the notifier function 00145 */ 00146 void removeRemoveNotifier( boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > notifier ); 00147 00148 /** 00149 * Add a specified notifier to the list of default notifiers which get connected to each removed branch. 00150 * 00151 * \param notifier the notifier function 00152 */ 00153 void addRemoveBranchNotifier( boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > notifier ); 00154 00155 /** 00156 * Remove a specified notifier from the list of default notifiers which get connected to each removed branch. 00157 * 00158 * \param notifier the notifier function 00159 */ 00160 void removeRemoveBranchNotifier( boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > notifier ); 00161 00162 /** 00163 * setter 00164 * \param roi 00165 */ 00166 void setSelectedRoi( osg::ref_ptr< WROI > roi ); 00167 00168 /** 00169 * getter 00170 * 00171 * \return Pointer to the currently (in the ROI manager) selected ROI 00172 */ 00173 osg::ref_ptr< WROI > getSelectedRoi(); 00174 00175 /** 00176 * getter for the properties object 00177 * \return the properties object 00178 */ 00179 boost::shared_ptr< WProperties > getProperties(); 00180 00181 /** 00182 * ROI list 00183 */ 00184 typedef std::vector< osg::ref_ptr< WROI > > ROIs; 00185 00186 /** 00187 * getter 00188 * \return all existing rois 00189 */ 00190 ROIs getRois() const; 00191 00192 /** 00193 * Branches list 00194 */ 00195 typedef std::vector< boost::shared_ptr< WRMBranch > > Branches; 00196 00197 /** 00198 * Get a copy of the current branch list. Please note that after getting the list, it might already have been changed by another thread. 00199 * 00200 * \return the list of current branches 00201 */ 00202 Branches getBranches() const; 00203 00204 protected: 00205 private: 00206 size_t m_size; //!< number of fibers in the dataset 00207 00208 std::list< boost::shared_ptr< WRMBranch > > m_branches; //!< list of branches in the logical tree structure 00209 00210 /** 00211 * Lock for associated notifiers set. 00212 */ 00213 boost::shared_mutex m_associatedNotifiersLock; 00214 00215 /** 00216 * The notifiers connected to added rois by default. 00217 */ 00218 std::list< boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > > m_addNotifiers; 00219 00220 /** 00221 * The notifiers connected to removed rois by default. 00222 */ 00223 std::list< boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > > m_removeNotifiers; 00224 00225 /** 00226 * The notifiers connected to removed rois by default. 00227 */ 00228 std::list< boost::shared_ptr< boost::function< void( boost::shared_ptr< WRMBranch > ) > > > m_removeBranchNotifiers; 00229 00230 00231 osg::ref_ptr< WROI > m_selectedRoi; //!< stores a pointer to the currently selected roi 00232 00233 /** 00234 * The property object for the module. 00235 */ 00236 boost::shared_ptr< WProperties > m_properties; 00237 00238 /** 00239 * dirty flag 00240 */ 00241 WPropBool m_dirty; 00242 }; 00243 00244 inline bool WROIManager::dirty( bool reset ) 00245 { 00246 bool ret = m_dirty->get(); 00247 if( reset ) 00248 { 00249 m_dirty->set( false ); 00250 } 00251 return ret; 00252 } 00253 00254 inline boost::shared_ptr< WProperties > WROIManager::getProperties() 00255 { 00256 return m_properties; 00257 } 00258 00259 #endif // WROIMANAGER_H