Commit bdff4b80 authored by Robin Eschbach's avatar Robin Eschbach
Browse files

Merge branch 'sprint_2' into 'hs-worms/TOP-2021'

[MERGE #40] Sprint 2

See merge request top/21s/sivert-vis/sivert-vis-project!19
parents 2ec37447 4786b3ab
......@@ -24,7 +24,7 @@
#include "WDataSetCSV.h"
WDataSetCSV::WDataSetCSV( WDataSetCSV::Content header, WDataSetCSV::Content data )
WDataSetCSV::WDataSetCSV( WDataSetCSV::ContentSPtr header, WDataSetCSV::ContentSPtr data )
: m_header( header ), m_data( data )
{
}
......@@ -37,12 +37,12 @@ WDataSetCSV::~WDataSetCSV()
{
}
WDataSetCSV::Content WDataSetCSV::getHeader()
WDataSetCSV::ContentSPtr WDataSetCSV::getHeader()
{
return m_header;
}
WDataSetCSV::Content WDataSetCSV::getData()
WDataSetCSV::ContentSPtr WDataSetCSV::getData()
{
return m_data;
}
......@@ -39,7 +39,12 @@ public:
/**
* represents a vector containing a vector of strings.
*/
typedef std::vector< std::vector<std::string> > Content;
typedef std::vector< std::vector< std::string > > Content;
/**
* represents a pointer to the Content
*/
typedef boost::shared_ptr< std::vector< std::vector< std::string > > > ContentSPtr;
/**
* Construct WDataSetCSV object
......@@ -47,7 +52,7 @@ public:
* \param header Column names of the CSV file.
* \param data Data content of the CSV file.
*/
explicit WDataSetCSV( Content header, Content data );
explicit WDataSetCSV( WDataSetCSV::ContentSPtr header, WDataSetCSV::ContentSPtr data );
/**
* The standard constructor.
......@@ -64,25 +69,25 @@ public:
*
* \return m_header as WDataSetCSV::Content object
*/
WDataSetCSV::Content getHeader();
WDataSetCSV::ContentSPtr getHeader();
/**
* Getter method to receive csv data
*
* \return m_data as WDataSetCSV::Content object
*/
WDataSetCSV::Content getData();
WDataSetCSV::ContentSPtr getData();
private:
/**
* Stores the column titles of a loaded CSV file.
*/
Content m_header;
WDataSetCSV::ContentSPtr m_header;
/**
* Stores the data of a loaded CSV file.
*/
Content m_data;
WDataSetCSV::ContentSPtr m_data;
};
#endif // WDATASETCSV_H
......@@ -28,7 +28,7 @@
#include <vector>
#include <boost/shared_ptr.hpp>
#include <cxxtest/Testsuite.h>
#include <cxxtest/TestSuite.h>
#include "../WDataSetPointsAndSizes.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/>.
//
//---------------------------------------------------------------------------
#include <string>
#include <vector>
#include "WMConverterCSV.h"
W_LOADABLE_MODULE( WMConverterCSV )
WMConverterCSV::WMConverterCSV():
WModule()
{
}
WMConverterCSV::~WMConverterCSV()
{
}
const std::string WMConverterCSV::getName() const
{
return "FilterProtonData";
}
const std::string WMConverterCSV::getDescription() const
{
return "Converter CSV-data To WDataSetPoints and WDataSetFibers";
}
boost::shared_ptr< WModule > WMConverterCSV::factory() const
{
return boost::shared_ptr< WModule >( new WMConverterCSV() );
}
const char** WMConverterCSV::getXPMIcon() const
{
return NULL;
}
void WMConverterCSV::moduleMain()
{
m_moduleState.setResetable( true, true );
m_moduleState.add( m_input->getDataChangedCondition() );
ready();
waitRestored();
while( !m_shutdownFlag() )
{
m_moduleState.wait();
boost::shared_ptr< WDataSetCSV > dataset = m_input->getData();
WDataSetCSV::Content m_csvHeader = dataset->getHeader();
WDataSetCSV::Content m_csvData = dataset->getData();
setPointsOutOfCSVData( m_csvHeader, m_csvData );
setFibersOutOfCSVData( m_csvHeader, m_csvData );
}
}
void WMConverterCSV::connectors()
{
m_input = WModuleInputData< WDataSetCSV >::createAndAdd( shared_from_this(), "in", "CSV_input" );
m_output_points = boost::shared_ptr< WModuleOutputData< WDataSet > >(
new WModuleOutputData< WDataSet >(
shared_from_this(),
"output points",
"Output CSV data as Point data" )
);
m_output_fibers = boost::shared_ptr< WModuleOutputData< WDataSet > >(
new WModuleOutputData< WDataSet >(
shared_from_this(),
"output fibers",
"Output CSV data as Fiber data" )
);
addConnector( m_output_points );
addConnector( m_output_fibers );
WModule::connectors();
}
void WMConverterCSV::properties()
{
}
int WMConverterCSV::getColumnNumberByName( std::string columnNameToMatch, std::vector<std::string> headerToSearchIn )
{
int pos = 0;
for( std::vector<std::string>::iterator it = headerToSearchIn.begin(); it != headerToSearchIn.end(); it++ )
{
if( *it == columnNameToMatch ) return pos;
pos++;
}
return pos;
}
void WMConverterCSV::setFibersOutOfCSVData( WDataSetCSV::Content header, WDataSetCSV::Content data )
{
SPFloatVector m_vertices = SPFloatVector( new std::vector<float>() );
SPSizeVector m_lineStartIndexes = SPSizeVector( new std::vector < size_t >() );
SPSizeVector m_lineLengths = SPSizeVector( new std::vector < size_t >() );
SPSizeVector m_verticesReverse = SPSizeVector( new std::vector < size_t >() );
SPFloatVector m_colors = SPFloatVector( new std::vector< float >() );
std::vector< int > eventIDs;
std::vector< float > edeps;
int xPosIndex = getColumnNumberByName( "posX", header.at( 0 ) );
int yPosIndex = getColumnNumberByName( "posY", header.at( 0 ) );
int zPosIndex = getColumnNumberByName( "posZ", header.at( 0 ) );
int eventIDIndex = getColumnNumberByName( "eventID", header.at( 0 ) );
int parentIDIndex = getColumnNumberByName( "parentID", header.at( 0 ) );
int edepIndex = getColumnNumberByName( "edep", header.at( 0 ) );
float maxEdep = 0.0;
for( WDataSetCSV::Content::iterator dataRow = data.begin(); dataRow != data.end(); dataRow++ )
{
float posX, posY, posZ, edep;
int eventID;
if( dataRow->empty() )
{
continue;
}
if(std::stoi( dataRow->at(parentIDIndex ) ) != 0 )
{
continue;
}
posX = boost::lexical_cast< float >( dataRow->at( xPosIndex ) );
posY = boost::lexical_cast< float >( dataRow->at( yPosIndex ) );
posZ = boost::lexical_cast< float >( dataRow->at( zPosIndex ) );
eventID = std::stoi( dataRow->at( eventIDIndex ) );
edep = boost::lexical_cast< float >( dataRow->at( edepIndex ) );
if( edep > maxEdep )
{
maxEdep = edep;
}
m_vertices->push_back( posX );
m_vertices->push_back( posY );
m_vertices->push_back( posZ );
eventIDs.push_back( eventID );
edeps.push_back( edep );
}
for( std::vector< float >::iterator currentEdep = edeps.begin(); currentEdep != edeps.end(); currentEdep++ )
{
*currentEdep = *currentEdep / maxEdep;
m_colors->push_back( *currentEdep * 1000 );
m_colors->push_back( *currentEdep * 100 );
m_colors->push_back( *currentEdep * 10 );
}
int fiberLength = 0;
int fiberStartIndex = 0;
int reversePos = 0;
int currentEventID = eventIDs.at( 0 );
m_lineStartIndexes->push_back( fiberStartIndex );
for(std::vector<int>::iterator eID = eventIDs.begin(); eID != eventIDs.end(); eID++ )
{
if(currentEventID != *eID )
{
currentEventID = *eID;
m_lineStartIndexes->push_back( fiberStartIndex );
m_lineLengths->push_back( fiberLength );
fiberLength = 0;
reversePos++;
}
fiberLength++;
fiberStartIndex++;
m_verticesReverse->push_back( reversePos );
}
m_lineLengths->push_back( fiberLength );
m_fibers = boost::shared_ptr< WDataSetFibers >(
new WDataSetFibers(
m_vertices,
m_lineStartIndexes,
m_lineLengths,
m_verticesReverse
)
);
m_fibers->addColorScheme( m_colors, "Energy deposition", "Color fibers based on their energy." );
m_output_fibers->updateData( m_fibers );
}
void WMConverterCSV::setPointsOutOfCSVData( WDataSetCSV::Content header, WDataSetCSV::Content data )
{
SPFloatVector m_vertices = SPFloatVector( new std::vector< float >() );
SPFloatVector m_colors = SPFloatVector( new std::vector< float >() );
SPFloatVector m_sizes = SPFloatVector( new std::vector< float >() );
int xPosIndex = getColumnNumberByName( "posX", header.at( 0 ) );
int yPosIndex = getColumnNumberByName( "posY", header.at( 0 ) );
int zPosIndex = getColumnNumberByName( "posZ", header.at( 0 ) );
int edepIndex = getColumnNumberByName( "edep", header.at( 0 ) );
float posX, posY, posZ, edep;
for(WDataSetCSV::Content::iterator dataRow = data.begin(); dataRow != data.end(); dataRow++ )
{
if( dataRow->empty() )
{
continue;
}
posX = boost::lexical_cast< float >( dataRow->at( xPosIndex ) );
posY = boost::lexical_cast< float >( dataRow->at( yPosIndex ) );
posZ = boost::lexical_cast< float >( dataRow->at( zPosIndex ) );
edep = boost::lexical_cast< float >( dataRow->at( edepIndex ) );
m_vertices->push_back( posX );
m_vertices->push_back( posY );
m_vertices->push_back( posZ );
m_sizes->push_back( edep );
// TODO(robin.eschbach): disable this, when #35 is done
m_colors->push_back( 0 );
m_colors->push_back( 0 );
m_colors->push_back( 0 );
}
m_points = boost::shared_ptr< WDataSetPointsAndSizes >(
new WDataSetPointsAndSizes(
m_vertices,
m_colors,
m_sizes
)
);
m_output_points->updateData( m_points );
}
......@@ -43,15 +43,15 @@ boost::shared_ptr< WDataSetCSV > WReaderCSV::read()
std::string cell;
std::vector< std::string > row;
WDataSetCSV::Content header;
WDataSetCSV::Content data;
WDataSetCSV::ContentSPtr header = WDataSetCSV::ContentSPtr( new WDataSetCSV::Content() );
WDataSetCSV::ContentSPtr data = WDataSetCSV::ContentSPtr( new WDataSetCSV::Content() );
std::fstream file;
file.open( m_fname );
if( !file.is_open() )
{
//throw()
throw WException( "File could not be opened!" );
}
while( std::getline( file, col ) )
......@@ -63,13 +63,13 @@ boost::shared_ptr< WDataSetCSV > WReaderCSV::read()
{
row.push_back( cell );
}
data.push_back( row );
data->push_back( row );
}
file.close();
header.push_back( data.at( 0 ) );
data.erase( data.begin() );
header->push_back( data->at( 0 ) );
data->erase( data->begin() );
return boost::shared_ptr< WDataSetCSV >( new WDataSetCSV( header, data ) );
}
......@@ -55,7 +55,8 @@ public:
/**
* Read the file and create a dataset as a vector.
*
* \return pointer to a WDataSetCSV
* \return pointer to a WDataSetCSV.
* \throws WException If the file could not be opened.
*/
virtual boost::shared_ptr< WDataSetCSV > read();
};
......
//---------------------------------------------------------------------------
//
// 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 "WMConverterIndexes.h"
WMConverterIndexes::WMConverterIndexes()
{
}
void WMConverterIndexes::update( WMProtonData::SPtr protonData )
{
m_parentID = protonData->getColumnIndex( "parentID" );
m_posX = protonData->getColumnIndex( "posX" );
m_posY = protonData->getColumnIndex( "posY" );
m_posZ = protonData->getColumnIndex( "posZ" );
m_edep = protonData->getColumnIndex( "edep" );
m_PDGEncoding = protonData->getColumnIndex( "PDGEncoding" );
m_eventID = protonData->getColumnIndex( "eventID" );
}
int WMConverterIndexes::getParentID()
{
return m_parentID;
}
int WMConverterIndexes::getPosX()
{
return m_posX;
}
int WMConverterIndexes::getPosY()
{
return m_posY;
}
int WMConverterIndexes::getPosZ()
{
return m_posZ;
}
int WMConverterIndexes::getEdep()
{
return m_edep;
}
int WMConverterIndexes::getPDGEncoding()
{
return m_PDGEncoding;
}
int WMConverterIndexes::getEventID()
{
return m_eventID;
}
//---------------------------------------------------------------------------
//
// 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 WMCONVERTERINDEXES_H
#define WMCONVERTERINDEXES_H
#include <boost/shared_ptr.hpp>
#include "WMProtonData.h"
/**
* Holds the indexes of the columns and is able to update them.
*/
class WMConverterIndexes
{
public:
/**
* A shared_ptr to this class.
*/
typedef boost::shared_ptr< WMConverterIndexes > SPtr;
/**
* Empty constructor for class creation.
*/
WMConverterIndexes();
/**
* Updates the indexes based on the data given.
* \param protonData The data which contains the columns.
*/
void update( WMProtonData::SPtr protonData );
/**
* Gets the parentID index as integer.
* \return int The parentID index.
*/
int getParentID();
/**
* Gets the posX index as integer.
* \return int The posX index.
*/
int getPosX();
/**
* Gets the posY index as integer.
* \return int The posY index.
*/
int getPosY();
/**
* Gets the posZ index as integer.
* \return int The posZ index.
*/
int getPosZ();
/**
* Gets the edep index as integer.
* \return int The edep index.
*/
int getEdep();
/**
* Gets the PDGEncoding index as integer.
* \return int The PDGEncoding index.
*/
int getPDGEncoding();
/**
* Gets the eventID index as integer.
* \return int The eventID index.
*/
int getEventID();
private:
int m_parentID = -1; //<! The parentID index.
int m_posX = -1; //<! The posX index.
int m_posY = -1; //<! The posY index.
int m_posZ = -1; //<! The posZ index.
int m_edep = -1; //<! The edep index.
int m_PDGEncoding = -1; //<! The PDGEncoding index.
int m_eventID = -1; //<! The eventID index.
};
#endif // WMCONVERTERINDEXES_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.