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

Cory Quammen cory.quammen at kitware.com
Wed Jul 22 13:05:06 EDT 2015


Ishan,

The actor->RotateZ(1); call rotates only the visible representation of the
cube, not the actual points that define the cube. Use
vtkTransformPolyDataFilter [1] to transform the cube source and save the
output of the transform filter.

[1]
http://www.vtk.org/doc/release/6.2/html/classvtkTransformPolyDataFilter.html

HTH,
Cory

On Wed, Jul 22, 2015 at 1:00 PM, Ishan Tembhekar <
ishan.tembhekar at caltech.edu> wrote:

> Hello everyone,
>
> I am new to using VTK and to this forum. I have tried searching for an
> answer for this issue for a while and wanted some help.
>
> I am writing a code in c++ that generates an output of a cube and stores
> it in a .vtp file. The code is as follows: (The variables center,
> _widthOfBottomFace, _widthOfSideFace, _widthInZDirection are defined
> elsewhere)
>
> vtkSmartPointer<vtkCubeSource> cubeSource =
>       vtkSmartPointer<vtkCubeSource>::New();
>
>     //set dimensions of cube
>     cubeSource->SetCenter(center[0], center[1], center[2]);
>     cubeSource->SetXLength(_widthOfBottomFace);
>     cubeSource->SetYLength(_widthOfSideFace);
>     cubeSource->SetZLength(_widthInZDirection);
>     cubeSource->Update();
>
>     //rotate the cube now
>     vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
>     mapper->SetInputData(cubeSource->GetOutput());
>
>     vtkActor* actor = vtkActor::New();
>     actor->SetMapper(mapper);
>     actor->SetOrigin(cubeSource->GetCenter());
>
>     actor->RotateZ(1);
>
>
>     //create the writer
>     vtkSmartPointer<vtkXMLPolyDataWriter> writer =
>       vtkSmartPointer<vtkXMLPolyDataWriter>::New();
>
>     // Build the filename
>     char buffer[500];
>     sprintf(buffer, "%06u", fileIndex);
>     string filename =string("CuboidalIndenter_") +
>       string(buffer) + string(".vtp");
>
>     //printf("writing file to %s\n", filename.c_str());
>     writer->SetFileName(filename.c_str());
>     writer->SetInputConnection(cubeSource->GetOutputPort());
>
>
>     // write the vtk file
>     writer->SetDataModeToBinary();
>     int result = writer->Write();
>     if (result != 1) {
>       printf("Error writing cuboidal indenter vtk file\n");
>
>
> I want to have the rotated cube as the output and currently I am using the
> object cubeSource which does not give me the rotated cube.
> Can someone tell me how I can write out the rotated cube ?
>
> Thank you so much!
>
> -Ishan
>
> _______________________________________________
> 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/5af0ae38/attachment.html>


More information about the vtkusers mailing list