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