204 lines
4.2 KiB
C++
204 lines
4.2 KiB
C++
|
|
|
||
|
|
#include <math.h>
|
||
|
|
#include <qapplication.h>
|
||
|
|
#include <include/qwt3d_surfaceplot.h>
|
||
|
|
#include <include/qwt3d_function.h>
|
||
|
|
#include <include/qwt3d_plot.h>
|
||
|
|
#include <include/qwt3d_parametricsurface.h>
|
||
|
|
#include <include/qwt3d_enrichment_std.h>
|
||
|
|
|
||
|
|
#include <QMessageBox>
|
||
|
|
#include "mylineplot3d.h"
|
||
|
|
#include "line3d.h"
|
||
|
|
|
||
|
|
|
||
|
|
using namespace Qwt3D;
|
||
|
|
|
||
|
|
class Rosenbrock:public Function{
|
||
|
|
public:
|
||
|
|
Rosenbrock(SurfacePlot & pw):Function(pw){}
|
||
|
|
Rosenbrock(){}
|
||
|
|
double operator ()(double x,double y){
|
||
|
|
return x*y/2;
|
||
|
|
return x*sin(y)* log(x) + y* cos(x);
|
||
|
|
return log(sin(x) * cos(y));
|
||
|
|
return log((1-x)*(1-x) + 100 * (y - x*x)*(y - x*x)) / 8;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
mylineplot3d::mylineplot3d()
|
||
|
|
{
|
||
|
|
myxMax = 80;
|
||
|
|
myyMax = 60;
|
||
|
|
myzMax = 60;
|
||
|
|
|
||
|
|
int xscal = myxMax/myzMax;
|
||
|
|
int yscal = myyMax/myzMax;
|
||
|
|
|
||
|
|
myCurxMax = 0.0;
|
||
|
|
myCurxMin = 0.0;
|
||
|
|
myCuryMax = 0.0;
|
||
|
|
myCuryMin = 0.0;
|
||
|
|
myCurzMax = 0.0;
|
||
|
|
myCurzMin = 0.0;
|
||
|
|
|
||
|
|
setPlotStyle(Qwt3D::LINE3D_STYLE);
|
||
|
|
//setPlotStyle(Qwt3D::NOPLOT);
|
||
|
|
coordinates()->setAutoScale();
|
||
|
|
|
||
|
|
// setTitle("A Simple SurfacePlot Demonstration");
|
||
|
|
setIsolines(10);
|
||
|
|
Rosenbrock rosenbrock;
|
||
|
|
/* coordinates()->setGridLines(true,true,Qwt3D::LEFT|Qwt3D::BACK|Qwt3D::FLOOR);
|
||
|
|
rosenbrock.setMesh(10,10);
|
||
|
|
rosenbrock.setDomain(0,myxMax,0,myyMax);
|
||
|
|
rosenbrock.setMinZ(0);
|
||
|
|
rosenbrock.setMaxZ(myzMax);
|
||
|
|
|
||
|
|
rosenbrock.create(*this);*/
|
||
|
|
setShift(1,0,0);
|
||
|
|
setRotation(30,0,15);
|
||
|
|
// setScale(1,1,10);
|
||
|
|
setCurMaxMin(0,myxMax,0,myyMax,0,myzMax);
|
||
|
|
// setScale(xscal,yscal,10);
|
||
|
|
setShift(0.15,0,0);
|
||
|
|
setZoom(1);
|
||
|
|
int axesCount = coordinates()->axes.size();
|
||
|
|
for (unsigned i=0; i != axesCount; ++i)
|
||
|
|
{
|
||
|
|
coordinates()->axes[i].setMajors(6);
|
||
|
|
coordinates()->axes[i].setMinors(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
coordinates()->axes[X1].setLabelString("Frequency,Hz");
|
||
|
|
coordinates()->axes[Y2].setLabelString("Time,S");
|
||
|
|
coordinates()->axes[Z4].setLabelString("m/s2");
|
||
|
|
|
||
|
|
setCoordinateStyle(BOX);
|
||
|
|
|
||
|
|
updateData();
|
||
|
|
updateGL();
|
||
|
|
|
||
|
|
}
|
||
|
|
mylineplot3d::~mylineplot3d()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void mylineplot3d::init()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void mylineplot3d::createLines()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void mylineplot3d::keyPressEvent(QKeyEvent * e)
|
||
|
|
{
|
||
|
|
int c = e->key();
|
||
|
|
|
||
|
|
if(e->key() == Qt::Key_Up)
|
||
|
|
{
|
||
|
|
setShift(1,0,0);
|
||
|
|
setRotation(30,0,15);
|
||
|
|
setScale(1,1,1);
|
||
|
|
setShift(0.15,0,0);
|
||
|
|
setZoom(0.9);
|
||
|
|
}
|
||
|
|
else if(c == 65)
|
||
|
|
{
|
||
|
|
printf("set scale %f %f %f\n ",xScale(),yScale()*1.2,zScale());
|
||
|
|
setScale(1,1,zScale() * 1.2);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void mylineplot3d::tick()
|
||
|
|
{
|
||
|
|
updateData();
|
||
|
|
updateGL();
|
||
|
|
}
|
||
|
|
|
||
|
|
void mylineplot3d::setCurMaxMin(double xmin,double xmax,double ymin,double ymax,double zmin,double zmax)
|
||
|
|
{
|
||
|
|
if (xmin < myCurxMin)
|
||
|
|
{
|
||
|
|
myCurxMin = xmin;
|
||
|
|
}
|
||
|
|
if (xmax > myCurxMax)
|
||
|
|
{
|
||
|
|
myCurxMax = xmax;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (ymin < myCuryMin)
|
||
|
|
{
|
||
|
|
myCuryMin = ymin;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (ymax > myCuryMax)
|
||
|
|
{
|
||
|
|
myCuryMax = ymax;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (zmin < myCurzMin)
|
||
|
|
{
|
||
|
|
myCurzMin = zmin;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (zmax > myCurzMax)
|
||
|
|
{
|
||
|
|
myCurzMax = zmax;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
if ((myCurxMax - myxMax) > 1 )
|
||
|
|
{
|
||
|
|
myxMax += 10;
|
||
|
|
myyMax = myxMax;
|
||
|
|
|
||
|
|
Rosenbrock rosenbrock;
|
||
|
|
rosenbrock.setMesh(5,5);
|
||
|
|
rosenbrock.setDomain(-10,myxMax,-10,myyMax);
|
||
|
|
rosenbrock.setMinZ(0);
|
||
|
|
rosenbrock.setMaxZ(myzMax);
|
||
|
|
rosenbrock.create(*this);
|
||
|
|
|
||
|
|
double _yScale = myxMax / myzMax;
|
||
|
|
_yScale = (myxMax / myzMax) > _yScale? (myyMax / myzMax): _yScale;
|
||
|
|
setScale(1,1,_yScale);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
if ((myCuryMax - myyMax) > 1)
|
||
|
|
{
|
||
|
|
myyMax += 10;
|
||
|
|
myxMax = myyMax;
|
||
|
|
Rosenbrock rosenbrock;
|
||
|
|
rosenbrock.setMesh(5,5);
|
||
|
|
rosenbrock.setDomain(-10,myxMax,-10,myyMax);
|
||
|
|
rosenbrock.setMinZ(0);
|
||
|
|
rosenbrock.setMaxZ(myzMax);
|
||
|
|
rosenbrock.create(*this);
|
||
|
|
|
||
|
|
double _yScale = myxMax / myzMax;
|
||
|
|
_yScale = (myxMax / myzMax) > _yScale? (myyMax / myzMax): _yScale;
|
||
|
|
setScale(1,1,_yScale);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (myCurzMax > myzMax)
|
||
|
|
{
|
||
|
|
myzMax += 10;
|
||
|
|
|
||
|
|
Rosenbrock rosenbrock;
|
||
|
|
rosenbrock.setMesh(5,5);
|
||
|
|
rosenbrock.setDomain(-10,myxMax,-10,myyMax);
|
||
|
|
rosenbrock.setMinZ(0);
|
||
|
|
rosenbrock.setMaxZ(myzMax);
|
||
|
|
rosenbrock.create(*this);
|
||
|
|
}
|
||
|
|
updateData();
|
||
|
|
updateGL();
|
||
|
|
}
|