1.VTK绘制直线

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <vtkSmartPointer.h>
#include <vtkCylinderSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>

//cubeRender
#include <vtkCubeSource.h>
#include <vtkJPEGReader.h>
#include <vtkTexture.h>
#include <vtkPNGReader.h>

//lineRender
#include <vtkLineSource.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>

void ShapeRender::LineRender() {
    
    vtkSmartPointer<vtkLineSource> lineSource = vtkSmartPointer<vtkLineSource>::New();
    //起点和终点的范围大约在 (0, 0, 0) 到 (1, 1, 1) 之间
    lineSource->SetPoint1(0.0, 0.0, 0.0);  // 设置起点坐标
    lineSource->SetPoint2(0.0, 0.5, 0.0);  // 设置终点坐标


    // 创建一个映射
    vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection(lineSource->GetOutputPort());

    // 创建一个角色
    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    // 设置直线的宽度
    actor->GetProperty()->SetLineWidth(3);
    // 设置直线的颜色
    actor->GetProperty()->SetColor(1.0, 1.0, 1.0);
    
    VTKRender(actor);
}

2.效果

image