source: trunk/packages/vizservers/vtkvis/RpVtkRenderer.h @ 2217

Last change on this file since 2217 was 2213, checked in by ldelgass, 13 years ago

vtkvis - rename camera orient command to camera set, new camera orient command
takes a quaternion to orient the scene.

  • Property svn:eol-style set to native
File size: 8.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    void setUseCumulativeDataRange(bool state, bool onlyVisible = false);
87
88    // Render window
89
90    void setWindowSize(int width, int height);
91
92    int getWindowWidth() const;
93
94    int getWindowHeight() const;
95
96    // Camera controls
97
98    void setCameraMode(CameraMode mode);
99
100    CameraMode getCameraMode() const;
101
102    void resetCamera(bool resetOrientation = true);
103
104    void setCameraZoomRegion(double x, double y, double width, double height);
105
106    void getCameraZoomRegion(double xywh[4]) const;
107
108    void getScreenWorldCoords(double xywh[4]) const;
109
110    void rotateCamera(double yaw, double pitch, double roll);
111
112    void setSceneOrientation(double quat[4]);
113
114    void setCameraOrientationAndPosition(double position[3],
115                                         double focalPoint[3],
116                                         double viewUp[3]);
117
118    void getCameraOrientationAndPosition(double position[3],
119                                         double focalPoint[3],
120                                         double viewUp[3]);
121
122    void panCamera(double x, double y, bool absolute = true);
123
124    void zoomCamera(double z, bool absolute = true);
125
126    // Rendering an image
127
128    void setBackgroundColor(float color[3]);
129
130    bool render();
131
132    void getRenderedFrame(vtkUnsignedCharArray *imgData);
133
134    // Axes
135
136    void setAxesGridVisibility(bool state);
137
138    void setAxesVisibility(bool state);
139
140    void setAxesColor(double color[3]);
141
142    void setAxisGridVisibility(Axis axis, bool state);
143
144    void setAxisVisibility(Axis axis, bool state);
145
146    void setAxisTitle(Axis axis, const char *title);
147
148    void setAxisUnits(Axis axis, const char *units);
149
150    // Colormaps
151
152    void addColorMap(const ColorMapId& id, ColorMap *colorMap);
153
154    void deleteColorMap(const ColorMapId& id);
155
156    ColorMap *getColorMap(const ColorMapId& id);
157
158    bool renderColorMap(const ColorMapId& id,
159                        const DataSetId& dataSetID,
160                        const char *title,
161                        int width, int height,
162                        vtkUnsignedCharArray *imgData);
163
164    // Color-mapped surfaces
165
166    void addPseudoColor(const DataSetId& id);
167
168    void deletePseudoColor(const DataSetId& id);
169
170    PseudoColor *getPseudoColor(const DataSetId& id);
171
172    void setPseudoColorColorMap(const DataSetId& id, const ColorMapId& colorMapId);
173
174    vtkLookupTable *getPseudoColorColorMap(const DataSetId& id);
175
176    void setPseudoColorOpacity(const DataSetId& id, double opacity);
177
178    void setPseudoColorVisibility(const DataSetId& id, bool state);
179
180    void setPseudoColorEdgeVisibility(const DataSetId& id, bool state);
181
182    void setPseudoColorEdgeColor(const DataSetId& id, float color[3]);
183
184    void setPseudoColorEdgeWidth(const DataSetId& id, float edgeWidth);
185
186    void setPseudoColorLighting(const DataSetId& id, bool state);
187
188    // Contour plots
189
190    void addContour2D(const DataSetId& id);
191
192    void deleteContour2D(const DataSetId& id);
193
194    Contour2D *getContour2D(const DataSetId& id);
195
196    void setContours(const DataSetId& id, int numContours);
197
198    void setContourList(const DataSetId& id, const std::vector<double>& contours);
199
200    void setContourOpacity(const DataSetId& id, double opacity);
201
202    void setContourVisibility(const DataSetId& id, bool state);
203
204    void setContourEdgeColor(const DataSetId& id, float color[3]);
205
206    void setContourEdgeWidth(const DataSetId& id, float edgeWidth);
207
208    void setContourLighting(const DataSetId& id, bool state);
209
210    // Meshes
211
212    void addPolyData(const DataSetId& id);
213   
214    void deletePolyData(const DataSetId& id);
215
216    PolyData *getPolyData(const DataSetId& id);
217
218    void setPolyDataOpacity(const DataSetId& id, double opacity);
219
220    void setPolyDataVisibility(const DataSetId& id, bool state);
221
222    void setPolyDataColor(const DataSetId& id, float color[3]);
223
224    void setPolyDataEdgeVisibility(const DataSetId& id, bool state);
225
226    void setPolyDataEdgeColor(const DataSetId& id, float color[3]);
227
228    void setPolyDataEdgeWidth(const DataSetId& id, float edgeWidth);
229
230    void setPolyDataWireframe(const DataSetId& id, bool state);
231
232    void setPolyDataLighting(const DataSetId& id, bool state);
233
234private:
235    static void printCameraInfo(vtkCamera *camera);
236    static inline double min2(double a, double b)
237    {
238        return ((a < b) ? a : b);
239    }
240    static inline double max2(double a, double b)
241    {
242        return ((a > b) ? a : b);
243    }
244    static void mergeBounds(double *boundsDest, const double *bounds1, const double *bounds2);
245
246    void collectBounds(double *bounds, bool onlyVisible);
247
248    void collectDataRanges(double *range, bool onlyVisible);
249
250    void updateRanges(bool useCumulative);
251
252    void computeDisplayToWorld(double x, double y, double z, double worldPt[4]);
253
254    void computeWorldToDisplay(double x, double y, double z, double displayPt[3]);
255
256    void computeScreenWorldCoords();
257
258    void storeCameraOrientation();
259    void restoreCameraOrientation();
260    void initCamera();
261    void initAxes();
262    void resetAxes();
263
264    bool _needsRedraw;
265    int _windowWidth, _windowHeight;
266    double _imgWorldOrigin[2];
267    double _imgWorldDims[2];
268    double _screenWorldCoords[4];
269    double _cameraPos[3];
270    double _cameraFocalPoint[3];
271    double _cameraUp[3];
272    double _cameraZoomRatio;
273    double _cameraPan[2];
274    float _bgColor[3];
275    bool _useCumulativeRange;
276    bool _cumulativeRangeOnlyVisible;
277    double _cumulativeDataRange[2];
278
279    ColorMapHashmap _colorMaps;
280    DataSetHashmap _dataSets;
281    PseudoColorHashmap _pseudoColors;
282    Contour2DHashmap _contours;
283    PolyDataHashmap _polyDatas;
284
285    CameraMode _cameraMode;
286
287    vtkSmartPointer<vtkPlaneCollection> _clippingPlanes;
288    vtkSmartPointer<vtkCubeAxesActor> _cubeAxesActor; // For 3D view
289#ifdef USE_CUSTOM_AXES
290    vtkSmartPointer<vtkRpCubeAxesActor2D> _cubeAxesActor2D; // For 2D view
291#else
292    vtkSmartPointer<vtkCubeAxesActor2D> _cubeAxesActor2D; // For 2D view
293#endif
294    vtkSmartPointer<vtkScalarBarActor> _scalarBarActor;
295    vtkSmartPointer<vtkRenderer> _renderer;
296    vtkSmartPointer<vtkRenderer> _legendRenderer;
297    vtkSmartPointer<vtkRenderWindow> _renderWindow;
298    vtkSmartPointer<vtkRenderWindow> _legendRenderWindow;
299};
300
301}
302}
303
304#endif
Note: See TracBrowser for help on using the repository browser.