35 #include "WMWriteTransferFunction.h"
36 #include "WMWriteTransferFunction.xpm"
37 #include "core/common/WAssert.h"
38 #include "core/common/WPathHelper.h"
39 #include "core/common/WPropertyHelper.h"
40 #include "core/common/WStringUtils.h"
62 return WMWriteTransferFunction_xpm;
67 return "Write Transfer Function";
73 return "Allows one to export transfer functions in several formats.";
122 warnLog() <<
"No data available to save.";
127 std::shared_ptr< WValueSetBase > vsb = d->getValueSet();
128 if( ( vsb->order() != 1 ) || ( vsb->dimension() != 4 ) || ( vsb->getDataType() != W_DT_UNSIGNED_CHAR ) )
130 errorLog() <<
"This is not a proper TF. Abort.";
135 std::shared_ptr< WValueSet< unsigned char > > vs = std::dynamic_pointer_cast< WValueSet< unsigned char > >( vsb );
138 boost::filesystem::path p =
m_savePath->get(
true );
140 debugLog() <<
"Save TF to \"" + p.string() +
"\".";
145 f.open( p.string().c_str() );
148 errorLog() <<
"Failed to open file. Abort.";
152 f <<
"# Exported using OpenWalnut. http://www.openwalnut.org" << std::endl;
153 f <<
"# TF export format:" << std::endl <<
154 "# Comments begin with #" << std::endl <<
155 "# 1st line: width height" << std::endl <<
156 "# Then, RGBA quadruples; line-wise; values space separated; in x direction first." << std::endl;
161 for(
size_t i = 0; i < vs->size(); ++i )
176 fhead.open( ( p.string() +
".header" ).c_str() );
179 errorLog() <<
"Failed to write header file " << ( p.string() +
".header" ).c_str() <<
". Abort.";
183 fhead <<
"# Exported using OpenWalnut. http://www.openwalnut.org" << std::endl;
184 fhead <<
"# TF export format:" << std::endl <<
185 "# Comments begin with #" << std::endl <<
186 "# 1st line: width height" << std::endl <<
187 "# 2nd line: filename to binary file, relative to header" << std::endl <<
188 "# The RGBA quadruples are stored in binary format as four unsigned char values per quadruples." << std::endl;
192 fhead << p.filename().string().c_str() << std::endl;
199 f.open( p.string().c_str(), std::ios::out | std::ios::binary );
202 errorLog() <<
"Failed to open file. Abort.";
206 f.write(
reinterpret_cast< const char*
>( vs->rawData() ), vs->rawSize() );
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.
Class to encapsulate boost::condition_variable_any.
std::shared_ptr< WDataSetSingle > SPtr
Convenience typedef for a std::shared_ptr.
Module to export transferfunctions.
WPropTrigger m_saveTrigger
DO the save operation.
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...
virtual const std::string getDescription() const
Gives back a description of this module.
WPropFilename m_savePath
Where to save the file to.
WModuleInputData< WDataSetSingle >::SPtr m_input
The connector used to get the TF.
virtual ~WMWriteTransferFunction()
Destructor.
virtual void moduleMain()
Entry point after loading the module.
virtual const std::string getName() const
Gives back the name of this module.
const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void properties()
Initialize the properties for this module.
WMWriteTransferFunction()
Constructor.
WPropBool m_saveAsRaw
Allows saving as raw data file instead of ascii.
virtual void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WCondition > m_propCondition
Condition used throughout the module to notify the thread if some changes happened (like properties h...
std::shared_ptr< WCondition > getDataChangedCondition()
Gets the condition variable that gets fired whenever new data has been sent.
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.
wlog::WStreamedLogger warnLog() const
Logger instance for comfortable warning- logs.
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.
wlog::WStreamedLogger errorLog() const
Logger instance for comfortable error logging.
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_TRIGGERED
Trigger property: got triggered.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)
std::string toString(const T &value)
Convert a given value to a string.