30 #include "WMPaintTexture.h"
31 #include "WMPaintTexture.xpm"
32 #include "core/common/WPropertyHelper.h"
33 #include "core/graphicsEngine/WGEColormapping.h"
34 #include "core/graphicsEngine/WGEUtils.h"
35 #include "core/graphicsEngine/WROIArbitrary.h"
36 #include "core/kernel/WKernel.h"
37 #include "core/kernel/WROIManager.h"
38 #include "core/kernel/WSelectionManager.h"
43 WMPaintTexture::WMPaintTexture():
48 WMPaintTexture::~WMPaintTexture()
60 return paintTexture_xpm;
64 return "Paint Texture";
69 return "This module allows painting areas in a 3D texture";
75 m_input = std::shared_ptr< WModuleInputData < WDataSetSingle > >(
79 m_output = std::shared_ptr< WModuleOutputData < WDataSetScalar > >(
90 m_painting =
m_properties->addProperty(
"Paint",
"If active, left click in the scene with pressed ctrl key"
152 std::shared_ptr< WDataSetSingle > newDataSet =
m_input->getData();
153 bool dataChanged = (
m_dataSet != newDataSet );
154 bool dataValid = ( newDataSet != NULL );
217 m_outData = std::shared_ptr< WDataSetScalar >();
239 debugLog() <<
"Finished! Good Bye!";
249 unsigned char* data =
m_texture->getImage()->data();
257 int voxelNum =
m_grid->getVoxelNum( paintPosition );
268 std::vector< size_t > ids =
m_grid->getNeighbours27( voxelNum );
269 for(
size_t i = 0; i < ids.size(); ++i )
278 std::vector< size_t > ids =
m_grid->getNeighbours27( voxelNum );
279 for(
size_t i = 0; i < ids.size(); ++i )
281 std::vector< size_t > allIds =
m_grid->getNeighbours27( ids[i] );
282 for(
size_t k = 0; k < allIds.size(); ++k )
291 if( pickInfo.
getName() ==
"Axial Slice" )
294 std::vector< size_t > ids =
m_grid->getNeighbours9XY( voxelNum );
295 for(
size_t i = 0; i < ids.size(); ++i )
300 if( pickInfo.
getName() ==
"Coronal Slice" )
303 std::vector< size_t > ids =
m_grid->getNeighbours9XZ( voxelNum );
304 for(
size_t i = 0; i < ids.size(); ++i )
309 if( pickInfo.
getName() ==
"Sagittal Slice" )
312 std::vector< size_t > ids =
m_grid->getNeighbours9YZ( voxelNum );
313 for(
size_t i = 0; i < ids.size(); ++i )
322 if( pickInfo.
getName() ==
"Axial Slice" )
325 std::vector< size_t > ids =
m_grid->getNeighbours9XY( voxelNum );
326 for(
size_t i = 0; i < ids.size(); ++i )
328 std::vector< size_t > allIds =
m_grid->getNeighbours9XY( ids[i] );
329 for(
size_t k = 0; k < allIds.size(); ++k )
335 if( pickInfo.
getName() ==
"Coronal Slice" )
338 std::vector< size_t > ids =
m_grid->getNeighbours9XZ( voxelNum );
339 for(
size_t i = 0; i < ids.size(); ++i )
341 std::vector< size_t > allIds =
m_grid->getNeighbours9XZ( ids[i] );
342 for(
size_t k = 0; k < allIds.size(); ++k )
348 if( pickInfo.
getName() ==
"Sagittal Slice" )
351 std::vector< size_t > ids =
m_grid->getNeighbours9YZ( voxelNum );
352 for(
size_t i = 0; i < ids.size(); ++i )
354 std::vector< size_t > allIds =
m_grid->getNeighbours9YZ( ids[i] );
355 for(
size_t k = 0; k < allIds.size(); ++k )
396 int voxelNum =
m_grid->getVoxelNum( paintPosition );
400 unsigned char* data =
m_texture->getImage()->data();
407 m_grid = std::dynamic_pointer_cast< WGridRegular3D >(
m_dataSet->getGrid() );
409 osg::ref_ptr< osg::Image > ima =
new osg::Image;
410 ima->allocateImage(
m_grid->getNbCoordsX(),
m_grid->getNbCoordsY(),
m_grid->getNbCoordsZ(), GL_LUMINANCE, GL_UNSIGNED_BYTE );
412 unsigned char* data = ima->data();
414 for(
unsigned int i = 0; i <
m_grid->size(); ++i )
420 m_texture->setFilterMinMag( osg::Texture3D::LINEAR );
421 m_texture->setWrapSTR( osg::Texture::CLAMP_TO_BORDER );
434 unsigned char* data =
m_texture->getImage()->data();
435 std::shared_ptr< std::vector< unsigned char > > values =
436 std::shared_ptr< std::vector< unsigned char > >(
new std::vector< unsigned char >(
m_grid->size(), 0.0 ) );
438 for(
unsigned int i = 0; i <
m_grid->size(); ++i )
440 ( *values )[i] = data[i];
443 std::shared_ptr< WValueSet< unsigned char > > vs =
447 m_outData->getTexture()->interpolation()->set(
false );
453 m_grid = std::dynamic_pointer_cast< WGridRegular3D >(
m_dataSet->getGrid() );
455 unsigned char* data =
m_texture->getImage()->data();
457 std::shared_ptr< WValueSet< unsigned char > > vals;
458 vals = std::dynamic_pointer_cast< WValueSet< unsigned char > >(
m_dataSet->getValueSet() );
460 for(
unsigned int i = 0; i <
m_grid->size(); ++i )
462 data[i] = vals->getScalar( i );
470 std::vector<float>roiVals(
m_grid->size(), 0 );
473 unsigned char* data =
m_texture->getImage()->data();
475 for(
size_t i = 0; i <
m_grid->size(); ++i )
477 if( data[i] == index )
486 osg::ref_ptr< WROI > newRoi = osg::ref_ptr< WROI >(
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.
This data set type contains scalars as values.
static void registerTexture(osg::ref_ptr< WGETexture3D > texture, std::string name="")
Register the specified texture to the colormapper.
static void deregisterTexture(osg::ref_ptr< WGETexture3D > texture)
De-register the specified texture to the colormapper.
This calls serves a simple purpose: have a texture and its scaling information together which allows ...
A class containing a list of named items.
std::vector< size_t > IndexList
The type used for storing index lists.
std::shared_ptr< WSelectionManager > getSelectionManager()
get for selection manager
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
std::shared_ptr< WROIManager > getRoiManager()
get for roi manager
std::shared_ptr< WGraphicsEngine > getGraphicsEngine() const
Returns pointer to currently running instance of graphics engine.
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.
Forward declaration of WPickInfo.
virtual void moduleMain()
Entry point after loading the module.
WPropSelection m_colorMapSelection
Selection property for color map.
WPropTrigger m_buttonCreateRoi
updates the output connector on demand, as we don't want to do this every paint command
void copyFromInput()
copies data from the input dataset into the paint texture
void doPaint()
this function listens to the pick handler, if the paint flag is true it will write into the out textu...
WPropBool m_painting
Interpolation?
std::shared_ptr< WDataSetSingle > m_dataSet
This is a pointer to the dataset the module is currently working on.
void setColorFromPick(WPickInfo pickInfo)
get the paint index at the picked voexel fromt he out texture and sets m_paintIndex accordingly
WPropSelection m_pencilSelection
Selection property for pencil size and shape.
WPropTrigger m_buttonCopyFromInput
copies the input dataset into the paint texture, this allows one to continue work
std::shared_ptr< WDataSetScalar > m_outData
This is a pointer to the current output.
std::shared_ptr< WGridRegular3D > m_grid
stores a pointer to the grid we use;
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.
WPropTrigger m_buttonUpdateOutput
updates the output connector on demand, as we don't want to do this every paint command
WPropInt m_paintIndex
specifies the value we paint into the output texture
void createROI()
creates a ROI from the currently selected paint value
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
void updateOutDataset()
updates the output connector
virtual const std::string getDescription() const
Gives back a description of this module.
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output
An output connector for the output scalar dsataset.
osg::ref_ptr< WGETexture3D > m_texture
stores a pointer to the texture we paint in
std::shared_ptr< WItemSelection > m_pencilSelectionsList
A list of pencil sizes and shapes.
std::queue< WPickInfo > m_paintQueue
new paint coordinates get added here
virtual void properties()
Initialize the properties for this module.
std::shared_ptr< WItemSelection > m_colorMapSelectionsList
A list of color map selection types.
virtual void activate()
Callback for m_active.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input
An input connector that accepts order 1 datasets.
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...
void createTexture()
creates a new texture
WPropBool m_queueAdded
true when a new paint coordinate is added to the queue
void queuePaint(WPickInfo pickInfo)
this function listens to the pick handler, if the paint flag is true it will add the paint position t...
virtual const std::string getName() const
Gives back the name of this module.
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 activate()
Callback for m_active.
WPropBool m_active
True whenever the module should be active.
virtual void connectors()
Initialize connectors in this function.
static const std::string unpickString
The string indicating picking has stopped.
Encapsulates info for pick action.
WPosition getPickPosition() const
Get position where object was hit.
WMouseButton getMouseButton() const
Get the mouse button associated with the pick.
std::string getName() const
Get name of picked object.
modifierKey getModifierKey() const
Get the modifier key associated with the pick.
This only is a 3d double vector.
A box containing information on an arbitrarily shaped a region of interest.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Base Class for all value set types.
@ PV_TRIGGER_TRIGGERED
Trigger property: got triggered.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
WColor createColorFromIndex(int index)
creates the same color as the atlas colormap shader from the index