[vtkusers] Writing a rotated vtkcubesource in a .vtp file

Ishan Tembhekar ishan.tembhekar at caltech.edu
Wed Jul 22 19:06:27 EDT 2015


Hi Cory,

Thanks for the tip. I have been trying to implement that for a while and
still hasn't worked for some reason.. This is the code I have:

//set dimensions of cube
    cubeSource->SetCenter(center[0], center[1], center[2]);
    cubeSource->SetXLength(_widthOfBottomFace);
    cubeSource->SetYLength(_widthOfSideFace);
    cubeSource->SetZLength(_widthInZDirection);
    cubeSource->Update();

    //create a transformation object
    vtkSmartPointer<vtkTransform> transformation =
      vtkSmartPointer<vtkTransform>::New();
    //use this transformation object in a transformFilter
    vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter =
      vtkSmartPointer<vtkTransformPolyDataFilter>::New();
    transformFilter->SetInputConnection(cubeSource->GetOutputPort());
    transformFilter->SetTransform(transformation);
    //first take the cube back to the origin for rotation
    transformation->Translate(-center[0],
                              -center[1],
                              -center[2]);
    //now rotate it with the given angle (in degrees)
    transformation->RotateZ(45.);
    //translate it back
    transformation->Translate(center[0],
                              center[1],
                              center[2]);
    transformFilter->Update();

I have attached the output that I get for various cases. The big box in the
center is just for reference. I am generating the small one by this code.

1) The black box corresponds to if I *do nothing. *So if I commented out
the transformation, then I would get the black box.
2) The pink box corresponds to *just negative translation.* So just the
first translate line of the code is executed and the rotation and positive
translation is not.
3) The small grey box is *negative translation and rotation*. So, the
positive translation is not executed.
4) The blue box is *negative translate, rotate and positive translate. *This
is when all of the above code is executed.

Observations:

1) and 2) look correct.
3) I would have expected the outcome to be located at the same point as the
pink box but rotated around the origin (which is shown as the red,green and
yellow cross)
4) This is where I wanted the outcome to be the black box but rotated.

Remarks: I think that the transform is somehow applying the transformation
to both the cube AND the axes. So in case 4, when I do negative translate,
the axis goes down as well. Then when I rotate, the axis rotates as well
and finally when I do positively translate, instead of going straight up,
the box goes along the "up" of the rotated axis and you see the blue box
where it is.

Can you help me here? Is there some way I can stop the axis from doing the
same things that my cube is doing? I apologize for the long email

Thanks again!

-Ishan

On Wed, Jul 22, 2015 at 11:18 AM, Cory Quammen <cory.quammen at kitware.com>
wrote:

> You'll need to translate your cube by the negated center of the cube, then
> rotate. You can do this all in the same vtkTransform object.
>
> - Cory
>
> On Wed, Jul 22, 2015 at 1:58 PM, ishantembhekar <
> ishan.tembhekar at caltech.edu> wrote:
>
>> <
>> http://vtk.1045678.n5.nabble.com/file/n5733047/Screen_Shot_2015-07-22_at_10.png
>> >
>>
>> Hi Cory,
>>
>> Thank you so much for your immediate response! The
>> vtkTransformPolyDataFilter worked and it now gives me a rotated cube. I
>> replaced the mapper and the actor with the following lines:
>>
>> //create a rotation object
>>     vtkSmartPointer<vtkTransform> rotation =
>>       vtkSmartPointer<vtkTransform>::New();
>>     //the angle is measured in degrees for some reason
>>     rotation->RotateZ(45.);
>>  //use this rotation object in a transformFilter
>>     vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter =
>>       vtkSmartPointer<vtkTransformPolyDataFilter>::New();
>>     transformFilter->SetInputConnection(cubeSource->GetOutputPort());
>>     transformFilter->SetTransform(rotation);
>>     transformFilter->Update();
>>
>> However, it is rotating about the z-axis and the origin (as shown in the
>> image I attached). What can I do for it to rotate about the center of the
>> cube? I tried using SetCenter for both the vtkTransform and the
>> PolyDataFilter but they do not have that method. Any ideas?
>>
>> Thanks once again!
>>
>> -Ishan
>>
>>
>>
>> --
>> View this message in context:
>> http://vtk.1045678.n5.nabble.com/Writing-a-rotated-vtkcubesource-in-a-vtp-file-tp5733044p5733047.html
>> Sent from the VTK - Users mailing list archive at Nabble.com.
>> _______________________________________________
>> 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
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>
>
>
> --
> Cory Quammen
> R&D Engineer
> Kitware, Inc.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150722/c89d0996/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2015-07-22 at 3.58.07 PM.png
Type: image/png
Size: 14129 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150722/c89d0996/attachment.png>


More information about the vtkusers mailing list