I have another problem for showing vtkPartitionedDataSetCollection data.
Could you please tell me how to show vtkPartitionedDataSetCollection? I know one method is to show the data separately. Is there any method to show vtkPartitionedDataSetCollection at once (only one mapper and one actor)?
The method for separately show the data as following:
vtkNew<vtkPoints> points1;
points1->InsertNextPoint(0.0, 0.0, 0.0);
points1->InsertNextPoint(1.0, 0.0, 0.0);
points1->InsertNextPoint(1.0, 1.0, 0.0);
points1->InsertNextPoint(0.0, 1.0, 0.0);
points1->InsertNextPoint(0.0, 0.0, 1.0);
points1->InsertNextPoint(1.0, 0.0, 1.0);
points1->InsertNextPoint(1.0, 1.0, 1.0);
points1->InsertNextPoint(0.0, 1.0, 1.0);
vtkNew<vtkPoints> points2;
points2->InsertNextPoint(1.0, 0.0, 0.0);
points2->InsertNextPoint(2.0, 0.0, 0.0);
points2->InsertNextPoint(2.0, 1.0, 0.0);
points2->InsertNextPoint(1.0, 1.0, 0.0);
points2->InsertNextPoint(1.0, 0.0, 1.0);
points2->InsertNextPoint(2.0, 0.0, 1.0);
points2->InsertNextPoint(2.0, 1.0, 1.0);
points2->InsertNextPoint(1.0, 1.0, 1.0);
vtkNew<vtkCellArray> cells1;
vtkIdType hex1[8] = {0, 1, 2, 3, 4, 5, 6, 7};
cells1->InsertNextCell(8, hex1);
vtkNew<vtkUnstructuredGrid> grid1;
grid1->SetPoints(points1);
grid1->SetCells(VTK_HEXAHEDRON, cells1);
vtkNew<vtkCellArray> cells2;
vtkIdType hex2[8] = {0, 1, 2, 3, 4, 5, 6, 7};
cells2->InsertNextCell(8, hex2);
vtkNew<vtkUnstructuredGrid> grid2;
grid2->SetPoints(points2);
grid2->SetCells(VTK_HEXAHEDRON, cells2);
vtkNew<vtkIdTypeArray> id1;
id1->InsertNextValue(0);
id1->InsertNextValue(1);
id1->InsertNextValue(4);
id1->InsertNextValue(3);
id1->InsertNextValue(6);
id1->InsertNextValue(7);
id1->InsertNextValue(10);
id1->InsertNextValue(9);
grid1->GetPointData()->SetGlobalIds(id1);
vtkNew<vtkIdTypeArray> id2;
id2->InsertNextValue(1);
id2->InsertNextValue(2);
id2->InsertNextValue(5);
id2->InsertNextValue(4);
id2->InsertNextValue(7);
id2->InsertNextValue(8);
id2->InsertNextValue(11);
id2->InsertNextValue(10);
grid2->GetPointData()->SetGlobalIds(id2);
vtkNew<vtkCylinderSource> cylinderSource;
cylinderSource->SetCenter(5,0,0);
cylinderSource->SetResolution(100);
cylinderSource->SetHeight(2.0);
cylinderSource->SetRadius(1.0);
cylinderSource->Update();
vtkNew<vtkSphereSource> sphereSource;
sphereSource->SetCenter(10, 0,0);
sphereSource->SetRadius(1.0);
sphereSource->SetThetaResolution(100);
sphereSource->SetPhiResolution(100);
sphereSource->Update();
vtkNew<vtkPartitionedDataSet> partionDataSet1;
partionDataSet1->SetNumberOfPartitions(2);
partionDataSet1->SetPartition(0, grid1);
partionDataSet1->SetPartition(1, sphereSource->GetOutput());
vtkNew<vtkPartitionedDataSet> partionDataSet2;
partionDataSet2->SetNumberOfPartitions(2);
partionDataSet2->SetPartition(0, grid2);
partionDataSet2->SetPartition(1, cylinderSource->GetOutput());
vtkNew<vtkPartitionedDataSetCollection> partionDataSetColl;
partionDataSetColl->SetNumberOfPartitionedDataSets(2);
partionDataSetColl->SetPartitionedDataSet(0, partionDataSet1);
partionDataSetColl->SetPartitionedDataSet(1, partionDataSet2);
double r=1, g=0, b=0;
vtkNew<vtkRenderer> renderer;
for(vtkIdType i = 0; i<partionDataSetColl->GetNumberOfPartitionedDataSets(); i++)
{
vtkSmartPointer<vtkPartitionedDataSet> partion = partionDataSetColl->GetPartitionedDataSet(i);
for(vtkIdType j=0; j<partion->GetNumberOfPartitions(); j++)
{
vtkSmartPointer<vtkDataSet> data = partionDataSetColl->GetPartition(i, j);
vtkNew<vtkDataSetMapper> mapper;
mapper->SetInputData(data);
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
vtkNew<vtkProperty> property;
property->SetColor(r, g, b);
actor->SetProperty(property);
r-=0.2;
g+=0.2;
b+=0.1;
renderer->AddActor(actor);
}
}
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(renderWindow);
renderer->SetBackground(0.1, 0.1, 0.1);
renderWindow->SetSize(800, 600);
renderWindow->Render();
interactor->Start();