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

Ishan Tembhekar ishan.tembhekar at caltech.edu
Wed Jul 22 13:00:21 EDT 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150722/11956cf0/attachment.html>


More information about the vtkusers mailing list