下面的代码是添加一个坐标系  

vtkTextProperty tprop = new vtkTextProperty();
   tprop.SetColor(1,1,1);
   tprop.ShadowOff();
   vtkCubeAxesActor2D axes2 = new vtkCubeAxesActor2D();
   axes2.SetInput(cast.GetOutput());
   axes2.SetCamera(panel.GetRenderer().GetActiveCamera());
   axes2.SetFlyModeToOuterEdges();
   axes2.SetFontFactor(1.1);
   axes2.SetAxisLabelTextProperty(tprop);
  
   //axes.SetFontFactor(8);
   panel.GetRenderer().AddViewProp(axes2);

   //   
   // vtkTextActor textActor = new vtkTextActor();
   // textActor.ScaledTextOn();
   // textActor.SetDisplayPosition(90, 50);
   // textActor.SetInput("This is a sphere");
   // textActor.GetPosition2Coordinate().SetCoordinateSystemToNormalizedViewport();
   // textActor.GetPosition2Coordinate().SetValue(0.6, 0.1);
   //
   // vtkTextProperty tprop2 = textActor.GetTextProperty();
   // tprop2.SetFontSize(18);
   // tprop2.SetFontFamilyToArial();
   // tprop2.SetJustificationToCentered();
   // tprop2.BoldOn();
   // tprop2.ItalicOn();
   // tprop2.ShadowOn();
   // tprop2.SetColor(0, 0, 1);
   // panel.GetRenderer().AddActor2D(textActor);

   // vtkCubeSource cubeSrc = new vtkCubeSource();
   // cubeSrc.SetXLength(100);
   // cubeSrc.SetYLength(100);
   // cubeSrc.SetZLength(100);
   //  
   // vtkPolyDataMapper cubeMapper = new vtkPolyDataMapper();
   // cubeMapper.SetInputConnection(cubeSrc.GetOutputPort());

   vtkAnnotatedCubeActor cube = new vtkAnnotatedCubeActor();
   cube.SetXPlusFaceText("R");
   cube.SetXMinusFaceText("L");
   cube.SetYPlusFaceText("A");
   cube.SetYMinusFaceText("P");
   cube.SetZPlusFaceText("I");
   cube.SetZMinusFaceText("S");
   cube.SetXFaceTextRotation(180);
   cube.SetYFaceTextRotation(180);
   cube.SetZFaceTextRotation(-90);

   cube.SetFaceTextScale(0.65);
   cube.GetCubeProperty().SetColor(1, 1, 1);
   cube.GetTextEdgesProperty().SetLineWidth(1);
   cube.GetTextEdgesProperty().SetDiffuse(0);
   cube.GetTextEdgesProperty().SetAmbient(1);
   cube.GetTextEdgesProperty().SetColor(0, 0, 0);
   //    
   //    
   cube.GetXPlusFaceProperty().SetColor(0, 0, 0);
   cube.GetXPlusFaceProperty().SetInterpolationToFlat();

   cube.GetXMinusFaceProperty().SetColor(0, 0, 0);
   cube.GetXMinusFaceProperty().SetInterpolationToFlat();
   //    
   cube.GetYPlusFaceProperty().SetColor(0, 0, 0);
   cube.GetYPlusFaceProperty().SetInterpolationToFlat();
   //   
   cube.GetYMinusFaceProperty().SetColor(0, 0, 0);
   cube.GetYMinusFaceProperty().SetInterpolationToFlat();
   //    
   cube.GetZPlusFaceProperty().SetColor(0, 0, 0);
   cube.GetZPlusFaceProperty().SetInterpolationToFlat();
   //    
   cube.GetZMinusFaceProperty().SetColor(0, 0, 0);
   cube.GetZMinusFaceProperty().SetInterpolationToFlat();

   vtkAxesActor axes = new vtkAxesActor();
   axes.SetShaftTypeToCylinder();
   axes.SetXAxisLabelText("x");
   axes.SetYAxisLabelText("y");
   axes.SetZAxisLabelText("z");
   axes.SetTotalLength(1.5, 1.5, 1.5);
   vtkTextProperty tprop4 = new vtkTextProperty();
   // tprop.ItalicOn();
   tprop4.ShadowOn();
   tprop4.SetFontFamilyToArial();

   // tprop.SetFontFamilyToTimes();
   axes.GetXAxisCaptionActor2D().SetCaptionTextProperty(tprop4);
   //
   vtkTextProperty tprop2 = new vtkTextProperty();
   tprop2.ShallowCopy(tprop4);
   axes.GetYAxisCaptionActor2D().SetCaptionTextProperty(tprop2);
   //    
   vtkTextProperty tprop3 = new vtkTextProperty();
   tprop3.ShallowCopy(tprop4);
   axes.GetZAxisCaptionActor2D().SetCaptionTextProperty(tprop3);

   vtkPropAssembly assembly = new vtkPropAssembly();

   assembly.AddPart(cube);
   assembly.AddPart(axes);

// vtkOrientationMarkerWidget产生的对象和原来的窗口不是在一个层次上,
   // 并且自动激活了该对象的单击和移动事件,也就是可以改变这个对象的
   // 大小和位置
   vtkOrientationMarkerWidget widget = new vtkOrientationMarkerWidget();
   widget.SetOutlineColor(0, 0, 0);
   widget.SetOrientationMarker(assembly); // 必须:传一个vtkProp对象
   widget.SetInteractor(panel.getIren());// 必须:传一个交互对象
   widget.SetViewport(0.8, 0.0, 1, 0.2);
   widget.SetEnabled(1);
   widget.InteractiveOff();
   // widget.InteractiveOn();
   // widget.SetOutlineColor(0, 0, 0);

注意:   widget.EnabledOn();
这个一定要写,不然切换或者刷新的时候,widget就不动了。

 

本文来源:http://hi.baidu.com/onlywater/item/b46e497bef8bbf3f714423c0