28 #include <boost/filesystem.hpp>
30 #include <osgDB/WriteFile>
32 #include "WMWebglSupport.h"
33 #include "WMWebglSupport.xpm"
34 #include "core/common/WPathHelper.h"
35 #include "core/common/WStringUtils.h"
36 #include "core/kernel/WKernel.h"
59 return WMWebglSupport_xpm;
63 return "WebGL Support";
70 return "Someone should add some documentation here. "
71 "Probably the best person would be the modules's creator, i.e. \"ralph\"";
76 m_meshInput = std::shared_ptr< WModuleInputData < WTriangleMesh > >(
81 m_meshOutput = std::shared_ptr< WModuleOutputData< WTriangleMesh > >(
141 debugLog() <<
"new triangle mesh conected";
147 debugLog() <<
"new scalar dataset connected";
153 debugLog() <<
"new vector dataset connected";
170 debugLog() <<
"Update pressed Gray";
190 for(
size_t i = 0; i <
m_triMesh->vertSize(); ++i )
197 double value =
m_datasetScalar->getValueAt( pos.x(), pos.y(), pos.z() );
204 float c = value / 255.0;
205 osg::Vec4 color( c, c, c, 1.0 );
215 for(
size_t i = 0; i <
m_triMesh->vertSize(); ++i )
225 debugLog() <<
"error at getting value from datatset";
231 osg::Vec4 color( value[0], value[1], value[2], 1.0 );
238 using namespace boost::filesystem;
240 std::shared_ptr< WGridRegular3D > grid = std::dynamic_pointer_cast< WGridRegular3D >( ( *m_datasetScalar ).getGrid() );
241 debugLog() << grid->getNbCoordsX() <<
" " << grid->getNbCoordsY() <<
" " << grid->getNbCoordsZ();
243 osg::ref_ptr< osg::Image > ima =
new osg::Image;
244 ima->allocateImage( 256, 256, 1, GL_LUMINANCE, GL_UNSIGNED_BYTE );
245 unsigned char* data = ima->data();
247 for(
size_t y = 0; y < 200; ++y )
249 for(
size_t i = 0; i < 256; ++i )
251 for(
size_t j = 0; j < 256; ++j )
253 data[256 * i + j] = 0;
257 for(
size_t x = 0; x < 160; ++x )
259 for(
size_t z = 0; z < 160; ++z )
261 uint8_t value =
static_cast<uint8_t
>(
m_datasetScalar->getValueAt( x, y, z ) );
262 data[ 256 * ( 48 + z ) + x + 48 ] = value;
266 fileName.remove_filename().string();
268 osgDB::writeImageFile( *ima, ( fileName.string() + fn ).c_str() );
271 osg::ref_ptr< osg::Image > ima1 =
new osg::Image;
272 ima1->allocateImage( 256, 256, 1, GL_LUMINANCE, GL_UNSIGNED_BYTE );
275 for(
size_t x = 0; x < 160; ++x )
277 for(
size_t i = 0; i < 256; ++i )
279 for(
size_t j = 0; j < 256; ++j )
281 data[256 * i + j] = 0;
284 for(
size_t y = 0; y < 200; ++y )
286 for(
size_t z = 0; z < 160; ++z )
288 uint8_t value =
static_cast<uint8_t
>(
m_datasetScalar->getValueAt( x, y, z ) );
289 data[ 256 * ( 48 + z ) + y + 28 ] = value;
293 fileName.remove_filename().string();
295 osgDB::writeImageFile( *ima1, ( fileName.string() + fn ).c_str() );
298 osg::ref_ptr< osg::Image > ima2 =
new osg::Image;
299 ima2->allocateImage( 256, 256, 1, GL_LUMINANCE, GL_UNSIGNED_BYTE );
302 for(
size_t z = 0; z < 160; ++z )
304 for(
size_t i = 0; i < 256; ++i )
306 for(
size_t j = 0; j < 256; ++j )
308 data[256 * i + j] = 0;
311 for(
size_t x = 0; x < 160; ++x )
313 for(
size_t y = 0; y < 200; ++y )
315 uint8_t value =
static_cast<uint8_t
>(
m_datasetScalar->getValueAt( x, y, z ) );
316 data[ 256 * ( y + 28 ) + x + 48 ] = value;
320 fileName.remove_filename().string();
322 osgDB::writeImageFile( *ima2, ( fileName.string() + fn ).c_str() );
328 using namespace boost::filesystem;
333 osg::ref_ptr< osg::Image > ima =
new osg::Image;
334 ima->allocateImage( 256, 256, 1, GL_RGB, GL_UNSIGNED_BYTE );
335 unsigned char* data = ima->data();
336 bool success =
false;
337 for(
size_t y = 0; y < 200; ++y )
339 for(
size_t i = 0; i < 256; ++i )
341 for(
size_t j = 0; j < 256; ++j )
343 data[256 * i * 3 + j * 3 ] = 0;
344 data[256 * i * 3 + j * 3 + 1 ] = 0;
345 data[256 * i * 3 + j * 3 + 2 ] = 0;
349 for(
size_t x = 0; x < 160; ++x )
351 for(
size_t z = 0; z < 160; ++z )
355 data[ 256 * ( 48 + z ) * 3 + ( x + 48 ) * 3 ] =
static_cast<uint8_t
>( value[0] );
356 data[ 256 * ( 48 + z ) * 3 + ( x + 48 ) * 3 + 1 ] =
static_cast<uint8_t
>( value[1] );
357 data[ 256 * ( 48 + z ) * 3 + ( x + 48 ) * 3 + 2 ] =
static_cast<uint8_t
>( value[2] );
361 fileName.remove_filename().string();
363 osgDB::writeImageFile( *ima, ( fileName.string() + fn ).c_str() );
366 osg::ref_ptr< osg::Image > ima1 =
new osg::Image;
367 ima1->allocateImage( 256, 256, 1, GL_RGB, GL_UNSIGNED_BYTE );
370 for(
size_t x = 0; x < 160; ++x )
372 for(
size_t i = 0; i < 256; ++i )
374 for(
size_t j = 0; j < 256; ++j )
376 data[256 * i * 3 + j * 3 ] = 0;
377 data[256 * i * 3 + j * 3 + 1 ] = 0;
378 data[256 * i * 3 + j * 3 + 2 ] = 0;
382 for(
size_t y = 0; y < 200; ++y )
384 for(
size_t z = 0; z < 160; ++z )
388 data[ 256 * ( 48 + z ) * 3 + ( y + 28 ) * 3 ] =
static_cast<uint8_t
>( value[0] );
389 data[ 256 * ( 48 + z ) * 3 + ( y + 28 ) * 3 + 1 ] =
static_cast<uint8_t
>( value[1] );
390 data[ 256 * ( 48 + z ) * 3 + ( y + 28 ) * 3 + 2 ] =
static_cast<uint8_t
>( value[2] );
394 fileName.remove_filename().string();
396 osgDB::writeImageFile( *ima1, ( fileName.string() + fn ).c_str() );
399 osg::ref_ptr< osg::Image > ima2 =
new osg::Image;
400 ima2->allocateImage( 256, 256, 1, GL_RGB, GL_UNSIGNED_BYTE );
403 for(
size_t z = 0; z < 160; ++z )
405 for(
size_t i = 0; i < 256; ++i )
407 for(
size_t j = 0; j < 256; ++j )
409 data[256 * i * 3 + j * 3 ] = 0;
410 data[256 * i * 3 + j * 3 + 1 ] = 0;
411 data[256 * i * 3 + j * 3 + 2 ] = 0;
415 for(
size_t x = 0; x < 160; ++x )
417 for(
size_t y = 0; y < 200; ++y )
422 data[ 256 * ( y + 28 ) * 3 + ( x + 48 ) * 3 ] =
static_cast<uint8_t
>( value[0] );
423 data[ 256 * ( y + 28 ) * 3 + ( x + 48 ) * 3 + 1 ] =
static_cast<uint8_t
>( value[1] );
424 data[ 256 * ( y + 28 ) * 3 + ( x + 48 ) * 3 + 2 ] =
static_cast<uint8_t
>( value[2] );
428 fileName.remove_filename().string();
430 osgDB::writeImageFile( *ima2, ( fileName.string() + fn ).c_str() );
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.
Someone should add some documentation here.
std::shared_ptr< WModuleInputData< WTriangleMesh > > m_meshInput
Input connector for a mesh.
WPropTrigger m_propTriggerSaveRGB
This property triggers the actual writing,.
std::shared_ptr< WDataSetScalar > m_datasetScalar
A pointer to the currently processed dataset.
std::shared_ptr< WDataSetVector > m_datasetVector
A pointer to the currently processed dataset.
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_datasetInputScalar
Input connector required by this module.
WPropTrigger m_propTriggerSaveGray
This property triggers the actual writing,.
std::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 const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void properties()
Initialize the properties for this module.
void colorTriMeshGray()
colors a connected triangle mesh with the connected gray scale texture
virtual ~WMWebglSupport()
destructor
std::shared_ptr< WTriangleMesh > m_triMesh
A pointer to the currently processed tri mesh.
virtual void moduleMain()
Entry point after loading the module.
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.
virtual void requirements()
Initialize requirements for this module.
void saveSlicesRGB()
saves a connected rgb 3D texture as set of 2D textures
WPropTrigger m_propTriggerUpdateOutputGray
This property triggers the actual writing,.
WPropTrigger m_propTriggerUpdateOutputRGB
This property triggers the actual writing,.
std::shared_ptr< WModuleOutputData< WTriangleMesh > > m_meshOutput
Input connector required by this module.
void saveSlicesGray()
saves a connected gray scale 3D texture as set of 2D textures
void colorTriMeshRGB()
colors a connected triangle mesh with the connected rgb texture
std::shared_ptr< WModuleInputData< WDataSetVector > > m_datasetInputVector
Input connector required by this module.
virtual const std::string getName() const
Gives back the name of this module.
WPropFilename m_fileName
The mesh will be written to this file.
WMWebglSupport()
constructor
Class offering an instantiate-able data connection between modules.
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.
This only is a 3d double vector.
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.