2020-12-16 activiz(vtk的c#包) 基础物体建立<一>

基本物体的建立都是按照Source->vtkPolyDataMapper->Actor这个顺序的。
需要说明的是,C#中SetInputConnection和GetOutputPort,与SetInput和GetOutput有时可以混用,有时不行,有时数据类型和VTK不同。建议在C#都采用第一种写法。

1. 长方体

vtkCubeSource cube = vtkCubeSource.New();
vtkPolyDataMapper cubeMapper = vtkPolyDataMapper.New();
cubeMapper.SetInputConnection(cube.GetOutputPort());
vtkActor cubeActor = vtkActor.New();
cubeActor.SetMapper(cubeMapper);
cube.SetXLength(2);
cube.SetZLength(2);
cube.SetYLength(10);
renderer.AddActor(cubeActor);

2. 圆柱

vtkCylinderSource cylinder = vtkCylinderSource.New();
vtkPolyDataMapper cylinderMapper = vtkPolyDataMapper.New();   // 新建制图器
cylinderMapper.SetInputConnection(cylinder.GetOutputPort());  // 连接管道
vtkActor cylinderActor = vtkActor.New();                    // 新建角色
cylinderActor.SetMapper(cylinderMapper);                    // 传递制图器                             
cylinder.SetHeight(height); //柱体设置
cylinder.SetRadius(radius);
cylinder.SetResolution(12);//表示圆的点数
cylinderActor.GetProperty().SetColor(0, 1, 0);              
renderer.AddActor(cylinderActor);

3. 小球

vtkSphereSource sphere = vtkSphereSource.New();      // 新建球
vtkShrinkPolyData shrink = vtkShrinkPolyData.New();  // 新建数据收缩操作器
shrink.SetInputConnection(sphere.GetOutputPort());   // 连接管道
shrink.SetShrinkFactor(1.0);
vtkPolyDataMapper sphereMapper = vtkPolyDataMapper.New();    // 新建制图器
sphereMapper.SetInputConnection(shrink.GetOutputPort());     // 连接管道
vtkActor sphereActor = vtkActor.New();                    // 新建角色
sphereActor.SetMapper(sphereMapper);                      // 传递制图器
renderer.AddActor(sphereActor);
sphere.SetCenter(top_xyz[0], top_xyz[1], top_xyz[2]);
sphere.SetThetaResolution(8);                        // 设置球纬度参数
sphere.SetPhiResolution(16);                         // 设置球经度参数
sphere.SetRadius(0.1);                               // 设置球的半径   
sphereActor.GetProperty().SetColor(1, 0, 0);              // 设置“角色”颜色[RGB]
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值