27 #include "core/kernel/WKernel.h"
29 #include "WMWriteField.h"
30 #include "core/dataHandler/WDataSetScalar.h"
31 #include "core/dataHandler/WGridRegular3D.h"
32 #include "core/common/WPathHelper.h"
37 WMWriteField::WMWriteField():
42 WMWriteField::~WMWriteField()
50 return boost::shared_ptr< WModule >(
new WMWriteField() );
63 return "This module writes a scalar field to a file. Different file formats are supported.";
68 m_field = boost::shared_ptr<WModuleInputData<WDataSetScalar> >(
70 "The field to be saved." ) );
119 const char* c_file =
m_outputFile->get().string().c_str();
120 std::ofstream dataFile( c_file, std::ios_base::binary );
132 dataFile.precision( 16 );
135 dataFile << (
"# vtk DataFile Version 2.0\n" );
136 dataFile << (
"Generated using OpenWalnut\n" );
137 dataFile << (
"ASCII\n" );
138 dataFile << (
"DATASET STRUCTURED_POINTS\n" );
141 boost::shared_ptr< WDataSetScalar > m_dataSet =
m_field->getData();
142 boost::shared_ptr<WGridRegular3D> grid = boost::dynamic_pointer_cast< WGridRegular3D >( m_dataSet->getGrid() );
143 WAssert( grid,
"Grid is not of type WGridRegular3D." );
145 size_t x_dim = grid->getNbCoordsX();
146 size_t y_dim = grid->getNbCoordsY();
147 size_t z_dim = grid->getNbCoordsZ();
148 dataFile <<
"DIMENSIONS " << x_dim <<
" "
152 size_t x_origin = grid->getOrigin()[0];
153 size_t y_origin = grid->getOrigin()[1];
154 size_t z_origin = grid->getOrigin()[2];
155 dataFile <<
"ORIGIN " << x_origin <<
" "
159 size_t x_asp = grid->getOffsetX();
160 size_t y_asp = grid->getOffsetY();
161 size_t z_asp = grid->getOffsetZ();
162 dataFile <<
"SPACING " << x_asp <<
" "
166 size_t nbPoints = x_dim * y_dim * z_dim;
167 dataFile <<
"POINT_DATA " << nbPoints <<
"\n";
168 dataFile <<
"SCALARS fieldValues float\n";
169 dataFile <<
"LOOKUP_TABLE default\n";
172 boost::shared_ptr< WValueSetBase > valueSet( m_dataSet->getValueSet() );
173 for(
size_t id = 0;
id < nbPoints; ++id )
175 dataFile << valueSet->getScalarDouble(
id ) <<
" ";
virtual void wait() const
Wait for the condition.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
Someone should add some documentation here.
virtual void moduleMain()
Entry point after loading the module.
boost::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
virtual void connectors()
Initialize the connectors this module is using.
virtual boost::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
boost::shared_ptr< WModuleInputData< WDataSetScalar > > m_field
Input connector required by this module.
bool saveVTKASCII() const
Store the field in legacy vtk file format.
virtual void requirements()
Initialize requirements for this module.
virtual void properties()
Initialize the properties for this module.
WPropTrigger m_saveTriggerProp
This property triggers the actual writing,.
WPropFilename m_outputFile
The field will be written to this file.
virtual const std::string getName() const
Gives back the name of this module.
virtual const std::string getDescription() const
Gives back a description of this module.
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 addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
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 getAppPath()
The path where the binary file resides in.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)