[vtkusers] vtkSphereWidget::GetPolyData can't get up-to-date data

Weiguang Guan guanw at rhpcs.mcmaster.ca
Thu Sep 1 08:56:32 EDT 2005


Hi Dean,

I'm glad it's been fixed. My intention was to raise attention to it. For 
people who use 4.4 or earlier version there is a workaround (which I use)  
--- Adding a member function
	vtkPolyData* GetPolyData() {
		return this->SphereSource->GetOutput(); 
	}

Weiguang
-- 
========================================================
Weiguang Guan, Research Engineer
RHPCS, McMaster University
========================================================

On Wed, 31 Aug 2005 dean.inglis at camris.ca wrote:

> Hi Weiguang, 
> 
> have you tried the cvs version?  The script below
> works for me...
> 
> Dean
> 
> 
> 
> Hi,
> 
> I find that vtkSphereWidget::GetPolyData can NOT get up-to-date polydata
> after InteractionEvent or EndInteraction events are invoked. This is true 
> at least for 4.4. Not sure whether nightly update has got rid of the 
> problem or not.
> 
> Weiguang
> 
> /////////////////////////////////
> 
> package require vtk
> package require vtkinteraction
> package require vtktesting
> 
> # This example demonstrates how to use the vtkSphereWidget to control the
> # position of a light.
> 
> # Start by loading some data.
> #
> vtkDEMReader dem
>     dem SetFileName "$VTK_DATA_ROOT/Data/SainteHelens.dem"
>     dem Update
> 
> set Scale 2
> vtkLookupTable lut
>   lut SetHueRange 0.6 0
>   lut SetSaturationRange 1.0 0
>   lut SetValueRange 0.5 1.0
> set lo [expr $Scale * [lindex [dem GetElevationBounds] 0]]
> set hi [expr $Scale * [lindex [dem GetElevationBounds] 1]]
> 
> vtkImageShrink3D shrink
>   shrink SetShrinkFactors 4 4 1
>   shrink SetInputConnection [dem GetOutputPort]
>   shrink AveragingOn
> 
> vtkImageDataGeometryFilter geom
>   geom SetInputConnection [shrink GetOutputPort]
>   geom ReleaseDataFlagOn
> 
> vtkWarpScalar warp
>   warp SetInputConnection [geom GetOutputPort]
>   warp SetNormal 0 0 1
>   warp UseNormalOn
>   warp SetScaleFactor $Scale
>   warp ReleaseDataFlagOn
> 
> vtkElevationFilter elevation
>   elevation SetInputConnection [warp GetOutputPort]
>   elevation SetLowPoint 0 0 $lo
>   elevation SetHighPoint 0 0 $hi
>   eval elevation SetScalarRange $lo $hi
>   elevation ReleaseDataFlagOn
> 
> vtkPolyDataNormals normals
>   normals SetInput [elevation GetPolyDataOutput]
>   normals SetFeatureAngle 60
>   normals ConsistencyOff
>   normals SplittingOff
>   normals ReleaseDataFlagOn
> 
> vtkPolyDataMapper demMapper
>   demMapper SetInputConnection [normals GetOutputPort]
>   eval demMapper SetScalarRange $lo $hi
>   demMapper SetLookupTable lut
>   demMapper ImmediateModeRenderingOn
> 
> vtkLODActor demActor
>   demActor SetMapper demMapper
> 
> # Create the RenderWindow, Renderer and both Actors
> #
> vtkRenderer ren1
> vtkRenderWindow renWin
>     renWin AddRenderer ren1
> vtkRenderWindowInteractor iren
>     iren SetRenderWindow renWin
>     iren LightFollowCameraOff
>     iren SetInteractorStyle ""
> 
> # Associate the line widget with the interactor
> vtkSphereWidget sphereWidget
> sphereWidget SetInteractor iren
> sphereWidget SetProp3D demActor
> sphereWidget SetPlaceFactor 4
> sphereWidget PlaceWidget
> sphereWidget TranslationOn
> sphereWidget ScaleOn
> sphereWidget HandleVisibilityOn
> sphereWidget AddObserver InteractionEvent MoveLight
> 
> sphereWidget AddObserver EndInteractionEvent MoveCopy
> 
> vtkPolyData spherePoly
> sphereWidget GetPolyData spherePoly 
> set bnds [spherePoly GetBounds]
> 
> set cx [expr 0.5 * [lindex [spherePoly GetBounds] 0] + 0.5* [lindex [spherePoly GetBounds] 1] ]
> set cy [expr 0.5 * [lindex [spherePoly GetBounds] 2] + 0.5* [lindex [spherePoly GetBounds] 3] ]
> set cz [expr 0.5 * [lindex [spherePoly GetBounds] 4] + 0.5* [lindex [spherePoly GetBounds] 5] ]
> 
> vtkTransformPolyDataFilter transFilter
> vtkTransform trans
> trans PostMultiply
> trans Translate [expr -1.0 * $cx] [expr -1.0 * $cy] [expr -1.0 * $cz]
> trans Scale 0.5 0.5 0.5 
> trans Translate $cx $cy $cz
> transFilter SetTransform trans
> transFilter SetInput spherePoly
> transFilter Update
> 
> vtkPolyDataMapper sphereMapper
> sphereMapper SetInput [transFilter GetOutput]
> 
> vtkActor sphereActor
> sphereActor SetMapper sphereMapper
> 
> # Add the actors to the renderer, set the background and size
> #
> ren1 AddActor demActor
> ren1 AddActor sphereActor
> 
> ren1 SetBackground 1 1 1
> renWin SetSize 300 300
> ren1 SetBackground 0.1 0.2 0.4
> 
> set cam1 [ren1 GetActiveCamera]
> $cam1 SetViewUp 0 0 1
> eval $cam1 SetFocalPoint [[dem GetOutput] GetCenter]
> $cam1 SetPosition 1 0 0
> ren1 ResetCamera
> $cam1 Elevation 25
> $cam1 Azimuth 125
> $cam1 Zoom 1.25
> 
> vtkLight light
> eval light SetFocalPoint [[dem GetOutput] GetCenter]
> ren1 AddLight light
> 
> sphereWidget On
> 
> # render the image
> #
> iren AddObserver UserEvent {wm deiconify .vtkInteract}
> renWin Render
> 
> # Prevent the tk window from showing up then start the event loop.
> wm withdraw .
> 
> # Actually probe the data
> 
> proc MoveLight {} {
>     eval light SetPosition [sphereWidget GetHandlePosition]
> }
> 
> proc MoveCopy {} {
>    sphereWidget GetPolyData spherePoly 
> 
> set bnds [spherePoly GetBounds]
> 
> set cx [expr 0.5 * [lindex [spherePoly GetBounds] 0] + 0.5* [lindex [spherePoly GetBounds] 1] ]
> set cy [expr 0.5 * [lindex [spherePoly GetBounds] 2] + 0.5* [lindex [spherePoly GetBounds] 3] ]
> set cz [expr 0.5 * [lindex [spherePoly GetBounds] 4] + 0.5* [lindex [spherePoly GetBounds] 5] ]
> 
> trans Identity
> trans PostMultiply
> trans Translate [expr -1.0 * $cx] [expr -1.0 * $cy] [expr -1.0 * $cz]
> trans Scale 0.5 0.5 0.5 
> trans Translate $cx $cy $cz
> transFilter SetInput spherePoly
> transFilter Update
> 
>    sphereMapper Modified
> }
> 
> 




More information about the vtkusers mailing list