visualize an OCCT topological shape in VTK viewer

I want to visualize an OCCT topological shape in VTK viewer.

I refer to the tutorial of VIS.However there throw exception in 'Mapper->SetInputConnection(DS->GetOutputPort());'

Here is my code:

// 1 . Create IVtkOCC_Shape instance(VIS wrapper for OCCT shape) and initialize it with TopoDS_Shape object containing the actual geometry.
//TopoDS_Shape aShape = makebottle();
TopoDS_Shape aShape;
BRep_Builder B;
BRepTools::Read(aShape, "D:\\OpenCASCADE7.0.0-vc12-64\\opencascade-7.0.0\\data\\occ\\face.brep",B);

//Initialize aShape variable: e.g. load it from BREP file
IVtkOCC_Shape::Handle aShapeImpl = new IVtkOCC_Shape(aShape);

//Handle(IVtkOCC_Shape)
aShapeImpl = new IVtkOCC_Shape(aShape);

// 2 .Create VTK polygonal data source for the target OCCT topological shape and initialize it with created 
// IVtkOCC_Shape instance. At this stage the faceter is implicitly plugged.
vtkSmartPointer DS = vtkSmartPointer ::New();
DS->SetShape(aShapeImpl); 

// 3. visualize the load shape in usual VTK way starting a pipline from the newly created specific source.
vtkSmartPointer Mapper = vtkSmartPointer::New();
Mapper->SetInputConnection(DS->GetOutputPort());
vtkSmartPointer Actor = vtkSmartPointer::New();
Actor->SetMapper(Mapper);
vtkSmartPointer renderer = vtkSmartPointer::New();
renderer->AddActor(Actor);
renderer->SetBackground(0.1, 0.2, 0.4);
vtkSmartPointer renWin = vtkSmartPointer::New();
renWin->AddRenderer(renderer);
renWin->SetSize(300, 300);
renWin->SetPosition(300, 300);
// vtkSmartPointer iren = vtkSmartPointer::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer style = vtkSmartPointer::New();
iren->SetInteractorStyle(style);
iren->Initialize();
iren->Start();

 

Heike Broichhausen's picture

Hello Rui,

this is exactly my problem as well. How did you sort this issue?

1364255742_147980's picture

Hello Rui Song ,

I also encountered this problem now, did you solve it? occ730

Alan Saillet's picture

I had the same issue.

When printing cpp std::cout << "GetNumberOfOutputPorts : " << occSource->GetNumberOfOutputPorts() << std::endl;, I had a negative value.

To fix it, during the compilation of OCCT, it you chosse "USE_VTK" the VTK 6.1 will be selected automatically in 3rparty dir. Change it to the version you want to use.

I am running with OCCT 7.8.1 and VTK 9.3 with this code:

#include <BRepPrimAPI_MakeBox.hxx>
#include <IVtkTools_ShapeDataSource.hxx>
#include <vtkType.h>
#include <vtkAutoInit.h>
#include <vtkRenderWindow.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>
#include <vtkInteractorStyleTrackballCamera.h>

VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)

int main()
{
BRepPrimAPI_MakeBox mkBox(1., 2., 3);
const TopoDS_Shape& shape = mkBox.Shape();

vtkNew<vtkRenderWindow> renWin;

vtkNew<vtkRenderer> ren;
renWin->AddRenderer(ren);
renWin->SetSize(640, 640);

vtkNew<vtkInteractorStyleTrackballCamera> istyle;
vtkNew<vtkRenderWindowInteractor> iren;

iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(istyle);

vtkNew<IVtkTools_ShapeDataSource> DS;
DS->SetShape(new IVtkOCC_Shape(shape));

vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(DS->GetOutputPort());

vtkNew<vtkActor> actor;
actor->SetMapper(mapper);

ren->AddActor(actor);

renWin->Render();
iren->Start();

return 0;
}