2

我创建了一个二十面体并对其进行了细分,我不想显示它,但它似乎未细分地显示它。这是我的代码:

vtkSmartPointer<vtkPlatonicSolidSource> icosahedron = vtkSmartPointer<vtkPlatonicSolidSource>::New();
     icosahedron->SetSolidTypeToIcosahedron();
     icosahedron->Update();

     cout << " Centre is " << icosahedron->GetOutput()->GetCenter()[0] << ", " << icosahedron->GetOutput()->GetCenter()[1] << ", " << icosahedron->GetOutput()->GetCenter()[2] << endl;
     cout << "    There are " << icosahedron->GetOutput()->GetNumberOfPolys() << " triangles." << endl;
     cout << " there are " << icosahedron->GetOutput()->GetNumberOfPoints() << " points " << endl;

     vtkSmartPointer<vtkPolyDataAlgorithm> subdivisionFilter;
     subdivisionFilter = vtkSmartPointer<vtkLinearSubdivisionFilter>::New();
     dynamic_cast<vtkLinearSubdivisionFilter *> (subdivisionFilter.GetPointer())->SetNumberOfSubdivisions(2);
     subdivisionFilter->SetInput(icosahedron->GetOutput());
     subdivisionFilter->Update();

     cout << " After " << endl;
     std::cout << "    There are " << subdivisionFilter->GetOutput()->GetNumberOfPoints() << " points." << std::endl;
     std::cout << "    There are " << subdivisionFilter->GetOutput()->GetNumberOfPolys() << " triangles." << std::endl;


     vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
     mapper->SetInputConnection(subdivisionFilter->GetOutputPort());

     vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
     actor->SetMapper(mapper);

     vtkSmartPointer<vtkRenderer> renderer =  vtkSmartPointer<vtkRenderer>::New();
     vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();

     renderWindow->AddRenderer(renderer);

     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
     renderWindowInteractor->SetRenderWindow(renderWindow);

     //Add the actors to the scene
     renderer->AddActor(actor);
     renderer->SetBackground(.1, .2, .3);

     //Render and interact
     renderWindow->Render();
     renderWindowInteractor->Start();

控制台输出为:

 Centre is 0, 0, 0
    There are 20 triangles.
 there are 12 points 
 After 
    There are 162 points.
    There are 320 triangles.

确认它确实被细分了。

4

1 回答 1

0

打开线框模式后我可以看到分区:

#include <vtkProperty.h>
....
actor->GetProperty()->SetRepresentationToWireframe();

您所看到的是该算法将新点添加到与现有三角形相同的平面中,因此当您将结果渲染为表面时,它看起来没有任何不同。

于 2013-10-22T19:02:12.963 回答