There are many points in 3D, we use them for volume rendering by vtkSurfaceReconstructionFilter,But the results seem ugly, and I wonder what the problem is?
Here are my code and results:
auto colors = vtkSmartPointer<vtkNamedColors>::New();
colors->SetColor("Bkg", 0.3, 0.4, 0.5);
vtkSmartPointer<vtkRenderer> contourRender = vtkSmartPointer<vtkRenderer>::New();
ifstream fs("../data/37.dat");
//vtkIdType idtype;
int feature_num;
fs>>feature_num;
if(feature_num >0){
for(int feature_idx = 0 ; feature_idx < feature_num; feature_idx++){
int feature_size;
fs>>feature_size;
std::cout<<"Feature size = "<<feature_size<<endl;
std::cout<<"Feature id = "<<feature_idx<<std::endl;
vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();
for(int feature_point_idx = 0 ; feature_point_idx < feature_size; feature_point_idx++){
int x, y, z;
fs>>x>>y>>z;
pts->InsertNextPoint(x,y,z);
}
vtkSmartPointer<vtkPolyData> polygonPolyData =vtkSmartPointer<vtkPolyData>::New();
polygonPolyData->SetPoints(pts);
std::cout<<"test 1"<<std::endl;
//add
//vtkSmartPointer<vtkSurfaceReconstructionFilter> surf = vtkSmartPointer<vtkSurfaceReconstructionFilter>::New();
vtkSmartPointer<vtkSurfaceReconstructionFilter> surf = vtkSmartPointer<vtkSurfaceReconstructionFilter>::New();
std::cout<<"test 2"<<std::endl;
surf->SetInputData(polygonPolyData);
std::cout<<"test 3"<<std::endl;
surf->Update();
std::cout<<"test 4"<<std::endl;
vtkSmartPointer<vtkContourFilter> contour = vtkSmartPointer<vtkContourFilter>::New();
contour->SetInputConnection(surf->GetOutputPort());
contour->SetValue(0, 0.0);
contour->SetValue(1, 1.0);
contour->SetValue(2, 2.0);
contour->Update();
vtkSmartPointer<vtkPolyDataMapper> contourMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
contourMapper->SetInputData(contour->GetOutput());
vtkSmartPointer<vtkActor> contourActor = vtkSmartPointer<vtkActor>::New();
contourActor->SetMapper(contourMapper);
contourActor->GetProperty()->SetColor(colors->GetColor3d("banana").GetData());
contourRender->AddActor(contourActor);
std::cout<<"test 5"<<std::endl;
}
}
contourRender->SetBackground(colors->GetColor3d("Bkg").GetData());
auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetSize(640, 80);
renderWindow->AddRenderer(contourRender);
auto renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
auto style = vtkSmartPointer<MouseInteractorHighLightActor>::New();
style->SetDefaultRenderer(contourRender);
renderWindowInteractor->SetInteractorStyle(style);
renderWindow->Render();
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
return EXIT_SUCCESS;