OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 "WROI.h"
26 
27 #include "WPickHandler.h"
28 
29 WROI::WROI() :
30  osg::Geode()
31 {
32  properties();
33 }
34 
36 {
37 }
38 
40 {
41  m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "This ROI's properties" ) );
42 
43  m_active = m_properties->addProperty( "active", "", true, boost::bind( &WROI::propertyChanged, this ) );
44  m_active->setHidden( true );
45 
46  m_show = m_properties->addProperty( "Show", "Toggles visibility of the roi", true, boost::bind( &WROI::propertyChanged, this ) );
47 
48  m_dirty = m_properties->addProperty( "Dirty", "", true ); // boost::bind( &WROI::propertyChanged, this ) );
49  m_dirty->setHidden( true );
50 
51  m_not = m_properties->addProperty( "Not", "Negates the effect of this ROI.", false, boost::bind( &WROI::propertyChanged, this ) );
52 }
53 
55 {
56  if( m_show->changed() )
57  {
58  if( m_show->get( true ) )
59  {
60  unhide();
61  }
62  else
63  {
64  hide();
65  }
66  }
67 
68  setDirty();
69 }
70 
71 boost::shared_ptr<WProperties> WROI::getProperties()
72 {
73  return m_properties;
74 }
75 
76 void WROI::setNot( bool isNot )
77 {
78  m_not->set( isNot );
79  setDirty();
80 }
81 
83 {
84  return m_not->get();
85 }
86 
88 {
89  return m_active->get();
90 }
91 
92 void WROI::setActive( bool active )
93 {
94  m_active->set( active );
95  setDirty();
96 }
97 
99 {
100  m_dirty->set( true );
101  signalRoiChange();
102 }
103 
105 {
106  return m_dirty->get();
107 }
108 
110 {
111  setNodeMask( 0x0 );
112 }
113 
115 {
116  setNodeMask( 0xFFFFFFFF );
117 }
118 
120 {
121  for( std::list< boost::shared_ptr< boost::function< void() > > >::iterator iter = m_changeNotifiers.begin();
122  iter != m_changeNotifiers.end(); ++iter )
123  {
124  ( **iter )();
125  }
126 }
127 
128 void WROI::addROIChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier )
129 {
130  boost::unique_lock< boost::shared_mutex > lock;
131  lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock );
132  m_changeNotifiers.push_back( notifier );
133  lock.unlock();
134 }
135 
136 void WROI::removeROIChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier )
137 {
138  boost::unique_lock< boost::shared_mutex > lock;
139  lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock );
140  std::list< boost::shared_ptr< boost::function< void() > > >::iterator it;
141  it = std::find( m_changeNotifiers.begin(), m_changeNotifiers.end(), notifier );
142  if( it != m_changeNotifiers.end() )
143  {
144  m_changeNotifiers.erase( it );
145  }
146  lock.unlock();
147 }