1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
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.
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.
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/>.
23
//---------------------------------------------------------------------------
28
#include "core/kernel/WKernel.h"
30
#include "core/common/WColor.h"
31
#include "core/common/WPropertyHelper.h"
33
#include "WMScalarSegmentation.xpm"
34
#include "WMScalarSegmentation.h"
36
// This line is needed by the module loader to actually find your module.
37
W_LOADABLE_MODULE( WMScalarSegmentation )
39
WMScalarSegmentation::WMScalarSegmentation():
43
m_algos.push_back( boost::shared_ptr< WSegmentationAlgo >( new WSegmentationAlgoThreshold() ) );
45
m_algos.push_back( boost::shared_ptr< WSegmentationAlgo >( new WSegmentationAlgoWatershed() ) );
46
m_algos.push_back( boost::shared_ptr< WSegmentationAlgo >( new WSegmentationAlgoOtsu() ) );
47
m_algos.push_back( boost::shared_ptr< WSegmentationAlgo >( new WSegmentationAlgoRegionGrowingConfidenceConnected() ) );
48
m_algos.push_back( boost::shared_ptr< WSegmentationAlgo >( new WSegmentationAlgoLevelSetCanny() ) );
52
WMScalarSegmentation::~WMScalarSegmentation()
57
boost::shared_ptr< WModule > WMScalarSegmentation::factory() const
59
return boost::shared_ptr< WModule >( new WMScalarSegmentation() );
62
const char** WMScalarSegmentation::getXPMIcon() const
64
return scalarSegmentation_xpm;
67
const std::string WMScalarSegmentation::getName() const
69
return "Scalar Segmentation";
72
const std::string WMScalarSegmentation::getDescription() const
74
return "This module segments scalar datasets.";
77
void WMScalarSegmentation::connectors()
79
m_input = boost::shared_ptr< WModuleInputData < WDataSetScalar > >(
80
new WModuleInputData< WDataSetScalar >( shared_from_this(), "inputSet", "The dataset to segment." )
83
addConnector( m_input );
85
m_output = boost::shared_ptr< WModuleOutputData < WDataSetScalar > >(
86
new WModuleOutputData< WDataSetScalar >( shared_from_this(), "outputSet", "The calculated dataset." )
89
addConnector( m_output );
91
WModule::connectors();
94
void WMScalarSegmentation::properties()
96
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
98
m_algoSelection = boost::shared_ptr< WItemSelection >( new WItemSelection );
99
for( AlgoList::iterator it = m_algos.begin(); it != m_algos.end(); ++it )
101
m_algoSelection->addItem( ( *it )->getName(), ( *it )->getDescription() );
103
m_algoType = m_properties->addProperty( "Segmentation algorithm", "Choose a segmentation method.",
104
m_algoSelection->getSelectorFirst(), m_propCondition );
106
for( AlgoList::iterator it = m_algos.begin(); it != m_algos.end(); ++it )
108
( *it )->initProperties( m_properties->addPropertyGroup( ( *it )->getName(), "The properties for this segmentation algorithm.", true ) );
111
m_algos.at( 0 )->hideProperties( false );
113
WPropertyHelper::PC_SELECTONLYONE::addTo( m_algoType );
114
WPropertyHelper::PC_NOTEMPTY::addTo( m_algoType );
116
WModule::properties();
119
void WMScalarSegmentation::moduleMain()
121
m_moduleState.setResetable( true, true );
122
m_moduleState.add( m_input->getDataChangedCondition() );
123
m_moduleState.add( m_propCondition );
124
for( AlgoList::iterator it = m_algos.begin(); it != m_algos.end(); ++it )
126
m_moduleState.add( ( *it )->getCondition() );
131
while( !m_shutdownFlag() )
133
m_moduleState.wait();
135
if( m_shutdownFlag() )
140
boost::shared_ptr< WDataSetScalar > newDataSet = m_input->getData();
141
bool dataChanged = ( m_dataSet != newDataSet );
142
bool dataValid = ( newDataSet );
144
if( dataChanged && dataValid )
146
m_dataSet = newDataSet;
147
if( !m_dataSet->getValueSet() || !m_dataSet->getGrid()
148
|| m_dataSet->getValueSet()->dimension() != 1 || m_dataSet->getValueSet()->order() != 0 )
150
m_dataSet = boost::shared_ptr< WDataSetScalar >();
154
bool algoChanged = m_algoType->changed();
158
WItemSelector w = m_algoType->get( true );
159
m_algos.at( m_algoIndex )->hideProperties( true );
160
m_algoIndex = w.getItemIndexOfSelected( 0 );
161
m_algos.at( m_algoIndex )->hideProperties( false );
164
bool propChanged = m_algos.at( m_algoIndex )->propChanged();
165
if( m_dataSet && ( dataChanged || propChanged || algoChanged ) )
169
m_output->updateData( m_result );
173
for( AlgoList::iterator it = m_algos.begin(); it != m_algos.end(); ++it )
175
m_moduleState.remove( ( *it )->getCondition() );
179
void WMScalarSegmentation::activate()
184
void WMScalarSegmentation::doSegmentation()
186
debugLog() << "Starting segmentation.";
187
m_result = m_algos.at( m_algoIndex )->segment( m_dataSet );
188
debugLog() << "Segmentation finished.";