source: trunk/packages/vizservers/nanovis/HeightMap.h @ 2892

Last change on this file since 2892 was 2877, checked in by ldelgass, 12 years ago

Some minor refactoring, also add some more fine grained config.h defines
(e.g. replace NV40 define with feature defines). Add tests for some required
OpenGL extensions (should always check for extensions or base version before
calling entry points from the extension). Also, clamp diffuse and specular
values on input and warn when they are out of range.

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