# Cascade appanding -TopoDS\_Shape- to -vtkAppendPolyData- or -vtkCleanPolyData- or simply convert -TopoDS\_Shape- to -vtkPolyData- NOT WORKING

**URL:** https://discourse.vtk.org/t/cascade-appanding-topods-shape-to-vtkappendpolydata-or-vtkcleanpolydata-or-simply-convert-topods-shape-to-vtkpolydata-not-working/7967
**Category:** Support
**Tags:** training
**Created:** [March 3, 2022, 12:21pm UTC](https://discourse.vtk.org/t/cascade-appanding-topods-shape-to-vtkappendpolydata-or-vtkcleanpolydata-or-simply-convert-topods-shape-to-vtkpolydata-not-working/7967 "2022-03-03T12:21:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![anon41080341](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/ea5d25/32.png) [@anon41080341](https://discourse.vtk.org/u/anon41080341)
#### Post date: [March 3, 2022, 12:21pm UTC](https://discourse.vtk.org/t/cascade-appanding-topods-shape-to-vtkappendpolydata-or-vtkcleanpolydata-or-simply-convert-topods-shape-to-vtkpolydata-not-working/7967/1 "2022-03-03T12:21:13Z")

</div>

//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.

//https://www.youtube.com/watch?v=QHyhWH6xgbE&list=PL\_WFkJrQIY2iVVchOPhl77xl432jeNYfQ&index=1&t=804s&ab\_channel=Quaoar%27sWorkshop

//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 !!

```auto
#include <BRepPrimAPI_MakeBox.hxx>
#include <IVtkTools_ShapeDataSource.hxx>
#include<vtkAutoInit.h>
#include<vtkRenderer.h>
#include<vtkRenderWindow.h>
#include<vtkInteractorStyleTrackballCamera.h>
#include<vtkRenderWindowInteractor.h>
#include<vtkPolyDataMapper.h>
//VTK_MODULE_INIT(vtkRenderingOpenGl2);
#include <IGESControl_Reader.hxx> 
#include <STEPCAFControl_Reader.hxx>
VTK_MODULE_INIT(vtkInteractionStyle);
//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()
{
	//TopoDS_ShapeBox
	BRepPrimAPI_MakeBox mkBox(1, 2, 3);//mkBox1.Build();	
	const TopoDS_Shape& TopoDS_ShapeBox = mkBox.Shape();

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

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

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

	//vtkPolyData initialization
	PolyDataVTKCone->ShallowCopy(VTKcone->GetOutput());
	PolyDataVTKSphere->ShallowCopy(VTKsphere->GetOutput());
	
	//Append the meshes
	vtkNew<vtkAppendPolyData> appendFilter;
	appendFilter->AddInputData(PolyDataVTKCone);
	appendFilter->AddInputData(PolyDataVTKSphere);

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

	// Remove any duplicate points.
	vtkNew<vtkCleanPolyData> cleanFilter;
	cleanFilter->SetInputConnection(appendFilter->GetOutputPort());
	cleanFilter->Update();

	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!! 
	mapper->SetInputConnection(cleanFilter->GetOutputPort());
	mapper->AddInputConnection(TOPOBOXource->GetOutputPort());
	vtkNew<vtkActor> actor;
	actor->SetMapper(mapper);
	//////////////////////////////////////
	vtkNew<vtkRenderWindow> renwin;
	vtkNew<vtkRenderer> ren;
	renwin->AddRenderer(ren);
	vtkNew<vtkInteractorStyleTrackballCamera> istyle;
	vtkNew<vtkRenderWindowInteractor> iren;
	iren->SetRenderWindow(renwin);
	iren->SetInteractorStyle(istyle);
	ren->AddActor(actor);
	renwin->Render();
	iren->Start();
	return 0;
}

```

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [March 6, 2022, 11:00pm UTC](https://discourse.vtk.org/t/cascade-appanding-topods-shape-to-vtkappendpolydata-or-vtkcleanpolydata-or-simply-convert-topods-shape-to-vtkpolydata-not-working/7967/2 "2022-03-06T23:00:53Z")

</div>

> [@anon41080341](#):
>
> `Is there a way to convert TopoDS_Shape to vtkPolyData ?`

No, you need to write the conversion code yourself. See here for an example:  
[https://github.com/f3d-app/f3d/blob/master/src/library/vtkF3DOCCTReader.cxx#L68](https://github.com/f3d-app/f3d/blob/master/src/library/vtkF3DOCCTReader.cxx#L68)

---

<div class="post-metadata">

### Author: ![anon41080341](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/ea5d25/32.png) [@anon41080341](https://discourse.vtk.org/u/anon41080341)
#### Post date: [March 9, 2022, 11:39am UTC](https://discourse.vtk.org/t/cascade-appanding-topods-shape-to-vtkappendpolydata-or-vtkcleanpolydata-or-simply-convert-topods-shape-to-vtkpolydata-not-working/7967/3 "2022-03-09T11:39:10Z")

</div>

Dear @mwestphal  
1)please check out my new post about the Latest OpenCascade YouTube. 🙏  
[https://discourse.vtk.org/t/lesson-17-1-point-membership-classification-with-opencascade-vtk/8009](https://discourse.vtk.org/t/lesson-17-1-point-membership-classification-with-opencascade-vtk/8009)

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. 🙄

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);

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

// Create cutter  
vtkNew cutter;  
cutter-\>SetCutFunction(VTKplane);  
cutter-\>SetInputConnection(VTKsphere-\>GetOutputPort()); // PUT TopoDS\_ShapeCONE instead!!  
cutter-\>Update();

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 🙏

---

<div class="post-metadata">

### Author: ![whophil](https://discourse.vtk.org/user_avatar/discourse.vtk.org/whophil/32/2857_2.png) [@whophil](https://discourse.vtk.org/u/whophil)
#### Post date: [March 19, 2022, 3:46pm UTC](https://discourse.vtk.org/t/cascade-appanding-topods-shape-to-vtkappendpolydata-or-vtkcleanpolydata-or-simply-convert-topods-shape-to-vtkpolydata-not-working/7967/4 "2022-03-19T15:46:04Z")

</div>

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

OpenCascade offers [this API](https://dev.opencascade.org/doc/refman/html/class_i_vtk_o_c_c___shape_mesher.html) for meshing `TopoDS_Shape` and creating `vtkPolyData`. I use this API without issues.
