[vtk-developers] The ImageStencil Issue
David Gobbi
dgobbi at atamai.com
Tue Aug 22 22:45:55 EDT 2006
Hi Dean,
I just committed a fix, so please try again when you have a chance. The
whole reason that the trick of calling SetSpacing() and SetOrigin() on
the stencil inputs of a vtkImageFilter works is because it bypasses the
pipeline, so converting that bit of code to the new pipeline made it
completely nonfunctional. I just had to set two lines of code back to
the way they were.
This fix will have to be considered "good enough" until stencils are
made to use the pipeline properly.
- David
dean.inglis at camris.ca wrote:
> David,
>
> have a look at php bug tracker item #1452.
> If I run the tcl script as is, the ROI
> is not updated correctly. If I modify the
> script to delay updating the vtkImageAccumulate
> and vtkTextActor pipeline until after the
> first render, things work out (see modified
> tcl script below). Prior to executives,
> the submitted bug script would work. I believe
> there is still a pipeline issue here. Sorry I
> can't be of much help: I still haven't found time
> to dive into and figure out executives...
>
>
>>> The vtkImageStencilSource class requires the Spacing and Origin of
>>> whichever image eventually uses the stencil to be propagated the wrong
>>> way along the pipeline. Ouch!
>>>
>>>
>
>
> Dean
>
> #///////////////////////////////////////
> package require vtk
> package require vtkinteraction
>
> proc UpdateROI {} {
>
> accum Update
> set aN [accum GetVoxelCount]
> set amin [accum GetMin]
> set amax [accum GetMax]
> set amean [accum GetMean]
> set astd [accum GetStandardDeviation]
>
> set atext {}
> append atext "N: "
> append atext [string toupper $aN]
> append atext ", \["
> append atext [string toupper [lindex $amin 0] ]
> append atext " -> "
> append atext [string toupper [lindex $amax 0] ]
> append atext "\] "
> append atext [string toupper [lindex $amean 0] ]
> append atext " +- "
> append atext [string toupper [lindex $astd 0] ]
> append atext " HU"
>
> textActor SetInput $atext
>
> # not sure if this is just on my Borland build
> # but the text actor will not show the modified input text
> # correctly (looks garbled and squished) unless
> # we wait till later to add the text actor
> #
> ren AddViewProp textActor
>
> }
>
> vtkVolume16Reader v16
> v16 SetDataDimensions 64 64
> v16 SetDataByteOrderToLittleEndian
> v16 SetImageRange 1 93
> v16 SetDataSpacing 3.2 3.2 1.5
> v16 SetFilePrefix "$VTK_DATA_ROOT/Data/headsq/quarter"
> v16 ReleaseDataFlagOn
> v16 SetDataMask 0x7fff
>
> vtkExtractVOI extract
> extract SetVOI 31 31 0 63 0 92
> extract SetSampleRate 1 1 1
> extract SetInput [v16 GetOutput]
> extract ReleaseDataFlagOff
> extract Update
>
> set range [[extract GetOutput] GetScalarRange]
> set min [lindex $range 0]
> set max [lindex $range 1]
> set diff [expr $max - $min]
> set avg [expr 0.5*($max + $min)]
> set bounds [[extract GetOutput] GetBounds]
>
> vtkPoints points
> points SetNumberOfPoints 5
>
> set x [lindex $bounds 0]
> set y0 [expr 0.25*[lindex $bounds 3]]
> set y1 [expr 0.75*[lindex $bounds 3]]
> set z0 [expr 0.25*[lindex $bounds 5]]
> set z1 [expr 0.75*[lindex $bounds 5]]
>
> points SetPoint 0 $x $y0 $z0
> points SetPoint 1 $x $y1 $z0
> points SetPoint 2 $x $y1 $z1
> points SetPoint 3 $x $y0 $z1
> points SetPoint 4 $x $y0 $z0
>
> vtkCellArray cells
> cells InsertNextCell 5
>
> for {set i 0} {$i < 5} {incr i} {
> cells InsertCellPoint $i
> }
>
> vtkPolyData region
> region SetPoints points
> region SetLines cells
>
> vtkPolyDataMapper regionMapper
> regionMapper SetInput region
>
> vtkActor regionActor
> regionActor SetMapper regionMapper
> [regionActor GetProperty ] SetColor 1 0 0
>
> vtkLinearExtrusionFilter extrude
> extrude SetScaleFactor 1
> extrude SetExtrusionTypeToNormalExtrusion
> extrude SetVector 1 0 0
> extrude SetInput region
>
> vtkPolyDataToImageStencil dataToStencil
> dataToStencil SetInput [extrude GetOutput]
>
> vtkImageStencil stencil
> stencil SetInput [extract GetOutput]
> stencil SetStencil [dataToStencil GetOutput]
> stencil ReverseStencilOff
> stencil SetBackgroundValue $min
>
> vtkImageMapToWindowLevelColors imageMapper
> imageMapper SetOutputFormatToLuminance
> imageMapper SetInput [stencil GetOutput]
> imageMapper SetLevel $avg
> imageMapper SetWindow $diff
>
> vtkImageActor imageActor
> imageActor SetInput [imageMapper GetOutput]
> imageActor SetDisplayExtent 31 31 0 63 0 92
> imageActor InterpolateOff
>
> vtkImageAccumulate accum
> accum SetInput [extract GetOutput]
> accum ReverseStencilOff
> accum SetStencil [stencil GetStencil]
> accum SetComponentSpacing 1 0 0
> accum SetComponentExtent 0 $diff 0 0 0 0
> accum SetComponentOrigin $min 0 0
> accum ReleaseDataFlagOff
>
> # comment out old bug submission
> #
> # accum Update
>
> # set aN [accum GetVoxelCount]
> # set amin [accum GetMin]
> # set amax [accum GetMax]
> # set amean [accum GetMean]
> # set astd [accum GetStandardDeviation]
>
> # set atext {}
> # append atext "N: "
> # append atext [string toupper $aN]
> # append atext ", \["
> # append atext [string toupper [lindex $amin 0] ]
> # append atext " -> "
> # append atext [string toupper [lindex $amax 0] ]
> # append atext "\] "
> # append atext [string toupper [lindex $amean 0] ]
> # append atext " +- "
> # append atext [string toupper [lindex $astd 0] ]
> # append atext " HU"
>
> vtkTextActor textActor
> textActor ScaledTextOff
> # textActor SetInput $atext
> textActor SetInput "ROI:"
> [textActor GetPositionCoordinate] SetCoordinateSystemToNormalizedDisplay
> [textActor GetPositionCoordinate] SetValue 0.05 0.05
>
> set tprop [textActor GetTextProperty]
> $tprop SetFontSize 16
> $tprop SetFontFamilyToArial
> $tprop BoldOff
> $tprop ItalicOff
> $tprop ShadowOff
> $tprop SetLineSpacing 0.9
> $tprop SetJustificationToLeft
> $tprop SetVerticalJustificationToBottom
> $tprop SetColor 1 1 0
>
> vtkRenderer ren
> ren SetBackground 0.4 0.4 0.5
>
> vtkRenderWindow renWin
> renWin AddRenderer ren
> renWin SetSize 400 400
>
> vtkInteractorStyleImage interactor
>
> vtkRenderWindowInteractor iren
> iren SetInteractorStyle interactor
> iren SetRenderWindow renWin
>
> ren AddViewProp imageActor
> ren AddViewProp regionActor
>
> # see comment above in UpdateROI proc
> #
> # ren AddViewProp textActor
>
> iren AddObserver UserEvent {wm deiconify .vtkInteract}
> renWin Render
>
> set cam [ren GetActiveCamera]
> $cam SetViewUp 0 1 0
> $cam Azimuth 270
> $cam Roll 270
> $cam Dolly 1.7
> ren ResetCameraClippingRange
>
> renWin Render
>
> # Prevent the tk window from showing up then start the event loop.
> wm withdraw .
>
> # pipeline works in current VTK CVS if we
> # now update the accumulate here with a tcl proc
> #
> UpdateROI
>
>
> _______________________________________________
> vtk-developers mailing list
> vtk-developers at vtk.org
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>
More information about the vtk-developers
mailing list