[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [analitza/aucahuasi/analitzaplot] analitzaplot: buildparametric surface (in AbstractSurface) will be
From: Percy_Camilo_Triveño_Aucahuasi <percy.camilo.ta () gmail ! com>
Date: 2012-07-13 19:00:25
Message-ID: 20120713190025.CEFC1A6094 () git ! kde ! org
[Download RAW message or body]
Git commit 50f62e8ffd90c9446ace68c0076f2bb2eea73814 by Percy Camilo Triveño \
Aucahuasi. Committed on 13/07/2012 at 21:00.
Pushed by aucahuasi into branch 'aucahuasi/analitzaplot'.
buildparametric surface (in AbstractSurface) will be the fallback/default option for \
building surfaces (in the future if an implicit surface can be parametrized it should \
use this method) Revert last commit about the use of QGLViewer, in this moment is the \
more easy solution for analitzaplot
M +4 -0 analitzaplot/CMakeLists.txt
M +24 -0 analitzaplot/mathutils.h
M +4 -0 analitzaplot/plotview2d.h
M +37 -549 analitzaplot/plotview3d.cpp
M +5 -81 analitzaplot/plotview3d.h
M +236 -0 analitzaplot/private/abstractsurface.cpp
M +14 -0 analitzaplot/private/abstractsurface.h
M +26 -158 analitzaplot/private/backends/cartesiansurface.cpp
M +22 -6 analitzaplot/private/backends/polarcurve.cpp
M +5 -1 analitzaplot/private/functiongraphfactory.cpp
M +5 -5 analitzaplot/private/functiongraphsmodel.cpp
M +3 -1 analitzaplot/private/functiongraphsmodel.h
M +5 -4 analitzaplot/private/mappinggraph.h
M +1 -0 analitzaplot/tests/plotview2dtest.cpp
M +15 -5 analitzaplot/tests/plotview3dtest.cpp
http://commits.kde.org/analitza/50f62e8ffd90c9446ace68c0076f2bb2eea73814
diff --git a/analitzaplot/CMakeLists.txt b/analitzaplot/CMakeLists.txt
index 2373b5a..e3553d9 100755
--- a/analitzaplot/CMakeLists.txt
+++ b/analitzaplot/CMakeLists.txt
@@ -9,6 +9,9 @@ find_package ( OpenGL REQUIRED )
if(NOT OPENGL_GLU_FOUND)
message(FATAL_ERROR "GLU was not found")
endif(NOT OPENGL_GLU_FOUND)
+
+find_library(QGLVIEWER_LIBRARY NAMES qglviewer-qt4 QGLViewer)
+
find_path(IEEEFP_DIR ieeefp.h)
if(IEEEFP_DIR)
include_directories(${IEEEFP_DIR})
@@ -96,6 +99,7 @@ target_link_libraries ( analitzaplot
#${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
analitza
+ ${QGLVIEWER_LIBRARY}
)
set_target_properties(analitzaplot PROPERTIES VERSION ${GENERIC_LIB_VERSION} \
SOVERSION ${GENERIC_LIB_SOVERSION} )
diff --git a/analitzaplot/mathutils.h b/analitzaplot/mathutils.h
index 4588668..e7615cd 100644
--- a/analitzaplot/mathutils.h
+++ b/analitzaplot/mathutils.h
@@ -256,4 +256,28 @@ static QLineF mirrorXY(const QLineF& l)
return QLineF(l.y1(), l.x1(), l.y2(), l.x2());
}
+//NOTE
+//qvector3d/qpointf no soporta doble precision, es mejor trabajar los calculos en \
double y para mostrarlos usar recien qvector3d +//por esa razon no pongo un return \
qvector3d y pongo las nuevas coords by ref +
+static void polarToCartesian(double radial, double polar, double &x, double &y)
+{
+ x = radial*cos(polar);
+ y = radial*sin(polar);
+}
+
+static void cylindricalToCartesian(double rho, double azimuth, double height, double \
&x, double &y, double &z) +{
+ x = rho*cos(azimuth);
+ y = rho*sin(azimuth);
+ z = height;
+}
+
+static void sphericalToCartesian(double radial, double azimuth, double polar, double \
&x, double &y, double &z) +{
+ x = radial*cos(azimuth)*sin(polar);
+ y = radial*cos(azimuth)*sin(polar);
+ z = radial*cos(polar);
+}
+
#endif // ANALITZAPLOT_FUNCTIONUTILS
diff --git a/analitzaplot/plotview2d.h b/analitzaplot/plotview2d.h
index a933a93..2f6a875 100644
--- a/analitzaplot/plotview2d.h
+++ b/analitzaplot/plotview2d.h
@@ -61,11 +61,15 @@ public:
/** Constructor. Constructs a new Graph2D. */
Graph2D(QWidget *parent = 0); // this ctor es para que pueda ser usado en el \
designer
+ //prererenciteme 1 constructor
+
Graph2D(VisualItemsModel* fm, QWidget *parent = 0);
/** Destructor. */
~Graph2D();
+// setmodel
+
QSize sizeHint() const { return QSize(100, 100); }
/** Saves the graphs to a file located at @p path. */
diff --git a/analitzaplot/plotview3d.cpp b/analitzaplot/plotview3d.cpp
index 8051bd9..e7a5712 100644
--- a/analitzaplot/plotview3d.cpp
+++ b/analitzaplot/plotview3d.cpp
@@ -30,206 +30,35 @@
#include "analitza/variables.h"
#include "analitza/vector.h"
#include <QDebug>
-#include <QTime>
-#include <GL/glu.h>
-///
-
-
-
-TrackBall::TrackBall(TrackMode mode)
- : m_angularVelocity(0)
- , m_paused(false)
- , m_pressed(false)
- , m_mode(mode)
-{
- m_axis = QVector3D(0, 1, 0);
- m_rotation = QQuaternion();
- m_lastTime = QTime::currentTime();
-}
-
-TrackBall::TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode)
- : m_axis(axis)
- , m_angularVelocity(angularVelocity)
- , m_paused(false)
- , m_pressed(false)
- , m_mode(mode)
-{
- m_rotation = QQuaternion();
- m_lastTime = QTime::currentTime();
-}
-
-void TrackBall::push(const QPointF& p, const QQuaternion &)
-{
- m_rotation = rotation();
- m_pressed = true;
- m_lastTime = QTime::currentTime();
- m_lastPos = p;
- m_angularVelocity = 0.0f;
-}
-
-void TrackBall::move(const QPointF& p, const QQuaternion &transformation)
-{
- if (!m_pressed)
- return;
-
- QTime currentTime = QTime::currentTime();
- int msecs = m_lastTime.msecsTo(currentTime);
- if (msecs <= 20)
- return;
-
- switch (m_mode) {
- case Plane:
- {
- QLineF delta(m_lastPos, p);
- m_angularVelocity = 180*delta.length() / (PI*msecs);
- m_axis = QVector3D(-delta.dy(), delta.dx(), 0.0f).normalized();
- m_axis = transformation.rotatedVector(m_axis);
- m_rotation = QQuaternion::fromAxisAndAngle(m_axis, 180 / PI * \
delta.length()) * m_rotation;
- }
- break;
- case Sphere:
- {
- QVector3D lastPos3D = QVector3D(m_lastPos.x(), m_lastPos.y(), 0.0f);
- float sqrZ = 1 - QVector3D::dotProduct(lastPos3D, lastPos3D);
- if (sqrZ > 0)
- lastPos3D.setZ(sqrt(sqrZ));
- else
- lastPos3D.normalize();
-
- QVector3D currentPos3D = QVector3D(p.x(), p.y(), 0.0f);
- sqrZ = 1 - QVector3D::dotProduct(currentPos3D, currentPos3D);
- if (sqrZ > 0)
- currentPos3D.setZ(sqrt(sqrZ));
- else
- currentPos3D.normalize();
-
- m_axis = QVector3D::crossProduct(lastPos3D, currentPos3D);
- float angle = 180 / PI * asin(sqrt(QVector3D::dotProduct(m_axis, m_axis)));
-
- m_angularVelocity = angle / msecs;
- m_axis.normalize();
- m_axis = transformation.rotatedVector(m_axis);
- m_rotation = QQuaternion::fromAxisAndAngle(m_axis, angle) * m_rotation;
- }
- break;
- }
-
- m_lastPos = p;
- m_lastTime = currentTime;
-}
-
-void TrackBall::release(const QPointF& p, const QQuaternion &transformation)
-{
- // Calling move() caused the rotation to stop if the framerate was too low.
- move(p, transformation);
- m_pressed = false;
-}
-
-void TrackBall::start()
-{
- m_lastTime = QTime::currentTime();
- m_paused = false;
-}
-
-void TrackBall::stop()
-{
- m_rotation = rotation();
- m_paused = true;
-}
-
-QQuaternion TrackBall::rotation() const
-{
- if (m_paused || m_pressed)
- return m_rotation;
-
- QTime currentTime = QTime::currentTime();
- float angle = m_angularVelocity * m_lastTime.msecsTo(currentTime);
- return QQuaternion::fromAxisAndAngle(m_axis, angle) * m_rotation;
-}
-
-///
-
-
-enum ActionsEnum {
- KEYRIGHT=1<<0, KEYLEFT=1<<1, KEYUP=1<<2, KEYDOWN=1<<3, KEYAVPAG=1<<4, \
KEYREPAG=1<<5, KEYS=1<<6, KEYW=1<<7,
- KEYQ=1<<8, KEYE=1<<9, LCLICK=1<<10, RCLICK=1<<11, MCLICK=1<<12
-};
-
View3D::View3D(QWidget *parent)
- : QGLWidget(parent)
- ,m_model(0), m_selection(0),default_step(0.15f), default_size(10.0f), \
zoom(1.0f), alpha(60.) + : QGLViewer(parent)
+ ,m_model(0), m_selection(0)
{
-
- setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
-
-
-// setGridIsDrawn(true);
-// setAxisIsDrawn(true);
- setFocusPolicy(Qt::ClickFocus);
- rotation[0] = 90.0;
- rotation[1] = 0.0;
- rotation[2] = 0.0;
-// mCamera = new Camera;
-
-// // Set up camera
-// camera()->setPosition(QVector3D(0, 0, 5));
-// camera()->setLookAt(QVector3D(0, 0, 0));
-// camera()->setUp(QVector3D(0, 1, 0));
-// camera()->setDepthRange(1, 100);
-// mRotation = 0;
-
-///
-
- this->_trackball = TrackBall(0.05f, QVector3D(0, 1, 0), TrackBall::Sphere);
+ setGridIsDrawn(true);
+ setAxisIsDrawn(true);
}
-View3D::View3D(VisualItemsModel* m, QWidget* parent): QGLWidget(parent)
- ,m_model(m), m_selection(0),default_step(0.15f), default_size(10.0f), \
zoom(1.0f), alpha(60.)
-{
- setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
-
-
-// setGridIsDrawn(true);
-// setAxisIsDrawn(true);
- setFocusPolicy(Qt::ClickFocus);
- rotation[0] = 90.0;
- rotation[1] = 0.0;
- rotation[2] = 0.0;
-// mCamera = new Camera;
-
-
- // Set up camera
-// camera()->setPosition(QVector3D(0, 0, 5));
-// camera()->setLookAt(QVector3D(0, 0, 0));
-// camera()->setUp(QVector3D(0, 1, 0));
-// camera()->setDepthRange(1, 100);
-// mRotation = 0;
-
- ///
-
- this->_trackball = TrackBall(0.05f, QVector3D(0, 1, 0), TrackBall::Sphere);
-
-}
-View3D::~View3D()
+View3D::View3D(VisualItemsModel* m, QWidget* parent): QGLViewer(parent)
+ ,m_model(m), m_selection(0)
{
-// delete mCamera;
+ setGridIsDrawn(true);
+ setAxisIsDrawn(true);
}
-
void View3D::setModel(VisualItemsModel *model)
{
m_model=model;
//TODO disconnect prev model
connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this, SLOT(updateFuncs(QModelIndex,QModelIndex)));
+ this, SLOT(updateFuncs(QModelIndex,QModelIndex)));
connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)),
- this, SLOT(addFuncs(QModelIndex,int,int)));
+ this, SLOT(addFuncs(QModelIndex,int,int)));
connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
- this, SLOT(removeFuncs(QModelIndex,int,int)));
-
+ this, SLOT(removeFuncs(QModelIndex,int,int)));
+
updateGL();
}
@@ -237,8 +66,8 @@ void View3D::setSelectionModel(QItemSelectionModel* selection)
{
Q_ASSERT(selection);
Q_ASSERT(selection->model() == m_model);
-
-
+
+
m_selection = selection;
connect(m_selection,SIGNAL(currentChanged(QModelIndex,QModelIndex)), \
SLOT(forceRepaint())); }
@@ -248,10 +77,10 @@ void View3D::addFuncs(const QModelIndex & parent, int start, int \
end) Q_ASSERT(!parent.isValid());
Q_ASSERT(start == end); // siempre se agrega un solo item al model
-
+
Surface* surf = static_cast<Surface*>(m_model->item(start));
surf->update(Box());
-
+
GLuint dlid = glGenLists(1);
m_displayLists[surf] = dlid;
@@ -283,14 +112,14 @@ void View3D::addFuncs(const QModelIndex & parent, int start, \
int end)
glEndList();
//END display list
-
+
}
void View3D::removeFuncs(const QModelIndex & parent, int start, int end)
{
Q_ASSERT(!parent.isValid());
Q_ASSERT(start == end); // siempre se agrega un solo item al model
-
+
glDeleteLists(m_displayLists[m_model->item(start)], 1);
}
@@ -302,383 +131,42 @@ void View3D::updateFuncs(const QModelIndex& start, const \
QModelIndex& end) int View3D::currentFunction() const
{
if (!m_model) return -1; // guard
-
+
int ret=-1;
if(m_selection) {
ret=m_selection->currentIndex().row();
}
-
+
return ret;
}
-
-void View3D::initializeGL()
-{
- qglColor(Qt::black);
-// glEnable(GL_DEPTH_TEST);
-// glEnable(GL_CULL_FACE);
-// glShadeModel(GL_SMOOTH);
-
-// QImage t, b;
-// GLuint texture[1];
-// b = QImage(8, 8, QImage::Format_Mono);
-// b.fill(QColor(0xff, 0xff, 0xff).rgb());
-// for(int i=0; i<b.height(); i++)
-// b.setPixel(4, i, 0);
-//
-// for(int i=0; i<b.width(); i++)
-// b.setPixel(i, 4, 0);
-//
-// t = QGLWidget::convertToGLFormat( b );
-// glGenTextures( 1, &texture[0] );
-// glBindTexture( GL_TEXTURE_2D, texture[0] );
-// glTexImage2D( GL_TEXTURE_2D, 0, 3, t.width(), t.height(), 0, GL_RGBA, \
GL_UNSIGNED_BYTE, t.bits() );
-//
-// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-//
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
- glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
-
-///
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_NORMALIZE);
-// glEnable(GL_DEPTH_TEST);
-//
- glShadeModel(GL_SMOOTH);
-// glEnable(GL_LIGHTING);
-// glEnable(GL_LIGHT0);
- glEnable(GL_MULTISAMPLE);
- //static GLfloat lightPosition[4] = { 0.1, 2.0, 3.0, 1.0 };
- GLfloat lightPosition[] = { 2.0, 0.0, 8.0, 0.5};
- glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
-
-
-
-}
-
-void View3D::resizeGL(int width, int height)
+void View3D::draw()
{
- height = height ? height : 1;
-
-// camera()->setViewport(0, 0, width, height);
-// glViewport(camera()->viewport().x(),camera()->viewport().y(),camera()->viewport().width(), \
camera()->viewport().height());
-
- glViewport(0,0,width,height);
-
-// camera()->setAspect(width/(float)height);
-// glMatrixMode(GL_PROJECTION);
-// glLoadIdentity();
-// glMultMatrixf((GLfloat*)mCamera->projectionMatrix().data());
-// gluPerspective(alpha,(GLfloat)width()/(GLfloat)height(),0.1f,100.0f);
-
-// glMatrixMode(GL_MODELVIEW);
-}
-
-
-
-QPointF View3D::pixelPosToViewPos(const QPointF& p)
-{
- return QPointF(2.0 * float(p.x()) / width() - 1.0,
- 1.0 - 2.0 * float(p.y()) / height());
-}
-
-
-
-void View3D::mousePressEvent(QMouseEvent *e)
-{
-// if(e->button() == Qt::LeftButton) {
-// press = e->pos();
-// keyspressed |= LCLICK;
-// }
-
-// lastMousePos = e->pos();
-
-///
-
- if(e->buttons() & Qt::LeftButton)
- {
- this->_trackball.push(pixelPosToViewPos(e->posF()), QQuaternion());
-//this->_trackball.push(pixelPosToViewPos(e->posF()), \
this->_trackball2.rotation().conjugate());
- e->accept();
- }
-}
-
-void View3D::mouseReleaseEvent(QMouseEvent *e)
-{
-// if(e->button() == Qt::LeftButton)
-// keyspressed &= ~LCLICK;
-
-///
- if(e->buttons() & Qt::LeftButton)
- {
- this->_trackball.release(pixelPosToViewPos(e->posF()),QQuaternion());
- e->accept();
- }
-}
-
-void View3D::mouseMoveEvent(QMouseEvent *e)
-{
-// if(keyspressed & LCLICK){
-// QPoint rel = e->pos() - press;
-// rotation[0] += rel.y();
-// rotation[2] -= rel.x();
-//
-// // press = e->pos();
-// // repaint();
-// // }
-//
-//
-// int dx = e->x() - lastMousePos.x();
-// int dy = e->y() - lastMousePos.y();
-// // if (e->buttons() & Qt::LeftButton) {
-// // trackball.rotate(dx, dy);
-// // }
-// lastMousePos = e->pos();
-
-
-///
-
- if(e->buttons() & Qt::LeftButton)
- {
- this->_trackball.move(pixelPosToViewPos(e->posF()), QQuaternion());
- updateGL();
- e->accept();
- } else {
- this->_trackball.release(pixelPosToViewPos(e->posF()), QQuaternion());
- }
-}
-
-
-void View3D::drawAxes()
-{
- glColor3f(0.8, 0.8, 0.4);
- renderText(11.0, 0.0, 0.0, "Y");
- renderText(0.0, 11.0, 0.0, "X");
- renderText(0.0, 0.0,-11.0, "Z");
-
- glBegin(GL_LINES);
- glColor3f(1.0f, 0.0f, 0.0f);
- glVertex3f(-10.0f, 0.0f, 0.0f);
- glVertex3f( 10.0f, 0.0f, 0.0f);
- glColor3f(0.0f, 1.0f, 0.0f);
- glVertex3f( 0.0f, 10.0f, 0.0f);
- glVertex3f( 0.0f,-10.0f, 0.0f);
- glColor3f(0.0f, 0.0f, 1.0f);
- glVertex3f( 0.0f, 0.0f, 10.0f);
- glVertex3f( 0.0f, 0.0f,-10.0f);
- glEnd();
-}
-
-static void multMatrix(const QMatrix4x4& m)
-{
-// static to prevent glMultMatrixf to fail on certain drivers
- static GLfloat mat[16];
- const qreal *data = m.constData();
- for (int index = 0; index < 16; ++index)
- mat[index] = data[index];
- glMultMatrixf(mat);
-}
-
-void View3D::paintGL()
-{
-// glMultMatrixf((GLfloat*)trackball.transform(*camera()).modelviewMatrix().data());
-
-// glRotatef(mRotation, 0, 1, 0);
-
-
-
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
-
-// if(keyspressed & KEYDOWN) rotation[0]+=3.f;
-// if(keyspressed & KEYUP) rotation[0]-=3.f;
-// if(keyspressed & KEYAVPAG) rotation[1]+=3.f;
-// if(keyspressed & KEYREPAG) rotation[1]-=3.f;
-// if(keyspressed & KEYLEFT) rotation[2]+=3.f;
-// if(keyspressed & KEYRIGHT) rotation[2]-=3.f;
-// if(keyspressed & KEYW) alpha/=2.f;
-// if(keyspressed & KEYS && alpha<=90.f) alpha*=2.f;
-// if(keyspressed & KEYQ) {
-// zoom/=2.0f;
-// }
-// if(keyspressed & KEYE) {
-// zoom*=2.0f;
-// }
-
-// if(rotation[0]>=360.f) rotation[0]-=360.f;
-// if(rotation[1]>=360.f) rotation[1]-=360.f;
-// if(rotation[2]>=360.f) rotation[2]-=360.f;
-
-// glMatrixMode(GL_PROJECTION);
-// glLoadIdentity();
-// gluPerspective(alpha,(GLfloat)width()/(GLfloat)height(),0.1f,100.0f);
-
-// float z=25.f;
-// glMatrixMode(GL_MODELVIEW);
-// glLoadIdentity();
-// glTranslatef(0,0,-z);
-// glRotatef(rotation[0], 1.0, 0.0, 0.0);
-// glRotatef(rotation[1], 0.0, 1.0, 0.0);
-// glRotatef(rotation[2], 0.0, 0.0, 1.0);
-
-// glMultMatrixf((GLfloat*)camera()->modelviewMatrix().data());
-
-///
-
-
- glMatrixMode(GL_PROJECTION);
-
- glLoadIdentity();
- gluPerspective(alpha, width() / (float)height(), 0.01, 24.0);
- gluLookAt(0.0,0.0,15.0,0,0,0,0,1,0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-// glTranslatef(0,0,-z);
-
- {
- QMatrix4x4 m;
- m.rotate(this->_trackball.rotation());
- multMatrix(m);
- }
-
-
-
- drawAxes();
foreach (VisualItem *item, m_displayLists.keys())
{
glCallList(m_displayLists[item]);
// qDebug() << itemid;
}
-
- glFlush();
-}
-
-QPixmap View3D::toPixmap()
-{
- return renderPixmap();
}
-void View3D::wheelEvent(QWheelEvent * e)
+void View3D::init()
{
- if(e->delta()>0)
- alpha/=2.f;
- else if(alpha<=90.f)
- alpha*=2.f;
-
+ glPushMatrix();
+ glTranslatef(6,5,5);
+ glRotatef(90.,0.,1.,0.);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_NORMALIZE);
+ glEnable(GL_DEPTH_TEST);
- updateGL();
-}
-
-
-void View3D::keyPressEvent( QKeyEvent *e )
-{
- switch(e->key()) {
- case Qt::Key_Up:
- keyspressed |= KEYUP;
- break;
- case Qt::Key_Down:
- keyspressed |= KEYDOWN;
- break;
- case Qt::Key_Left:
- keyspressed |= KEYLEFT;
- break;
- case Qt::Key_Right:
- keyspressed |= KEYRIGHT;
- break;
- case Qt::Key_PageUp:
- keyspressed |= KEYREPAG;
- break;
- case Qt::Key_PageDown:
- keyspressed |= KEYAVPAG;
- break;
- case Qt::Key_W:
- keyspressed |= KEYW;
- break;
- case Qt::Key_S:
- keyspressed |= KEYS;
- break;
- case Qt::Key_Q: //Be careful
- keyspressed |= KEYQ;
- break;
- case Qt::Key_E: //Be careful
- keyspressed |= KEYE;
- break;
- }
-// sendStatus(QString("-%1-").arg(keyspressed, 16));
- repaint();
-}
-
-
-void View3D::keyReleaseEvent( QKeyEvent *e )
-{
- switch(e->key()) {
- case Qt::Key_Up:
- keyspressed &= ~KEYUP;
- break;
- case Qt::Key_Down:
- keyspressed &= ~KEYDOWN;
- break;
- case Qt::Key_Left:
- keyspressed &= ~KEYLEFT;
- break;
- case Qt::Key_Right:
- keyspressed &= ~KEYRIGHT;
- break;
- case Qt::Key_PageUp:
- keyspressed &= ~KEYREPAG;
- break;
- case Qt::Key_PageDown:
- keyspressed &= ~KEYAVPAG;
- break;
- case Qt::Key_W:
- keyspressed &= ~KEYW;
- break;
- case Qt::Key_S:
- keyspressed &= ~KEYS;
- break;
- case Qt::Key_Q: //Be careful
- keyspressed &= ~KEYQ;
- break;
- case Qt::Key_E: //Be careful
- keyspressed &= ~KEYE;
- break;
-
- }
-// sendStatus(QString(".%1.").arg(keyspressed, 16));
- repaint();
-}
-
-void View3D::timeOut()
-{
- rotation[0] += 20.0;
- rotation[1] += 20.0;
- rotation[2] += 20.0;
- repaint();
-}
+ glShadeModel(GL_SMOOTH);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+ glEnable(GL_MULTISAMPLE);
+ static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
+ glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
-void View3D::setSize(double newSize)
-{
- default_size = newSize;
- repaint();
}
-void View3D::resetView()
-{
- default_step=0.15f;
- default_size=8.0f;
- if(zoom!=1.0f) {
- zoom=1.0f;
- }
- alpha=60.;
-
- rotation[0] = 90.0;
- rotation[1] = 0.0;
- rotation[2] = 0.0;
- updateGL();
-}
diff --git a/analitzaplot/plotview3d.h b/analitzaplot/plotview3d.h
index 3574e8c..e5d48a9 100644
--- a/analitzaplot/plotview3d.h
+++ b/analitzaplot/plotview3d.h
@@ -19,118 +19,42 @@
#ifndef KEOMATH_VIEW3D_H
#define KEOMATH_VIEW3D_H
+#include "QGLViewer/qglviewer.h"
#include <QMouseEvent>
#include <analitzaplot/mathutils.h>
#include <analitzaplot/private/functiongraph.h>
#include <QModelIndex>
-#include <QTime>
-#include <QGLWidget>
class VisualItemsModel;
class QItemSelectionModel;
-
- class TrackBall
- {
- public:
- enum TrackMode
- {
- Plane,
- Sphere,
- };
- TrackBall(TrackMode mode = Sphere);
- TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode = \
Sphere);
- // coordinates in [-1,1]x[-1,1]
- void push(const QPointF& p, const QQuaternion &transformation);
- void move(const QPointF& p, const QQuaternion &transformation);
- void release(const QPointF& p, const QQuaternion &transformation);
- void start(); // starts clock
- void stop(); // stops clock
- QQuaternion rotation() const;
- private:
- QQuaternion m_rotation;
- QVector3D m_axis;
- float m_angularVelocity;
-
- QPointF m_lastPos;
- QTime m_lastTime;
- bool m_paused;
- bool m_pressed;
- TrackMode m_mode;
- };
-
-
// class Solver3D;
-class ANALITZAPLOT_EXPORT View3D : public QGLWidget
+class ANALITZAPLOT_EXPORT View3D : public QGLViewer
{
Q_OBJECT
public:
View3D(QWidget *parent = 0);
View3D(VisualItemsModel *m, QWidget *parent = 0);
- virtual ~View3D();
void setModel(VisualItemsModel *m);
void setSelectionModel(QItemSelectionModel* selection);
- /** Returns the pixmap painting. */
-
-// Camera *camera() const { return mCamera; }
-
- QPixmap toPixmap();
+
public slots:
void updateFuncs(const QModelIndex &indexf,const QModelIndex &indext);
void addFuncs(const QModelIndex &index,int,int);
void removeFuncs(const QModelIndex &index,int,int);
- void resetView();
private:
int currentFunction() const;
-
- void initializeGL();
- void resizeGL(int w, int h);
- void paintGL();
+ void draw();
+ void init();
VisualItemsModel *m_model;
QItemSelectionModel* m_selection;
// <graphid, displaylistid>
QMap<VisualItem*, GLuint> m_displayLists;
-
-
- void drawAxes();
-
- void keyPressEvent(QKeyEvent *e);
- void keyReleaseEvent(QKeyEvent *e);
- void timeOut();
- void mousePressEvent(QMouseEvent *e); QPoint press;
- void mouseMoveEvent(QMouseEvent *e);
- void mouseReleaseEvent(QMouseEvent* e);
- void wheelEvent(QWheelEvent *e);
-QPointF pixelPosToViewPos(const QPointF& p);
-
-
- /** Sets the @p max maximum size. */
- void setSize(double max);
- double zoom;
- float rotation[3];
- float alpha;
- bool trans;
- unsigned short keyspressed;
- double default_size;
- double default_step;
-
- int m_n;
-
-// Camera* mCamera;
-// TrackBall trackball;
- float mRotation;
- QPoint lastMousePos;
-
-
-
- ///
-
- TrackBall _trackball;
};
#endif
diff --git a/analitzaplot/private/abstractsurface.cpp \
b/analitzaplot/private/abstractsurface.cpp index 5457b8e..f2b74d8 100644
--- a/analitzaplot/private/abstractsurface.cpp
+++ b/analitzaplot/private/abstractsurface.cpp
@@ -19,6 +19,9 @@
#include "abstractsurface.h"
+#define MAXAROUND 64
+#define MAXSTRIP 64
+#define MAXALONG 64
AbstractSurface::AbstractSurface(const Analitza::Expression& e)
: AbstractFunctionGraph(e)
@@ -36,6 +39,239 @@ AbstractSurface::~AbstractSurface()
{
}
+
+
+template<typename BinaryFunctor>
+bool AbstractSurface::buildParametricSurface()
+{
+
+ QStringList bvars = parameters();
+
+ //TODO remove the assert en el caso de implicitas se deberia tratar siempre de \
crear la superficies parametrica primero + Q_ASSERT(bvars.size() == 2); // solo \
para superficies que puedan ser parametrizadas +
+ static QPair<double, double> intervalx = interval(bvars.at(0));
+ static QPair<double, double> intervaly = interval(bvars.at(1));
+
+
+
+ ///
+ qreal umin;
+ qreal umax;
+ qreal vmin;
+ qreal vmax;
+ int usteps;
+ int vsteps;
+
+ ///
+ usteps=MAXALONG;
+ vsteps=MAXAROUND;
+/*
+ qDebug() << intervalx;
+ umin = intervalx.first;
+ umax = intervalx.second;
+ vmin = intervaly.first;
+ vmax = intervalx.second;*/
+
+
+// // umin = 0;
+// umax = 0.9;
+// vmin = 0;
+// vmax = 3.141/4;
+
+
+ switch (coordinateSystem())
+ {
+ case Cylindrical:
+ {
+// Q_ASSERT()
+
+ break;
+ }
+ case Spherical:
+ {
+
+ break;
+ }
+ }
+ faces.clear();
+
+
+///
+
+ QVector3D surface[MAXALONG][MAXAROUND];
+
+ int i, j;
+ float u, v;
+
+ for ( i=0; i<usteps; i++ )
+ for ( j=0; j<vsteps; j++ )
+ {
+ u = (umin+((umax-umin)/(float)(usteps-1))*(float)(i));
+ v = (vmin+((vmax-vmin)/(float)(vsteps-1))*(float)(j));
+
+
+ //BEGIN
+
+ arg(bvars.at(0))->setValue(u);
+ arg(bvars.at(1))->setValue(v);
+
+ // qDebug() << QVector3D(u, v, \
analyzer->calculateLambda().toReal().value()); +
+ QVector3D point;
+
+// switch (analyzer->type().returnValue().type())
+// {
+// case Analitza::ExpressionType::Vector:
+// {
+//
+// break;
+// }
+//
+// case Analitza::ExpressionType::Value:
+// {
+// point.setX(1);
+// point.setY(1);
+// point.setZ(analyzer->calculateLambda().toReal().value());
+//
+// switch (coordinateSystem())
+// {
+// case Cylindrical:
+// {
+// point.setX(u*cos(v));
+// point.setY(u*sin(v));
+// \
point.setZ(analyzer->calculateLambda().toReal().value()); + \
//out + ///
+// double \
h=analyzer->calculateLambda().toReal().value(); +// \
double x = 0; +// double y = 0;
+// double z = 0;
+// cylindricalToCartesian(u,v,h,x,y,z);
+// point.setX(x);
+// point.setY(y);
+// point.setZ(z);
+
+ ///
+
+// break;
+// }
+// case Spherical:
+// {
+// point.setX(point.x()*sin(u)*cos(v));
+// point.setY(point.y()*sin(u)*sin(v));
+// point.setZ(point.z()*cos(u));
+//
+// break;
+// }
+// }
+//
+// break;
+// }
+// }
+//
+ //END
+
+ surface[i][j] = BinaryFunctor(u,v);
+ }
+
+ for (i = 0; i < usteps -1; i++ )
+ for ( j=0; j<vsteps-1; j++ )
+ {
+ doQuad(1, 1, surface[i][j], surface[i+1][j], surface[i][j+1], \
surface[i+1][j+1]); + }
+
+ return !faces.isEmpty();
+}
+
+void AbstractSurface::doQuad(int n, int m, const QVector3D &p0, const QVector3D \
&p1, const QVector3D &p2, const QVector3D &p3) +{
+ int i;
+
+ QVector3D A, B, C, D;
+
+ for (i=0; i<m; i++)
+ {
+ A = QVector3D((p0.x()*(float)(m-i) + p1.x()*(float)i)/(float)m,
+ (p0.y()*(float)(m-i) + p1.y()*(float)i)/(float)m,
+ (p0.z()*(float)(m-i) + p1.z()*(float)i)/(float)m);
+
+ B = QVector3D((p0.x()*(float)(m-i-1) + p1.x()*(float)(i+1))/(float)m,
+ (p0.y()*(float)(m-i-1) + p1.y()*(float)(i+1))/(float)m,
+ (p0.z()*(float)(m-i-1) + p1.z()*(float)(i+1))/(float)m);
+
+ C = QVector3D((p2.x()*(float)(m-i) + p3.x()*(float)i)/(float)m,
+ (p2.y()*(float)(m-i) + p3.y()*(float)i)/(float)m,
+ (p2.z()*(float)(m-i) + p3.z()*(float)i)/(float)m);
+
+ D = QVector3D((p2.x()*(float)(m-i-1) + p3.x()*(float)(i+1))/(float)m,
+ (p2.y()*(float)(m-i-1) + p3.y()*(float)(i+1))/(float)m,
+ (p2.z()*(float)(m-i-1) + p3.z()*(float)(i+1))/(float)m);
+
+ doStrip(n, A, B, C, D);
+ }
+}
+
+void AbstractSurface::doStrip(int n, const QVector3D &p0, const QVector3D &p1, \
const QVector3D &p2, const QVector3D &p3) +{
+ int i, j;
+ QVector3D A, B, buffer[3];
+ QVector3D theStrip[MAXSTRIP][2];
+
+ for (i=0; i<=n; i++)
+ {
+ A = QVector3D((p0.x()*(float)(n-i) + p2.x()*(float)i)/(float)n,
+ (p0.y()*(float)(n-i) + p2.y()*(float)i)/(float)n,
+ (p0.z()*(float)(n-i) + p2.z()*(float)i)/(float)n);
+
+ B = QVector3D((p1.x()*(float)(n-i) + p3.x()*(float)i)/(float)n,
+ (p1.y()*(float)(n-i) + p3.y()*(float)i)/(float)n,
+ (p1.z()*(float)(n-i) + p3.z()*(float)i)/(float)n);
+
+ theStrip[i][0] = A;
+ theStrip[i][1] = B;
+ }
+
+ buffer[0] = theStrip[0][0];
+ buffer[1] = theStrip[0][1];
+ for (i=1; i<=n; i++)
+ for (j=0; j<2; j++)
+ {
+ buffer[2] = theStrip[i][j];
+ createFace(buffer);
+ buffer[0] = buffer[1];
+ buffer[1] = buffer[2];
+ }
+}
+
+void AbstractSurface::createFace( QVector3D *buffer )
+{
+ QVector3D Normal, diff1, diff2;
+
+ diff1 = QVector3D(buffer[1].x() - buffer[0].x(),
+ buffer[1].y() - buffer[0].y(),
+ buffer[1].z() - buffer[0].z());
+
+ diff2 = QVector3D(buffer[2].x() - buffer[1].x(),
+ buffer[2].y() - buffer[1].y(),
+ buffer[2].z() - buffer[1].z());
+
+ Normal = QVector3D(diff1.y()*diff2.z() - diff2.y()*diff1.z(),
+ diff1.z()*diff2.x() - diff1.x()*diff2.z(),
+ diff1.x()*diff2.y() - diff1.y()*diff2.x());
+
+ Face face;
+ face.normal = Normal;
+ face.p1 = buffer[0];
+ face.p2 = buffer[1];
+ face.p3 = buffer[2];
+
+// qDebug() << face.p1 << face.p2 << face.p3;
+
+ faces.append(face);
+}
+
+
\ No newline at end of file
diff --git a/analitzaplot/private/abstractsurface.h \
b/analitzaplot/private/abstractsurface.h index 209a5d5..af26656 100644
--- a/analitzaplot/private/abstractsurface.h
+++ b/analitzaplot/private/abstractsurface.h
@@ -27,6 +27,9 @@
name (const Analitza::Expression &functionExpression) : \
AbstractSurface(functionExpression) { } \ name (const Analitza::Expression \
&functionExpression, Analitza::Variables *variables) : \
AbstractSurface(functionExpression, variables) { }
+#include <functional>
+
+
class ANALITZAPLOT_EXPORT AbstractSurface : public AbstractFunctionGraph //strategy \
pattern for curves {
@@ -42,6 +45,17 @@ public:
protected:
AbstractSurface() {}
AbstractSurface(const AbstractSurface& other) {}
+
+ template<typename BinaryFunctor>
+ bool buildParametricSurface();
+
+private:
+ void doQuad(int n, int m, const QVector3D &p0, const QVector3D &p1, const \
QVector3D &p2, const QVector3D &p3); + void doStrip(int n, const QVector3D &p0, \
const QVector3D &p1, const QVector3D &p2, const QVector3D &p3); + void createFace( \
QVector3D *buffer ); +
+
+
};
#endif // ABSTRACTSURFACE_H
diff --git a/analitzaplot/private/backends/cartesiansurface.cpp \
b/analitzaplot/private/backends/cartesiansurface.cpp index 908545f..84c8eec 100644
--- a/analitzaplot/private/backends/cartesiansurface.cpp
+++ b/analitzaplot/private/backends/cartesiansurface.cpp
@@ -30,14 +30,10 @@
//TODO macros para las prop e abajo
-#define MAXAROUND 64
-#define MAXSTRIP 64
-#define MAXALONG 64
-
-class ANALITZAPLOT_EXPORT CartesianSurface : public AbstractSurface/*, static class? \
better macros FooClass*/ +class ANALITZAPLOT_EXPORT Fxy : public AbstractSurface/*, \
static class? better macros FooClass*/ {
public:
- CONSTRUCTORS(CartesianSurface)
+ CONSTRUCTORS(Fxy)
TYPE_NAME("CartesianSurfacez=f(x,y)")
EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter(
Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter(
@@ -53,170 +49,42 @@ public:
void update(const Box& viewport);
private:
- double UU(int i);
- double VV(int j);
- QVector3D shape(float u,float v);
- void doSurface();
- void doQuad(int n, int m, const QVector3D &p0, const QVector3D &p1, const \
QVector3D &p2, const QVector3D &p3);
- void doStrip(int n, const QVector3D &p0, const QVector3D &p1, const QVector3D \
&p2, const QVector3D &p3);
- void _emit( QVector3D *buffer );
-
- qreal umin;
- qreal umax;
- qreal vmin;
- qreal vmax;
- int usteps;
- int vsteps;
-
- QVector3D surface[MAXALONG][MAXAROUND];
- QVector3D theStrip[MAXSTRIP][2];
-};
-
-void CartesianSurface::update(const Box& viewport)
-{
- usteps=MAXALONG;
- vsteps=MAXAROUND;
- static QPair<double, double> intervalx = interval("x");
- static QPair<double, double> intervaly = interval("y");
-
- umin = intervalx.first;
- umax = intervalx.second;
- vmin = intervaly.first;
- vmax = intervalx.second;
-
- faces.clear();
- doSurface();
-}
+};
-double CartesianSurface::UU(int i)
+void Fxy::update(const Box& viewport)
{
- return (umin+((umax-umin)/(float)(usteps-1))*(float)(i));
+// buildParametricSurface();
}
-double CartesianSurface::VV(int j)
-{
- return (vmin+((vmax-vmin)/(float)(vsteps-1))*(float)(j));
-}
+REGISTER_SURFACE(Fxy)
-QVector3D CartesianSurface::shape(float u,float v)
+class ANALITZAPLOT_EXPORT Fxz : public AbstractSurface/*, static class? better \
macros FooClass*/ {
- arg("x")->setValue(u);
- arg("y")->setValue(v);
+public:
+ CONSTRUCTORS(Fxz)
+ TYPE_NAME("CartesianSurfaceY=f(x,z)")
+ EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter(
+ \
Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter( + \
Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter( + \
Analitza::ExpressionType(Analitza::ExpressionType::Value))) + \
COORDDINATE_SYSTEM(Cartesian) + PARAMETERS("x,z")
+ ICON_NAME("none")
+ EXAMPLES("x+z")
-// qDebug() << QVector3D(u, v, analyzer->calculateLambda().toReal().value());
-
- return QVector3D(u, v, analyzer->calculateLambda().toReal().value());
-}
-
-void CartesianSurface::doSurface()
-{
- int i, j;
- float u, v;
-
- for ( i=0; i<usteps; i++ )
- for ( j=0; j<vsteps; j++ )
- {
- u = UU(i);
- v = VV(j);
-
- QVector3D point = shape(u,v);
-
- surface[i][j] = QVector3D(point.x(), point.y(), point.z());
- }
-
- for (i = 0; i < usteps -1; i++ )
- for ( j=0; j<vsteps-1; j++ )
- {
- doQuad(1, 1, surface[i][j], surface[i+1][j], surface[i][j+1], \
surface[i+1][j+1]);
- }
-}
-
-void CartesianSurface::doQuad(int n, int m, const QVector3D &p0, const QVector3D \
&p1, const QVector3D &p2, const QVector3D &p3)
-{
- int i;
-
- QVector3D A, B, C, D;
-
- for (i=0; i<m; i++)
- {
- A = QVector3D((p0.x()*(float)(m-i) + p1.x()*(float)i)/(float)m,
- (p0.y()*(float)(m-i) + p1.y()*(float)i)/(float)m,
- (p0.z()*(float)(m-i) + p1.z()*(float)i)/(float)m);
-
- B = QVector3D((p0.x()*(float)(m-i-1) + p1.x()*(float)(i+1))/(float)m,
- (p0.y()*(float)(m-i-1) + p1.y()*(float)(i+1))/(float)m,
- (p0.z()*(float)(m-i-1) + p1.z()*(float)(i+1))/(float)m);
-
- C = QVector3D((p2.x()*(float)(m-i) + p3.x()*(float)i)/(float)m,
- (p2.y()*(float)(m-i) + p3.y()*(float)i)/(float)m,
- (p2.z()*(float)(m-i) + p3.z()*(float)i)/(float)m);
-
- D = QVector3D((p2.x()*(float)(m-i-1) + p3.x()*(float)(i+1))/(float)m,
- (p2.y()*(float)(m-i-1) + p3.y()*(float)(i+1))/(float)m,
- (p2.z()*(float)(m-i-1) + p3.z()*(float)(i+1))/(float)m);
-
- doStrip(n, A, B, C, D);
- }
-}
+ //Own
-void CartesianSurface::doStrip(int n, const QVector3D &p0, const QVector3D &p1, \
const QVector3D &p2, const QVector3D &p3)
-{
- int i, j;
- QVector3D A, B, buffer[3];
-
- for (i=0; i<=n; i++)
- {
- A = QVector3D((p0.x()*(float)(n-i) + p2.x()*(float)i)/(float)n,
- (p0.y()*(float)(n-i) + p2.y()*(float)i)/(float)n,
- (p0.z()*(float)(n-i) + p2.z()*(float)i)/(float)n);
-
- B = QVector3D((p1.x()*(float)(n-i) + p3.x()*(float)i)/(float)n,
- (p1.y()*(float)(n-i) + p3.y()*(float)i)/(float)n,
- (p1.z()*(float)(n-i) + p3.z()*(float)i)/(float)n);
-
- theStrip[i][0] = A;
- theStrip[i][1] = B;
- }
+ void update(const Box& viewport);
- buffer[0] = theStrip[0][0];
- buffer[1] = theStrip[0][1];
- for (i=1; i<=n; i++)
- for (j=0; j<2; j++)
- {
- buffer[2] = theStrip[i][j];
- _emit(buffer);
- buffer[0] = buffer[1];
- buffer[1] = buffer[2];
- }
-}
+private:
-void CartesianSurface::_emit( QVector3D *buffer )
-{
- QVector3D Normal, diff1, diff2;
+};
- diff1 = QVector3D(buffer[1].x() - buffer[0].x(),
- buffer[1].y() - buffer[0].y(),
- buffer[1].z() - buffer[0].z());
-
- diff2 = QVector3D(buffer[2].x() - buffer[1].x(),
- buffer[2].y() - buffer[1].y(),
- buffer[2].z() - buffer[1].z());
-
- Normal = QVector3D(diff1.y()*diff2.z() - diff2.y()*diff1.z(),
- diff1.z()*diff2.x() - diff1.x()*diff2.z(),
- diff1.x()*diff2.y() - diff1.y()*diff2.x());
-
- Face face;
- face.normal = Normal;
- face.p1 = buffer[0];
- face.p2 = buffer[1];
- face.p3 = buffer[2];
-
-// qDebug() << face.p1 << face.p2 << face.p3;
-
- faces.append(face);
+void Fxz::update(const Box& viewport)
+{
+// buildParametricSurface();
}
-REGISTER_SURFACE(CartesianSurface)
+REGISTER_SURFACE(Fxz)
diff --git a/analitzaplot/private/backends/polarcurve.cpp \
b/analitzaplot/private/backends/polarcurve.cpp index 77fcfaa..040e088 100644
--- a/analitzaplot/private/backends/polarcurve.cpp
+++ b/analitzaplot/private/backends/polarcurve.cpp
@@ -48,8 +48,6 @@ public:
//
-private:
- inline QPointF fromPolar(double r, double th) { return QPointF(r*std::cos(th), \
r*std::sin(th)); }
};
@@ -84,7 +82,10 @@ void FunctionPolar::update(const QRect& viewport)
arg("q")->setValue(th);
double r = analyzer->calculateLambda().toReal().value();
- addPoint(fromPolar(r, th));
+ double x = 0;
+ double y = 0;
+ polarToCartesian(r,th, x,y);
+ addPoint(QPointF(x,y));
}
}
@@ -125,13 +126,22 @@ QPair<QPointF, QString> FunctionPolar::image(const QPointF &p)
do {
arg("q")->setValue(th);
r = analyzer->calculateLambda().toReal().value();
- dp = fromPolar(r, th);
+
+
+ double x = 0;
+ double y = 0;
+ polarToCartesian(r,th, x,y);
+
+ dp = QPointF(x,y);
dist = (dp-p);
d = sqrt(dist.x()*dist.x() + dist.y()*dist.y());
arg("q")->setValue(th+2.*pi);
r = analyzer->calculateLambda().toReal().value();
- dp = fromPolar(r, th);
+
+ polarToCartesian(r,th, x,y);
+
+ dp = QPointF(x,y);
dist = (dp-p);
d2 = sqrt(dist.x()*dist.x() + dist.y()*dist.y());
@@ -145,7 +155,13 @@ QPair<QPointF, QString> FunctionPolar::image(const QPointF &p)
if(!res.isReal())
appendError(i18n("We can only draw Real results."));
r = res.toReal().value();
- dp = fromPolar(r, th);
+
+
+ double x = 0;
+ double y = 0;
+ polarToCartesian(r,th, x,y);
+
+ dp = QPointF(x, y);
pos = QString("r=%1 th=%2").arg(r,3,'f',2).arg(th,3,'f',2);
return QPair<QPointF, QString>(dp, pos);
diff --git a/analitzaplot/private/functiongraphfactory.cpp \
b/analitzaplot/private/functiongraphfactory.cpp index 7b0fcc5..59c7ea4 100644
--- a/analitzaplot/private/functiongraphfactory.cpp
+++ b/analitzaplot/private/functiongraphfactory.cpp
@@ -135,12 +135,16 @@ bool \
FunctionGraphFactory::registerFunctionGraph(BuilderFunctionWithVars builder {
int dim = spaceDimension(expressionTypeFunction(), argumentsFunction() );
-// Q_ASSERT(!contains(id(argumentsFunction(), dim)));
// Q_ASSERT(expressionTypeFunction().type() == \
Analitza::ExpressionType::Lambda); DEPRECATED implicit is not a lambda
+
+
+
QString id = QString::number(dim)+"|"+
QString::number((int)coordinateSystemFunction())+"|"+
argumentsFunction().join(",");
+
+ Q_ASSERT(!contains(id)); // verificar que no se registren los mismos tipos
typeNameFunctions[id] = typeNameFunction;
expressionTypeFunctions[id] = expressionTypeFunction;
diff --git a/analitzaplot/private/functiongraphsmodel.cpp \
b/analitzaplot/private/functiongraphsmodel.cpp index 59fc989..d660857 100644
--- a/analitzaplot/private/functiongraphsmodel.cpp
+++ b/analitzaplot/private/functiongraphsmodel.cpp
@@ -180,11 +180,11 @@ void VisualItemsModel::removeItem(int row)
m_itemCanCallModelRemoveItem = false;
- if (!tmpcurve->m_inDestructorSoDontDeleteMe)
- {
- delete tmpcurve;
- tmpcurve = 0;
- }
+// if (!tmpcurve->m_inDestructorSoDontDeleteMe)
+// {
+// delete tmpcurve;
+// tmpcurve = 0;
+// }
m_itemCanCallModelRemoveItem = true;
diff --git a/analitzaplot/private/functiongraphsmodel.h \
b/analitzaplot/private/functiongraphsmodel.h index a376fb3..6416625 100644
--- a/analitzaplot/private/functiongraphsmodel.h
+++ b/analitzaplot/private/functiongraphsmodel.h
@@ -38,12 +38,14 @@ class Variables;
class Expression;
}
+
+// QStandardItemModel
class ANALITZAPLOT_EXPORT VisualItemsModel : public QAbstractListModel
{
friend class VisualItem;
Q_OBJECT
-
+// if(item->type()==CurveType)
public:
VisualItemsModel(QObject * parent = 0);
VisualItemsModel(Analitza::Variables *v, QObject * parent = 0);
diff --git a/analitzaplot/private/mappinggraph.h \
b/analitzaplot/private/mappinggraph.h index 8757921..8505329 100644
--- a/analitzaplot/private/mappinggraph.h
+++ b/analitzaplot/private/mappinggraph.h
@@ -22,6 +22,7 @@
#include <QStringList>
#include <QColor>
+#include <qstandarditemmodel.h>
#include "../mathutils.h"
@@ -33,16 +34,16 @@ class Expression;
class VisualItemsModel;
-class ANALITZAPLOT_EXPORT VisualItem
+class ANALITZAPLOT_EXPORT VisualItem
{
-friend class VisualItemsModel; // use case: if this item gets deleted by "delete \
someitem" the model will emit/exec removeitem signal
-
+friend class VisualItemsModel;
+
public:
enum PlotStyle { Solid = 0, Wired = 1, Dots = 3 };
explicit VisualItem(const QString &name, const QColor& col);
virtual ~VisualItem();
-
+
virtual Analitza::Variables * variables() const = 0;
virtual void setVariables(Analitza::Variables *variables) = 0;
diff --git a/analitzaplot/tests/plotview2dtest.cpp \
b/analitzaplot/tests/plotview2dtest.cpp index e3a653c..aa1b732 100644
--- a/analitzaplot/tests/plotview2dtest.cpp
+++ b/analitzaplot/tests/plotview2dtest.cpp
@@ -65,6 +65,7 @@ int main(int argc, char *argv[])
model->addPlaneCurve(Analitza::Expression("t->vector{t*t+1, t+2}"), "vec", \
Qt::yellow);
PlaneCurve *item2 = \
model->addPlaneCurve(Analitza::Expression("5*(x**2+y**2)**3=15*(x*y*72)**2"), "impl", \
Qt::red);
model->addPlaneCurve(Analitza::Expression("x->2+x*x"), "otra simple", Qt::blue);
+
// qDebug() << item2->expression().toString();
diff --git a/analitzaplot/tests/plotview3dtest.cpp \
b/analitzaplot/tests/plotview3dtest.cpp index ae90ef7..05183ed 100644
--- a/analitzaplot/tests/plotview3dtest.cpp
+++ b/analitzaplot/tests/plotview3dtest.cpp
@@ -35,6 +35,12 @@
#include <analitza/polynomial.h>
+#include <functional>
+
+
+
+
+
int main(int argc, char *argv[])
{
KAboutData aboutData("PlotView3DTest",
@@ -55,6 +61,7 @@ int main(int argc, char *argv[])
//BEGIN test calls
+
VisualItemsModel *model = new VisualItemsModel(mainWindow);
QItemSelectionModel *selection = new QItemSelectionModel(model);
@@ -62,11 +69,14 @@ int main(int argc, char *argv[])
view3d->setModel(model);
view3d->setSelectionModel(selection);
- model->addSurface(Analitza::Expression("(x,y)->x*x"), "Hola", Qt::cyan);
- model->addSurface(Analitza::Expression("(x,y)->y*y"), "Hola", Qt::yellow);
- model->addSurface(Analitza::Expression("(x,y)->x*x+y*y"), "Hola", Qt::gray);
-
- model->removeItem(1);
+// model->addSurface(Analitza::Expression("(x,y)->x*x"), "Hola", Qt::cyan);
+// model->addSurface(Analitza::Expression("(x,y)->y*y"), "Hola", Qt::yellow);
+// model->addSurface(Analitza::Expression("(x,y)->x*x+y*y"), "Hola", Qt::gray);
+//
+// model->removeItem(1);
+// model->removeItem(1);
+// model->removeItem(1);
+// model->removeItem(1);
// qDebug() << model->item(0)->spaceDimension() << static_cast<const \
Surface*>(model->item(0))->faces().size();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic