Commit e5f52e42 authored by hungdangquoc's avatar hungdangquoc
Browse files

[FIX #140] new algorithm to save selected points

parent bfea5ce5
......@@ -97,20 +97,15 @@ void WEventIDLimitationPropertyHandler::determineMinMaxEventID()
}
}
std::cout << minCap << " | " << maxCap << std::endl << std::endl;
m_minCap->setMin( minCap );
m_minCap->setMax( maxCap );
m_maxCap->setMin( minCap );
m_maxCap->setMax( maxCap );
if( m_maxCap->get() > maxCap )
{
m_maxCap->set( maxCap );
}
if( m_minCap->get() < minCap )
{
m_minCap->set( minCap );
}
m_minCap->set( minCap );
m_maxCap->set( maxCap );
}
WPropInt WEventIDLimitationPropertyHandler::getMinCap()
......
......@@ -31,6 +31,7 @@
#include "WMWriteCSV.h"
#define STRING(num) #num
W_LOADABLE_MODULE( WMWriteCSV )
......@@ -131,9 +132,9 @@ void WMWriteCSV::propertyCallback()
writeToFile();
}
std::list< std::tuple < osg::Vec3, int > > WMWriteCSV::getListOfInternalVertex( WDataSetFibers::SPtr fibers )
std::list< std::tuple < float, float, float, int > > WMWriteCSV::getListOfInternalVertex( WDataSetFibers::SPtr fibers )
{
std::list< std::tuple < osg::Vec3, int > > listOfInternalVertex;
std::list< std::tuple < float, float, float, int > > listOfInternalVertex;
WDataSetFibers::VertexArray vertices = fibers->getVertices();
WDataSetFibers::IndexArray verticesReverse = fibers->getVerticesReverse();
......@@ -155,14 +156,21 @@ std::list< std::tuple < osg::Vec3, int > > WMWriteCSV::getListOfInternalVertex(
case 3:
{
osg::Vec3 vecVertex( vertexX, vertexY, vertexZ );
listOfInternalVertex.push_back( std::make_tuple( vecVertex, verticesReverse->at( reverseCounter++ ) ) );
if(idx < vertices->size())
listOfInternalVertex.push_back(
std::make_tuple(
vertexX,
vertexY,
vertexZ,
verticesReverse->at( reverseCounter++ ) ) );
if( idx < vertices->size() )
{
vertexX = vertices->at( idx );
}
vertexCounter = 0;
break;
}
}
......@@ -172,58 +180,57 @@ std::list< std::tuple < osg::Vec3, int > > WMWriteCSV::getListOfInternalVertex(
return listOfInternalVertex;
}
std::list< std::tuple < int, int > > WMWriteCSV::getListOfPositionAndID(
std::list< std::tuple < osg::Vec3, int > > listOfInternalVertex,
WDataSetPoints::SPtr points )
std::string WMWriteCSV::getPathToSave()
{
std::list< std::tuple < int, int > > listOfPositionAndID;
std::string sourceFilename = m_filename->get().string();
sourceFilename = sourceFilename.substr( 0, sourceFilename.find( ".csv" ) );
return sourceFilename + ".csv";
}
for( size_t pos = 0; pos < points->size(); pos++ )
std::string WMWriteCSV::getNewCSVHeader()
{
std::vector< std::string > csvHeader = m_CSVInput->getData()->getHeader()->at( 0 );
std::string newColumnName = "SelectedEventID";
size_t counter = 1;
while( std::find( csvHeader.begin(), csvHeader.end(), newColumnName ) != csvHeader.end() )
{
osg::Vec3 vertexPoints = points->operator[]( pos );
for( auto element = listOfInternalVertex.begin(); element != listOfInternalVertex.end(); element++ )
{
osg::Vec3 selectedVertex = std::get< 0 >( *element );
int selectedVertexIndex = std::get< 1 >( *element );
newColumnName = "SelectedEventID_" + boost::lexical_cast< std::string >( counter );
counter++;
}
if( vertexPoints.x() == selectedVertex.x() &&
vertexPoints.y() == selectedVertex.y() &&
vertexPoints.z() == selectedVertex.z() )
{
listOfInternalVertex.erase( element );
listOfPositionAndID.push_back( std::make_tuple( pos + 1, selectedVertexIndex ) );
break;
}
}
return newColumnName;
}
bool WMWriteCSV::contains( std::string sourceString, float num )
{
std::stringstream ss;
ss << num;
return sourceString.find( ss.str() ) != std::string::npos;
}
size_t WMWriteCSV::createStartCounter( std::list< std::tuple < float, float, float, int > > listOfInternalVertex )
{
size_t eventIDcounter = 0;
if( listOfInternalVertex.size() <= 0 )
for( auto element = listOfInternalVertex.begin(); element != listOfInternalVertex.end(); element++ )
{
int selectedVertexIndex = std::get< 3 >( *element );
if( eventIDcounter < selectedVertexIndex )
{
break;
eventIDcounter = selectedVertexIndex;
}
}
return listOfPositionAndID;
return eventIDcounter + 1;
}
void WMWriteCSV::writeToFile()
{
std::string sourceFilename = m_filename->get().string();
sourceFilename = sourceFilename.substr( 0, sourceFilename.find( ".csv" ) );
std::string outputFilename = sourceFilename + ".csv";
WDataSetCSV::SeperatedRowSPtr csvContent = m_CSVInput->getData()->getRawDataSet();
std::vector< std::string > csvHeader = m_CSVInput->getData()->getHeader()->at( 0 );
WDataSetFibers::SPtr fibers = m_PointsAndFibersInput->getData()->getFibers();
WDataSetPoints::SPtr points = m_PointsAndFibersInput->getData()->getPoints();
std::list< std::tuple < int, int > > listOfPositionAndID = getListOfPositionAndID(
getListOfInternalVertex( fibers ),
points );
std::ofstream newCSVFile( outputFilename );
std::list< std::tuple < float, float, float, int > > listOfInternalVertex = getListOfInternalVertex( fibers );
std::ofstream newCSVFile( getPathToSave() );
if( !newCSVFile.is_open() )
{
......@@ -231,33 +238,42 @@ void WMWriteCSV::writeToFile()
}
bool isMatch = false;
size_t eventIDcounter = createStartCounter( listOfInternalVertex );
//set new csv-header ( SelectedEventID )
newCSVFile << csvContent->at( 0 ) << "," << getNewCSVHeader() << std::endl;
std::string newColumnName = "SelectedEventID";
size_t counter = 1;
while( std::find( csvHeader.begin(), csvHeader.end(), newColumnName ) != csvHeader.end() )
//set new csv-content ( content of SelectedEventID )
for( size_t row = 1; row < csvContent->size(); row++ )
{
newColumnName = "SelectedEventID_" + boost::lexical_cast< std::string >( counter );
counter++;
}
std::string rowAsString = csvContent->at( row );
newCSVFile << csvContent->at( 0 ) << "," << newColumnName << std::endl;
csvContent->erase( csvContent->begin() );
for( size_t row = 0; row < csvContent->size(); row++ )
{
for( auto element = listOfPositionAndID.begin(); element != listOfPositionAndID.end(); element++ )
for( auto element = listOfInternalVertex.begin(); element != listOfInternalVertex.end(); element++ )
{
size_t selectedPosition = std::get< 0 >( *element );
int selectedVertexIndex = std::get< 1 >( *element );
float posX = std::get< 0 >( *element );
if( !contains( rowAsString, posX ) )
{
continue;
}
if( row == selectedPosition )
float posY = std::get< 1 >( *element );
if( !contains( rowAsString, posY ) )
{
continue;
}
float posZ = std::get< 2 >( *element );
if( !contains( rowAsString, posZ ) )
{
newCSVFile << csvContent->at( row ) << "," << selectedVertexIndex << std::endl;
continue;
}
listOfPositionAndID.erase( element );
isMatch = true;
break;
}
int selectedVertexIndex = std::get< 3 >( *element );
newCSVFile << rowAsString << "," << selectedVertexIndex << std::endl;
isMatch = true;
listOfInternalVertex.erase( element );
break;
}
if( isMatch )
......@@ -266,9 +282,11 @@ void WMWriteCSV::writeToFile()
}
else
{
newCSVFile << csvContent->at( row ) << ",-1" << std::endl;
newCSVFile << rowAsString << "," << std::to_string( eventIDcounter++ ) << std::endl;
}
}
newCSVFile.close();
}
......@@ -118,17 +118,36 @@ private:
* \param fibers selected points as fibers from Point-Connector
* \return list of internal vertex with id
*/
std::list< std::tuple < osg::Vec3, int > > getListOfInternalVertex( WDataSetFibers::SPtr fibers );
std::list< std::tuple < float, float, float, int > > getListOfInternalVertex( WDataSetFibers::SPtr fibers );
/**
* Helpermethod to create a List of internal Position with id
* \param listOfInternalVertex selected points as fibers from Point-Connector
* \param points selected points as fibers from Point-Connector
* \return list of internal position of row and the selectedEventID
* Helpermethod: Returns the path from Filedialog
* \return Returns the filename
*/
std::list< std::tuple < int, int > > getListOfPositionAndID(
std::list< std::tuple < osg::Vec3, int > > listOfInternalVertex,
WDataSetPoints::SPtr points );
std::string getPathToSave();
/**
* The Helpermethod goes through the header and searches for -SelectedEventID-,
* if one was found, append the number of headers found
* to the header (example: SelectedEventID_4)
* \return return the new Headername
*/
std::string getNewCSVHeader();
/**
* Helpermethod: checks whether the source domain contains the specified float
* \param sourceString source string
* \param num search number
* \return If found then true otherwise false
*/
bool contains( std::string sourceString, float num);
/**
* Helpermethod goes through the existing EvenIDs and returns the next one.
* \param listOfInternalVertex get selected EventIDs
* \return next free EventID
*/
size_t createStartCounter( std::list< std::tuple < float, float, float, int > > listOfInternalVertex );
/**
* The filename property -> where to write the csv file
......
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