~ubuntu-branches/ubuntu/trusty/kalgebra/trusty-updates

« back to all changes in this revision

Viewing changes to src/graph3d.h

  • Committer: Bazaar Package Importer
  • Author(s): Philip Muškovac
  • Date: 2011-07-08 20:10:34 UTC
  • Revision ID: james.westby@ubuntu.com-20110708201034-0cqpagx7uz4pu82n
Tags: upstream-4.6.90+repack1
Import upstream version 4.6.90+repack1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************************
 
2
 *  Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org>                               *
 
3
 *                                                                                   *
 
4
 *  This program is free software; you can redistribute it and/or                    *
 
5
 *  modify it under the terms of the GNU General Public License                      *
 
6
 *  as published by the Free Software Foundation; either version 2                   *
 
7
 *  of the License, or (at your option) any later version.                           *
 
8
 *                                                                                   *
 
9
 *  This program is distributed in the hope that it will be useful,                  *
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
 
12
 *  GNU General Public License for more details.                                     *
 
13
 *                                                                                   *
 
14
 *  You should have received a copy of the GNU General Public License                *
 
15
 *  along with this program; if not, write to the Free Software                      *
 
16
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
 
17
 *************************************************************************************/
 
18
 
 
19
#ifndef GRAPH3D_H
 
20
#define GRAPH3D_H
 
21
 
 
22
#include <QGLWidget>
 
23
#include <QtCore/QThread>
 
24
 
 
25
#include "analitza/analyzer.h"
 
26
 
 
27
/**
 
28
 *      Used to calculate 3D Graphs in parallel.
 
29
 *      @author Aleix Pol i Gonzalez <aleixpol@kde.org>  
 
30
 */
 
31
 
 
32
class Calculate3D : public QThread
 
33
{
 
34
public:
 
35
        /** Constructor. Creates a Calculate3D thread.
 
36
                @param p        parent object.
 
37
                @param na       Analitza module used fot the calculations.
 
38
                @param poi      memory space where the results will be located.
 
39
                @param fr       Beginning of the calculated values.
 
40
                @param to       End of the calculated values.
 
41
                @param m        Distance of each dimension from the (0, 0) to be calculated.
 
42
                @param s        Step between each 2 values.
 
43
        */
 
44
        Calculate3D(QObject *p, const Analitza::Analyzer &na, double** poi, int fr, int to, double m, double s) : 
 
45
                QThread(p), a(na), points(poi), from(fr), to(to), size(m), step(s) {}
 
46
        
 
47
        /** Runs the thread. */
 
48
        void run();
 
49
        
 
50
        /** Sets the end of the segment to calculate. */
 
51
        void setTo(int nto) { to = nto; }
 
52
private:
 
53
        Analitza::Analyzer a;
 
54
        double **points;
 
55
        int from;
 
56
        int to;
 
57
        
 
58
        double size;
 
59
        double step;
 
60
};
 
61
 
 
62
/**
 
63
 *      The Graph3D provides a 3D OpenGL graph representation.
 
64
 *      @author Aleix Pol i Gonzalez
 
65
 */
 
66
 
 
67
class Graph3D : public QGLWidget
 
68
{
 
69
        Q_OBJECT
 
70
        public:
 
71
                /** Defines how will be the graph representated. */
 
72
                enum Type {
 
73
                        Dots=0,  ///< Dots will be drawn.
 
74
                        Lines=1, ///< Lines will be drawn.
 
75
                        Solid=2  ///< A solid graph will be drawn with a line texture.
 
76
                };
 
77
                
 
78
                /** Constructor. Creates a new Graph3D widget. */
 
79
                Graph3D(QWidget *parent = 0);
 
80
                
 
81
                /** Destructor. */
 
82
                ~Graph3D();
 
83
                
 
84
                /** Sets @p exp as the function's expression. */
 
85
                void setFunc(const Analitza::Expression& exp);
 
86
                
 
87
                /** Toggles the transparency for Solid graphs. */
 
88
                void setTransparency(bool tr) { trans = tr; glDraw(); }
 
89
                
 
90
                /** Returns whether there is transparency. */
 
91
                bool transparency() const { return trans; }
 
92
                
 
93
                /** Returns the pixmap painting. */
 
94
                QPixmap toPixmap();
 
95
                
 
96
                /** Sets the @p max maximum size. */
 
97
                void setSize(double max);
 
98
                
 
99
                /** Sets the interval between two points. */
 
100
                void setStep(double res);
 
101
                
 
102
                /** Sets the Z coordinate. */
 
103
                void setZoom(float alpha);
 
104
                
 
105
                /** Sets the showed method. */
 
106
                void setMethod(Type m);
 
107
                
 
108
                void wheelEvent(QWheelEvent *e);
 
109
                
 
110
                static bool checkExpression(const QStringList& bvars, const Analitza::ExpressionType& actual);
 
111
                
 
112
        public slots:
 
113
                /** Resets the view coordinates. */
 
114
                void resetView();
 
115
                
 
116
        signals:
 
117
                /** Emits a status message. */
 
118
                void status(const QString &msg);
 
119
                
 
120
        private:
 
121
                void drawAxes();
 
122
                
 
123
                virtual void initializeGL() ;
 
124
                virtual void resizeGL( int width, int height ) ;
 
125
                virtual void paintGL() ;
 
126
                
 
127
                void keyPressEvent(QKeyEvent *e);
 
128
                void keyReleaseEvent(QKeyEvent *e);
 
129
                void timeOut();
 
130
                void mousePressEvent(QMouseEvent *e); QPoint press;
 
131
                void mouseReleaseEvent(QMouseEvent *e);
 
132
                void mouseMoveEvent(QMouseEvent *e);
 
133
                void mem();
 
134
                bool create(const Analitza::Expression& func3d);
 
135
                void sendStatus(const QString& msg) { emit status(msg); }
 
136
                
 
137
                Analitza::Analyzer a;
 
138
                double default_step;
 
139
                double default_size;
 
140
                double zoom;
 
141
                double **points;
 
142
                float rotation[3];
 
143
                float alpha;
 
144
                Type method;
 
145
                bool trans;
 
146
                unsigned short keyspressed;
 
147
                
 
148
                int m_n;
 
149
};
 
150
 
 
151
#endif