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 | |
---|
12 | namespace graphics { |
---|
13 | class RenderContext; |
---|
14 | }; |
---|
15 | |
---|
16 | /** |
---|
17 | *@class HeightMap |
---|
18 | *@brief Create a surface from height map and line contour of the generated surface |
---|
19 | */ |
---|
20 | class HeightMap { |
---|
21 | unsigned int _vertexBufferObjectID; |
---|
22 | unsigned int _textureBufferObjectID; |
---|
23 | |
---|
24 | int _vertexCount; |
---|
25 | CGparameter _tf; |
---|
26 | R2Geometry* _contour; |
---|
27 | TransferFunction* _colorMap; |
---|
28 | NvShader* _shader; |
---|
29 | int* _indexBuffer; |
---|
30 | int _indexCount; |
---|
31 | Vector3 _contourColor; |
---|
32 | |
---|
33 | bool _contourVisible; |
---|
34 | bool _visible; |
---|
35 | |
---|
36 | Vector3 _scale; |
---|
37 | Vector3 _centerPoint; |
---|
38 | |
---|
39 | double _vmin; // minimum (unscaled) value in data |
---|
40 | double _vmax; // maximum (unscaled) value in data |
---|
41 | |
---|
42 | |
---|
43 | public : |
---|
44 | /** |
---|
45 | *@brief Constructor |
---|
46 | */ |
---|
47 | HeightMap(); |
---|
48 | /** |
---|
49 | *@brief Destructor |
---|
50 | */ |
---|
51 | ~HeightMap(); |
---|
52 | |
---|
53 | private : |
---|
54 | void createIndexBuffer(int xCount, int zCount, int*& indexBuffer, int& indexCount, float* heights); |
---|
55 | Vector3* createHeightVertices(float startX, float startY, float endX, float endY, int xCount, int yCount, float* height); |
---|
56 | void reset(); |
---|
57 | public : |
---|
58 | void render(graphics::RenderContext* renderContext); |
---|
59 | /** |
---|
60 | *@brief Create a height map with heigh values |
---|
61 | *@param startX a x position of the first height value |
---|
62 | *@param startY a y position of the first height value |
---|
63 | *@param endX a x position of the last height value |
---|
64 | *@param endY a y position of the last height value |
---|
65 | *@param xCount the number of columns of height values |
---|
66 | *@param yCount the number of rows of height values |
---|
67 | *@param height a pointer value adrressing xCount * yCount values of heights |
---|
68 | */ |
---|
69 | void setHeight(float startX, float startY, float endX, float endY, int xCount, int yCount, float* height); |
---|
70 | |
---|
71 | /** |
---|
72 | *@brief Create a height map with a set of points |
---|
73 | *@param xCount the number of columns of height values |
---|
74 | *@param yCount the number of rows of height values |
---|
75 | */ |
---|
76 | void setHeight(int xCount, int yCount, Vector3* heights); |
---|
77 | |
---|
78 | /** |
---|
79 | *@brief Define a color map for color shading of heightmap |
---|
80 | */ |
---|
81 | void setColorMap(TransferFunction* colorMap); |
---|
82 | |
---|
83 | /** |
---|
84 | *@brief Get the color map defined for shading of this heightmap |
---|
85 | */ |
---|
86 | TransferFunction *getColorMap(void); |
---|
87 | |
---|
88 | /** |
---|
89 | *@brief Set the visibility of the height map |
---|
90 | */ |
---|
91 | void setVisible(bool visible); |
---|
92 | |
---|
93 | /** |
---|
94 | *@brief Return the status of the visibility |
---|
95 | */ |
---|
96 | bool isVisible() const; |
---|
97 | |
---|
98 | /** |
---|
99 | *@brief Set the visibility of the line contour |
---|
100 | */ |
---|
101 | void setLineContourVisible(bool visible); |
---|
102 | |
---|
103 | /** |
---|
104 | *@brief Defind the color of the line contour |
---|
105 | */ |
---|
106 | void setLineContourColor(float *rgb); |
---|
107 | |
---|
108 | double range_min(void); |
---|
109 | double range_max(void); |
---|
110 | }; |
---|
111 | |
---|
112 | inline void HeightMap::setVisible(bool visible) |
---|
113 | { |
---|
114 | _visible = visible; |
---|
115 | } |
---|
116 | |
---|
117 | inline bool HeightMap::isVisible() const |
---|
118 | { |
---|
119 | return _visible; |
---|
120 | } |
---|
121 | |
---|
122 | inline void HeightMap::setLineContourVisible(bool visible) |
---|
123 | { |
---|
124 | _contourVisible = visible; |
---|
125 | } |
---|
126 | |
---|
127 | inline void HeightMap::setLineContourColor(float rgb[]) |
---|
128 | { |
---|
129 | _contourColor.x = rgb[0]; |
---|
130 | _contourColor.y = rgb[1]; |
---|
131 | _contourColor.z = rgb[2]; |
---|
132 | } |
---|
133 | |
---|
134 | inline TransferFunction * |
---|
135 | HeightMap::getColorMap() |
---|
136 | { |
---|
137 | return _colorMap; |
---|
138 | } |
---|
139 | |
---|
140 | inline double |
---|
141 | HeightMap::range_min() |
---|
142 | { |
---|
143 | return _vmin; |
---|
144 | } |
---|
145 | |
---|
146 | inline double |
---|
147 | HeightMap::range_max() |
---|
148 | { |
---|
149 | return _vmax; |
---|
150 | } |
---|
151 | #endif |
---|