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

Last change on this file since 2120 was 2120, checked in by gah, 14 years ago
File size: 6.4 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(DataSetId id);
69
70    void deleteDataSet(DataSetId id);
71
72    DataSet *getDataSet(DataSetId id);
73
74    bool setData(DataSetId id, char *data, int nbytes);
75
76    bool setDataFile(DataSetId id, const char *filename);
77
78    double getDataValueAtPixel(DataSetId id, int x, int y);
79
80    double getDataValue(DataSetId id, double x, double y, double z);
81
82    void setOpacity(DataSetId id, double opacity);
83
84    void setVisibility(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(ColorMapId id, ColorMap *colorMap);
135
136    void deleteColorMap(ColorMapId id);
137
138    ColorMap *getColorMap(ColorMapId id);
139
140    void renderColorMap(ColorMapId id, const char *title,
141                        int width, int height,
142                        vtkUnsignedCharArray *imgData);
143
144    // Color-mapped surfaces
145
146    void addPseudoColor(DataSetId id);
147
148    void deletePseudoColor(DataSetId id);
149
150    PseudoColor *getPseudoColor(DataSetId id);
151
152    void setPseudoColorColorMap(DataSetId id, ColorMapId colorMapId);
153
154    vtkLookupTable *getPseudoColorColorMap(DataSetId id);
155
156    void setPseudoColorVisibility(DataSetId id, bool state);
157
158    void setPseudoColorEdgeVisibility(DataSetId id, bool state);
159
160    void setPseudoColorEdgeColor(DataSetId id, float color[3]);
161
162    void setPseudoColorEdgeWidth(DataSetId id, float edgeWidth);
163
164    void setPseudoColorLighting(DataSetId id, bool state);
165
166    // Contour plots
167
168    void addContour2D(DataSetId id);
169
170    void deleteContour2D(DataSetId id);
171
172    Contour2D *getContour2D(DataSetId id);
173
174    void setContours(DataSetId id, int numContours);
175
176    void setContourList(DataSetId id, const std::vector<double>& contours);
177
178    void setContourVisibility(DataSetId id, bool state);
179
180    void setContourEdgeColor(DataSetId id, float color[3]);
181
182    void setContourEdgeWidth(DataSetId id, float edgeWidth);
183
184    void setContourLighting(DataSetId id, bool state);
185
186    // Meshes
187
188    void addPolyData(DataSetId id);
189   
190    void deletePolyData(DataSetId id);
191
192    PolyData *getPolyData(DataSetId id);
193
194    void setPolyDataVisibility(DataSetId id, bool state);
195
196    void setPolyDataColor(DataSetId id, float color[3]);
197
198    void setPolyDataEdgeVisibility(DataSetId id, bool state);
199
200    void setPolyDataEdgeColor(DataSetId id, float color[3]);
201
202    void setPolyDataEdgeWidth(DataSetId id, float edgeWidth);
203
204    void setPolyDataWireframe(DataSetId id, bool state);
205
206    void setPolyDataLighting(DataSetId id, bool state);
207
208private:
209    static void printCameraInfo(vtkCamera *camera);
210    static inline double min2(double a, double b)
211    {
212        return ((a < b) ? a : b);
213    }
214    static inline double max2(double a, double b)
215    {
216        return ((a > b) ? a : b);
217    }
218    static void mergeBounds(double *boundsDest, const double *bounds1, const double *bounds2);
219
220    void collectBounds(double *bounds, bool onlyVisible);
221
222    void storeCameraOrientation();
223    void restoreCameraOrientation();
224    void initCamera();
225    void initAxes();
226    void resetAxes();
227
228    bool _needsRedraw;
229    int _windowWidth, _windowHeight;
230    double _imgWorldOrigin[2];
231    double _imgWorldDims[2];
232    double _cameraPos[3];
233    double _cameraFocalPoint[3];
234    double _cameraUp[3];
235    float _bgColor[3];
236
237    ColorMapHashmap _colorMaps;
238    DataSetHashmap _dataSets;
239    PseudoColorHashmap _pseudoColors;
240    Contour2DHashmap _contours;
241    PolyDataHashmap _polyDatas;
242
243    CameraMode _cameraMode;
244
245    vtkSmartPointer<vtkPlaneCollection> _clippingPlanes;
246    vtkSmartPointer<vtkCubeAxesActor> _cubeAxesActor; // For 3D view
247#ifdef USE_CUSTOM_AXES
248    vtkSmartPointer<vtkRpCubeAxesActor2D> _cubeAxesActor2D; // For 2D view
249#else
250    vtkSmartPointer<vtkCubeAxesActor2D> _cubeAxesActor2D; // For 2D view
251#endif
252    vtkSmartPointer<vtkScalarBarActor> _scalarBarActor;
253    vtkSmartPointer<vtkRenderer> _renderer;
254    vtkSmartPointer<vtkRenderer> _legendRenderer;
255    vtkSmartPointer<vtkRenderWindow> _renderWindow;
256    vtkSmartPointer<vtkRenderWindow> _legendRenderWindow;
257};
258
259}
260}
261
262#endif
Note: See TracBrowser for help on using the repository browser.