vtkSmartPointer<vtkCubeAxesActor2D> cubeAxesActor = vtkSmartPointer<vtkCubeAxesActor2D>::New();
// 设置Camera
cubeAxesActor ->SetCamera(m_renderer->GetActiveCamera());
// 设置FlyMode
cubeAxesActor ->SetFlyMode(vtkCubeAxesActor2D::VTK_FLY_OUTER_EDGES);
// 设置 显示图象
cubeAxesActor ->SetViewProp(actor);
// renderer中添加坐标轴
renderer->AddActor(cubeAxesActor);
//@{
/**
* Use the bounding box of this input dataset to draw the cube axes. If this
* is not specified, then the class will attempt to determine the bounds from
* the defined Prop or Bounds.
*/
virtual void SetInputConnection(vtkAlgorithmOutput*);
virtual void SetInputData(vtkDataSet*);
virtual vtkDataSet* GetInput();
//@}
//@{
/**
* Use the bounding box of this prop to draw the cube axes. The
* ViewProp is used to determine the bounds only if the Input is not
* defined.
*/
void SetViewProp(vtkProp* prop);
vtkGetObjectMacro(ViewProp, vtkProp);
//@}
当dataset和prop都没有被指定的时候使用Bounds
//@{
/**
* Explicitly specify the region in space around which to draw the bounds.
* The bounds is used only when no Input or Prop is specified. The bounds
* are specified according to (xmin,xmax, ymin,ymax, zmin,zmax), making
* sure that the min's are less than the max's.
*/
vtkSetVector6Macro(Bounds,double);
double *GetBounds() override;
void GetBounds(double& xmin, double& xmax, double& ymin, double& ymax,
double& zmin, double& zmax);
void GetBounds(double bounds[6]);
//@}
使用 SetRanges(xmin,xmax, ymin,ymax, zmin,zmax)
设置坐标轴示数范围
//@{
/**
* Explicitly specify the range of values used on the bounds.
* The ranges are specified according to (xmin,xmax, ymin,ymax, zmin,zmax),
* making sure that the min's are less than the max's.
*/
vtkSetVector6Macro(Ranges,double);
double *GetRanges();
void GetRanges(double& xmin, double& xmax, double& ymin, double& ymax,
double& zmin, double& zmax);
void GetRanges(double ranges[6]);
//@}
//@{
/**
* Set/Get the camera to perform scaling and translation of the
* vtkCubeAxesActor2D.
*/
virtual void SetCamera(vtkCamera*);
vtkGetObjectMacro(Camera,vtkCamera);
//@}
enum FlyMode
{
VTK_FLY_OUTER_EDGES = 0,
VTK_FLY_CLOSEST_TRIAD = 1,
VTK_FLY_NONE = 2
};
//@{
/**
* Specify a mode to control how the axes are drawn: either outer edges
* or closest triad to the camera position, or you may also disable flying
* of the axes.
*/
vtkSetClampMacro(FlyMode, int, VTK_FLY_OUTER_EDGES, VTK_FLY_NONE);
vtkGetMacro(FlyMode, int);
void SetFlyModeToOuterEdges()
{this->SetFlyMode(VTK_FLY_OUTER_EDGES);};
void SetFlyModeToClosestTriad()
{this->SetFlyMode(VTK_FLY_CLOSEST_TRIAD);};
void SetFlyModeToNone()
{this->SetFlyMode(VTK_FLY_NONE);};
//@}
//@{
/**
* Set/Get the labels for the x, y, and z axes. By default,
* use "X", "Y" and "Z".
*/
vtkSetStringMacro(XLabel);
vtkGetStringMacro(XLabel);
vtkSetStringMacro(YLabel);
vtkGetStringMacro(YLabel);
vtkSetStringMacro(ZLabel);
vtkGetStringMacro(ZLabel);
//@}
/**
* Retrieve handles to the X, Y and Z axis (so that you can set their text
* properties for example)
*/
vtkAxisActor2D *GetXAxisActor2D()
{return this->XAxis;}
vtkAxisActor2D *GetYAxisActor2D()
{return this->YAxis;}
vtkAxisActor2D *GetZAxisActor2D()
{return this->ZAxis;}
//@{
//@{
/**
* Set/Get the title text property of all axes. Note that each axis can
* be controlled individually through the GetX/Y/ZAxisActor2D() methods.
*/
virtual void SetAxisTitleTextProperty(vtkTextProperty *p);
vtkGetObjectMacro(AxisTitleTextProperty,vtkTextProperty);
//@}
//@{
/**
* Set/Get the labels text property of all axes. Note that each axis can
* be controlled individually through the GetX/Y/ZAxisActor2D() methods.
*/
virtual void SetAxisLabelTextProperty(vtkTextProperty *p);
vtkGetObjectMacro(AxisLabelTextProperty,vtkTextProperty);
//@}
//@{
/**
* Set/Get the format with which to print the labels on each of the
* x-y-z axes.
*/
vtkSetStringMacro(LabelFormat);
vtkGetStringMacro(LabelFormat);
//@}
//@{
/**
* Set/Get the factor that controls the overall size of the fonts used
* to label and title the axes.
*/
vtkSetClampMacro(FontFactor, double, 0.1, 2.0);
vtkGetMacro(FontFactor, double);
//@}
//@{
/**
* Set/Get the inertial factor that controls how often (i.e, how
* many renders) the axes can switch position (jump from one axes
* to another).
*/
vtkSetClampMacro(Inertia, int, 1, VTK_INT_MAX);
vtkGetMacro(Inertia, int);
//@}
//@{
/**
* Turn on and off the visibility of each axis.
*/
vtkSetMacro(XAxisVisibility,int);
vtkGetMacro(XAxisVisibility,int);
vtkBooleanMacro(XAxisVisibility,int);
vtkSetMacro(YAxisVisibility,int);
vtkGetMacro(YAxisVisibility,int);
vtkBooleanMacro(YAxisVisibility,int);
vtkSetMacro(ZAxisVisibility,int);
vtkGetMacro(ZAxisVisibility,int);
vtkBooleanMacro(ZAxisVisibility,int);
//@}
参考
vtkCubeAxesActor2D.h
vtkCubeAxesActor2D.cxx