Add ContourLineExtractor to Sandbox
[SARndbox.git] / DEM.h
blobe80eb374fb166bf311ea586d138e23c682556b9c
1 /***********************************************************************
2 DEM - Class to represent digital elevation models (DEMs) as float-valued
3 texture objects.
4 Copyright (c) 2013-2016 Oliver Kreylos
6 This file is part of the Augmented Reality Sandbox (SARndbox).
8 The Augmented Reality Sandbox is free software; you can redistribute it
9 and/or modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The Augmented Reality Sandbox is distributed in the hope that it will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with the Augmented Reality Sandbox; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ***********************************************************************/
23 #ifndef DEM_INCLUDED
24 #define DEM_INCLUDED
26 #include <GL/gl.h>
27 #include <GL/GLObject.h>
29 #include "Types.h"
31 class DEM: public GLObject {
32 /* Embedded classes: */
33 private:
34 struct DataItem: public GLObject::DataItem {
35 /* Elements: */
36 public:
37 GLuint textureObjectId; // ID of texture object holding digital elevation model
39 /* Constructors and destructors: */
40 DataItem(void);
41 virtual ~DataItem(void);
44 /* Elements: */
45 private:
46 int demSize[2]; // Width and height of the DEM grid
47 Scalar demBox[4]; // Lower-left and upper-right corner coordinates of the DEM
48 float* dem; // Array of DEM elevation measurements
49 OGTransform transform; // Transformation from camera space to DEM space (z up)
50 Scalar verticalScale; // Vertical scale (exaggeration) factor
51 Scalar verticalScaleBase; // Base elevation around which vertical scale is applied
52 PTransform demTransform; // Full transformation matrix from camera space to DEM pixel space
53 GLfloat demTransformMatrix[16]; // Full transformation matrix from camera space to DEM pixel space to upload to OpenGL
55 /* Private methods: */
56 void calcMatrix(void); // Calculates the camera space to DEM pixel space transformation
58 /* Constructors and destructors: */
59 public:
60 DEM(void); // Creates an uninitialized DEM
61 virtual ~DEM(void);
63 /* Methods from class GLObject: */
64 virtual void initContext(GLContextData& contextData) const;
66 /* New methods: */
67 void load(const char* demFileName); // Loads the DEM from the given file
68 const Scalar* getDemBox(void)
69 const { // Returns the DEM's bounding box as lower-left x, lower-left y, upper-right x, upper-right y
70 return demBox;
72 float calcAverageElevation(void) const; // Calculates the average elevation of the DEM
73 void setTransform(const OGTransform& newTransform, Scalar newVerticalScale,
74 Scalar newVerticalScaleBase); // Sets the DEM transformation
75 const PTransform& getDemTransform(void)
76 const { // Returns the full transformation from camera space to vertically-scaled DEM pixel space
77 return demTransform;
79 Scalar getVerticalScale(void)
80 const { // Returns the scaling factor from camera space elevations to DEM elevations
81 return transform.getScaling() / verticalScale;
83 void bindTexture(GLContextData& contextData)
84 const; // Binds the DEM texture object to the currently active texture unit
85 void uploadDemTransform(GLint location)
86 const; // Uploads the DEM transformation into the GLSL 4x4 matrix at the given uniform location
89 #endif