程序修改如下:
vtkSphereSource sphere0 = vtkSphereSource.New();
vtkSphereSource sphereX = vtkSphereSource.New();
sphereX.SetCenter(5, 0, 0);
vtkSphereSource sphereY = vtkSphereSource.New();
sphereY.SetCenter(0, 5, 0);
vtkSphereSource sphereZ = vtkSphereSource.New();
sphereZ.SetCenter(0, 0, 5);
vtkCylinderSource cylinder = vtkCylinderSource.New();
cylinder.SetHeight(3.0);
cylinder.SetRadius(0.1);
cylinder.SetResolution(10);
vtkPolyDataMapper sphere0Mapper = vtkPolyDataMapper.New();
sphere0Mapper.SetInputConnection(sphere0.GetOutputPort());
vtkPolyDataMapper sphereMapperX = vtkPolyDataMapper.New();
sphereMapperX.SetInputConnection(sphereX.GetOutputPort());
vtkPolyDataMapper sphereMapperY = vtkPolyDataMapper.New();
sphereMapperY.SetInputConnection(sphereY.GetOutputPort());
vtkPolyDataMapper sphereMapperZ = vtkPolyDataMapper.New();
sphereMapperZ.SetInputConnection(sphereZ.GetOutputPort());
vtkPolyDataMapper cylinderMapper = vtkPolyDataMapper.New();
cylinderMapper.SetInputConnection(cylinder.GetOutputPort());
vtkActor sphereactor = vtkActor.New();
sphereactor.SetMapper(sphere0Mapper);
sphereactor.GetProperty().SetColor(1, 0, 0);
vtkActor sphereactorX = vtkActor.New();
sphereactorX.SetMapper(sphereMapperX);
sphereactorX.GetProperty().SetColor(0, 1, 0);
vtkActor sphereactorY = vtkActor.New();
sphereactorY.SetMapper(sphereMapperY);
sphereactorY.GetProperty().SetColor(0, 0, 1);
vtkActor sphereactorZ = vtkActor.New();
sphereactorZ.SetMapper(sphereMapperZ);
sphereactorZ.GetProperty().SetColor(1, 1, 0);
vtkActor cylinderactor = vtkActor.New();
cylinderactor.SetMapper(cylinderMapper);
cylinderactor.GetProperty().SetColor(0, 1, 1);
vtkRenderWindow RenderWin = renderWindowControl.RenderWindow;
vtkRenderer VTKrenderer = RenderWin.GetRenderers().GetFirstRenderer();
VTKrenderer.AddViewProp(sphereactor);
VTKrenderer.AddViewProp(cylinderactor);
VTKrenderer.AddActor(sphereactorX);
VTKrenderer.AddActor(sphereactorY);
VTKrenderer.AddActor(sphereactorZ);
vtkCamera camera1 = VTKrenderer.GetActiveCamera();
VTKrenderer.ResetCamera();
RenderWin.Render();
程序执行效果如下:
其中红色小球位于原点,绿色小球位于X轴上,距离原点5个单位,蓝色小球位于Y轴上,距离原点5个单位,黄色小球位于Z轴上,距离原点5个单位,青色圆柱体位于原点,方向沿Y轴方向
......
vtkActor cylinderactor = vtkActor.New();
cylinderactor.SetMapper(cylinderMapper);
cylinderactor.GetProperty().SetColor(0, 1, 1);
vtkTransform transform = vtkTransform.New();
transform.Translate(5, 0, 0);
cylinderactor.SetUserTransform(transform);
vtkRenderWindow RenderWin = renderWindowControl.RenderWindow;
vtkRenderer VTKrenderer = RenderWin.GetRenderers().GetFirstRenderer();
......
源程序中加入以上红色语句,圆柱体沿X轴平移5个单位,平移后圆柱体中心与绿色小球重合,程序运行效果如下:
将程序语句修改如下:
transform.Translate(0, 5, 5);
执行效果如下,圆柱体沿Y轴和Z轴各平移5个单位
在平移语句后增加旋转语句,控制圆柱体先沿X轴平移5个单位,在围绕Z轴旋转90度。
vtkTransform transform = vtkTransform.New();
transform.Translate(5, 0, 0);
transform.RotateZ(90);
cylinderactor.SetUserTransform(transform);
程序执行效果如下,圆柱体并没有按照我们设想的那样运动,而是先围绕Z轴旋转90度,再沿着X轴平移5个单位
接下类我们把平移和旋转的语句改变顺序,
vtkTransform transform = vtkTransform.New();
transform.RotateZ(90);
transform.Translate(5, 0, 0);
cylinderactor.SetUserTransform(transform);
程序运行效果如下,先平移再旋转
接着修改程序如下:
vtkTransform transform = vtkTransform.New();
transform.PostMultiply();
transform.Translate(5, 0, 0);
transform.RotateZ(90);
cylinderactor.SetUserTransform(transform);
程序运行效果如下,这回圆柱体先沿X轴平移5个单位,再围绕Z轴旋转90度
修改程序如下:
vtkTransform transform = vtkTransform.New();
transform.PostMultiply();
transform.RotateZ(90);
transform.Translate(5, 0, 0);
cylinderactor.SetUserTransform(transform);
程序运行结果如下,先旋转再平移
继续修改程序,增加缩放
vtkTransform transform = vtkTransform.New();
transform.PostMultiply();
transform.Scale(5, 0.5, 2);
transform.Translate(5, 0, 0);
cylinderactor.SetUserTransform(transform);
程序运行结果如图,可以看到圆柱体沿X方向放大,沿Z方向也放大,沿Y方向缩短,现在圆柱体横截面为椭圆
继续修改程序,缩放+平移+旋转
vtkTransform transform = vtkTransform.New();
transform.PostMultiply();
transform.Scale(5, 0.5, 2);
transform.Translate(5, 0, 0);
transform.RotateZ(90);
cylinderactor.SetUserTransform(transform);
继续修改程序,先平移,再缩放
vtkTransform transform = vtkTransform.New();
transform.PostMultiply();
transform.Translate(5, 0, 0);
transform.Scale(0.5, 0.5, 1);
cylinderactor.SetUserTransform(transform);
程序运行结果如图,圆柱体不仅X方向缩短,而且圆柱体中心点的X坐标也减小了,说明对几何体X轴进行缩放,是对几何体点云中每个点的X坐标值进行缩放,其他轴也一样。