[vtkusers] vtkImagePlaneWidget: how to update plane's orientation?

Miguel Sotaquirá msotaquira at gmail.com
Sat Mar 24 01:37:29 EDT 2012


Ok, now the planeWidget is oriented as expected (turns out that the
method GetResliceOutput() from vtkImagePlaneWidget wasn't giving me the
correct ImageData information, but I sorted it out).

Now I'm using the transformation to update both the planeWidget and the
vtkImageResliceViewer with the new orientation. However, when I try to
update all four views only the pane containing the 3D volume is correctly
updated, the other views remain the same (see code below).

How can I correctly update all four views? Is there something wrong during
rendering? (the last block of code below).

Thanks,
Miguel


// Transform
vtkSmartPointer<vtkTransform> transform
= vtkSmartPointer<vtkTransform>::New();
transform->PreMultiply();
transform->Translate(wc[0],wc[1],wc[2]);
transform->RotateWXYZ(90,v2[0],v2[1],v2[2]);
transform->Translate(-wc[0],-wc[1],-wc[2]);

// Modify resliceImageViewer using transformation ("whichPlane": the plane
I'm rotating; riw: the corresponding ResliceImageViewer)
double newpt[3];
vtkPlaneSource * ps = static_cast<vtkPlaneSource
*> (this->riw[whichPlane]->GetResliceCursorWidget()->
GetResliceCursorRepresentation()->GetPlaneSource());
transform->TransformPoint(this->planeWidget[whichPlane]->GetPoint1(),newpt);
ps->SetPoint1(newpt);
transform->TransformPoint(this->planeWidget[whichPlane]->GetPoint2(),newpt);
ps->SetPoint2(newpt);
transform->TransformPoint(this->planeWidget[whichPlane]->GetOrigin(),newpt);
ps->SetOrigin(newpt);

// Update placement of all planeWidgets
for(int i = 0; i < 3; i++)
{
vtkPlaneSource * psw = static_cast< vtkPlaneSource * >
(this->planeWidget[i]->GetPolyDataAlgorithm());
 psw->SetOrigin(this->riw[i]->GetResliceCursorWidget()->
GetResliceCursorRepresentation()->GetPlaneSource()->GetOrigin());
psw->SetPoint1(this->riw[i]->GetResliceCursorWidget()->
GetResliceCursorRepresentation()->GetPlaneSource()->GetPoint1());
psw->SetPoint2(this->riw[i]->GetResliceCursorWidget()->
GetResliceCursorRepresentation()->GetPlaneSource()->GetPoint2());
 this->planeWidget[i]->UpdatePlacement();
}

// So far so good. Up to this point only the pane containing the 3D view is
updated. When rendering (block below) nothing happens (????)
for (int i = 0; i < 3; i++
{
    this->riw[i]->Render();
}


2012/3/24 Miguel Sotaquirá <msotaquira at gmail.com>

> I tried normalizing v2 and I obtained the exact same result. In both cases
> (with and without normalization) the plane has the correct orientation but
> is always located on one of the edges of the volume, not on its center.
>
> Miguel
>
>
> 2012/3/23 Darshan Pai <darshanpai at gmail.com>
>
>> I think you need to normalize v2 before you compose the transform
>>
>> Sent from my iPad
>>
>> On Mar 23, 2012, at 3:09 PM, Miguel Sotaquirá <msotaquira at gmail.com>
>> wrote:
>>
>> Hi again,
>>
>> So I've managed to rotate the plane widget 90 degrees (see code below)
>> but somehow the rotated plane is not located on the center of the 3D
>> volume. In the code below I define the origin of the plane widget (wc) as
>> the center of the volume in x,y,z coordinates. I don't know if I'm not
>> defining correctly this center or the transformation (or both?)
>>
>> How can I ensure that the center of the plane matches the center of the
>> volume?
>>
>> Thanks,
>> Miguel
>>
>> // Get volume's center
>> vtkSmartPointer<vtkImageData> imageData
>> = this->planeWidget[whichPlane]->GetResliceOutput();
>> double spacing[3];
>> imageData->GetSpacing(spacing);
>> double origin[3];
>> imageData->GetOrigin(origin);
>> int extent[6];
>> imageData->GetWholeExtent(extent);
>>  // Define widget's center as the center of the volume
>> double wc[3];
>> wc[0] = origin[0] + 0.5 * spacing[0] * ( extent[0] + extent[1] );
>> wc[1] = origin[1] + 0.5 * spacing[1] * ( extent[2] + extent[3] );
>> wc[2] = origin[2] + 0.5 * spacing[2] * ( extent[4] + extent[5] );
>>  // planeWidget's vector 2 (used as the axis of rotation)
>> double v2[3];
>> this->planeWidget[whichPlane]->GetVector2(v2);
>> // Transform
>> vtkSmartPointer<vtkTransform> transform
>> = vtkSmartPointer<vtkTransform>::New();
>> transform->PreMultiply();
>> transform->Translate(wc[0],wc[1],wc[2]);
>> transform->RotateWXYZ(90,v2[0],v2[1],v2[2]);
>> transform->Translate(-wc[0],-wc[1],-wc[2]);
>> // Modify and update planeWidget
>> double newpt[3];
>>
>> transform->TransformPoint(this->planeWidget[whichPlane]->GetPoint1(),newpt);
>> this->planeWidget[whichPlane]->SetPoint1(newpt);
>>
>> transform->TransformPoint(this->planeWidget[whichPlane]->GetPoint2(),newpt);
>> this->planeWidget[whichPlane]->SetPoint2(newpt);
>>
>> transform->TransformPoint(this->planeWidget[whichPlane]->GetOrigin(),newpt);
>> this->planeWidget[whichPlane]->SetOrigin(newpt);
>> planeWidget[whichPlane]->UpdatePlacement();
>>
>>
>>
>> 2012/3/23 Miguel Sotaquirá <msotaquira at gmail.com>
>>
>>> Hi everybody!
>>>
>>> I've implemented a four pane viewer using the example found
>>> at Examples/GUI/Qt/FourPaneViewer/QtVTKRenderWindows.cxx. This viewer
>>> allows me to explore a 3-D volume using a set of three vtkImagePlaneWidgets
>>> that can be interactively placed (translated, rotated) by the user using
>>> mouse events.
>>>
>>> What I want to do now after user interaction is to take one of these
>>> planes and rotate it 90 degrees along its normal, and update the four panes
>>> accordingly. In order to do so I'm using this workflow:
>>>
>>> - Define a vtkTransform (transform) and SetMatrix as
>>> vtkImagePlaneWidget's current orientation:
>>>     vtkSmartPointer<vtkTransform> transform
>>> = vtkSmartPointer<vtkTransform>::New();
>>>     transform->PreMultiply();
>>>     transform->SetMatrix(planeWidget->GetResliceAxes());
>>>
>>> - Apply 90 degrees rotation around Y axis:
>>>     transform->RotateY(90);
>>>
>>> - Update planeWidget using methods SetOrigin, SetPoint1, SetPoint2 and
>>> UpdatePlacement, where origin, point1, point2 are extracted from "transform"
>>>
>>> When using this approach I get strange results: neither planeWidget's
>>> origin nor its extension are well defined, and I'm not able to update the
>>> four panes accordingly. The origin is located outside the 3-D volume, and
>>> the extension does not cover the entire volume.
>>>
>>> Am I missing something? How to correctly update planeWidget's
>>> orientation? Thanks for your help,
>>>
>>> Miguel
>>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120324/832706cc/attachment.htm>


More information about the vtkusers mailing list