OpenWalnut  1.4.0
WSelectorBranch.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 <vector>
27 
28 #include "WSelectorBranch.h"
29 
30 WSelectorBranch::WSelectorBranch( boost::shared_ptr< const WDataSetFibers > fibers, boost::shared_ptr<WRMBranch> branch ) :
31  m_fibers( fibers ),
32  m_size( fibers->size() ),
33  m_dirty( true ),
34  m_branch( branch )
35 {
36  m_bitField = boost::shared_ptr< std::vector<bool> >( new std::vector<bool>( m_size, false ) );
37 
39  boost::shared_ptr< boost::function< void() > >( new boost::function< void() >( boost::bind( &WSelectorBranch::setDirty, this ) ) );
40  m_branch->addChangeNotifier( m_changeSignal );
41 
43  boost::shared_ptr< boost::function< void() > >( new boost::function< void() >( boost::bind( &WSelectorBranch::setDirty, this ) ) );
44 }
45 
47 {
48  m_branch->removeChangeNotifier( m_changeSignal );
49 
50  // We need the following because not all ROIs are removed per slot below
51  for( std::list< boost::shared_ptr< WSelectorRoi > >::iterator roiIter = m_rois.begin(); roiIter != m_rois.end(); ++roiIter )
52  {
53  ( *roiIter )->getRoi()->removeROIChangeNotifier( m_changeRoiSignal );
54  }
55 }
56 
57 void WSelectorBranch::addRoi( boost::shared_ptr< WSelectorRoi > roi )
58 {
59  m_rois.push_back( roi );
60  roi->getRoi()->addROIChangeNotifier( m_changeRoiSignal );
61 }
62 
63 std::list< boost::shared_ptr< WSelectorRoi > > WSelectorBranch::getROIs()
64 {
65  return m_rois;
66 }
67 
69 {
70  m_dirty = true;
71 }
72 
73 void WSelectorBranch::removeRoi( osg::ref_ptr< WROI > roi )
74 {
75  for( std::list< boost::shared_ptr< WSelectorRoi > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
76  {
77  if( ( *iter )->getRoi() == roi )
78  {
79  ( *iter )->getRoi()->removeROIChangeNotifier( m_changeRoiSignal );
80  m_rois.erase( iter );
81  break;
82  }
83  }
84 }
85 
87 {
88  bool atLeastOneActive = false;
89 
90  for( std::list< boost::shared_ptr< WSelectorRoi > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
91  {
92  if( ( *iter )->getRoi()->active() )
93  {
94  atLeastOneActive = true;
95  }
96  }
97 
98  if( atLeastOneActive )
99  {
100  m_workerBitfield = boost::shared_ptr< std::vector< bool > >( new std::vector< bool >( m_size, true ) );
101 
102  for( std::list< boost::shared_ptr< WSelectorRoi > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
103  {
104  if( ( *iter )->getRoi()->active() )
105  {
106  boost::shared_ptr< std::vector<bool> > bf = ( *iter )->getBitField();
107  bool isnot = ( *iter )->getRoi()->isNot();
108  if( !isnot )
109  {
110  for( size_t i = 0 ; i < m_size ; ++i )
111  {
112  ( *m_workerBitfield )[i] = ( *m_workerBitfield )[i] & ( *bf )[i];
113  }
114  }
115  else
116  {
117  for( size_t i = 0 ; i < m_size ; ++i )
118  {
119  ( *m_workerBitfield )[i] = ( *m_workerBitfield )[i] & !( *bf )[i];
120  }
121  }
122  }
123  }
124 
125  if( m_branch->isNot() )
126  {
127  for( size_t i = 0 ; i < m_size ; ++i )
128  {
129  ( *m_workerBitfield )[i] = !( *m_workerBitfield )[i];
130  }
131  }
132  }
133  else
134  {
135  m_workerBitfield = boost::shared_ptr< std::vector< bool > >( new std::vector< bool >( m_size, false ) );
136  }
137 
139 }
140 
142 {
143  return m_branch->colorProperty()->toPropColor()->get( true );
144 }
WSelectorBranch(boost::shared_ptr< const WDataSetFibers > fibers, boost::shared_ptr< WRMBranch > branch)
constructor
boost::shared_ptr< std::vector< bool > > m_workerBitfield
the bitfield we work on
bool m_dirty
dirty flag
size_t m_size
size of the fiber dataset, stored for convinience
void recalculate()
updates the output bitfield with the information from all rois in this branch
boost::shared_ptr< boost::function< void() > > m_changeSignal
Signal that can be used to update the selector branch.
void setDirty()
Sets the dirty flag.
boost::shared_ptr< boost::function< void() > > m_changeRoiSignal
Signal that can be used to update the selector branch.
std::list< boost::shared_ptr< WSelectorRoi > > m_rois
list of rois in this branch
~WSelectorBranch()
destructor
void addRoi(boost::shared_ptr< WSelectorRoi > roi)
adds a roi to the branch
boost::shared_ptr< std::vector< bool > > m_bitField
the bitfield given to the outside world
boost::shared_ptr< WRMBranch > m_branch
pointer to the branch object in the roi manager
void removeRoi(osg::ref_ptr< WROI > roi)
Removes a roi fromt he branch.
WColor getBranchColor() const
Return the current branch color.
std::list< boost::shared_ptr< WSelectorRoi > > getROIs()
Queries the ROIs.