View Issue Details

IDProjectCategoryView StatusLast Update
0002392Slicer4Core: MRMLpublic2014-03-06 05:55
Reporterungi Assigned Toalexy  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version 
Target VersionSlicer 4.2.0Fixed in VersionSlicer 4.4.0 
Summary0002392: ScalarVisibility in new ModelNode -- colors appear late
Description

I'd like to create a model that uses scalars for multi-color appearance. But the model appears all gray (no color). However, anything that causes the DisplayNode to update after the script, makes the colors appear. See below the shortest code I could write to reproduce the bug. Just paste it in the python interactor.
It's funny when I manually repeat the last line after running the whole script, the colors appear. So it looks like Slicer needs a bit of time before the displayNode.Modified(). (But a time.sleep() didn't help :-) )

import slicer, vtk

Create polydata with scalars.

s1 = vtk.vtkCylinderSource()
s1.SetHeight( 50 )
s1.SetRadius( 10 )
s1.Update()
p1 = s1.GetOutput()
a1 = vtk.vtkDoubleArray()
a1.SetNumberOfComponents( 1 )
a1.SetNumberOfTuples( p1.GetNumberOfPoints() )
a1.SetName( "MyColors" )
for i in range( p1.GetNumberOfPoints() ):
a1.SetValue( i, 60 )

p1.GetPointData().AddArray( a1 )

Create polydata with different scalars.

s2 = vtk.vtkCylinderSource()
s2.SetHeight( 20 )
s2.SetRadius( 20 )
s2.Update()
p2 = s2.GetOutput()
a2 = vtk.vtkDoubleArray()
a2.SetNumberOfComponents( 1 )
a2.SetNumberOfTuples( p2.GetNumberOfPoints() )
a2.SetName( "MyColors" )
for i in range( p2.GetNumberOfPoints() ):
a2.SetValue( i, 80 )

p2.GetPointData().AddArray( a2 )

Append two polydata into one.

append = vtk.vtkAppendPolyData()
append.AddInput( p1 )
append.AddInput( p2 )

Create a model node and add it to the scene.

scene = slicer.mrmlScene
modelNode = slicer.vtkMRMLModelNode()
modelNode.SetScene( scene )
modelNode.SetName( "MyModel" )
modelNode.SetAndObservePolyData( append.GetOutput() )
displayNode = slicer.vtkMRMLModelDisplayNode()
displayNode.SetScene( scene )
displayNode.SetName( "MyModelDisplay" )
scene.AddNode( displayNode )
modelNode.SetAndObserveDisplayNodeID( displayNode.GetID() )
displayNode.SetPolyData( modelNode.GetPolyData() )
displayNode.SetScalarVisibility( 1 )
displayNode.SetAmbient( 0.2 )
displayNode.SetActiveScalarName( "MyColors" )
displayNode.SetAndObserveColorNodeID( "vtkMRMLColorTableNodeRainbow" )
scene.AddNode( modelNode )

displayNode.Modified()

Additional Information

Hi Tamas,

The problem is:

  • vtkMRMLModelDisplayableManager::SetModelDisplayProperty tries to set (line 1422) the active scalar "MyColor" on the Model node polydata that doesn't have field data yet because it is the output of a VTK pipeline ( vtkAppendPolyData ) that is not yet updated.

4 solutions:

  • short term: Call Update() on the polydata you set on the model node
  • middle term a) : Call Update() on the polydata in vtkMRMLModelDisplayableManager
  • middle term b) : Call Update() on the polydata in vtkMRMLModelNode::SetActivePointScalars if pointdata doesn't find an array
  • long term: vtkMRMLModelNode::SetActivePointScalars should use vtkAssignAttribute to be able to set the active scalar in the "VTK pipeline" rather than on the intermediate vtkPolyData pointdata.

Can you please create a mantis issue.

Thanks,
Julien.

TagsNo tags attached.

Relationships

related to 0003349 closedjcfr Fix pipeline for glyphing 

Activities

alexy

alexy

2012-09-18 08:55

developer   ~0006123

Implemented middle term solution as described by Julien.
Update polydata in case it is computed in a vtk pilpeline.
revision: 21000

jcfr

jcfr

2014-03-06 05:07

administrator   ~0010966

Closing resolved issues that have not been updated in more than 3 months

Issue History

Date Modified Username Field Change
2012-08-10 18:43 ungi New Issue
2012-08-10 18:43 ungi Status new => assigned
2012-08-10 18:43 ungi Assigned To => alexy
2012-08-22 05:56 jcfr Target Version => Slicer 4.3.0
2012-08-28 14:08 pieper Target Version Slicer 4.3.0 => Slicer 4.2.0 - Feature freeze Sept 1st 2012
2012-09-18 08:55 alexy Note Added: 0006123
2012-09-18 08:55 alexy Status assigned => resolved
2012-09-18 08:55 alexy Resolution open => fixed
2013-09-17 11:33 yuzheng Relationship added related to 0003349
2014-03-06 05:07 jcfr Note Added: 0010966
2014-03-06 05:10 jcfr Status resolved => closed
2014-03-06 05:55 jcfr Fixed in Version => Slicer 4.4.0