[2798] | 1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
[3502] | 2 | /* |
---|
| 3 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
| 4 | * |
---|
| 5 | */ |
---|
[2831] | 6 | #ifndef HEIGHTMAP_H |
---|
| 7 | #define HEIGHTMAP_H |
---|
[776] | 8 | |
---|
[3465] | 9 | #include <graphics/Geometry.h> |
---|
| 10 | #include <graphics/RenderContext.h> |
---|
[3492] | 11 | #include <vrmath/Vector3f.h> |
---|
[2831] | 12 | |
---|
[776] | 13 | #include "TransferFunction.h" |
---|
| 14 | #include "NvShader.h" |
---|
[929] | 15 | #include "AxisRange.h" |
---|
[776] | 16 | |
---|
[1111] | 17 | class Grid; |
---|
| 18 | |
---|
[820] | 19 | /** |
---|
| 20 | *@brief Create a surface from height map and line contour of the generated surface |
---|
| 21 | */ |
---|
[2831] | 22 | class HeightMap |
---|
| 23 | { |
---|
| 24 | public: |
---|
| 25 | HeightMap(); |
---|
[1111] | 26 | |
---|
[1984] | 27 | ~HeightMap(); |
---|
[776] | 28 | |
---|
[3463] | 29 | void render(nv::graphics::RenderContext *renderContext); |
---|
[2831] | 30 | |
---|
[820] | 31 | /** |
---|
[3497] | 32 | *@brief Create a height map with height values |
---|
[2953] | 33 | *@param startX x position of the first height value |
---|
| 34 | *@param startY y position of the first height value |
---|
| 35 | *@param endX x position of the last height value |
---|
| 36 | *@param endY y position of the last height value |
---|
[820] | 37 | *@param xCount the number of columns of height values |
---|
| 38 | *@param yCount the number of rows of height values |
---|
| 39 | *@param height a pointer value adrressing xCount * yCount values of heights |
---|
| 40 | */ |
---|
[1111] | 41 | void setHeight(float startX, float startY, float endX, float endY, |
---|
[2831] | 42 | int xCount, int yCount, float *height); |
---|
[2956] | 43 | #if 0 |
---|
[820] | 44 | /** |
---|
| 45 | *@brief Create a height map with a set of points |
---|
| 46 | *@param xCount the number of columns of height values |
---|
| 47 | *@param yCount the number of rows of height values |
---|
| 48 | */ |
---|
[3492] | 49 | void setHeight(int xCount, int yCount, vrmath::Vector3f *heights); |
---|
[2956] | 50 | #endif |
---|
[2927] | 51 | void mapToGrid(Grid *gridPtr); |
---|
[2831] | 52 | |
---|
[820] | 53 | /** |
---|
[834] | 54 | *@brief Define a color map for color shading of heightmap |
---|
[820] | 55 | */ |
---|
[2831] | 56 | void transferFunction(TransferFunction *tfPtr) |
---|
| 57 | { |
---|
| 58 | _tfPtr = tfPtr; |
---|
[1493] | 59 | } |
---|
[2831] | 60 | |
---|
[820] | 61 | /** |
---|
[834] | 62 | *@brief Get the color map defined for shading of this heightmap |
---|
| 63 | */ |
---|
[2831] | 64 | TransferFunction *transferFunction() |
---|
| 65 | { |
---|
| 66 | return _tfPtr; |
---|
[929] | 67 | } |
---|
[2831] | 68 | |
---|
[834] | 69 | /** |
---|
[820] | 70 | *@brief Set the visibility of the height map |
---|
| 71 | */ |
---|
[2831] | 72 | void setVisible(bool visible) |
---|
| 73 | { |
---|
| 74 | _visible = visible; |
---|
[929] | 75 | } |
---|
[820] | 76 | |
---|
| 77 | /** |
---|
| 78 | *@brief Return the status of the visibility |
---|
| 79 | */ |
---|
[2831] | 80 | bool isVisible() const |
---|
| 81 | { |
---|
| 82 | return _visible; |
---|
[929] | 83 | } |
---|
[2831] | 84 | |
---|
[820] | 85 | /** |
---|
| 86 | *@brief Set the visibility of the line contour |
---|
| 87 | */ |
---|
[2831] | 88 | void setLineContourVisible(bool visible) |
---|
| 89 | { |
---|
| 90 | _contourVisible = visible; |
---|
[929] | 91 | } |
---|
[820] | 92 | |
---|
[2831] | 93 | void opacity(float opacity) |
---|
| 94 | { |
---|
| 95 | _opacity = opacity; |
---|
[1546] | 96 | } |
---|
[2831] | 97 | |
---|
| 98 | float opacity() |
---|
| 99 | { |
---|
[1546] | 100 | return _opacity; |
---|
| 101 | } |
---|
[2831] | 102 | |
---|
[820] | 103 | /** |
---|
| 104 | *@brief Defind the color of the line contour |
---|
| 105 | */ |
---|
[2831] | 106 | void setLineContourColor(float *rgb) |
---|
| 107 | { |
---|
[929] | 108 | _contourColor.x = rgb[0]; |
---|
| 109 | _contourColor.y = rgb[1]; |
---|
| 110 | _contourColor.z = rgb[2]; |
---|
| 111 | } |
---|
[2831] | 112 | |
---|
[3492] | 113 | void getWorldSpaceBounds(vrmath::Vector3f& bboxMin, vrmath::Vector3f& bboxMax) const; |
---|
| 114 | |
---|
[2831] | 115 | AxisRange xAxis, yAxis, zAxis, wAxis; |
---|
[2877] | 116 | static bool updatePending; |
---|
[2831] | 117 | static double valueMin, valueMax; |
---|
| 118 | |
---|
| 119 | private: |
---|
[2953] | 120 | void createIndexBuffer(int xCount, int zCount, float *heights); |
---|
[3492] | 121 | vrmath::Vector3f *createHeightVertices(float startX, float startY, |
---|
| 122 | float endX, float endY, |
---|
| 123 | int xCount, int yCount, float *height); |
---|
[2831] | 124 | void reset(); |
---|
| 125 | |
---|
| 126 | unsigned int _vertexBufferObjectID; |
---|
[2956] | 127 | unsigned int _texcoordBufferObjectID; |
---|
[2831] | 128 | int _vertexCount; |
---|
[3463] | 129 | nv::graphics::Geometry *_contour; |
---|
[2831] | 130 | TransferFunction *_tfPtr; |
---|
| 131 | float _opacity; |
---|
| 132 | NvShader *_shader; |
---|
| 133 | int *_indexBuffer; |
---|
| 134 | int _indexCount; |
---|
[3492] | 135 | vrmath::Vector3f _contourColor; |
---|
[2953] | 136 | |
---|
[2831] | 137 | bool _contourVisible; |
---|
| 138 | bool _visible; |
---|
[2953] | 139 | |
---|
[3492] | 140 | vrmath::Vector3f _scale; |
---|
| 141 | vrmath::Vector3f _centerPoint; |
---|
[2831] | 142 | int _xNum, _yNum; // Number of elements x and y axes in grid. |
---|
| 143 | float *_heights; // Array of original (unscaled) heights |
---|
| 144 | // (y-values) |
---|
[776] | 145 | }; |
---|
| 146 | |
---|
| 147 | #endif |
---|