Commit b7be281a authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] added module for reading VIM particle files.

parent 7ce5d8c1
......@@ -3,6 +3,7 @@ ADD_MODULE( fiberTranslator )
ADD_MODULE( readAmiraMesh )
ADD_MODULE( readMesh )
ADD_MODULE( readRawData )
ADD_MODULE( readVIM )
ADD_MODULE( writeAmiraMesh )
ADD_MODULE( writeDendrogram )
ADD_MODULE( writeMesh )
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <fstream>
#include <string>
#include <vector>
#include "core/kernel/WKernel.h"
#include "core/common/WPathHelper.h"
#include "core/common/WStringUtils.h"
#include "WMReadVIM.h"
// 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.
W_LOADABLE_MODULE( WMReadVIM )
WMReadVIM::WMReadVIM():
WModule()
{
// Init
}
WMReadVIM::~WMReadVIM()
{
// Cleanup!
}
boost::shared_ptr< WModule > WMReadVIM::factory() const
{
return boost::shared_ptr< WModule >( new WMReadVIM() );
}
const std::string WMReadVIM::getName() const
{
// Specify your module name here. This name must be UNIQUE!
return "Read VIM";
}
const std::string WMReadVIM::getDescription() const
{
// Specify your module description here. Be detailed. This text is read by the user.
return "This module reads VIM files containing particle data.";
}
void WMReadVIM::connectors()
{
m_output = WModuleOutputData < WDataSetPoints >::createAndAdd( shared_from_this(), "out", "The loaded dataset" );
// call WModule's initialization
WModule::connectors();
}
void WMReadVIM::properties()
{
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
m_filename = m_properties->addProperty( "VIM file", "The VIM file to load", WPathHelper::getAppPath() );
WPropertyHelper::PC_PATHEXISTS::addTo( m_filename );
m_aTrigger = m_properties->addProperty( "Read", "Read file.", WPVBaseTypes::PV_TRIGGER_READY,
m_propCondition );
WModule::properties();
}
void WMReadVIM::moduleMain()
{
m_moduleState.setResetable( true, true );
m_moduleState.add( m_propCondition );
// Signal ready state. Now your module can be connected by the container, which owns the module.
ready();
waitRestored();
// main loop
while( !m_shutdownFlag() )
{
m_moduleState.wait();
// woke up since the module is requested to finish
if( m_shutdownFlag() )
{
break;
}
if( m_aTrigger->get( true ) == WPVBaseTypes::PV_TRIGGER_TRIGGERED )
{
// open file
boost::filesystem::path p = m_filename->get();
std::ifstream ifs;
ifs.open( p.string().c_str(), std::ifstream::in );
if( !ifs || ifs.bad() )
{
errorLog() << "Could not open file \"" << p.string() << "\".";
continue;
}
boost::shared_ptr< WProgress > progress1 = boost::shared_ptr< WProgress >( new WProgress( "Loading" ) );
m_progress->addSubProgress( progress1 );
// target memory
WDataSetPoints::VertexArray vertices( new WDataSetPoints::VertexArray::element_type() );
WDataSetPoints::ColorArray colors( new WDataSetPoints::ColorArray::element_type() );
WBoundingBox bb;
infoLog() << "Start Loading ...";
// interpret file
std::string line;
std::vector< std::string > tokens;
size_t numPoints = 0;
while( !ifs.eof() )
{
std::getline( ifs, line );
tokens = string_utils::tokenize( line );
if( ( tokens.size() == 9 ) && ( tokens[ 0 ] == "!" ) ) // mathc
{
// coordinate:
WVector3f coord(
string_utils::fromString< float >( tokens[2] ),
string_utils::fromString< float >( tokens[3] ),
string_utils::fromString< float >( tokens[4] )
);
// expand bb
bb.expandBy( coord );
// read 3rd to 5th number
vertices->push_back( coord.x() );
vertices->push_back( coord.y() );
vertices->push_back( coord.z() );
colors->push_back( 1.0 );
colors->push_back( 1.0 );
colors->push_back( 1.0 );
numPoints++;
}
}
infoLog() << "Loaded " << numPoints << " points from file. Done.";
// finally provide output data
boost::shared_ptr< WDataSetPoints> newOutput( new WDataSetPoints( vertices, colors, bb ) );
m_output->updateData( newOutput );
// done. close file and report finish
progress1->finish();
ifs.close();
m_aTrigger->set( WPVBaseTypes::PV_TRIGGER_READY, false );
}
}
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMREADVIM_H
#define WMREADVIM_H
#include <string>
#include "core/dataHandler/WDataSetPoints.h"
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleOutputData.h"
/**
* This module is intended to allow the user to filter a fiber dataset using the current ROI config
*
* \ingroup modules
*/
class WMReadVIM: public WModule
{
public:
/**
* Default constructor.
*/
WMReadVIM();
/**
* Destructor.
*/
virtual ~WMReadVIM();
/**
* Gives back the name of this module.
* \return the module's name.
*/
virtual const std::string getName() const;
/**
* Gives back a description of this module.
* \return description to module.
*/
virtual const std::string getDescription() const;
/**
* Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
* should never be initialized or modified in some other way. A simple new instance is required.
*
* \return the prototype used to create every module in OpenWalnut.
*/
virtual boost::shared_ptr< WModule > factory() const;
protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual void moduleMain();
/**
* Initialize the connectors this module is using.
*/
virtual void connectors();
/**
* Initialize the properties for this module.
*/
virtual void properties();
private:
/**
* The output connector for the filtered data.
*/
boost::shared_ptr< WModuleOutputData< WDataSetPoints > > m_output;
/**
* A condition used to notify about changes in several properties.
*/
boost::shared_ptr< WCondition > m_propCondition;
/**
* Trigger read
*/
WPropTrigger m_aTrigger;
/**
* The file to load
*/
WPropFilename m_filename;
};
#endif // WMREADVIM_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
// Provide additional material and descriptions for your module. You can
// provide this for multiple modules if you like.
// NOTE: everything but the module name is optional, even if this makes no
// sense at all.
// This defines some properties of the module "Template". This must
// match the name specified in WMTemplate::getName().
"Read VIM"
{
// Provide an icon. If the icon exists, it overrides the one provided by your
// getXPMIcon method. This path is relative to your module's resource directory.
icon="icon.png";
// Where to find the module?
website = "http://www.openwalnut.org";
// Provide a description, If you do so, this description overrides the one
// provided by your getDescription method.
// HINT: multi-line strings are not supported. Please provide long texts in
// one line.
description = "This module reads VIM files. containing particle data.";
// Provide a list of authors. These authors can have further information associated with them.
author = "OpenWalnut Project";
// Provide author information. Especially a contact address is very handy.
// This associates some URL and Mail contact info to "OpenWalnut Project".
"OpenWalnut Project"
{
url="http://www.openwalnut.org";
email="contact@openwalnut.org";
what="Design, Development and Bug fixing";
};
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment