HyperspaceExplorer 0.7.1
|
00001 /* 00002 Hyperspace Explorer - visualizing higher-dimensional geometry 00003 Copyright (C) 2010 Lene Preuss <lene.preuss@gmail.com> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 00019 */ 00020 00021 #ifndef C4DVIEW_H 00022 #define C4DVIEW_H 00023 00024 #include "ViewImpl.h" 00025 #include "ValuesDialogImpl.h" 00026 #include "Rotation.h" 00027 00028 #include <QTimer> 00029 #include <QGLWidget> 00030 00031 00032 class QPaintEvent; 00033 class QStatusBar; 00034 00035 class C4DView; 00036 class Displayable; 00037 class RealFunction; 00038 class Surface; 00039 00040 class CustomFunction; 00041 class CustomPolarFunction; 00042 class CustomSurface; 00043 class CustomComplexFunction; 00044 00048 00050 00053 class C4DView : 00054 public QGLWidget, 00055 public UI::ViewImpl { 00056 00057 00058 private: 00060 00064 template<class function> class CustomFunctionSlot { 00065 public: 00066 static void createCustomFunction(C4DView *view); 00067 static void createCustomSurface(C4DView *view); 00068 }; 00069 00070 class Menu4D; 00071 class MouseHandler4D; 00072 00073 Q_OBJECT 00074 00075 public: 00076 C4DView(QWidget * = 0); 00077 virtual ~C4DView(); 00078 00080 00082 virtual void applyTransform(const VecMath::Rotation<4> &R, 00083 const VecMath::Vector<4> &T); 00084 00086 virtual void animate(); 00087 00089 virtual void setSize(unsigned w, unsigned h); 00090 00092 virtual void setBackground(const Color &); 00094 virtual void setColors(bool); 00096 virtual void setCoordinates(bool); 00098 virtual void setFog(bool); 00100 virtual void setHyperfog(bool); 00102 virtual void setLighting(bool); 00104 virtual void setShading(bool); 00106 virtual void setTransparence(bool); 00107 00108 virtual void drawVertex(const VecMath::Vector< 4 > &x, const VecMath::Vector< 3 > &xscr); 00109 virtual void drawLine(const VecMath::Vector< 4 > &x0, const VecMath::Vector< 4 > &x1, 00110 const VecMath::Vector< 3 > &xscr0, const VecMath::Vector< 3 > &xscr1); 00111 virtual void drawQuadrangle(const VecMath::Vector< 4 > &x0, const VecMath::Vector< 4 > &x1, 00112 const VecMath::Vector< 4 > &x2, const VecMath::Vector< 4 > &x3, 00113 const VecMath::Vector< 3 > &xscr0, const VecMath::Vector< 3 > &xscr1, 00114 const VecMath::Vector< 3 > &xscr2, const VecMath::Vector< 3 > &xscr3); 00115 virtual void drawPolygon(const std::vector< VecMath::Vector< 4 > >&x , 00116 const std::vector< VecMath::Vector< 3 > >&xscr ); 00117 00119 00121 double Benchmark3D(int, double, double, double, bool = true); 00123 double Benchmark4D(int, double, double, double, bool = true); 00124 00125 private slots: 00127 virtual void ApplyChanges(const ParameterMap &); 00128 00130 void OnAnimationTimer(); 00131 00132 private: 00134 void Transform(const VecMath::Rotation<4> &R, const VecMath::Vector<4> &T); 00136 void Transform(); 00137 00139 void Project(); 00140 00142 void PreRedraw(); 00144 void Redraw(); 00145 00147 void RenderScene(); 00148 00150 void InitCross(); 00151 void SetupDepthCue(bool); 00152 void DrawCoordinates(void); 00153 00154 void StartAnimation(); 00155 void StopAnimation(); 00156 void RandomAnimation(bool); 00157 00158 QPixmap makePixmap(); 00159 void writeFrame(); 00160 00161 void checkAnglesForOverflow(); 00162 void UpdateStatus(QString = ""); 00163 00164 void AssignValues(const std::shared_ptr<Displayable> &); 00165 00166 double Size(); 00167 00169 virtual void mouseMoveEvent(QMouseEvent *); 00171 virtual void mousePressEvent(QMouseEvent *); 00173 virtual void mouseReleaseEvent( QMouseEvent *); 00175 virtual void mouseDoubleClickEvent( QMouseEvent *); 00177 virtual void paintEvent(QPaintEvent * = 0); 00179 virtual void resizeEvent( QResizeEvent * ); 00181 virtual void initializeGL(void); 00183 virtual void resizeGL (int, int); 00184 00186 void setm_rot(const VecMath::Rotation<3, GLdouble> &_r) { 00187 _rot = _r; 00188 } 00190 const VecMath::Rotation<3, GLdouble> &m_rot() { 00191 return _rot; 00192 } 00194 void addm_rot(const VecMath::Rotation<3, GLdouble> &_dmr) { 00195 _rot += _dmr; 00196 } 00197 00199 void setm_trans(const VecMath::Vector<3, GLdouble> &_t) { 00200 _trans = _t; 00201 } 00203 const VecMath::Vector<3, GLdouble> &m_trans() { 00204 return _trans; 00205 } 00207 void addm_trans(const VecMath::Vector<3, GLdouble> &_dmt) { 00208 _trans += _dmt; 00209 } 00210 00212 void setanimationFrame(unsigned b) { _animationFrame = b; } 00214 unsigned animationFrame() const { return _animationFrame; } 00216 void setanimationMaxFrames(unsigned b) { _animationMaxFrames = b; } 00218 unsigned animationMaxFrames() const { return _animationMaxFrames; } 00220 unsigned animation_fps() const { return _animation_fps; } 00221 00223 void setObjectList(GLint b) { _objectList = b; } 00225 GLint ObjectList() const { return _objectList; } 00227 void setCoordinateCross(GLint b) { _coordinateCross = b; } 00229 GLint CoordinateCross() const { return _coordinateCross; } 00230 00232 void setAnimated(bool b) { _animated = b; } 00234 bool Animated() const { return _animated; } 00236 void setCurrentlyRendering(bool b) { _currentlyRendering = b; } 00238 bool CurrentlyRendering() const { return _currentlyRendering; } 00239 00241 void setAnimationTimer(QTimer * b) { _animationTimer = b; } 00243 QTimer * AnimationTimer() const { return _animationTimer; } 00245 void setAnimateRandomTimer(QTimer * b) { _animateRandomTimer = b; } 00247 QTimer * AnimateRandomTimer() const { return _animateRandomTimer; } 00248 00250 void setValues(UI::Dialogs::ValuesDialogImpl * b) { _values = b; } 00252 UI::Dialogs::ValuesDialogImpl * Values() const { return _values; } 00253 00255 void setMenu(Menu4D *b) { _menu = b; } 00257 Menu4D *Menu() const { return _menu; } 00259 void setMouseHandler(MouseHandler4D *m) { _mouseHandler = m; } 00261 MouseHandler4D *MouseHandler() const { return _mouseHandler; } 00262 00263 private: 00264 void SetupDepthCue (float, float); 00265 void InitLight (void); 00266 void InitShade (void); 00267 void InitFog (void); 00268 void InitTransparence (void); 00269 00270 private: // member variables 00271 00273 VecMath::Rotation<3, GLdouble> _rot; 00275 VecMath::Vector<3, GLdouble> _trans; 00276 00277 unsigned _animationFrame; 00278 unsigned _animationMaxFrames; 00279 const unsigned _animation_fps; 00280 00281 bool _animated; 00282 00283 bool _currentlyRendering; 00284 00285 GLint _objectList; 00286 GLint _coordinateCross; 00287 00289 QTimer *_animationTimer; 00291 QTimer *_animateRandomTimer; 00292 00294 UI::Dialogs::ValuesDialogImpl *_values; 00295 00296 Menu4D *_menu; 00297 MouseHandler4D *_mouseHandler; 00298 00300 std::vector<std::vector<VecMath::Vector<4> > > _cross; 00302 std::vector<std::vector<VecMath::Vector<4> > > _crossTrans; 00304 std::vector<std::vector<VecMath::Vector<3> > > _crossScr; 00305 00306 static std::string _helpFile; 00307 00309 friend class CustomFunctionSlot<CustomFunction>; 00311 friend class CustomFunctionSlot<CustomPolarFunction>; 00313 friend class CustomFunctionSlot<CustomComplexFunction>; 00315 friend class CustomFunctionSlot<CustomSurface>; 00316 00317 friend class FunctionSlotHelper; 00318 friend class SurfaceSlotHelper; 00319 friend class SlotHelper; 00320 00321 }; 00322 00323 #endif // !defined(C4DVIEW)