qwtplot3d 中的坐标系统

来源:互联网 发布:网络的使用界限 编辑:程序博客网 时间:2024/05/01 10:57

本文最初写于 2010-10-12于 sohu 博客,这次博客搬家一起搬到这里来。

版权所有,转载请注明出处。

 

qwtplot3d中绘制三维图形时可以细致的设置图形的方方面面,这里对设置坐标系统(CoordinateSystem),包括坐标轴(Axis)、标签(Label)、颜色条(ColorLegend)的方法做一个简单的笔记。

从类的派生关系来看,几个类都是派生自同一个基类 Drawable 的:

Drawable
|-<--Axis
|-<--ColorLegend
|-<--CoordinateSystem
|-<--Label

但是从逻辑关系上考虑,应该是这样的。首先 Plot3D 及其派生类代表了一个实际的绘图对象,这个绘图对象中包含坐标系统、标签等,坐标系统又包括坐标轴。

因此,可以这样表示:

Plot3D <--CoordinateSystem <-- Axis
     |-<-- ColorLegend
     |-<-- Label

实际写程序时也是这样的。Plot3D 类中有个成员函数:

Qwt3D::CoordinateSystem *  coordinates ()

利用这个成员函数可以返回一个指向坐标系统的指针。然后就可以访问相应的坐标系统了。

Qwt3D::ColorLegend *  legend ()

这个成员函数则可以返回一个指向颜色条的指针。

CoordinateSystem 类中的成员函数很多,其中最主要的有:

void  setStyle ()
void  setPosition ()
void  setAxesColor ()
void  setNumberFont ()
void  setNumberColor ()
void  setStandardScale ()
void  adjustNumbers ()
void  adjustLabels ()
void  setGridLinesColor ()
void  setLabelFont ()
void  setLabelColor ()
void  setLineWidth ()
void  setTicLength ()
void  setAutoScale ()
void  setAutoDecoration ()
void  setLineSmooth ()
void  setGridLines ()

可以看出,利用这些函数已经可以对显示的图像很多方面进行控制了。但是如果需要更精细的控制。比如利用 setAxesColor 函数虽然可以设置坐标轴的颜色,但是无法单独设置某一个坐标轴。这时就需要 Axis 类了。

CoordinateSystem 类中有个公共成员变量:
std::vector< Axis >  axes

这个 vector 中包含 12 个 Axis 对象,分别对应 12 个坐标轴。这样就可以直接访问某一个坐标轴对其进行精确的控制了。

Axis 类包括的成员函数很多,这里只列举几个。

void  setTicLength ()
void  setTicOrientation ()
void  setLabelFont ()
void  setLabelString ()
void  setLabelColor ()
void  setScale ()
void  setNumberFont ()
void  setAutoScale ()
void  setMajors ()
void  setMinors ()


颜色条(ColorLegend) 在其他一些代码中通常称为 ColorBar。

主要的成员函数包括:
void  setRelPosition ()
void  setOrientation ()
void  setLimits ()
void  setMajors ()
void  setMinors ()
void  drawScale ()
void  drawNumbers ()
void  setAutoScale ()
void  setScale ()
void  setScale ()
void  setTitleString ()
void  setTitleFont ()

Label 类主要的成员函数包括(这个类如何使用还没想明白):

 
void  setFont ()
void  adjust ()
void  setPosition ()
void  setRelPosition ()
virtual void  setColor ()
virtual void  setColor ()
void  setString ()


下面是一个简单的例子:

  #include <math.h>  #include <qapplication.h>  #include <qwt3d_surfaceplot.h>  #include <qwt3d_function.h>    using namespace Qwt3D;  class Rosenbrock : public Function  {  public:    Rosenbrock(SurfacePlot& pw)    :Function(pw)    {    }    double operator()(double x, double y)    {      return log((1-x)*(1-x) + 100 * (y - x*x)*(y - x*x)) / 8;    }  };  class Plot : public SurfacePlot  {  public:      Plot();  };  Plot::Plot()  {    setTitle("A Simple SurfacePlot Demonstration");        Rosenbrock rosenbrock(*this);    rosenbrock.setMesh(41,31);    rosenbrock.setDomain(-1.73,1.5,-1.5,1.5);    rosenbrock.setMinZ(-10);    rosenbrock.create();    setRotation(30,0,15);    setScale(1,1,1);    setShift(0.15,0,0);    setZoom(0.9);    for (unsigned i=0; i!=coordinates()->axes.size(); ++i)    {      coordinates()->axes[i].setMajors(7);      coordinates()->axes[i].setMinors(4);    }    coordinates()->axes[X1].setLabelString("x-axis");    coordinates()->axes[Y1].setLabelString("y-axis");    //coordinates()->axes[Z1].setLabelString(QChar(0x38f)); // Omega - see http://www.unicode.org/charts/    setCoordinateStyle(BOX);    updateData();    updateGL();  }  int main(int argc, char **argv)  {      QApplication a(argc, argv);      Plot plot;#if QT_VERSION < 0x040000      a.setMainWidget(&plot);#endif      plot.resize(800,600);      plot.show();      return a.exec();  }
原创粉丝点击