From b85a292ce06475d560bfa1195b63a8bfe211f22d Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Wed, 11 Jul 2012 14:15:27 -0500 Subject: Add 0.2.7 release of qwtplot3d for future TQt3 conversion and use --- lib/tqwtplot3d/src/qwt3d_surfaceplot.cpp | 183 +++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 lib/tqwtplot3d/src/qwt3d_surfaceplot.cpp (limited to 'lib/tqwtplot3d/src/qwt3d_surfaceplot.cpp') diff --git a/lib/tqwtplot3d/src/qwt3d_surfaceplot.cpp b/lib/tqwtplot3d/src/qwt3d_surfaceplot.cpp new file mode 100644 index 0000000..3caae31 --- /dev/null +++ b/lib/tqwtplot3d/src/qwt3d_surfaceplot.cpp @@ -0,0 +1,183 @@ +#include "qwt3d_surfaceplot.h" + +using namespace std; +using namespace Qwt3D; + +/** +Initializes with dataNormals()==false, NOFLOOR, resolution() == 1 +*/ +#if QT_VERSION < 0x040000 +SurfacePlot::SurfacePlot( QWidget* parent, const char* name ) + : Plot3D( parent, name ) +#else +SurfacePlot::SurfacePlot( QWidget * parent, const QGLWidget * shareWidget) + : Plot3D( parent, shareWidget) +#endif +{ + datanormals_p = false; + normalLength_p = 0.02; + normalQuality_p = 3; + + resolution_p = 1; + actualDataG_ = new GridData(); + actualDataC_ = new CellData(); + + actualData_p = actualDataG_; + + floorstyle_ = NOFLOOR; +} + +SurfacePlot::~SurfacePlot() +{ + delete actualDataG_; + delete actualDataC_; +} + +void SurfacePlot::showNormals(bool b) +{ + datanormals_p = b; +} + +/** +Values < 0 or > 1 are ignored +*/ +void SurfacePlot::setNormalLength(double val) +{ + if (val<0 || val>1) + return; + normalLength_p = val; +} + +/** +Values < 3 are ignored +*/ +void SurfacePlot::setNormalQuality(int val) +{ + if (val<3) + return; + normalQuality_p = val; +} + +/** + Calculates the smallest x-y-z parallelepiped enclosing the data. + It can be accessed by hull(); +*/ +void SurfacePlot::calculateHull() +{ + if (actualData_p->empty()) + return; + setHull(actualData_p->hull()); +} + +/*! + Sets data resolution (res == 1 original resolution) and updates widget + If res < 1, the function does nothing +*/ +void SurfacePlot::setResolution( int res ) +{ + if (!actualData_p || actualData_p->datatype == Qwt3D::POLYGON) + return; + + if ((resolution_p == res) || res < 1) + return; + + resolution_p = res; + updateNormals(); + updateData(); + if (initializedGL()) + updateGL(); + + emit resolutionChanged(res); +} + +void SurfacePlot::updateNormals() +{ + SaveGlDeleteLists(displaylists_p[NormalObject], 1); + + if (plotStyle() == NOPLOT && !normals() || !actualData_p) + return; + + displaylists_p[NormalObject] = glGenLists(1); + glNewList(displaylists_p[NormalObject], GL_COMPILE); + + if (actualData_p->datatype == Qwt3D::POLYGON) + createNormalsC(); + else if (actualData_p->datatype == Qwt3D::GRID) + createNormalsG(); + + glEndList(); +} + +void SurfacePlot::createData() +{ + if (!actualData_p) + return; + if (actualData_p->datatype == Qwt3D::POLYGON) + createDataC(); + else if (actualData_p->datatype == Qwt3D::GRID) + createDataG(); +} + + +void SurfacePlot::createFloorData() +{ + if (!actualData_p) + return; + if (actualData_p->datatype == Qwt3D::POLYGON) + createFloorDataC(); + else if (actualData_p->datatype == Qwt3D::GRID) + createFloorDataG(); +} + +/** + The returned value is not affected by resolution(). The pair gives (columns,rows) for grid data +, (number of cells,1) for free formed data (datatype() == POLYGON) and (0,0) else +*/ +pair SurfacePlot::facets() const +{ + if (!hasData()) + return pair(0,0); + + if (actualData_p->datatype == Qwt3D::POLYGON) + return pair(int(actualDataC_->cells.size()), 1); + else if (actualData_p->datatype == Qwt3D::GRID) + return pair(actualDataG_->columns(), actualDataG_->rows()); + else + return pair(0,0); +} + +void SurfacePlot::createPoints() +{ + Dot pt; + createEnrichment(pt); +} + +void SurfacePlot::createEnrichment(Enrichment& p) +{ + if (!actualData_p) + return; + + //todo future work + if (p.type() != Enrichment::VERTEXENRICHMENT) + return; + + p.assign(*this); + p.drawBegin(); + + VertexEnrichment* ve = (VertexEnrichment*)&p; + if (actualData_p->datatype == Qwt3D::POLYGON) + { + for (unsigned i = 0; i != actualDataC_->normals.size(); ++i) + ve->draw(actualDataC_->nodes[i]); + } + else if (actualData_p->datatype == Qwt3D::GRID) + { + int step = resolution(); + for (int i = 0; i <= actualDataG_->columns() - step; i += step) + for (int j = 0; j <= actualDataG_->rows() - step; j += step) + ve->draw(Triple(actualDataG_->vertices[i][j][0], + actualDataG_->vertices[i][j][1], + actualDataG_->vertices[i][j][2])); + } + p.drawEnd(); +} -- cgit v1.2.3