Hi,
I am trying to represent voxels using vtkcubesource and find it very slow in rendering. The number of cubes are approximately around 100k. here is the code snippet.
for( auto k = 0; k<zsteps; ++k)
for(auto j = 0; j<jsteps; ++j)
for(auto i = 0; i<isteps; ++i)
{
vtkNew<vtkCubeSource> cubesource;
cubesource->setcenter( center.x, center.y, center.z);
cubesource->SetXLength(GetStepX());
cubesource->SetYLength(GetStepY());
cubesource->SetZLength(GetStepZ());
vtkNew<vtkPolyDataMapper> icube;
icube->SetInputConnection(cubesource->GetOutputPort());
vtkNew<vtkActor> cubeActor;
cubeActor->SetMapper(icube);
renderer->AddActor(cubeActor);
}
renderer->ResetCamera();
renderWindow()->AddRenderer(renderer);
This displays the 3d profile but is terribly slow to the point where it is unusable. It takes nearly 5 minutes to render the structure and any further interactions (such as rotate or zoom in/out) with the graph takes about 45s up to a minute.
Since this approach uses one actor and mapper per each cubesource i tried using a single actor and mapper with glyph3d object which also yielded the same result. The rendering was still very slow. Here is the code with single actor and mapper
vtkNew<vtkPoints> points;
vtkNew<vtkPolyData> polydata;
vtkNew<vtkIntArray> scalars;
vtkNew<vtkGlyph3D> glyph3D;
for( auto k = 0; k<zsteps; ++k)
for(auto j = 0; j<jsteps; ++j)
for(auto i = 0; i<isteps; ++i)
{
points->InsertNextPoint(pcenter.GetX(), pcenter.GetY(), pcenter.GetZ());
scalars->InsertNextValue(iMaterial);
}
polydata->SetPoints(points);
polydata->GetPointData()->SetScalars(scalars);
vtkNew<vtkCubeSource> cubesource;
cubesource->SetXLength(GetStepX());
cubesource->SetYLength(GetStepY());
cubesource->SetZLength(GetStepZ());
glyph3D->OrientOff(); // disable orientation
//glyph3D->SetScaleModeToScaleByVectorComponents(); // sacle along each axis
glyph3D->SetSourceConnection(cubesource->GetOutputPort());
glyph3D->SetInputData(polydata);
glyph3D->Update();
vtkNew<vtkPolyDataMapper> icube;
icube->SetInputConnection(glyph3D->GetOutputPort());
vtkNew<vtkActor> cubeActor;
cubeActor->SetMapper(icube);
icube->Update();
renderer->AddActor(cubeActor);
renderer->ResetCamera();
renderWindow()->AddRenderer(renderer);
The dataset is structured points with unform spacing in 3 dimensions. The dataset is too large for a volumetric rendering. Is there any other datastructure in vtk better suited to our usecase and to help with the rendering slowness in particular. I have looked into vtkimagedata and vtkstructuredpoints but am not entirely sure.
Any help is appreciated.