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
//---------------------------------------------------------------------------
29
#include "core/kernel/WKernel.h"
30
#include "core/common/WPathHelper.h"
31
#include "core/common/WStringUtils.h"
33
#include "WMReadVIM.h"
35
// This line is needed by the module loader to actually find your module. You need to add this to your module too. Do NOT add a ";" here.
36
W_LOADABLE_MODULE( WMReadVIM )
38
WMReadVIM::WMReadVIM():
44
WMReadVIM::~WMReadVIM()
49
boost::shared_ptr< WModule > WMReadVIM::factory() const
51
return boost::shared_ptr< WModule >( new WMReadVIM() );
54
const std::string WMReadVIM::getName() const
56
// Specify your module name here. This name must be UNIQUE!
60
const std::string WMReadVIM::getDescription() const
62
// Specify your module description here. Be detailed. This text is read by the user.
63
return "This module reads VIM files containing particle data.";
66
void WMReadVIM::connectors()
68
m_output = WModuleOutputData < WDataSetPoints >::createAndAdd( shared_from_this(), "out", "The loaded dataset" );
70
// call WModule's initialization
71
WModule::connectors();
74
void WMReadVIM::properties()
76
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
78
m_filename = m_properties->addProperty( "VIM file", "The VIM file to load", WPathHelper::getAppPath() );
79
WPropertyHelper::PC_PATHEXISTS::addTo( m_filename );
81
m_aTrigger = m_properties->addProperty( "Read", "Read file.", WPVBaseTypes::PV_TRIGGER_READY,
84
WModule::properties();
87
void WMReadVIM::moduleMain()
89
m_moduleState.setResetable( true, true );
90
m_moduleState.add( m_propCondition );
92
// Signal ready state. Now your module can be connected by the container, which owns the module.
97
while( !m_shutdownFlag() )
101
// woke up since the module is requested to finish
102
if( m_shutdownFlag() )
107
if( m_aTrigger->get( true ) == WPVBaseTypes::PV_TRIGGER_TRIGGERED )
110
boost::filesystem::path p = m_filename->get();
113
ifs.open( p.string().c_str(), std::ifstream::in );
114
if( !ifs || ifs.bad() )
116
errorLog() << "Could not open file \"" << p.string() << "\".";
120
boost::shared_ptr< WProgress > progress1( new WProgress( "Loading" ) );
121
m_progress->addSubProgress( progress1 );
124
WDataSetPoints::VertexArray vertices( new WDataSetPoints::VertexArray::element_type() );
125
WDataSetPoints::ColorArray colors( new WDataSetPoints::ColorArray::element_type() );
128
infoLog() << "Start Loading ...";
132
std::vector< std::string > tokens;
133
size_t numPoints = 0;
136
std::getline( ifs, line );
137
tokens = string_utils::tokenize( line );
139
if( ( tokens.size() == 9 ) && ( tokens[ 0 ] == "!" ) ) // mathc
143
string_utils::fromString< float >( tokens[2] ),
144
string_utils::fromString< float >( tokens[3] ),
145
string_utils::fromString< float >( tokens[4] )
149
bb.expandBy( coord );
151
// read 3rd to 5th number
152
vertices->push_back( coord.x() );
153
vertices->push_back( coord.y() );
154
vertices->push_back( coord.z() );
155
colors->push_back( 1.0 );
156
colors->push_back( 1.0 );
157
colors->push_back( 1.0 );
163
infoLog() << "Loaded " << numPoints << " points from file. Done.";
165
// finally provide output data
166
boost::shared_ptr< WDataSetPoints> newOutput( new WDataSetPoints( vertices, colors, bb ) );
167
m_output->updateData( newOutput );
169
// done. close file and report finish
172
m_aTrigger->set( WPVBaseTypes::PV_TRIGGER_READY, false );