From user's Wiki!
Jump to: navigation, search

This page provides some tips on changing the way the data entities are shown, as their opacity, color, representation...


Some times you want to make a plug-in that has a processor that outputs a data entity that must be visualized in some way that is different of the default. Or maybe is the input data entity whose visualization has to be changed in order to appreciate differences between the input and the output. Either way, the typical user solution is to change the visualization properties using the user interface. This can be a cumbersome work if a widget is to be run in a batch manner and the user does not want to lose his time with visualization properties matrers. There is though a developer approach.

Getting the node

Suppose a typical scenario where you have a method in your widget class that is connected to the a data entity through the corresponding processor slot, so that when the processor updates that output, the method is invoked, and now you can do whatever postprocessing with that data entity, like for example publishing it on the data tree.

void MyWidgetPanelWidget::OnModifiedFirstOutputDataEntity()
        Core::DataEntity::Pointer firstOutputDataEntity = m_Processor->GetOutputDataEntity( MyWidgetProcessor::OUTPUT_FIRST );

        // Publish unless you have configured the widget with ProcessorObserver flag
        Core::DataTreeHelper::PublishOutput( firstOutputDataEntity, GetRenderingTree(), true, false, true );
    coreCatchExceptionsLogAndNoThrowMacro( "MyWidgetPanelWidget::OnModifiedFirstOutputDataEntity" )

To access the node, you have to know beforehand what kind of node is really wrapped inside the node of the tree. As normally every plug-in depends of MITK plug-in, the node will be of kind MITK, defined in mitkDataTreeNode.h in case you need it. To retreve the node, we need to write to simple lines:

        mitk::DataTreeNode::Pointer node;
        Core::CastAnyProcessingData( GetRenderingTree()->GetNode( firstOutputDataEntity ), node );

After this, we can change some of the properties of the node, like the opacity:

        if( node.IsNotNull() )
            node->SetOpacity( 0.4 );

We can also get further, and retrieve other properties, like, for example, the material property, defined in "mitkMaterialProperty.h", and it's done this way:

        if( node.IsNotNull() )
            mitk::MaterialProperty::Pointer material;
            material = static_cast<mitk::MaterialProperty*>( node->GetProperty( "material" ) );
            if( material.IsNotNull() )
                // Change the diffuse color
                material->SetDiffuseColor( 1.0, 0, 0 );
                // Change the way we see the data entity to points
                material->SetRepresentation( mitk::MaterialProperty::Points );
                // Set the size we like to see the points
                material->SetPointSize( 5 );
                // Update for immediate effect

It's important to call the method Update of the node, in order to see the changes inmediately. If not, we will have to refresh the views to cause a render update.

That's it. Quite easy, isn't it?

Go back to Developers