source: git/src/gfxcore.h @ dbd50e2

RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereostereo-2025walls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since dbd50e2 was cc9e2c65, checked in by Olly Betts <olly@…>, 10 years ago

lib/,src/: Add "Colour by Gradient".

  • Property mode set to 100644
File size: 16.2 KB
Line 
1//
2//  gfxcore.h
3//
4//  Core drawing code for Aven.
5//
6//  Copyright (C) 2000-2001,2002,2005 Mark R. Shinwell.
7//  Copyright (C) 2001-2004,2005,2006,2007,2010,2011,2012,2013,2014,2015 Olly Betts
8//  Copyright (C) 2005 Martin Green
9//
10//  This program is free software; you can redistribute it and/or modify
11//  it under the terms of the GNU General Public License as published by
12//  the Free Software Foundation; either version 2 of the License, or
13//  (at your option) any later version.
14//
15//  This program is distributed in the hope that it will be useful,
16//  but WITHOUT ANY WARRANTY; without even the implied warranty of
17//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18//  GNU General Public License for more details.
19//
20//  You should have received a copy of the GNU General Public License
21//  along with this program; if not, write to the Free Software
22//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23//
24
25#ifndef gfxcore_h
26#define gfxcore_h
27
28#include <float.h>
29#include <limits.h>
30#include <time.h>
31
32#include "img_hosted.h"
33
34#include "guicontrol.h"
35#include "labelinfo.h"
36#include "vector3.h"
37#include "wx.h"
38#include "gla.h"
39
40#include <list>
41#include <utility>
42#include <vector>
43
44using namespace std;
45
46class MainFrm;
47class traverse;
48
49class XSect;
50class PointInfo;
51class MovieMaker;
52
53class PresentationMark : public Point {
54  public:
55    Double angle, tilt_angle;
56    Double scale;
57    Double time;
58    PresentationMark() : Point(), angle(0), tilt_angle(0), scale(0), time(0)
59        { }
60    PresentationMark(const Vector3 & v, Double angle_, Double tilt_angle_,
61                     Double scale_, Double time_ = 0)
62        : Point(v), angle(angle_), tilt_angle(tilt_angle_), scale(scale_),
63          time(time_)
64        { }
65    bool is_valid() const { return scale > 0; }
66};
67
68struct ZoomBox {
69  public:
70    int x1, y1, x2, y2;
71
72    ZoomBox()
73        : x1(INT_MAX) { }
74
75    bool active() const { return x1 != INT_MAX; }
76
77    void set(const wxPoint & p1, const wxPoint & p2) {
78        x1 = p1.x;
79        y1 = p1.y;
80        x2 = p2.x;
81        y2 = p2.y;
82    }
83
84    void unset() {
85        x1 = INT_MAX;
86    }
87};
88
89enum {
90    COLOUR_BY_NONE,
91    COLOUR_BY_DEPTH,
92    COLOUR_BY_DATE,
93    COLOUR_BY_ERROR,
94    COLOUR_BY_GRADIENT,
95    COLOUR_BY_LENGTH,
96    COLOUR_BY_LIMIT_ // Leave this last.
97};
98
99enum {
100    UPDATE_NONE,
101    UPDATE_BLOBS,
102    UPDATE_BLOBS_AND_CROSSES
103};
104
105enum {
106      SPLAYS_HIDE,
107      SPLAYS_SHOW_FADED,
108      SPLAYS_SHOW_NORMAL,
109};
110
111// It's pointless to redraw the screen as often as we can on a fast machine,
112// since the display hardware will only update so many times per second.
113// This is the maximum framerate we'll redraw at.
114const int MAX_FRAMERATE = 50;
115
116class GfxCore : public GLACanvas {
117    Double m_Scale;
118    int m_ScaleBarWidth;
119
120    typedef enum {
121        LIST_COMPASS,
122        LIST_CLINO,
123        LIST_CLINO_BACK,
124        LIST_SCALE_BAR,
125        LIST_DEPTH_KEY,
126        LIST_DATE_KEY,
127        LIST_ERROR_KEY,
128        LIST_GRADIENT_KEY,
129        LIST_LENGTH_KEY,
130        LIST_UNDERGROUND_LEGS,
131        LIST_TUBES,
132        LIST_SURFACE_LEGS,
133        LIST_BLOBS,
134        LIST_CROSSES,
135        LIST_GRID,
136        LIST_SHADOW,
137        LIST_LIMIT_ // Leave this last.
138    } drawing_list;
139
140    static const int NUM_COLOUR_BANDS = 13;
141
142    void SetPanBase() {
143        base_pan = m_PanAngle;
144        base_pan_time = timer.Time() - (1000 / MAX_FRAMERATE);
145    }
146
147    void SetTiltBase() {
148        base_tilt = m_TiltAngle;
149        base_tilt_time = timer.Time() - (1000 / MAX_FRAMERATE);
150    }
151
152public:
153    typedef enum {
154        CURSOR_DEFAULT,
155        CURSOR_POINTING_HAND,
156        CURSOR_DRAGGING_HAND,
157        CURSOR_HORIZONTAL_RESIZE,
158        CURSOR_ROTATE_HORIZONTALLY,
159        CURSOR_ROTATE_VERTICALLY,
160        CURSOR_ROTATE_EITHER_WAY,
161        CURSOR_ZOOM,
162        CURSOR_ZOOM_ROTATE
163    } cursor;
164
165private:
166    GUIControl* m_Control;
167    char* m_LabelGrid;
168    MainFrm* m_Parent;
169    bool m_DoneFirstShow;
170    Double m_TiltAngle;
171    Double m_PanAngle;
172    bool m_Rotating;
173    Double m_RotationStep;
174    int m_SwitchingTo;
175    bool m_Crosses;
176    bool m_Legs;
177    int m_Splays;
178    bool m_Names;
179    bool m_Scalebar;
180    bool m_ColourKey;
181    bool m_OverlappingNames;
182    bool m_Compass;
183    bool m_Clino;
184    bool m_Tubes;
185    int m_ColourBy;
186
187    bool m_HaveData;
188    bool m_MouseOutsideCompass;
189    bool m_MouseOutsideElev;
190    bool m_Surface;
191    bool m_Entrances;
192    bool m_FixedPts;
193    bool m_ExportedPts;
194    bool m_Grid;
195    bool m_BoundingBox;
196
197    bool m_Degrees;
198    bool m_Metric;
199    bool m_Percent;
200
201    bool m_HitTestDebug;
202
203    list<LabelInfo*> *m_PointGrid;
204    bool m_HitTestGridValid;
205
206    LabelInfo temp_here;
207    const LabelInfo * m_here;
208    const LabelInfo * m_there;
209
210    wxStopWatch timer;
211    long base_tilt_time;
212    long base_pan_time;
213    Double base_tilt;
214    Double base_pan;
215
216    GLAPen m_Pens[NUM_COLOUR_BANDS + 1];
217
218#define PLAYING 1
219    int presentation_mode; // for now, 0 => off, PLAYING => continuous play
220    bool pres_reverse;
221    double pres_speed;
222    PresentationMark next_mark;
223    double next_mark_time;
224    double this_mark_total;
225
226    MovieMaker * movie;
227
228    cursor current_cursor;
229
230    int sqrd_measure_threshold;
231
232    // The legends for each entry in the colour key.
233    wxString key_legends[NUM_COLOUR_BANDS];
234
235    wxPoint key_lowerleft[COLOUR_BY_LIMIT_];
236
237    ZoomBox zoombox;
238
239    void PlaceVertexWithColour(const Vector3 &v, Double factor = 1.0);
240    void PlaceVertexWithColour(const Vector3 & v, GLint tex_x, GLint tex_y,
241                               Double factor);
242    void SetDepthColour(Double z, Double factor);
243    void PlaceVertexWithDepthColour(const Vector3 & v, Double factor = 1.0);
244    void PlaceVertexWithDepthColour(const Vector3 & v, GLint tex_x, GLint tex_y, Double factor);
245
246    void SetColourFrom01(double how_far, Double factor);
247
248    void SetColourFromDate(int date, Double factor);
249    void SetColourFromError(double E, Double factor);
250    void SetColourFromGradient(double angle, Double factor);
251    void SetColourFromLength(double len, Double factor);
252
253    int GetClinoOffset() const;
254    void DrawTick(int angle_cw);
255    void DrawArrow(gla_colour col1, gla_colour col2);
256
257    void SkinPassage(vector<XSect> & centreline, bool draw = true);
258
259    virtual void GenerateList(unsigned int l);
260    void GenerateDisplayList();
261    void GenerateDisplayListTubes();
262    void GenerateDisplayListSurface();
263    void GenerateDisplayListShadow();
264    void GenerateBlobsDisplayList();
265
266    void DrawIndicators();
267
268    void TryToFreeArrays();
269    void FirstShow();
270
271    void DrawScaleBar();
272    void DrawColourKey(int num_bands, const wxString & other, const wxString & units);
273    void DrawDepthKey();
274    void DrawDateKey();
275    void DrawErrorKey();
276    void DrawGradientKey();
277    void DrawLengthKey();
278    void DrawCompass();
279    void DrawClino();
280    void DrawClinoBack();
281    void Draw2dIndicators();
282    void DrawGrid();
283
284    void NattyDrawNames();
285    void SimpleDrawNames();
286
287    void DefaultParameters();
288
289    void Repaint();
290
291    void CreateHitTestGrid();
292
293    int GetCompassXPosition() const;
294    int GetClinoXPosition() const;
295    int GetIndicatorYPosition() const;
296    int GetIndicatorRadius() const;
297
298    void ToggleFlag(bool* flag, int update = UPDATE_NONE);
299
300    const GLAPen& GetPen(int band) const {
301        assert(band >= 0 && band < NUM_COLOUR_BANDS);
302        return m_Pens[band];
303    }
304
305    const GLAPen& GetSurfacePen() const { return m_Pens[NUM_COLOUR_BANDS]; }
306
307    int GetNumColourBands() const { return NUM_COLOUR_BANDS; }
308
309    void DrawShadowedBoundingBox();
310    void DrawBoundingBox();
311
312public:
313    GfxCore(MainFrm* parent, wxWindow* parent_window, GUIControl* control);
314    ~GfxCore();
315
316    void Initialise(bool same_file);
317    void InitialiseTerrain();
318
319    void UpdateBlobs();
320    void ForceRefresh();
321
322    void RefreshLine(const Point* a, const Point* b, const Point* c);
323
324    void SetHereFromTree(const LabelInfo * p);
325
326    void SetHere();
327    void SetHere(const LabelInfo * p);
328    void SetThere();
329    void SetThere(const LabelInfo * p);
330
331    void CentreOn(const Point &p);
332
333    void TranslateCave(int dx, int dy);
334    void TiltCave(Double tilt_angle);
335    void TurnCave(Double angle);
336    void TurnCaveTo(Double angle);
337
338    void OnPaint(wxPaintEvent&);
339    void OnSize(wxSizeEvent& event);
340    void OnIdle(wxIdleEvent& event);
341
342    void OnMouseMove(wxMouseEvent& event) { m_Control->OnMouseMove(event); }
343    void OnLeaveWindow(wxMouseEvent& event);
344
345    void OnLButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnLButtonDown(event); }
346    void OnLButtonUp(wxMouseEvent& event) { m_Control->OnLButtonUp(event); }
347    void OnMButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnMButtonDown(event); }
348    void OnMButtonUp(wxMouseEvent& event) { m_Control->OnMButtonUp(event); }
349    void OnRButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnRButtonDown(event); }
350    void OnRButtonUp(wxMouseEvent& event) { m_Control->OnRButtonUp(event); }
351    void OnMouseWheel(wxMouseEvent& event) { SetFocus(); m_Control->OnMouseWheel(event); }
352    void OnKeyPress(wxKeyEvent &event) { m_Control->OnKeyPress(event); }
353
354    void Animate();
355    bool Animating() const {
356        return m_Rotating || m_SwitchingTo || presentation_mode != 0;
357    }
358
359    void ClearCoords();
360    void SetCoords(wxPoint);
361
362    // Determine whether the compass is currently shown.
363    bool ShowingCompass() const { return m_Compass; }
364    // Determine whether the clino is currently shown.
365    bool ShowingClino() const { return m_Clino; }
366
367    bool PointWithinCompass(wxPoint point) const;
368    bool PointWithinClino(wxPoint point) const;
369    bool PointWithinScaleBar(wxPoint point) const;
370    bool PointWithinColourKey(wxPoint point) const;
371
372    void SetCompassFromPoint(wxPoint point);
373    void SetClinoFromPoint(wxPoint point);
374    void SetScaleBarFromOffset(wxCoord dx);
375
376    void RedrawIndicators();
377
378    void StartRotation();
379    void ToggleRotation();
380    void StopRotation();
381    bool IsExtendedElevation() const;
382    void ReverseRotation();
383    void RotateSlower(bool accel);
384    void RotateFaster(bool accel);
385
386    void SwitchToElevation();
387    void SwitchToPlan();
388
389    void SetViewTo(Double xmin, Double xmax, Double ymin, Double ymax, Double zmin, Double zmax);
390
391    double GetCompassValue() const { return m_PanAngle; }
392    bool ShowingPlan() const;
393    bool ShowingElevation() const;
394    bool ShowingMeasuringLine() const;
395    bool HereIsReal() const { return m_here && m_here != &temp_here; }
396
397    bool CanRaiseViewpoint() const;
398    bool CanLowerViewpoint() const;
399
400    bool IsRotating() const { return m_Rotating; }
401    bool HasData() const { return m_DoneFirstShow && m_HaveData; }
402    bool HasDepth() const;
403    bool HasErrorInformation() const;
404    bool HasDateInformation() const;
405
406    double GetScale() const { return m_Scale; }
407    void SetScale(Double scale);
408
409    bool ShowingStationNames() const { return m_Names; }
410    bool ShowingOverlappingNames() const { return m_OverlappingNames; }
411    bool ShowingCrosses() const { return m_Crosses; }
412    bool ShowingGrid() const { return m_Grid; }
413
414    int ColouringBy() const { return m_ColourBy; }
415
416    bool HasUndergroundLegs() const;
417    bool HasSplays() const;
418    bool HasSurfaceLegs() const;
419    bool HasTubes() const;
420
421    bool ShowingUndergroundLegs() const { return m_Legs; }
422    int ShowingSplaysMode() const { return m_Splays; }
423    bool ShowingSurfaceLegs() const { return m_Surface; }
424
425    bool ShowingColourKey() const { return m_ColourKey; }
426    bool ShowingScaleBar() const { return m_Scalebar; }
427
428    bool ShowingEntrances() const { return m_Entrances; }
429    bool ShowingFixedPts() const { return m_FixedPts; }
430    bool ShowingExportedPts() const { return m_ExportedPts; }
431
432    int GetNumEntrances() const;
433    int GetNumFixedPts() const;
434    int GetNumExportedPts() const;
435
436    void ToggleUndergroundLegs() {
437        ToggleFlag(&m_Legs, UPDATE_BLOBS_AND_CROSSES);
438    }
439    void SetSplaysMode(int mode) {
440        m_Splays = mode;
441        UpdateBlobs();
442        InvalidateList(LIST_UNDERGROUND_LEGS);
443        ForceRefresh();
444    }
445    void ToggleSurfaceLegs() {
446        ToggleFlag(&m_Surface, UPDATE_BLOBS_AND_CROSSES);
447    }
448    void ToggleCompass() {
449        ToggleFlag(&m_Compass);
450        InvalidateList(LIST_SCALE_BAR);
451    }
452    void ToggleClino() {
453        ToggleFlag(&m_Clino);
454        InvalidateList(LIST_SCALE_BAR);
455    }
456    void ToggleScaleBar() { ToggleFlag(&m_Scalebar); }
457    void ToggleEntrances() { ToggleFlag(&m_Entrances, UPDATE_BLOBS); }
458    void ToggleFixedPts() { ToggleFlag(&m_FixedPts, UPDATE_BLOBS); }
459    void ToggleExportedPts() { ToggleFlag(&m_ExportedPts, UPDATE_BLOBS); }
460    void ToggleGrid() { ToggleFlag(&m_Grid); }
461    void ToggleCrosses() { ToggleFlag(&m_Crosses); }
462    void ToggleStationNames() { ToggleFlag(&m_Names); }
463    void ToggleOverlappingNames() { ToggleFlag(&m_OverlappingNames); }
464    void ToggleColourKey() { ToggleFlag(&m_ColourKey); }
465    void ToggleMetric() {
466        ToggleFlag(&m_Metric);
467        InvalidateList(LIST_DEPTH_KEY);
468        InvalidateList(LIST_LENGTH_KEY);
469        InvalidateList(LIST_SCALE_BAR);
470    }
471    void ToggleHitTestDebug() {
472        ToggleFlag(&m_HitTestDebug);
473    }
474    void ToggleDegrees() {
475        ToggleFlag(&m_Degrees);
476        InvalidateList(LIST_GRADIENT_KEY);
477    }
478    void TogglePercent() { ToggleFlag(&m_Percent); }
479    void ToggleTubes() { ToggleFlag(&m_Tubes); }
480    void TogglePerspective() { GLACanvas::TogglePerspective(); ForceRefresh(); }
481    void ToggleSmoothShading();
482    bool DisplayingBoundingBox() const { return m_BoundingBox; }
483    void ToggleBoundingBox() { ToggleFlag(&m_BoundingBox); }
484    void ToggleFatFinger();
485
486    bool GetMetric() const { return m_Metric; }
487    bool GetDegrees() const { return m_Degrees; }
488    bool GetPercent() const { return m_Percent; }
489    bool GetTubes() const { return m_Tubes; }
490
491    bool CheckHitTestGrid(const wxPoint& point, bool centre);
492
493    void ClearTreeSelection();
494
495    void Defaults();
496
497    void FullScreenMode();
498
499    bool IsFullScreen() const;
500
501    bool FullScreenModeShowingMenus() const;
502
503    void FullScreenModeShowMenus(bool show);
504
505    void DragFinished();
506
507    void SplitLineAcrossBands(int band, int band2,
508                              const Vector3 &p, const Vector3 &q,
509                              Double factor = 1.0);
510    int GetDepthColour(Double z) const;
511    Double GetDepthBoundaryBetweenBands(int a, int b) const;
512    void AddPolyline(const traverse & centreline);
513    void AddPolylineDepth(const traverse & centreline);
514    void AddPolylineDate(const traverse & centreline);
515    void AddPolylineError(const traverse & centreline);
516    void AddPolylineGradient(const traverse & centreline);
517    void AddPolylineLength(const traverse & centreline);
518    void AddQuadrilateral(const Vector3 &a, const Vector3 &b,
519                          const Vector3 &c, const Vector3 &d);
520    void AddPolylineShadow(const traverse & centreline);
521    void AddQuadrilateralDepth(const Vector3 &a, const Vector3 &b,
522                               const Vector3 &c, const Vector3 &d);
523    void AddQuadrilateralDate(const Vector3 &a, const Vector3 &b,
524                              const Vector3 &c, const Vector3 &d);
525    void AddQuadrilateralError(const Vector3 &a, const Vector3 &b,
526                               const Vector3 &c, const Vector3 &d);
527    void AddQuadrilateralGradient(const Vector3 &a, const Vector3 &b,
528                                  const Vector3 &c, const Vector3 &d);
529    void AddQuadrilateralLength(const Vector3 &a, const Vector3 &b,
530                                const Vector3 &c, const Vector3 &d);
531    void MoveViewer(double forward, double up, double right);
532
533    void (GfxCore::* AddQuad)(const Vector3 &a, const Vector3 &b,
534                              const Vector3 &c, const Vector3 &d);
535    void (GfxCore::* AddPoly)(const traverse & centreline);
536
537    PresentationMark GetView() const;
538    void SetView(const PresentationMark & p);
539    void PlayPres(double speed, bool change_speed = true);
540    int GetPresentationMode() const { return presentation_mode; }
541    double GetPresentationSpeed() const { return presentation_mode ? pres_speed : 0; }
542
543    void SetColourBy(int colour_by);
544    bool ExportMovie(const wxString & fnm);
545    void OnPrint(const wxString &filename, const wxString &title,
546                 const wxString &datestamp, time_t datestamp_numeric,
547                 const wxString &cs_proj,
548                 bool close_after_print = false);
549    void OnExport(const wxString &filename, const wxString &title,
550                  const wxString &datestamp, time_t datestamp_numeric,
551                  const wxString &cs_proj);
552    void UpdateCursor(GfxCore::cursor new_cursor);
553    bool MeasuringLineActive() const;
554
555    bool HandleRClick(wxPoint point);
556
557    void InvalidateAllLists() {
558        for (int i = 0; i < LIST_LIMIT_; ++i) {
559            InvalidateList(i);
560        }
561    }
562
563    void SetZoomBox(wxPoint p1, wxPoint p2, bool centred, bool aspect);
564
565    void UnsetZoomBox() {
566        if (!zoombox.active()) return;
567        zoombox.unset();
568        ForceRefresh();
569    }
570
571    void ZoomBoxGo();
572
573private:
574    DECLARE_EVENT_TABLE()
575};
576
577#endif
Note: See TracBrowser for help on using the repository browser.