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