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