2013-07-11 59 views
2

我已經創建了一個二十面體並對其進行了細分,但我沒有嘗試顯示它,但似乎顯示它未細分。這裏是我的代碼:VTK:顯示細分多邊形

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. 

確認其確實被細分。

+0

@HighPerformanceMark,問題是如何顯示它?如上所述,儘管將'subdivisionFilter-> GetOutputPort()'傳遞給映射器,它顯示原始未細分的二十面體不是細分的。 – Aly

回答

0

我可以開啓線框模式之後看到的各個部門:

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

你們看到的是,該算法是在同一平面上增加新的點作爲現有的三角形,所以當你渲染的結果作爲一個表面,它看起來沒什麼不同。