OpenWalnut  1.4.0
WROI.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 <string>
27 
28 #include "WROI.h"
29 #include "WPickHandler.h"
30 
31 WROI::WROI():
32  osg::Geode()
33 {
34  properties();
35 }
36 
38 {
39 }
40 
42 {
43  m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "This ROI's properties" ) );
44 
45  m_name = m_properties->addProperty( "Name", "The name of this ROI.", std::string( "ROI" ) );
46  m_active = m_properties->addProperty( "Active", "Enable or disable the ROI.", true, boost::bind( &WROI::propertyChanged, this ) );
47  m_show = m_properties->addProperty( "Show", "Toggles visibility of the ROI but does not disable it.", true,
48  boost::bind( &WROI::propertyChanged, this ) );
49  m_not = m_properties->addProperty( "Not", "Negates the effect of this ROI.", false, boost::bind( &WROI::propertyChanged, this ) );
50  m_dirty = m_properties->addProperty( "Dirty", "", true ); // boost::bind( &WROI::propertyChanged, this ) );
51  m_dirty->setHidden( true );
52 }
53 
55 {
56  return m_not;
57 }
58 
59 WPropBool WROI::showProperty()
60 {
61  return m_show;
62 }
63 
64 WPropString WROI::nameProperty()
65 {
66  return m_name;
67 }
68 
70 {
71  return m_active;
72 }
73 
75 {
76  if( m_show->changed() )
77  {
78  if( m_show->get( true ) )
79  {
80  unhide();
81  }
82  else
83  {
84  hide();
85  }
86  }
87 
88  setDirty();
89 }
90 
91 boost::shared_ptr<WProperties> WROI::getProperties()
92 {
93  return m_properties;
94 }
95 
96 void WROI::setNot( bool isNot )
97 {
98  m_not->set( isNot );
99  setDirty();
100 }
101 
103 {
104  return m_not->get();
105 }
106 
108 {
109  return m_active->get();
110 }
111 
112 void WROI::setActive( bool active )
113 {
114  m_active->set( active );
115  setDirty();
116 }
117 
119 {
120  m_dirty->set( true );
121  signalRoiChange();
122 }
123 
125 {
126  return m_dirty->get();
127 }
128 
130 {
131  setNodeMask( 0x0 );
132 }
133 
135 {
136  setNodeMask( 0xFFFFFFFF );
137 }
138 
140 {
141  for( std::list< boost::shared_ptr< boost::function< void() > > >::iterator iter = m_changeNotifiers.begin();
142  iter != m_changeNotifiers.end(); ++iter )
143  {
144  ( **iter )();
145  }
146 }
147 
148 void WROI::addROIChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier )
149 {
150  boost::unique_lock< boost::shared_mutex > lock;
151  lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock );
152  m_changeNotifiers.push_back( notifier );
153  lock.unlock();
154 }
155 
156 void WROI::removeROIChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier )
157 {
158  boost::unique_lock< boost::shared_mutex > lock;
159  lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock );
160  std::list< boost::shared_ptr< boost::function< void() > > >::iterator it;
161  it = std::find( m_changeNotifiers.begin(), m_changeNotifiers.end(), notifier );
162  if( it != m_changeNotifiers.end() )
163  {
164  m_changeNotifiers.erase( it );
165  }
166  lock.unlock();
167 }
WPropBool showProperty()
The property for toggling ROI visibility.
Definition: WROI.cpp:59
void setDirty()
sets the dirty flag
Definition: WROI.cpp:118
WPropString nameProperty()
The name property.
Definition: WROI.cpp:64
boost::shared_ptr< WProperties > getProperties()
Getter.
Definition: WROI.cpp:91
boost::shared_mutex m_associatedNotifiersLock
Lock for associated notifiers set.
Definition: WROI.h:223
WPropBool invertProperty()
Invert property.
Definition: WROI.cpp:54
WPropBool m_show
indicates if the roi is visible in the scene
Definition: WROI.h:192
void setActive(bool active)
setter
Definition: WROI.cpp:112
void removeROIChangeNotifier(boost::shared_ptr< boost::function< void() > > notifier)
Remove a specified notifier from the list of default notifiers which get connected to each roi...
Definition: WROI.cpp:156
WPropBool m_active
indicates if the roi is active
Definition: WROI.h:187
void propertyChanged()
callback when a property gets changed
Definition: WROI.cpp:74
void signalRoiChange()
signals a roi change to all subscribers
Definition: WROI.cpp:139
bool isNot()
getter for NOT flag
Definition: WROI.cpp:102
void properties()
initializes the roi's properties
Definition: WROI.cpp:41
boost::shared_ptr< WProperties > m_properties
the property object for the module
Definition: WROI.h:176
void properties()
initializes properties
Definition: WRMBranch.cpp:45
WPropString m_name
name of the ROI.
Definition: WROI.h:202
WPropBool m_dirty
dirty flag, indicating the graphics needs updating, it is no longer used for bitfield updating since ...
Definition: WROI.h:182
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
bool active()
getter
Definition: WROI.cpp:107
std::list< boost::shared_ptr< boost::function< void() > > > m_changeNotifiers
The notifiers connected to added rois by default.
Definition: WROI.h:217
WPropBool m_not
indicates if the roi is negated
Definition: WROI.h:197
void unhide()
unhides the roi in the scene
Definition: WROI.cpp:134
void addROIChangeNotifier(boost::shared_ptr< boost::function< void() > > notifier)
Add a specified notifier to the list of default notifiers which get connected to each roi...
Definition: WROI.cpp:148
virtual ~WROI()
Need virtual destructor because of virtual function.
Definition: WROI.cpp:37
WPropBool activeProperty()
The active property.
Definition: WROI.cpp:69
void setNot(bool isNot=true)
sets the NOT flag
Definition: WROI.cpp:96
void hide()
hides the roi in the scene
Definition: WROI.cpp:129
bool dirty()
Getter for modified flag.
Definition: WROI.cpp:124