OpenWalnut  1.5.0dev
WRMBranch.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <list>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 #include "../graphicsEngine/WGraphicsEngine.h"
31 #include "WRMBranch.h"
32 #include "WROIManager.h"
33 
34 
35 WRMBranch::WRMBranch( std::shared_ptr< WROIManager > roiManager ) :
36  m_roiManager( roiManager )
37 {
38  properties();
39 }
40 
42 {
43 }
44 
46 {
47  m_properties = std::shared_ptr< WProperties >( new WProperties( "Properties", "This branch's properties" ) );
48 
49  m_dirty = m_properties->addProperty( "Dirty", "", true, boost::bind( &WRMBranch::propertyChanged, this ) );
50  m_dirty->setHidden( true );
51  m_name = m_properties->addProperty( "Name", "The name of this branch.", std::string( "Branch" ) );
52  m_isNot = m_properties->addProperty( "Not", "Negate the effect of this branch.", false, boost::bind( &WRMBranch::propertyChanged, this ) );
53  m_bundleColor = m_properties->addProperty( "Bundle color", "Color the selected fibers using this color.", WColor( 1.0, 0.0, 0.0, 1.0 ),
54  boost::bind( &WRMBranch::propertyChanged, this ) );
55 
56  m_changeRoiSignal = std::shared_ptr< boost::function< void() > >( new boost::function< void() >( boost::bind( &WRMBranch::setDirty, this ) ) );
57 }
58 
60 {
61  return m_properties;
62 }
63 
65 {
66  setDirty();
67 }
68 
70 {
71  return m_name;
72 }
73 
75 {
76  return m_isNot;
77 }
78 
80 {
81  return m_bundleColor;
82 }
83 
84 void WRMBranch::addRoi( osg::ref_ptr< WROI > roi )
85 {
86  m_rois.push_back( roi );
87  roi->addROIChangeNotifier( m_changeRoiSignal );
88  setDirty();
89 }
90 
91 bool WRMBranch::contains( osg::ref_ptr< WROI > roi )
92 {
93  for( std::vector< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
94  {
95  if( ( *iter ) == roi )
96  {
97  return true;
98  }
99  }
100  return false;
101 }
102 
103 void WRMBranch::removeRoi( osg::ref_ptr< WROI > roi )
104 {
105  roi->removeROIChangeNotifier( m_changeRoiSignal );
106  for( std::vector< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
107  {
108  if( ( *iter ) == roi )
109  {
110  m_rois.erase( iter );
111  setDirty();
112  break;
113  }
114  }
115 }
116 
117 void WRMBranch::getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ) // NOLINT
118 {
119  for( std::vector< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
120  {
121  roiVec.push_back( ( *iter ) );
122  }
123 }
124 
126 {
127  WROIManager::ROIs ret;
128  for( std::vector< osg::ref_ptr< WROI > >::const_iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
129  {
130  ret.push_back( ( *iter ) );
131  }
132  return ret;
133 }
134 
136 {
137  for( std::vector< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
138  {
139  WGraphicsEngine::getGraphicsEngine()->getScene()->remove( ( *iter ) );
140  }
141 
142  m_rois.clear();
143 }
144 
146 {
147  m_dirty->set( true );
148  m_roiManager->setDirty();
149 
150  for( std::list< std::shared_ptr< boost::function< void() > > >::iterator iter = m_changeNotifiers.begin();
151  iter != m_changeNotifiers.end(); ++iter )
152  {
153  ( **iter )();
154  }
155 }
156 
157 osg::ref_ptr< WROI > WRMBranch::getFirstRoi()
158 {
159  return m_rois.front();
160 }
161 
162 std::shared_ptr< WROIManager > WRMBranch::getRoiManager()
163 {
164  return m_roiManager;
165 }
166 
167 std::shared_ptr< WProperties > WRMBranch::getProperties()
168 {
169  return m_properties;
170 }
171 
172 void WRMBranch::addChangeNotifier( std::shared_ptr< boost::function< void() > > notifier )
173 {
174  std::unique_lock< std::shared_mutex > lock;
175  lock = std::unique_lock< std::shared_mutex >( m_associatedNotifiersLock );
176  m_changeNotifiers.push_back( notifier );
177  lock.unlock();
178 }
179 
180 void WRMBranch::removeChangeNotifier( std::shared_ptr< boost::function< void() > > notifier )
181 {
182  std::unique_lock< std::shared_mutex > lock;
183  lock = std::unique_lock< std::shared_mutex >( m_associatedNotifiersLock );
184  std::list< std::shared_ptr< boost::function< void() > > >::iterator it;
185  it = std::find( m_changeNotifiers.begin(), m_changeNotifiers.end(), notifier );
186  if( it != m_changeNotifiers.end() )
187  {
188  m_changeNotifiers.erase( it );
189  }
190  lock.unlock();
191 }
static std::shared_ptr< WGraphicsEngine > getGraphicsEngine()
Returns instance of the graphics engine.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
std::shared_ptr< WPropertyGroup > SPtr
shared pointer to object of this type
std::list< std::shared_ptr< boost::function< void() > > > m_changeNotifiers
The notifiers connected to added rois by default.
Definition: WRMBranch.h:247
void setDirty()
sets dirty flag true and notifies the branch
Definition: WRMBranch.cpp:145
WRMBranch(std::shared_ptr< WROIManager > roiManager)
construtor
Definition: WRMBranch.cpp:35
~WRMBranch()
destructor
Definition: WRMBranch.cpp:41
void addChangeNotifier(std::shared_ptr< boost::function< void() > > notifier)
Add a specified notifier to the list of default notifiers which get connected to each branch.
Definition: WRMBranch.cpp:172
std::shared_ptr< boost::function< void() > > m_changeRoiSignal
Signal that can be used to update the ROImanager branch.
Definition: WRMBranch.h:249
void removeChangeNotifier(std::shared_ptr< boost::function< void() > > notifier)
Remove a specified notifier from the list of default notifiers which get connected to each branch.
Definition: WRMBranch.cpp:180
std::vector< osg::ref_ptr< WROI > > m_rois
list of rois in this this branch,
Definition: WRMBranch.h:220
WPropertyGroup::SPtr getProperties() const
Get the properties of this branch as group.
Definition: WRMBranch.cpp:59
void addRoi(osg::ref_ptr< WROI > roi)
adds a roi to the branch
Definition: WRMBranch.cpp:84
std::shared_ptr< WProperties > m_properties
the property object for the module
Definition: WRMBranch.h:225
WPropBool invertProperty()
Get the "not" property.
Definition: WRMBranch.cpp:74
osg::ref_ptr< WROI > getFirstRoi()
returns a pointer to the first roi in the branch
Definition: WRMBranch.cpp:157
void removeAllRois()
removes all rois from the branch
Definition: WRMBranch.cpp:135
std::shared_ptr< WROIManager > m_roiManager
stores a pointer to the roi manager
Definition: WRMBranch.h:218
std::shared_ptr< WROIManager > getRoiManager()
getter for roi manager pointer
Definition: WRMBranch.cpp:162
WPropBool m_isNot
indicates if the branch is negated
Definition: WRMBranch.h:232
std::shared_mutex m_associatedNotifiersLock
Lock for associated notifiers set.
Definition: WRMBranch.h:254
WPropBool m_dirty
dirty flag to indicate if anything has changed within the branch
Definition: WRMBranch.h:227
WPropString nameProperty()
Get name property.
Definition: WRMBranch.cpp:69
bool contains(osg::ref_ptr< WROI > roi)
checks wether a roi is in this branch
Definition: WRMBranch.cpp:91
WPropString m_name
Name property.
Definition: WRMBranch.h:242
void propertyChanged()
slot gets called when a property has changed
Definition: WRMBranch.cpp:64
WPropColor colorProperty()
The branch color property.
Definition: WRMBranch.cpp:79
WPropColor m_bundleColor
The color used when in isosurface mode for blending.
Definition: WRMBranch.h:237
void properties()
initializes properties
Definition: WRMBranch.cpp:45
std::vector< osg::ref_ptr< WROI > > getRois() const
Create a list of ROIs of the current point in time.
Definition: WRMBranch.cpp:125
void removeRoi(osg::ref_ptr< WROI > roi)
removes a roi from the branch
Definition: WRMBranch.cpp:103
std::vector< osg::ref_ptr< WROI > > ROIs
ROI list.
Definition: WROIManager.h:183