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

Last change on this file since 2217 was 2213, checked in by ldelgass, 14 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
RevLine 
[2100]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>
[2112]13#include <vtkCubeAxesActor.h>
[2100]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
[2112]28#include "ColorMap.h"
[2100]29#include "RpVtkDataSet.h"
30#include "RpPseudoColor.h"
31#include "RpContour2D.h"
[2112]32#include "RpPolyData.h"
[2100]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
[2112]52    enum CameraMode {
53        PERSPECTIVE,
54        ORTHO,
55        IMAGE
56    };
57
[2100]58    typedef std::string DataSetId;
59    typedef std::string ColorMapId;
60    typedef std::tr1::unordered_map<DataSetId, DataSet *> DataSetHashmap;
[2112]61    typedef std::tr1::unordered_map<ColorMapId, ColorMap *> ColorMapHashmap;
[2100]62    typedef std::tr1::unordered_map<DataSetId, PseudoColor *> PseudoColorHashmap;
63    typedef std::tr1::unordered_map<DataSetId, Contour2D *> Contour2DHashmap;
[2112]64    typedef std::tr1::unordered_map<DataSetId, PolyData *> PolyDataHashmap;
[2100]65
[2112]66    // Data sets
67
[2123]68    void addDataSet(const DataSetId& id);
[2100]69
[2123]70    void deleteDataSet(const DataSetId& id);
[2100]71
[2123]72    DataSet *getDataSet(const DataSetId& id);
[2100]73
[2123]74    bool setData(const DataSetId& id, char *data, int nbytes);
[2100]75
[2123]76    bool setDataFile(const DataSetId& id, const char *filename);
[2100]77
[2123]78    double getDataValueAtPixel(const DataSetId& id, int x, int y);
[2100]79
[2123]80    double getDataValue(const DataSetId& id, double x, double y, double z);
[2100]81
[2123]82    void setOpacity(const DataSetId& id, double opacity);
[2100]83
[2123]84    void setVisibility(const DataSetId& id, bool state);
[2100]85
[2194]86    void setUseCumulativeDataRange(bool state, bool onlyVisible = false);
87
[2112]88    // Render window
[2100]89
[2112]90    void setWindowSize(int width, int height);
[2100]91
92    int getWindowWidth() const;
93
94    int getWindowHeight() const;
95
[2112]96    // Camera controls
97
98    void setCameraMode(CameraMode mode);
99
[2194]100    CameraMode getCameraMode() const;
101
[2112]102    void resetCamera(bool resetOrientation = true);
103
104    void setCameraZoomRegion(double x, double y, double width, double height);
105
[2194]106    void getCameraZoomRegion(double xywh[4]) const;
107
108    void getScreenWorldCoords(double xywh[4]) const;
109
[2112]110    void rotateCamera(double yaw, double pitch, double roll);
111
[2213]112    void setSceneOrientation(double quat[4]);
[2200]113
[2213]114    void setCameraOrientationAndPosition(double position[3],
115                                         double focalPoint[3],
116                                         double viewUp[3]);
[2200]117
[2213]118    void getCameraOrientationAndPosition(double position[3],
119                                         double focalPoint[3],
120                                         double viewUp[3]);
121
[2194]122    void panCamera(double x, double y, bool absolute = true);
[2112]123
[2194]124    void zoomCamera(double z, bool absolute = true);
[2112]125
126    // Rendering an image
127
128    void setBackgroundColor(float color[3]);
129
130    bool render();
131
[2100]132    void getRenderedFrame(vtkUnsignedCharArray *imgData);
133
[2112]134    // Axes
[2100]135
[2112]136    void setAxesGridVisibility(bool state);
137
[2100]138    void setAxesVisibility(bool state);
139
[2115]140    void setAxesColor(double color[3]);
141
[2112]142    void setAxisGridVisibility(Axis axis, bool state);
143
[2100]144    void setAxisVisibility(Axis axis, bool state);
145
[2112]146    void setAxisTitle(Axis axis, const char *title);
[2100]147
[2112]148    void setAxisUnits(Axis axis, const char *units);
[2100]149
[2112]150    // Colormaps
151
[2123]152    void addColorMap(const ColorMapId& id, ColorMap *colorMap);
[2112]153
[2123]154    void deleteColorMap(const ColorMapId& id);
[2100]155
[2123]156    ColorMap *getColorMap(const ColorMapId& id);
[2100]157
[2146]158    bool renderColorMap(const ColorMapId& id,
159                        const DataSetId& dataSetID,
160                        const char *title,
[2100]161                        int width, int height,
162                        vtkUnsignedCharArray *imgData);
163
[2112]164    // Color-mapped surfaces
[2100]165
[2123]166    void addPseudoColor(const DataSetId& id);
[2100]167
[2123]168    void deletePseudoColor(const DataSetId& id);
[2100]169
[2123]170    PseudoColor *getPseudoColor(const DataSetId& id);
[2100]171
[2123]172    void setPseudoColorColorMap(const DataSetId& id, const ColorMapId& colorMapId);
[2100]173
[2123]174    vtkLookupTable *getPseudoColorColorMap(const DataSetId& id);
[2100]175
[2137]176    void setPseudoColorOpacity(const DataSetId& id, double opacity);
177
[2123]178    void setPseudoColorVisibility(const DataSetId& id, bool state);
[2100]179
[2123]180    void setPseudoColorEdgeVisibility(const DataSetId& id, bool state);
[2100]181
[2123]182    void setPseudoColorEdgeColor(const DataSetId& id, float color[3]);
[2112]183
[2123]184    void setPseudoColorEdgeWidth(const DataSetId& id, float edgeWidth);
[2112]185
[2123]186    void setPseudoColorLighting(const DataSetId& id, bool state);
[2114]187
[2112]188    // Contour plots
189
[2123]190    void addContour2D(const DataSetId& id);
[2100]191
[2123]192    void deleteContour2D(const DataSetId& id);
[2100]193
[2123]194    Contour2D *getContour2D(const DataSetId& id);
[2100]195
[2123]196    void setContours(const DataSetId& id, int numContours);
[2100]197
[2123]198    void setContourList(const DataSetId& id, const std::vector<double>& contours);
[2100]199
[2137]200    void setContourOpacity(const DataSetId& id, double opacity);
201
[2123]202    void setContourVisibility(const DataSetId& id, bool state);
[2100]203
[2123]204    void setContourEdgeColor(const DataSetId& id, float color[3]);
[2100]205
[2123]206    void setContourEdgeWidth(const DataSetId& id, float edgeWidth);
[2100]207
[2123]208    void setContourLighting(const DataSetId& id, bool state);
[2114]209
[2112]210    // Meshes
211
[2123]212    void addPolyData(const DataSetId& id);
[2112]213   
[2123]214    void deletePolyData(const DataSetId& id);
[2112]215
[2123]216    PolyData *getPolyData(const DataSetId& id);
[2112]217
[2137]218    void setPolyDataOpacity(const DataSetId& id, double opacity);
219
[2123]220    void setPolyDataVisibility(const DataSetId& id, bool state);
[2112]221
[2123]222    void setPolyDataColor(const DataSetId& id, float color[3]);
[2112]223
[2123]224    void setPolyDataEdgeVisibility(const DataSetId& id, bool state);
[2112]225
[2123]226    void setPolyDataEdgeColor(const DataSetId& id, float color[3]);
[2112]227
[2123]228    void setPolyDataEdgeWidth(const DataSetId& id, float edgeWidth);
[2112]229
[2123]230    void setPolyDataWireframe(const DataSetId& id, bool state);
[2112]231
[2123]232    void setPolyDataLighting(const DataSetId& id, bool state);
[2114]233
[2100]234private:
235    static void printCameraInfo(vtkCamera *camera);
[2112]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);
[2100]245
[2112]246    void collectBounds(double *bounds, bool onlyVisible);
247
[2194]248    void collectDataRanges(double *range, bool onlyVisible);
[2121]249
[2146]250    void updateRanges(bool useCumulative);
251
[2200]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
[2194]256    void computeScreenWorldCoords();
257
[2112]258    void storeCameraOrientation();
259    void restoreCameraOrientation();
260    void initCamera();
[2100]261    void initAxes();
[2112]262    void resetAxes();
[2100]263
264    bool _needsRedraw;
265    int _windowWidth, _windowHeight;
266    double _imgWorldOrigin[2];
267    double _imgWorldDims[2];
[2194]268    double _screenWorldCoords[4];
[2112]269    double _cameraPos[3];
270    double _cameraFocalPoint[3];
271    double _cameraUp[3];
[2194]272    double _cameraZoomRatio;
273    double _cameraPan[2];
[2100]274    float _bgColor[3];
[2194]275    bool _useCumulativeRange;
276    bool _cumulativeRangeOnlyVisible;
[2121]277    double _cumulativeDataRange[2];
[2100]278
279    ColorMapHashmap _colorMaps;
280    DataSetHashmap _dataSets;
281    PseudoColorHashmap _pseudoColors;
282    Contour2DHashmap _contours;
[2112]283    PolyDataHashmap _polyDatas;
[2100]284
[2112]285    CameraMode _cameraMode;
286
[2100]287    vtkSmartPointer<vtkPlaneCollection> _clippingPlanes;
[2112]288    vtkSmartPointer<vtkCubeAxesActor> _cubeAxesActor; // For 3D view
[2100]289#ifdef USE_CUSTOM_AXES
[2112]290    vtkSmartPointer<vtkRpCubeAxesActor2D> _cubeAxesActor2D; // For 2D view
[2100]291#else
[2112]292    vtkSmartPointer<vtkCubeAxesActor2D> _cubeAxesActor2D; // For 2D view
[2100]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.