[vtkusers] How to use vtkTransform with vtkImagePlaneWidget

Uril Yakubov uyakubov at rotman-baycrest.on.ca
Wed Oct 29 10:46:23 EDT 2008


Hi Dean,

Thank you for help.

I have question. I executed code that you sent me and came to the
conclusion that rotation centered by origin and I need centered at the
center of the image. Using GetWholeExtent of the Image data I got xMin,
xMax, yMin, yMax, zMin, zMax. I have for example xMin = 0 xMax = 255
yMin = 0 yMax = 255 zMin = 0 zMax = 57   so I calculated center of the
image 127, 127, 28.

    set pt1 [planeWidgetZ GetPoint1 ]
    set pt2 [planeWidgetZ GetPoint2 ]
    set wo [planeWidgetZ GetOrigin ] 
    set normal [planeWidgetZ GetNormal ]

    set transform [vtkTransform New]
    $transform PostMultiply

    eval $transform Translate -127.0 -127.0 -28.0
    eval $transform RotateX  1  # Rotation around X 
    eval $transform Translate 127.0 127.0 28.0


    set points [vtkPoints New ]
    eval $points InsertNextPoint $pt1
    eval $points InsertNextPoint $pt2
    eval $points InsertNextPoint $wo

    set newpoints [vtkPoints New ]
    eval $transform TransformPoints $points $newpoints

    eval planeWidgetZ SetPoint1 [$newpoints GetPoint 0  ]
    eval planeWidgetZ SetPoint2 [$newpoints GetPoint 1  ]
    eval planeWidgetZ SetOrigin [$newpoints GetPoint 2  ]
    eval planeWidgetZ UpdatePlacement 
   
    set pt11 [$newpoints GetPoint 0  ]
    set pt12 [$newpoints GetPoint 1  ]
    set pt13 [$newpoints GetPoint 2  ]

Now it is better but still it is not exactly  centered at the center of
the image. Do you now what could be the problem?



Thank you,

Uril.




On Thu, 2008-08-07 at 08:12 -0400, Dean Inglis wrote:
> Hi Uril,
> 
>  
> 
> If you look at the doxygen documentation for this class,
> 
> you will see that you can recover the center and normal of the plane,
> 
> GetCenter GetNormal, as well as the three points defining a pair of 
> 
> orthonormal axes corresponding to its bottom and left side edges:
> 
> GetOrigin, GetPoint1, GetPoint2.  vtkTransform can be used
> 
> to rotate those points around the plane normal, 
> 
> as long as you know the origin of the image data that it slices
> through:
> 
>  
> 
> vtkImagePlaneWidget widget  
> 
> widget->GetPoint1(pt1);
> 
> widget->GetPoint2(pt2);
> 
> widget->GetOrigin(wo);
> 
> widget->GetNormal(n);
> 
>  
> 
> vtkImageData image
> 
> image->GetOrigin(io);
> 
>  
> 
> vtkTransform transform
> 
> // may have to be transform->PreMultiply() or
> transform->PostMultiply() here … I always forget
> 
> transform->Translate(io);
> 
> transform->RotateWXYZ(angle,n[0], n[1], n[2]);
> 
> transform->Translate(-io[0], -io[1], -io[2]);
> 
>  
> 
>  
> 
> vtkPoints points
> 
> points->InsertNextPoint(pt1);
> 
> points->InsertNextPoint(pt2);
> 
> points->InsertNextPoint(wo);
> 
>  
> 
> vtkPoints newpoints
> 
>  
> 
> transform->TransformPoints(points,newpoints);
> 
>  
> 
> widget->SetPoint1(newpoints->GetPoint(0));
> 
> widget->SetPoint2(newpoints->GetPoint(1));
> 
> widget->SetOrigin(newpoints->GetPoint(2));
> 
> widget->UpdatePlacement();
> 
>  
> 
>  
> 
>  
> 
> Dean
> 
> 




More information about the vtkusers mailing list