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