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