Cascade appanding -TopoDS_Shape- to -vtkAppendPolyData- or -vtkCleanPolyData- or simply convert -TopoDS_Shape- to -vtkPolyData- NOT WORKING

//Dear OCC VTK stuff

//In short, The problem is, I cannot append TopoDS_Shape to vtkAppendPolyData nor to vtkCleanPolyData.

//I cant even convert TopoDS_Shape to vtkPolyData.

//If you run this simple example, this is the same as shown in Lesson 17 but in VTK.


//you will see the same blade from my previous examples(and some extra shapes from the VTK library)

//The problem is that I can show only the points and the shapes, but I cannot append to them, my IGES Import.

//Or even to a simple TopoDS_Shape box from BRepPrimAPI_MakeBox

//I have Written two Questions in the correct places. if you could spare the time.

//thank you very much for any help !!

#include <BRepPrimAPI_MakeBox.hxx>
#include <IVtkTools_ShapeDataSource.hxx>
#include <IGESControl_Reader.hxx> 
#include <STEPCAFControl_Reader.hxx>
//Lesson 17
#include <Bnd_Box.hxx>
#include <BRepBndLib.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <vtkCubeSource.h>
#include <vtkSphereSource.h>
#include <vtkConeSource.h>
#include <vtkAppendPolyData.h >
#include <vtkCleanPolyData.h >
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
int main()
	BRepPrimAPI_MakeBox mkBox(1, 2, 3);//mkBox1.Build();	
	const TopoDS_Shape& TopoDS_ShapeBox = mkBox.Shape();

	vtkNew<vtkSphereSource> VTKsphere;
	VTKsphere->SetCenter(5, 0, 0);

	vtkNew<vtkConeSource> VTKcone;
	VTKcone->SetCenter(-5, 0, 0);

	//vtkPolyData creation
	vtkNew<vtkPolyData> PolyDataVTKCone;
	vtkNew<vtkPolyData> PolyDataVTKSphere;

	//vtkPolyData initialization
	//Append the meshes
	vtkNew<vtkAppendPolyData> appendFilter;

	/////First question /////////////////////////////////////////////////////
	//Is there a way to convert TopoDS_Shape to vtkPolyData ?
	//the following ways,didnt work.doing somting wrong.
	//vtkNew<vtkPolyData> PolyDataTopoDS_ShapeBox;
	//3)appendFilter->AddInputData(new IVtkOCC_Shape(TopoDS_ShapeBox));

	// Remove any duplicate points.
	vtkNew<vtkCleanPolyData> cleanFilter;

	vtkNew<IVtkTools_ShapeDataSource> TOPOBOXource;
	TOPOBOXource->SetShape(new IVtkOCC_Shape(TopoDS_ShapeBox));///NO SHOW ON SCREEN !!

	// Create a mapper and actor
	vtkNew<vtkPolyDataMapper> mapper;

	/////Second Question/////////////////////////////////////////////////////
	//if appending my TopoDS_Shapes cant be done (box created by BRepPrimAPI_MakeBox)
	//Why does AddInputConnection does not append my BRepPrimAPI_MakeBox and my cleanFilter?(with the TOPOBOXource and VTK SHAPES) 
	//Should and can i,Append IGESource and TOPOBOXource as they are both IVtkTools_ShapeDataSource type
	//And if so how?
	//Thank You Vey Much!! 
	vtkNew<vtkActor> actor;
	vtkNew<vtkRenderWindow> renwin;
	vtkNew<vtkRenderer> ren;
	vtkNew<vtkInteractorStyleTrackballCamera> istyle;
	vtkNew<vtkRenderWindowInteractor> iren;
	return 0;

No, you need to write the conversion code yourself. See here for an example:

Dear @mwestphal
1)please check out my new post about the Latest OpenCascade YouTube. :pray:

If you will look inside, you will notice, I represent a Cone with old AIS OCC BRepPrimAPI_MakeCone.
Wich will be represented as TopoDS_Shape.

2)Is there no simple conversion so that i can insert a TopoDS_Shape in the next lines. :roll_eyes:

gp_Ax2 sphere_origin(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1));
BRepPrimAPI_MakeCone mkCone(sphere_origin, 1.0,0.01,1);
const TopoDS_Shape& TopoDS_ShapemkConeTMP = mkCone.Shape();
TopoDS_Shape TopoDS_ShapeCONE = static_cast<TopoDS_Shape>(TopoDS_ShapemkConeTMP);

vtkNew VTKplane;
VTKplane->SetOrigin(0, 0, 0);
VTKplane->SetNormal(0, 0, 1);

// Create cutter
vtkNew cutter;
cutter->SetInputConnection(VTKsphere->GetOutputPort()); // PUT TopoDS_ShapeCONE instead!!

Of Course, my Goul is to be able to put TopoDS_ShapeIGES, In this code.
But , the mesh is also represented in TopoDS_Shape. So the question remains the same.

Thank you as always. for the time and effort :pray:

This seems to be more of an OpenCascade question than a VTK one.

OpenCascade offers this API for meshing TopoDS_Shape and creating vtkPolyData. I use this API without issues.

1 Like