Commit c519a05c authored by Hung Dang-Quoc's avatar Hung Dang-Quoc
Browse files

Merge branch 'top2021s3/#60_support_new_csv_dataset' into 'sprint_3'

[MERGE #60] Top2021s3/#60 support new csv dataset,

See merge request top/21s/sivert-vis/sivert-vis-project!26
parents 339f5a31 4e74122a
......@@ -29,12 +29,13 @@
WMCsvConverter::WMCsvConverter( WMProtonData::SPtr protonData, boost::shared_ptr< WMPropertyStatus > propertyStatus )
{
m_protonData = protonData;
m_propertyStatus = propertyStatus;
m_vectors = WMConverterVectors::SPtr( new WMConverterVectors() );
m_indexes = WMConverterIndexes::SPtr( new WMConverterIndexes() );
setOutputFromCSV( protonData );
setOutputFromCSV( );
}
boost::shared_ptr< WDataSetFibers > WMCsvConverter::getFibers()
......@@ -47,6 +48,47 @@ boost::shared_ptr< WDataSetPoints > WMCsvConverter::getPoints()
return m_points;
}
void WMCsvConverter::setOutputFromCSV( )
{
if( !m_protonData->isRequiredDataAvailable() )
{
return;
}
WDataSetCSV::ContentSPtr data = m_protonData->getCSVData();
m_plainColor = m_propertyStatus->getVisualizationPropertyHandler()->getColorSelection()->get( true );
m_vectors->clear();
m_indexes->update( m_protonData );
float maxEdep = 0.0;
for( WDataSetCSV::Content::iterator dataRow = data->begin(); dataRow < data->end(); dataRow++ )
{
if( !canShow( dataRow ) )
{
continue;
}
addVertex( dataRow );
addColor( dataRow );
addEdepAndSize( dataRow, &maxEdep );
addEventID( dataRow );
}
if( checkIfOutputIsNull() )
{
return;
}
normalizeEdeps( m_vectors->getEdeps(), m_vectors->getColors(), maxEdep );
createOutputPoints();
createOutputFibers();
}
boost::shared_ptr< WDataSetSingle > WMCsvConverter::getTransferFunction()
{
return m_transferFunction;
......@@ -65,23 +107,31 @@ boost::shared_ptr< std::vector<unsigned char> > WMCsvConverter::sampleTransferFu
void WMCsvConverter::normalizeEdeps( SPFloatVector edeps, SPFloatVector colorArray, float maxEdep )
{
boost::shared_ptr< std::vector<unsigned char> > data = sampleTransferFunction();
setTransferFunction( data );
for( std::vector< float >::iterator currentEdep = edeps->begin(); currentEdep != edeps->end(); currentEdep++ )
if( m_protonData->isColumnAvailable( "edep" ) )
{
int clusterSize = 9.0 *( ( 2.4 * ( pow( *currentEdep, 0.338 ) ) ) / 4.0 );
float r = data->at( clusterSize * 4 ) / 255.0;
float g = data->at( clusterSize * 4 + 1 ) / 255.0;
float b = data->at( clusterSize * 4 + 2 ) / 255.0;
float a = data->at( clusterSize * 4 + 3 ) / 255.0;
colorArray->push_back( r );
colorArray->push_back( g );
colorArray->push_back( b );
colorArray->push_back( a );
if( m_propertyStatus->getVisualizationPropertyHandler()->getColorFromEdep()->get() )
{
boost::shared_ptr< std::vector< unsigned char > > data = sampleTransferFunction();
setTransferFunction( data );
for( std::vector< float >::iterator currentEdep = edeps->begin();
currentEdep != edeps->end();
currentEdep++ )
{
int clusterSize = 9.0 * ( ( 2.4 * ( pow( *currentEdep, 0.338 ) ) ) / 4.0 );
float r = data->at( clusterSize * 4 ) / 255.0;
float g = data->at( clusterSize * 4 + 1 ) / 255.0;
float b = data->at( clusterSize * 4 + 2 ) / 255.0;
float a = data->at( clusterSize * 4 + 3 ) / 255.0;
colorArray->push_back( r );
colorArray->push_back( g );
colorArray->push_back( b );
colorArray->push_back( a );
}
}
}
}
......@@ -92,36 +142,62 @@ bool WMCsvConverter::canShow( WDataSetCSV::Content::iterator dataRow )
return false;
}
if( !m_propertyStatus->getFilterPropertyHandler()->getShowPrimaries()->get() && std::stoi( dataRow->at( m_indexes->getParentID() ) ) == 0 )
if( m_protonData->isColumnAvailable( "parentID" ) &&
m_protonData->isColumnAvailable( "trackID" ) )
{
return false;
}
if( !m_propertyStatus->getFilterPropertyHandler()->getShowPrimaries()->get() && std::stoi( dataRow->at( m_indexes->getParentID() ) ) == 0 )
{
return false;
}
if( !m_propertyStatus->getFilterPropertyHandler()->getShowSecondaries()->get() && std::stoi( dataRow->at( m_indexes->getParentID() ) ) != 0 )
{
return false;
if( !m_propertyStatus->getFilterPropertyHandler()->getShowSecondaries()->get() && std::stoi( dataRow->at( m_indexes->getParentID() ) ) != 0 )
{
return false;
}
}
if( !m_propertyStatus->getFilterPropertyHandler()->isPDGTypeSelected( std::stoi( dataRow->at( m_propertyStatus->getFilterPropertyHandler()->getCurrentColumnIndex() ) ) ) )
if( m_protonData->isColumnAvailable( "PDGEncoding" ) )
{
return false;
if( !m_propertyStatus->getFilterPropertyHandler()->isPDGTypeSelected(
std::stoi( dataRow->at( m_indexes->getPDGEncoding( ) ) ) ) )
{
return false;
}
}
int eventID = std::stoi( dataRow->at( m_indexes->getEventID() ) );
if( eventID < m_propertyStatus->getEventIDLimitationPropertyHandler()->getMinCap()->get() ||
eventID > m_propertyStatus->getEventIDLimitationPropertyHandler()->getMaxCap()->get() )
if( m_protonData->isColumnAvailable("eventID"))
{
return false;
if(dataRow->at( m_indexes->getEventID() ) == "NULL")
{
return true;
}
int eventID = std::stoi( dataRow->at( m_indexes->getEventID() ) );
if( eventID < m_propertyStatus->getEventIDLimitationPropertyHandler()->getMinCap()->get() ||
eventID > m_propertyStatus->getEventIDLimitationPropertyHandler()->getMaxCap()->get() )
{
return false;
}
}
return true;
}
void WMCsvConverter::addVertexAndColor( WDataSetCSV::Content::iterator dataRow )
void WMCsvConverter::addVertex( WDataSetCSV::Content::iterator dataRow )
{
m_vectors->getVertices()->push_back( boost::lexical_cast< float >( dataRow->at( m_indexes->getPosX() ) ) );
m_vectors->getVertices()->push_back( boost::lexical_cast< float >( dataRow->at( m_indexes->getPosY() ) ) );
m_vectors->getVertices()->push_back( boost::lexical_cast< float >( dataRow->at( m_indexes->getPosZ() ) ) );
}
void WMCsvConverter::addColor( WDataSetCSV::Content::iterator dataRow )
{
if(!m_protonData->isColumnAvailable("edep"))
{
m_vectors->getColors()->push_back( 0 );
m_vectors->getColors()->push_back( 0 );
m_vectors->getColors()->push_back( 0 );
}
if( !m_propertyStatus->getVisualizationPropertyHandler()->getColorFromEdep()->get() )
{
......@@ -133,6 +209,11 @@ void WMCsvConverter::addVertexAndColor( WDataSetCSV::Content::iterator dataRow )
void WMCsvConverter::addEdepAndSize( WDataSetCSV::Content::iterator dataRow, float* maxEdep )
{
if( !m_protonData->isColumnAvailable( "edep" ) )
{
return;
}
float edep = boost::lexical_cast< float >( dataRow->at( m_indexes->getEdep() ) );
if( edep > *maxEdep )
{
......@@ -144,6 +225,11 @@ void WMCsvConverter::addEdepAndSize( WDataSetCSV::Content::iterator dataRow, flo
void WMCsvConverter::calculateFibers()
{
if(!m_protonData->isColumnAvailable("eventID"))
{
return;
}
int fiberLength = 0;
int fiberStartIndex = 0;
int reversePos = 0;
......@@ -171,80 +257,75 @@ void WMCsvConverter::calculateFibers()
m_vectors->getFiberLengths()->push_back( fiberLength );
}
void WMCsvConverter::createPointsAndFibers()
void WMCsvConverter::createOutputPoints()
{
if( m_propertyStatus->getVisualizationPropertyHandler()->getSizesFromEdep()->get() )
if( m_protonData->isColumnAvailable( "edep" ) )
{
m_points = boost::shared_ptr< WDataSetPointsAndSizes >(
new WDataSetPointsAndSizes(
m_vectors->getVertices(),
m_vectors->getColors(),
m_vectors->getSizes()
)
);
}
else
{
m_points = boost::shared_ptr < WDataSetPoints >(
new WDataSetPoints(
m_vectors->getVertices(),
m_vectors->getColors()
)
);
if( m_propertyStatus->getVisualizationPropertyHandler()->getSizesFromEdep()->get() )
{
m_points = boost::shared_ptr< WDataSetPointsAndSizes >(
new WDataSetPointsAndSizes(
m_vectors->getVertices(),
m_vectors->getColors(),
m_vectors->getSizes()
)
);
return;
}
}
m_fibers = boost::shared_ptr< WDataSetFibers >(
new WDataSetFibers(
m_points = boost::shared_ptr < WDataSetPoints >(
new WDataSetPoints(
m_vectors->getVertices(),
m_vectors->getFiberStartIndexes(),
m_vectors->getFiberLengths(),
m_vectors->getVerticesReverse()
m_vectors->getColors()
)
);
m_fibers->addColorScheme( m_vectors->getColors(), "Energy deposition", "Color fibers based on their energy." );
}
void WMCsvConverter::setOutputFromCSV( WMProtonData::SPtr protonData )
void WMCsvConverter::createOutputFibers()
{
if( !protonData->columnsInitialized() )
calculateFibers();
if(!m_protonData->isColumnAvailable("eventID"))
{
m_fibers = boost::shared_ptr< WDataSetFibers >(
new WDataSetFibers(
SPFloatVector( new std::vector< float >() ),
SPSizeVector( new std::vector< size_t >() ),
SPSizeVector( new std::vector< size_t >() ),
SPSizeVector( new std::vector< size_t >() )
)
);
return;
}
WDataSetCSV::ContentSPtr data = protonData->getCSVData();
m_plainColor = m_propertyStatus->getVisualizationPropertyHandler()->getColorSelection()->get( true );
m_vectors->clear();
m_indexes->update( protonData );
float maxEdep = 0.0;
for( WDataSetCSV::Content::iterator dataRow = data->begin(); dataRow < data->end(); dataRow++ )
else
{
if( !canShow( dataRow ) )
{
continue;
}
addVertexAndColor( dataRow );
addEdepAndSize( dataRow, &maxEdep );
m_vectors->getEventIDs()->push_back( std::stoi( dataRow->at( m_indexes->getEventID() ) ) );
m_fibers = boost::shared_ptr< WDataSetFibers >(
new WDataSetFibers(
m_vectors->getVertices(),
m_vectors->getFiberStartIndexes(),
m_vectors->getFiberLengths(),
m_vectors->getVerticesReverse()
)
);
}
if( checkIfOutputIsNull() )
if(m_protonData->isColumnAvailable("edep"))
{
return;
m_fibers->addColorScheme( m_vectors->getColors(), "Energy deposition", "Color fibers based on their energy." );
}
}
if( m_propertyStatus->getVisualizationPropertyHandler()->getColorFromEdep()->get() )
{
normalizeEdeps( m_vectors->getEdeps(), m_vectors->getColors(), maxEdep );
}
void WMCsvConverter::addEventID( WDataSetCSV::Content::iterator dataRow )
{
if(m_protonData->isColumnAvailable("eventID"))
{
if(dataRow->at( m_indexes->getEventID() ) == "NULL")
{
return;
}
calculateFibers();
createPointsAndFibers();
m_vectors->getEventIDs()->push_back( std::stoi( dataRow->at( m_indexes->getEventID() ) ) );
}
}
void WMCsvConverter::setTransferFunction( boost::shared_ptr< std::vector<unsigned char> > data )
......
......@@ -89,6 +89,11 @@ public:
boost::shared_ptr< WDataSetSingle > getTransferFunction();
private:
/**
* Stores information form csv content. Content object containing data
*/
WMProtonData::SPtr m_protonData;
/**
* Stores information for the fiber display
*/
......@@ -146,11 +151,18 @@ private:
bool canShow( WDataSetCSV::Content::iterator dataRow );
/**
* Create vertex and color for point renderer (vertex for fiber renderer)
* Create vertex for point/fiber renderer
*
* \param dataRow each row of the csv file (content of row)
*/
void addVertexAndColor( WDataSetCSV::Content::iterator dataRow );
void addVertex( WDataSetCSV::Content::iterator dataRow );
/**
* Create color for point/Fiber renderer
*
* \param dataRow each row of the csv file (content of row)
*/
void addColor( WDataSetCSV::Content::iterator dataRow );
/**
* Create edep and sizes for point/fiber renderer
......@@ -160,22 +172,32 @@ private:
*/
void addEdepAndSize( WDataSetCSV::Content::iterator dataRow, float* maxEdep );
/**
* Create eventID for Fiber renderer
*
* \param dataRow each row of the csv file (content of row)
*/
void addEventID( WDataSetCSV::Content::iterator dataRow );
/**
* calculate the property of WDataSetFiber (index, length, verticesReverse)
*/
void calculateFibers();
/**
* Create the fibers and points for fiber/points renderer
* Create the fibers for fiber renderer
*/
void createPointsAndFibers();
void createOutputFibers();
/**
* Create the points for points renderer
*/
void createOutputPoints();
/**
* Create outputs, so it can be displayed by the fiber display and the point renderer.
*
* \param protonData WDataSetCSV::Content object containing data.
*/
void setOutputFromCSV( WMProtonData::SPtr protonData );
void setOutputFromCSV( );
/**
* Creates output for transfer function
......
......@@ -83,20 +83,24 @@ void WMFilterProtonData::moduleMain()
m_propertyStatus->setColumnPropertyHandler( WMColumnPropertyHandler::SPtr( new WMColumnPropertyHandler( m_protonData, m_properties,
boost::bind( &WMFilterProtonData::setOutputFromCSV, this ) ) ) );
m_propertyStatus->setFilterPropertyHandler( WMFilterPropertyHandler::SPtr( new WMFilterPropertyHandler( m_protonData, m_properties,
m_propertyStatus->getColumnPropertyHandler(), boost::bind( &WMFilterProtonData::setOutputFromCSV, this ) ) ) );
m_propertyStatus->setFilterPropertyHandler( WMFilterPropertyHandler::SPtr( new WMFilterPropertyHandler( m_protonData, m_properties,
boost::bind( &WMFilterProtonData::setOutputFromCSV, this ) ) ) );
m_propertyStatus->setVisualizationPropertyHandler( WMVisualizationPropertyHandler::SPtr(
new WMVisualizationPropertyHandler( m_protonData, m_properties, boost::bind( &WMFilterProtonData::setOutputFromCSV, this ) ) ) );
m_propertyStatus->setEventIDLimitationPropertyHandler( WMEventIDLimitationPropertyHandler::SPtr(
new WMEventIDLimitationPropertyHandler( m_protonData, m_properties, boost::bind( &WMFilterProtonData::setOutputFromCSV, this ) ) ) );
m_propertyStatus->getColumnPropertyHandler()->setSelectionEventMethod( boost::bind( &WMFilterProtonData::updateProperty, this ) );
}
else
{
m_protonData->setCSVHeader( m_input->getData()->getHeader() );
m_protonData->setCSVData( m_input->getData()->getData() );
}
m_propertyStatus->getFilterPropertyHandler()->createPDGMap(
( m_localPath / getMetaInformation()->query< std::string >( "common/pdgnames" , "NoFile" ) ).string() );
m_propertyStatus->getColumnPropertyHandler()->createProperties();
m_propertyStatus->getFilterPropertyHandler()->createProperties();
m_propertyStatus->getVisualizationPropertyHandler()->createProperties();
......@@ -122,7 +126,7 @@ void WMFilterProtonData::properties()
WModule::properties();
}
void WMFilterProtonData::setOutputFromCSV( )
void WMFilterProtonData::setOutputFromCSV()
{
m_converter = boost::shared_ptr< WMCsvConverter >( new WMCsvConverter( m_protonData, m_propertyStatus ) );
......@@ -130,3 +134,11 @@ void WMFilterProtonData::setOutputFromCSV( )
m_output_fibers->updateData( m_converter->getFibers() );
m_output_transferFunction->updateData( m_converter->getTransferFunction() );
}
void WMFilterProtonData::updateProperty()
{
m_propertyStatus->getColumnPropertyHandler()->updateProperty();
m_propertyStatus->getFilterPropertyHandler()->updateProperty();
m_propertyStatus->getVisualizationPropertyHandler()->updateProperty();
m_propertyStatus->getEventIDLimitationPropertyHandler()->updateProperty();
}
......@@ -164,6 +164,12 @@ private:
* Create outputs, so it can be displayed by the fiber display and the point renderer.
*/
void setOutputFromCSV( );
/**
* update added group property and subproperty
*/
void updateProperty();
};
#endif // WMFILTERPROTONDATA_H
......@@ -31,6 +31,8 @@ WMProtonData::WMProtonData( WDataSetCSV::ContentSPtr csvHeader, WDataSetCSV::Con
{
setCSVHeader( csvHeader );
setCSVData( csvData );
updateAvailabilityOfColumns();
}
void WMProtonData::setCSVHeader( WDataSetCSV::ContentSPtr csvHeader )
......@@ -45,7 +47,7 @@ void WMProtonData::setCSVHeader( WDataSetCSV::ContentSPtr csvHeader )
// TODO(robin.eschbach) change csvheader type to vector< string > or maybe to map
std::vector< std::string > header = m_csvHeader->at( 0 );
for( auto i = 0; i < header.size(); i++ )
for( size_t i = 0; i < header.size(); i++ )
{
m_columnMap[header[i]] = i;
}
......@@ -69,6 +71,14 @@ WDataSetCSV::ContentSPtr WMProtonData::getCSVHeader()
void WMProtonData::setColumnIndex( std::string columnName, int index )
{
m_columnMap[columnName] = index;
if( index < 0 )
{
m_availabilityColumnMap[columnName] = false;
}
else
{
m_availabilityColumnMap[columnName] = true;
}
}
int WMProtonData::getColumnIndex( std::string columnName )
......@@ -81,13 +91,13 @@ int WMProtonData::getColumnIndex( std::string columnName )
return m_columnMap[columnName];
}
bool WMProtonData::columnsInitialized()
bool WMProtonData::isRequiredDataAvailable()
{
static const std::string necessaryColumns[] = {
"PDGEncoding", "posX", "posY", "posZ", "edep", "eventID", "trackID", "parentID"
"posX", "posY", "posZ"
};
for( int i = 0; i < sizeof( necessaryColumns ) / sizeof( std::string ); i++ )
for( size_t i = 0; i < sizeof( necessaryColumns ) / sizeof( std::string ); i++ )
{
std::string column = necessaryColumns[i];
if( getColumnIndex( column ) < 0 )
......@@ -98,3 +108,47 @@ bool WMProtonData::columnsInitialized()
return true;
}
bool WMProtonData::isNonrequiredDataAvailable()
{
static const std::string unNecessaryColumns[] = {
"PDGEncoding", "edep", "trackID", "parentID", "eventID"
};
for( size_t i = 0; i < sizeof( unNecessaryColumns ) / sizeof( std::string ); i++ )
{
std::string column = unNecessaryColumns[i];
if( getColumnIndex( column ) < 0 )
{
return true;
}
}
return false;
}
bool WMProtonData::isColumnAvailable( std::string columnName )
{
return m_availabilityColumnMap[columnName];
}
void WMProtonData::updateAvailabilityOfColumns()
{
static const std::string necessaryColumns[] = {
"PDGEncoding", "posX", "posY", "posZ", "edep", "eventID" , "trackID", "parentID"
};
std::cout << std::endl;
for( size_t i = 0; i < sizeof( necessaryColumns ) / sizeof( std::string ); i++ )
{
std::string column = necessaryColumns[i];
if( getColumnIndex( column ) < 0 )
{
m_availabilityColumnMap[column] = false;
}
else
{
m_availabilityColumnMap[column] = true;
}
}
}
......@@ -98,7 +98,21 @@ public:
*
* \return true when initialized. false if they are not initialized
*/
bool columnsInitialized();
bool isRequiredDataAvailable();
/**
* checks whether columns are missing
*
* \return true if column is missing . false if column is not missing
*/
bool isNonrequiredDataAvailable();
/**
* checks whether columns are available
*
* \return true if column is available . false if column is not available
*/
bool isColumnAvailable( std::string columnName );
private:
/**
......@@ -115,6 +129,16 @@ private: