本文最初写于 2010-08-20 于 sohu 博客,这次博客搬家一起搬到这里来。
版权所有,转载请注明出处。
下面给出一个根据曲面数据点画出曲面的例子。
关键点在于
loadFromData (double **data, unsigned int columns, unsigned int rows, double minx, double maxx, double miny, double maxy);另外,
double** allocateData(int columns, int rows); void deleteData(double**data, int columns) ;这两个辅助函数是从QWT3D 的源代码找来的。原来是 NativeReader 类中的函数。很有用,就被拿出来了。
using namespace Qwt3D; double** allocateData(int columns, int rows) { double** data = new double* [columns] ; for ( int i = 0; i < columns; ++i) { data[i] = new double [rows]; } return data; } void deleteData(double**data, int columns) { for ( int i = 0; i < columns; i++) { delete [] data[i]; } delete [] data; } class Plot : public SurfacePlot { public: Plot(); }; Plot::Plot() { int i,j; double x, y, z; double** data = allocateData(100, 100); for(i = 0; i< 100; i++) { for(j = 0; j< 100;j++) { x = (i - 50) / 5.0; y = (j - 50) / 5.0; z = hypot(x, y); data[i][j] = cos(z); } } loadFromData (data, 100, 100, -10, 10, -10, 10); deleteData(data, 100); setScale(1,1,5); setCoordinateStyle(BOX); updateData(); updateGL(); } int main(int argc, char **argv) { QApplication a(argc, argv); Plot plot; plot.resize(800,600); plot.show(); return a.exec(); }