~ubuntu-branches/ubuntu/precise/openwalnut/precise

« back to all changes in this revision

Viewing changes to src/modules/distanceMapIsosurface/WMDistanceMapIsosurface.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Eichelbaum
  • Date: 2011-06-21 10:26:54 UTC
  • Revision ID: james.westby@ubuntu.com-20110621102654-rq0zf436q949biih
Tags: upstream-1.2.5
ImportĀ upstreamĀ versionĀ 1.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <stdint.h>
 
26
#include <string>
 
27
#include <algorithm>
 
28
#include <vector>
 
29
 
 
30
#include "WMDistanceMapIsosurface.h"
 
31
#include "WMDistanceMapIsosurface.xpm"
 
32
 
 
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"
 
38
 
 
39
// This line is needed by the module loader to actually find your module.
 
40
W_LOADABLE_MODULE( WMDistanceMapIsosurface )
 
41
 
 
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." )
 
50
{
 
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().
 
55
}
 
56
 
 
57
WMDistanceMapIsosurface::~WMDistanceMapIsosurface()
 
58
{
 
59
}
 
60
 
 
61
boost::shared_ptr< WModule > WMDistanceMapIsosurface::factory() const
 
62
{
 
63
    return boost::shared_ptr< WModule >( new WMDistanceMapIsosurface() );
 
64
}
 
65
 
 
66
const char** WMDistanceMapIsosurface::getXPMIcon() const
 
67
{
 
68
    return distancemapIsosurface_xpm;
 
69
}
 
70
 
 
71
void WMDistanceMapIsosurface::moduleMain()
 
72
{
 
73
    //////////////////////////////////////////////////////////////////////////////////
 
74
    // Marching Cubes
 
75
    //////////////////////////////////////////////////////////////////////////////////
 
76
 
 
77
    // create an instance using the prototypes
 
78
    m_marchingCubesModule = WModuleFactory::getModuleFactory()->create( WModuleFactory::getModuleFactory()->getPrototypeByName( "Isosurface" ) );
 
79
 
 
80
    // add the marching cubes to the container
 
81
    add( m_marchingCubesModule );
 
82
 
 
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 );
 
91
 
 
92
 
 
93
    m_useTextureProp = mcProps->getProperty( "Use texture" )->toPropBool();
 
94
    m_useTextureProp->set( true );
 
95
    m_properties->addProperty( m_useTextureProp );
 
96
 
 
97
    m_surfaceColorProp = mcProps->getProperty( "Surface color" )->toPropColor();
 
98
    m_properties->addProperty( m_surfaceColorProp );
 
99
 
 
100
    m_opacityProp = mcProps->getProperty( "Opacity %" )->toPropInt();
 
101
    m_properties->addProperty( m_opacityProp );
 
102
 
 
103
 
 
104
    //////////////////////////////////////////////////////////////////////////////////
 
105
    // Distance Map
 
106
    //////////////////////////////////////////////////////////////////////////////////
 
107
 
 
108
    // create a new instance of WMDistanceMap
 
109
    m_distanceMapModule = WModuleFactory::getModuleFactory()->create( WModuleFactory::getModuleFactory()->getPrototypeByName( "Distance Map" ) );
 
110
 
 
111
    // add it to the container
 
112
    add( m_distanceMapModule );
 
113
 
 
114
    // wait until it is ready
 
115
    m_distanceMapModule->isReady().wait();
 
116
 
 
117
    //////////////////////////////////////////////////////////////////////////////////
 
118
    // Hard wire both modules
 
119
    //////////////////////////////////////////////////////////////////////////////////
 
120
 
 
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? ;-)
 
127
 
 
128
    //////////////////////////////////////////////////////////////////////////////////
 
129
    // Setup forwarding of this modules connectors with the contained ones
 
130
    //////////////////////////////////////////////////////////////////////////////////
 
131
 
 
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" ) );
 
136
 
 
137
    //////////////////////////////////////////////////////////////////////////////////
 
138
    // Done! Modules are set up.
 
139
    //////////////////////////////////////////////////////////////////////////////////
 
140
 
 
141
    // signal ready state
 
142
    ready();
 
143
 
 
144
    // wait for stop request
 
145
    waitForStop();
 
146
 
 
147
    // stop container and the contained modules.
 
148
    stop();
 
149
}
 
150
 
 
151
void WMDistanceMapIsosurface::connectors()
 
152
{
 
153
    // initialize connectors
 
154
 
 
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." )
 
159
        );
 
160
 
 
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 );
 
163
 
 
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." )
 
168
        );
 
169
 
 
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 );
 
172
 
 
173
    // call WModules initialization
 
174
    WModule::connectors();
 
175
}
 
176
 
 
177
void WMDistanceMapIsosurface::requirements()
 
178
{
 
179
    m_requirements.push_back( new WPrototypeRequirement( "Distance Map" ) );
 
180
    m_requirements.push_back( new WPrototypeRequirement( "Isosurface" ) );
 
181
}
 
182
 
 
183
void WMDistanceMapIsosurface::activate()
 
184
{
 
185
    m_marchingCubesModule->getProperties()->getProperty( "active" )->toPropBool()->set( m_active->get() );
 
186
}
 
187