activiz.net 显示圆柱体

简介

  • activiz.net是VTK的C#版本,可以很方便地进行三维绘制等操作

问题

  • 显示圆柱体时,activiz.net的vtkCylinderSource只能显示沿着y轴方向的圆柱体,方向不能修改,如下图的圆柱体

    activiz.net 显示圆柱体_第1张图片

生成这个圆柱体的vtkActor的代码如下

vtkCylinderSource cs = vtkCylinderSource.New();
cs.SetCenter(0, 0, height/2);
cs.SetRadius(radius);
cs.SetHeight(height);
cs.SetCapping(0);


cs.SetResolution(50);

vtkPolyDataMapper dm = vtkPolyDataMapper.New();
dm.SetInputConnection( cs.GetOutputPort() );

vtkActor a2 = vtkActor.New();
a2.SetMapper(dm);

vtkProperty pp = vtkProperty.New();
pp.SetOpacity(0.5);
pp.SetColor(0, 1, 1);
pp.SetLighting(false);

a2.SetProperty( pp );

解决方案

  • 已经知道了圆柱长轴的两个端点,可以结合vtkLineSourcevtkTubeFilter来生成具有方向性的圆柱体。结果图如下

    activiz.net 显示圆柱体_第2张图片

生成对应的vtkActor的代码如下

vtkLineSource ls = vtkLineSource.New();
ls.SetPoint1( 0, 0, 0 );
ls.SetPoint2(0, 0, height);
vtkTubeFilter tf = vtkTubeFilter.New();
tf.SetInputConnection( ls.GetOutputPort() );
tf.SetRadius( radius );
tf.SetNumberOfSides( 100 );
tf.CappingOff();

vtkPolyDataMapper dm = vtkPolyDataMapper.New();
dm.SetInputConnection( tf.GetOutputPort() );

vtkActor a2 = vtkActor.New();
a2.SetMapper(dm);

vtkProperty pp = vtkProperty.New();
pp.SetOpacity(0.5);
pp.SetColor(0, 1, 1);
pp.SetLighting(false);

a2.SetProperty( pp );

参考链接

  • http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/Cylinder
  • http://blog.csdn.net/menjiawan/article/details/45217707

你可能感兴趣的:(C#相关,VTK相关,vtk,c#,activiz)