//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 !!
#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;
}