source: branches/blt4/packages/vizservers/vtkvis/RpVtkRenderer.h @ 2170

Last change on this file since 2170 was 2170, checked in by gah, 13 years ago
File size: 7.1 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (C) 2011, Purdue Research Foundation
4 *
5 * Author: Leif Delgass <ldelgass@purdue.edu>
6 */
7
8#ifndef __RAPPTURE_VTKVIS_RENDERER_H__
9#define __RAPPTURE_VTKVIS_RENDERER_H__
10
11#include <vtkSmartPointer.h>
12#include <vtkLookupTable.h>
13#include <vtkCubeAxesActor.h>
14#ifdef USE_CUSTOM_AXES
15#include <vtkRpCubeAxesActor2D.h>
16#else
17#include <vtkCubeAxesActor2D.h>
18#endif
19#include <vtkScalarBarActor.h>
20#include <vtkRenderer.h>
21#include <vtkRenderWindow.h>
22#include <vtkUnsignedCharArray.h>
23
24#include <string>
25#include <vector>
26#include <tr1/unordered_map>
27
28#include "ColorMap.h"
29#include "RpVtkDataSet.h"
30#include "RpPseudoColor.h"
31#include "RpContour2D.h"
32#include "RpPolyData.h"
33
34namespace Rappture {
35namespace VtkVis {
36
37/**
38 * \brief VTK Renderer
39 */
40class Renderer
41{
42public:
43    Renderer();
44    virtual ~Renderer();
45
46    enum Axis {
47        X_AXIS,
48        Y_AXIS,
49        Z_AXIS
50    };
51
52    enum CameraMode {
53        PERSPECTIVE,
54        ORTHO,
55        IMAGE
56    };
57
58    typedef std::string DataSetId;
59    typedef std::string ColorMapId;
60    typedef std::tr1::unordered_map<DataSetId, DataSet *> DataSetHashmap;
61    typedef std::tr1::unordered_map<ColorMapId, ColorMap *> ColorMapHashmap;
62    typedef std::tr1::unordered_map<DataSetId, PseudoColor *> PseudoColorHashmap;
63    typedef std::tr1::unordered_map<DataSetId, Contour2D *> Contour2DHashmap;
64    typedef std::tr1::unordered_map<DataSetId, PolyData *> PolyDataHashmap;
65
66    // Data sets
67
68    void addDataSet(const DataSetId& id);
69
70    void deleteDataSet(const DataSetId& id);
71
72    DataSet *getDataSet(const DataSetId& id);
73
74    bool setData(const DataSetId& id, char *data, int nbytes);
75
76    bool setDataFile(const DataSetId& id, const char *filename);
77
78    double getDataValueAtPixel(const DataSetId& id, int x, int y);
79
80    double getDataValue(const DataSetId& id, double x, double y, double z);
81
82    void setOpacity(const DataSetId& id, double opacity);
83
84    void setVisibility(const DataSetId& id, bool state);
85
86    // Render window
87
88    void setWindowSize(int width, int height);
89
90    int getWindowWidth() const;
91
92    int getWindowHeight() const;
93
94    // Camera controls
95
96    void setCameraMode(CameraMode mode);
97
98    void resetCamera(bool resetOrientation = true);
99
100    void setCameraZoomRegion(double x, double y, double width, double height);
101
102    void rotateCamera(double yaw, double pitch, double roll);
103
104    void panCamera(double x, double y);
105
106    void zoomCamera(double z);
107
108    // Rendering an image
109
110    void setBackgroundColor(float color[3]);
111
112    bool render();
113
114    void getRenderedFrame(vtkUnsignedCharArray *imgData);
115
116    // Axes
117
118    void setAxesGridVisibility(bool state);
119
120    void setAxesVisibility(bool state);
121
122    void setAxesColor(double color[3]);
123
124    void setAxisGridVisibility(Axis axis, bool state);
125
126    void setAxisVisibility(Axis axis, bool state);
127
128    void setAxisTitle(Axis axis, const char *title);
129
130    void setAxisUnits(Axis axis, const char *units);
131
132    // Colormaps
133
134    void addColorMap(const ColorMapId& id, ColorMap *colorMap);
135
136    void deleteColorMap(const ColorMapId& id);
137
138    ColorMap *getColorMap(const ColorMapId& id);
139
140    bool renderColorMap(const ColorMapId& id,
141                        const DataSetId& dataSetID,
142                        const char *title,
143                        int width, int height,
144                        vtkUnsignedCharArray *imgData);
145
146    // Color-mapped surfaces
147
148    void addPseudoColor(const DataSetId& id);
149
150    void deletePseudoColor(const DataSetId& id);
151
152    PseudoColor *getPseudoColor(const DataSetId& id);
153
154    void setPseudoColorColorMap(const DataSetId& id, const ColorMapId& colorMapId);
155
156    vtkLookupTable *getPseudoColorColorMap(const DataSetId& id);
157
158    void setPseudoColorOpacity(const DataSetId& id, double opacity);
159
160    void setPseudoColorVisibility(const DataSetId& id, bool state);
161
162    void setPseudoColorEdgeVisibility(const DataSetId& id, bool state);
163
164    void setPseudoColorEdgeColor(const DataSetId& id, float color[3]);
165
166    void setPseudoColorEdgeWidth(const DataSetId& id, float edgeWidth);
167
168    void setPseudoColorLighting(const DataSetId& id, bool state);
169
170    // Contour plots
171
172    void addContour2D(const DataSetId& id);
173
174    void deleteContour2D(const DataSetId& id);
175
176    Contour2D *getContour2D(const DataSetId& id);
177
178    void setContours(const DataSetId& id, int numContours);
179
180    void setContourList(const DataSetId& id, const std::vector<double>& contours);
181
182    void setContourOpacity(const DataSetId& id, double opacity);
183
184    void setContourVisibility(const DataSetId& id, bool state);
185
186    void setContourEdgeColor(const DataSetId& id, float color[3]);
187
188    void setContourEdgeWidth(const DataSetId& id, float edgeWidth);
189
190    void setContourLighting(const DataSetId& id, bool state);
191
192    // Meshes
193
194    void addPolyData(const DataSetId& id);
195   
196    void deletePolyData(const DataSetId& id);
197
198    PolyData *getPolyData(const DataSetId& id);
199
200    void setPolyDataOpacity(const DataSetId& id, double opacity);
201
202    void setPolyDataVisibility(const DataSetId& id, bool state);
203
204    void setPolyDataColor(const DataSetId& id, float color[3]);
205
206    void setPolyDataEdgeVisibility(const DataSetId& id, bool state);
207
208    void setPolyDataEdgeColor(const DataSetId& id, float color[3]);
209
210    void setPolyDataEdgeWidth(const DataSetId& id, float edgeWidth);
211
212    void setPolyDataWireframe(const DataSetId& id, bool state);
213
214    void setPolyDataLighting(const DataSetId& id, bool state);
215
216private:
217    static void printCameraInfo(vtkCamera *camera);
218    static inline double min2(double a, double b)
219    {
220        return ((a < b) ? a : b);
221    }
222    static inline double max2(double a, double b)
223    {
224        return ((a > b) ? a : b);
225    }
226    static void mergeBounds(double *boundsDest, const double *bounds1, const double *bounds2);
227
228    void collectBounds(double *bounds, bool onlyVisible);
229
230    void collectDataRanges(double *range);
231
232    void updateRanges(bool useCumulative);
233
234    void storeCameraOrientation();
235    void restoreCameraOrientation();
236    void initCamera();
237    void initAxes();
238    void resetAxes();
239
240    bool _needsRedraw;
241    int _windowWidth, _windowHeight;
242    double _imgWorldOrigin[2];
243    double _imgWorldDims[2];
244    double _cameraPos[3];
245    double _cameraFocalPoint[3];
246    double _cameraUp[3];
247    float _bgColor[3];
248    bool _useCumulativeRanges;
249    double _cumulativeDataRange[2];
250
251    ColorMapHashmap _colorMaps;
252    DataSetHashmap _dataSets;
253    PseudoColorHashmap _pseudoColors;
254    Contour2DHashmap _contours;
255    PolyDataHashmap _polyDatas;
256
257    CameraMode _cameraMode;
258
259    vtkSmartPointer<vtkPlaneCollection> _clippingPlanes;
260    vtkSmartPointer<vtkCubeAxesActor> _cubeAxesActor; // For 3D view
261#ifdef USE_CUSTOM_AXES
262    vtkSmartPointer<vtkRpCubeAxesActor2D> _cubeAxesActor2D; // For 2D view
263#else
264    vtkSmartPointer<vtkCubeAxesActor2D> _cubeAxesActor2D; // For 2D view
265#endif
266    vtkSmartPointer<vtkScalarBarActor> _scalarBarActor;
267    vtkSmartPointer<vtkRenderer> _renderer;
268    vtkSmartPointer<vtkRenderer> _legendRenderer;
269    vtkSmartPointer<vtkRenderWindow> _renderWindow;
270    vtkSmartPointer<vtkRenderWindow> _legendRenderWindow;
271};
272
273}
274}
275
276#endif
Note: See TracBrowser for help on using the repository browser.