1.VTK绘制圆锥体

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20

//
#include <vtkConeSource.h>

void ShapeRender::ConeRender() {
    // 创建圆锥对象
    vtkSmartPointer<vtkConeSource> cone = vtkSmartPointer<vtkConeSource>::New();
    //设置圆锥面,越大越接近圆锥面;可以对比下,设置10与100的区别
    cone->SetResolution(100);
    
    // 创建 Mapper
    vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection(cone->GetOutputPort());
    
    // 创建 Actor
    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->SetColor(1.0, 0.0, 1.0);  // 设置颜色为紫色
    VTKRender(actor);
}

2.效果

  • cone->SetResolution(10)时

image

  • cone->SetResolution(100)时

image