Search code examples
c++qtvtkopencascade

Defining the center of a VTKPolyDataMapper


I have an application that imports a STEP file an transforms the geometry to a OpenCascade object. Then, this object is visualized through a VTK viewer.

This is the code (C++, QT):

Import STEP file and convert it in a OpenCascade object

QString pathFileName = "component.step" ;
STEPControl_Reader reader;
reader.ReadFile(pathFileName.toStdString().c_str());
reader.NbRootsForTransfer();
reader.TransferRoots();
TopoDS_Shape shape;
shape = reader.OneShape();
BRepTools::Clean(shape);

Visualize the shape using VTK

IVtkOCC_Shape::Handle shapeImpl = new IVtkOCC_Shape(shape);
vtkSmartPointer<IVtkTools_ShapeDataSource> DS = vtkSmartPointer<IVtkTools_ShapeDataSource>::New();
DS->SetShape(shapeImpl);

vtkSmartPointer<vtkPolyDataMapper> Mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
Mapper->SetInputConnection(DS->GetOutputPort());
vtkSmartPointer<vtkActor> Actor = vtkSmartPointer<vtkActor>::New();
Actor->SetMapper(Mapper);

vtkSmartPointer<vtkRenderer> Renderer = vtkSmartPointer<vtkRenderer>::New();
Renderer->AddActor(Actor);

The result is shown here:

enter image description here

It is not bad, however, the coordinate axis is quite far away, as we can see if I zoom in:

enter image description here

If I print the center of the mapper, I get these values:

X: 0

Y: 172.333

Z: 0

I would like to set the "Y" to cero, but I have no idea of how to do it, since the attribute "center" of the class is protected.


Solution

  • vtkAxesActor *axes = vtkAxesActor::New();
    vtkOrientationMarkerWidget *widget = vtkOrientationMarkerWidget::New();
    widget->SetDefaultRenderer(renderer);
    widget->SetOrientationMarker(axes);
    widget->SetInteractor(ren);
    widget->EnabledOn();
    

    If you add code like this, you can see coordinate axis on left bottom corner.