VTK Procedural Source Object

VTK 使用 Procedural Source Object 来展示一些固定的三维物体,比如 多边形柱体、多边球体、棱锥等等,在三维画布下添加 Prop 的示例代码如下:

auto sphere = vtkSmartPointer::New();
sphere->SetRadius(24);

auto cylinder = vtkSmartPointer::New();
cylinder->SetResolution(3);
cylinder->SetHeight(48);
cylinder->SetRadius(48);

auto mapperSphere = vtkSmartPointer::New();
mapperSphere->SetInputConnection(sphere->GetOutputPort());

auto actorSphere = vtkSmartPointer::New();
actorSphere->SetMapper(mapperSphere);
actorSphere->SetPosition(0, 0, 0);

auto mapperCylinder = vtkSmartPointer::New();
mapperCylinder->SetInputConnection(cylinder->GetOutputPort());

auto actorCylinder = vtkSmartPointer::New();
actorCylinder->SetMapper(mapperCylinder);
actorCylinder->SetPosition(144, 0, 0);

auto renderer = vtkSmartPointer::New();
renderer->AddActor(actorSphere);
renderer->AddActor(actorCylinder);

renderer->SetBackground(0.6, 0.6, 0.6);

auto actorAxes = vtkSmartPointer::New();
actorAxes->SetPosition(0, 0, 0);
actorAxes->SetTotalLength(120, 120, 120);
actorAxes->SetShaftType(0);
actorAxes->SetAxisLabels(0);
actorAxes->SetCylinderRadius(0.02);

renderer->AddActor(actorAxes);

auto win = vtkSmartPointer::New();
win->AddRenderer(renderer);

ui->widgetVtk->setRenderWindow(win);

需要注意的地方是,在给 Actor 调用 SetPosition 的时候,这个位置算的是三维物体的重心位置到原点的相对距离,而原点的位置默认是(0, 0, 0);
可以通过 Source 的 SetCenter 来重置原点的位置。

你可能感兴趣的:(VTK Procedural Source Object)