30 #include "WMWriteCSV.h"
31 #include "core/common/WPathHelper.h"
32 #include "core/kernel/WKernel.h"
48 return std::shared_ptr< WModule >(
new WMWriteCSV() );
53 static const char * disc_xpm[] =
55 "16 16 7 1",
" c None",
". c #000080",
"+ c #000000",
"@ c #FFFF00",
"# c #E0E0E0",
56 "$ c #FFFFFF",
"% c #C0C0C0",
"..+++++++++++..+",
"..@@@@@@@@@@@..+",
"..###########..+",
57 "..$$$$$$$$$$$..+",
"..###########..+",
"..$$$$$$$$$$$..+",
"..###########..+",
"..$$$$$$$$$$$..+",
58 "...............+",
"....%%%%%%%....+",
"....%..%%%%....+",
"....%..%%%%....+",
"....%..%%%%....+",
59 "....%..%%%%....+",
"+...%%%%%%%....+",
"++++++++++++++++"
71 return "Writes a connected data set to a CSV file.";
84 debugLog() <<
"Waiting for data ...";
95 "The dataset of the connected points" );
99 "The dataset to write in" );
117 std::shared_ptr< WDataSetCSV > csvdataSet =
m_CSVInput->getData();
118 std::shared_ptr< WDataSetFibers > fibersdataSet =
m_fibersInput->getData();
122 throw WException(
"The Data-Modul-CSV-connection is missing." );
127 throw WException(
"The Point-Connector-connection is missing." );
135 std::list< std::tuple < float, float, float, size_t > > listOfInternalVertex;
140 size_t vertexCounter = 0;
141 size_t reverseCounter = 0;
147 for(
size_t idx = 0; idx <= vertices->size(); idx++ )
149 switch( vertexCounter )
151 case 0: vertexX = vertices->at( idx );
break;
152 case 1: vertexY = vertices->at( idx );
break;
153 case 2: vertexZ = vertices->at( idx );
break;
156 osg::Vec3 vecVertex( vertexX, vertexY, vertexZ );
157 listOfInternalVertex.push_back(
162 verticesReverse->at( reverseCounter++ ) ) );
164 if( idx < vertices->size() )
166 vertexX = vertices->at( idx );
176 return listOfInternalVertex;
181 std::string sourceFilename =
m_filename->get().string();
182 sourceFilename = sourceFilename.substr( 0, sourceFilename.find(
".csv" ) );
183 return sourceFilename +
".csv";
188 std::vector< std::string > csvHeader =
m_CSVInput->getData()->getHeader()->at( 0 );
189 std::string newColumnName =
"SelectedEventID";
191 while( std::find( csvHeader.begin(), csvHeader.end(), newColumnName ) != csvHeader.end() )
193 newColumnName =
"SelectedEventID_" + boost::lexical_cast< std::string >( counter );
197 return newColumnName;
202 std::stringstream ss;
204 return sourceString.find( ss.str() ) != std::string::npos;
209 size_t eventIDcounter = 0;
211 for(
auto element = listOfInternalVertex.begin(); element != listOfInternalVertex.end(); element++ )
213 size_t selectedVertexIndex = std::get< 3 >( *element );
215 if( eventIDcounter < selectedVertexIndex )
217 eventIDcounter = selectedVertexIndex;
220 return eventIDcounter + 1;
229 if( !newCSVFile.is_open() )
231 throw WException(
"Could not create new CSV in the selected source folder" );
234 bool isMatch =
false;
238 newCSVFile << csvContent->at( 0 ) <<
"," <<
getNewCSVHeader() << std::endl;
241 for(
size_t row = 1; row < csvContent->size(); row++ )
243 std::string rowAsString = csvContent->at( row );
245 for(
auto element = listOfInternalVertex.begin(); element != listOfInternalVertex.end(); element++ )
247 float posX = std::get< 0 >( *element );
248 if( !
contains( rowAsString, posX ) )
253 float posY = std::get< 1 >( *element );
254 if( !
contains( rowAsString, posY ) )
259 float posZ = std::get< 2 >( *element );
260 if( !
contains( rowAsString, posZ ) )
265 size_t selectedVertexIndex = std::get< 3 >( *element );
266 newCSVFile << rowAsString <<
"," << selectedVertexIndex << std::endl;
269 listOfInternalVertex.erase( element );
279 newCSVFile << rowAsString <<
"," << std::to_string( eventIDcounter++ ) << std::endl;
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
std::shared_ptr< std::vector< std::string > > SeperatedRowSPtr
represents a pointer to a vector of csv-raw-row as string
std::shared_ptr< std::vector< size_t > > IndexArray
Index list indexing fibers in VertexArray in terms of vertex numbers.
std::shared_ptr< WDataSetFibers > SPtr
Pointer to dataset.
std::shared_ptr< std::vector< float > > VertexArray
List of vertex coordinates in term of components of vertices.
Class for safe the point-connector data.
void writeToFile()
This performs all work necessary to actually write the data to the file.
std::list< std::tuple< float, float, float, size_t > > getListOfInternalVertex(WDataSetFibers::SPtr fibers)
Helpermethod to create a List of internal vertex with id.
WPropFilename m_filename
The filename property -> where to write the csv file.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
std::string getNewCSVHeader()
The Helpermethod goes through the header and searches for -SelectedEventID-, if one was found,...
void propertyCallback()
Trigger Event for Dialogfile.
std::shared_ptr< WModuleInputData< WDataSetCSV > > m_CSVInput
Input connector required by this module.
virtual const std::string getName() const
Gives back the name of this module.
size_t createStartCounter(std::list< std::tuple< float, float, float, size_t > > listOfInternalVertex)
Helpermethod goes through the existing EvenIDs and returns the next one.
std::shared_ptr< WModuleInputData< WDataSetFibers > > m_fibersInput
Input connector required by this module.
virtual const std::string getDescription() const
Gives back a description of this module.
bool contains(std::string sourceString, float num)
Helpermethod: checks whether the source domain contains the specified float.
virtual void properties()
Initialize the properties for this module.
virtual void connectors()
Initialize the connectors this module is using.
virtual void moduleMain()
Entry point after loading the module.
WMWriteCSV()
Standard constructor.
std::string getPathToSave()
Helpermethod: Returns the path from Filedialog.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
Class representing a single module of OpenWalnut.
virtual void properties()
Initialize properties in this function.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
void removeConnectors()
Removes all connectors properly.
std::shared_ptr< WProperties > m_properties
The property object for the module.
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
virtual void connectors()
Initialize connectors in this function.
static boost::filesystem::path getHomePath()
The path to the OW dir in the user's home.
boost::function< void(std::shared_ptr< WPropertyBase >)> PropertyChangeNotifierType
Signal signature emitted during set operations.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
void addTo(WPropFilename prop)
Add the PC_CONFIRMOVERWRITE constraint to the property.