VTK中创建圆柱体

1 使用vtkCylinderSource来创建。vtkCylinderSource可以创建沿着世界坐标系Y轴方向的圆柱体,但是不能任意设置圆柱体长轴的方向。

vtkSmartPointer cylinder = vtkSmartPointer::New();
cylinder->SetHeight(20.0);
cylinder->SetCenter(origin[0] - 5.0 * normal[0], origin[1] - 5.0 * normal[1], origin[2] - 5.0 * normal[2]);
cylinder->SetRadius(3.0);
cylinder->SetResolution(100);


2 如果已经知道了圆柱长轴的两个端点,可以结合vtkLineSource和vtkTubeFilter来生成具有方向性的圆柱体

vtkSmartPointer line = vtkSmartPointer::New();
line->SetPoint1(origin[0], origin[1], origin[2]);
line->SetPoint2(origin[0] - 5.0 * normal[0], origin[1] - 5.0 * normal[1], origin[2] - 5.0 * normal[2]);

vtkSmartPointer tubeFilter = vtkSmartPointer::New();
tubeFilter->SetInputConnection(line->GetOutputPort());
tubeFilter->SetRadius(3.0);
tubeFilter->SetNumberOfSides(100);
tubeFilter->CappingOn();


你可能感兴趣的:(计算机图形学)