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
//---------------------------------------------------------------------------
30
#include "WMDistanceMapIsosurface.h"
31
#include "WMDistanceMapIsosurface.xpm"
33
#include "core/kernel/WKernel.h"
34
#include "core/kernel/WModuleFactory.h"
35
#include "core/kernel/WPrototypeRequirement.h"
36
#include "core/dataHandler/WSubject.h"
37
#include "core/dataHandler/WGridRegular3D.h"
39
// This line is needed by the module loader to actually find your module.
40
W_LOADABLE_MODULE( WMDistanceMapIsosurface )
42
WMDistanceMapIsosurface::WMDistanceMapIsosurface():
43
WModuleContainer( "Distance Map Isosurface",
44
"Computes a smoothed version of the dataset"
45
" and a distance map on it. Finally it renders"
46
" this distance map using an isosurface. This isosurface"
47
" can be textured with values from scalar data sets in order to display"
48
" the structures at the given distance."
49
" This is <b>only</b> useful for peeled data." )
51
// WARNING: initializing connectors inside the constructor will lead to an exception.
52
// NOTE: Do not use the module factory inside this constructor. This will cause a dead lock as the module factory is locked
53
// during construction of this instance and can then not be used to create another instance (Isosurface in this case). If you
54
// want to initialize some modules using the module factory BEFORE the moduleMain() call, overwrite WModule::initialize().
57
WMDistanceMapIsosurface::~WMDistanceMapIsosurface()
61
boost::shared_ptr< WModule > WMDistanceMapIsosurface::factory() const
63
return boost::shared_ptr< WModule >( new WMDistanceMapIsosurface() );
66
const char** WMDistanceMapIsosurface::getXPMIcon() const
68
return distancemapIsosurface_xpm;
71
void WMDistanceMapIsosurface::moduleMain()
73
//////////////////////////////////////////////////////////////////////////////////
75
//////////////////////////////////////////////////////////////////////////////////
77
// create an instance using the prototypes
78
m_marchingCubesModule = WModuleFactory::getModuleFactory()->create( WModuleFactory::getModuleFactory()->getPrototypeByName( "Isosurface" ) );
80
// add the marching cubes to the container
81
add( m_marchingCubesModule );
83
// now wait for it to be ready
84
m_marchingCubesModule->isReady().wait();
85
boost::shared_ptr< WProperties > mcProps = m_marchingCubesModule->getProperties();
86
m_isoValueProp = mcProps->getProperty( "Iso value" )->toPropDouble();
87
m_isoValueProp->set( 0.2 );
88
m_isoValueProp->setMin( 0.0 );
89
m_isoValueProp->setMax( 1.0 );
90
m_properties->addProperty( m_isoValueProp );
93
m_useTextureProp = mcProps->getProperty( "Use texture" )->toPropBool();
94
m_useTextureProp->set( true );
95
m_properties->addProperty( m_useTextureProp );
97
m_surfaceColorProp = mcProps->getProperty( "Surface color" )->toPropColor();
98
m_properties->addProperty( m_surfaceColorProp );
100
m_opacityProp = mcProps->getProperty( "Opacity %" )->toPropInt();
101
m_properties->addProperty( m_opacityProp );
104
//////////////////////////////////////////////////////////////////////////////////
106
//////////////////////////////////////////////////////////////////////////////////
108
// create a new instance of WMDistanceMap
109
m_distanceMapModule = WModuleFactory::getModuleFactory()->create( WModuleFactory::getModuleFactory()->getPrototypeByName( "Distance Map" ) );
111
// add it to the container
112
add( m_distanceMapModule );
114
// wait until it is ready
115
m_distanceMapModule->isReady().wait();
117
//////////////////////////////////////////////////////////////////////////////////
118
// Hard wire both modules
119
//////////////////////////////////////////////////////////////////////////////////
121
// NOTE: you can use the WModuleContainer::applyModule functions here, which, in this case, is possible, since the connectors
122
// can be connected unambiguously (one to one connection). But to show how hard wiring works, we do it manually here.
123
m_marchingCubesModule->getInputConnector( "values" )->connect( m_distanceMapModule->getOutputConnector( "out" ) );
124
// this is the same as doing it the other way around.
125
// m_distanceMapModule->getOutputConnector( "out" )->connect( m_marchingCubesModule->getInputConnector( "values" ) );
126
// simple, isn't it? ;-)
128
//////////////////////////////////////////////////////////////////////////////////
129
// Setup forwarding of this modules connectors with the contained ones
130
//////////////////////////////////////////////////////////////////////////////////
132
// connect the distance map output to the container output to ensure other modules can use the distance map if they want to
133
m_output->forward( m_distanceMapModule->getOutputConnector( "out" ) );
134
// we want the container input connector "in" to be connected to the input of WMDistanceMap
135
m_input->forward( m_distanceMapModule->getInputConnector( "in" ) );
137
//////////////////////////////////////////////////////////////////////////////////
138
// Done! Modules are set up.
139
//////////////////////////////////////////////////////////////////////////////////
141
// signal ready state
144
// wait for stop request
147
// stop container and the contained modules.
151
void WMDistanceMapIsosurface::connectors()
153
// initialize connectors
155
// this is the scalar field input
156
m_input = boost::shared_ptr< WModuleInputForwardData< WDataSetScalar > >(
157
new WModuleInputForwardData< WDataSetScalar >( shared_from_this(),
158
"in", "Dataset to compute distance map for." )
161
// add it to the list of connectors. Please note, that a connector NOT added via addConnector will not work as expected.
162
addConnector( m_input );
164
// this output is used to provide the distance map to other modules.
165
m_output = boost::shared_ptr< WModuleOutputForwardData< WDataSetScalar > >(
166
new WModuleOutputForwardData< WDataSetScalar >( shared_from_this(),
167
"out", "Distance map for the input data set." )
170
// add it to the list of connectors. Please note, that a connector NOT added via addConnector will not work as expected.
171
addConnector( m_output );
173
// call WModules initialization
174
WModule::connectors();
177
void WMDistanceMapIsosurface::requirements()
179
m_requirements.push_back( new WPrototypeRequirement( "Distance Map" ) );
180
m_requirements.push_back( new WPrototypeRequirement( "Isosurface" ) );
183
void WMDistanceMapIsosurface::activate()
185
m_marchingCubesModule->getProperties()->getProperty( "active" )->toPropBool()->set( m_active->get() );