source: vtkvis/trunk/Renderer.h @ 4650

Last change on this file since 4650 was 4090, checked in by ldelgass, 10 years ago

Add commands to manually set cut plane on image slice

  • Property svn:eol-style set to native
File size: 37.2 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (C) 2004-2012  HUBzero Foundation, LLC
4 *
5 * Author: Leif Delgass <ldelgass@purdue.edu>
6 */
7
8#ifndef VTKVIS_RENDERER_H
9#define VTKVIS_RENDERER_H
10
11#include <string>
12#include <vector>
13#include <tr1/unordered_map>
14#include <typeinfo>
15
16#include <vtkSmartPointer.h>
17#ifdef USE_CUSTOM_AXES
18#include "vtkRpCubeAxesActor.h"
19#else
20#include <vtkCubeAxesActor.h>
21#endif
22#include <vtkAxesActor.h>
23#include <vtkAnnotatedCubeActor.h>
24#include <vtkScalarBarActor.h>
25#include <vtkRenderer.h>
26#include <vtkRenderWindow.h>
27#include <vtkUnsignedCharArray.h>
28
29#include "ColorMap.h"
30#include "Types.h"
31#include "DataSet.h"
32#include "Arc.h"
33#include "Arrow.h"
34#include "Box.h"
35#include "Cone.h"
36#include "Contour2D.h"
37#include "Contour3D.h"
38#include "Cutplane.h"
39#include "Cylinder.h"
40#include "Disk.h"
41#include "Glyphs.h"
42#include "Group.h"
43#include "HeightMap.h"
44#include "Image.h"
45#include "ImageCutplane.h"
46#include "LIC.h"
47#include "Line.h"
48#include "Molecule.h"
49#include "Outline.h"
50#include "Parallelepiped.h"
51#include "PolyData.h"
52#include "Polygon.h"
53#include "PseudoColor.h"
54#include "Sphere.h"
55#include "Streamlines.h"
56#include "Text3D.h"
57#include "Volume.h"
58#include "Warp.h"
59#include "Trace.h"
60
61// Controls if TGA format is sent to client
62//#define RENDER_TARGA
63#define TARGA_BYTES_PER_PIXEL 3
64
65namespace VtkVis {
66
67/**
68 * \brief VTK Renderer
69 */
70class Renderer
71{
72public:
73    Renderer();
74    virtual ~Renderer();
75
76    enum AxisRangeMode {
77        RANGE_AUTO = 0,
78        RANGE_SCALE_BOUNDS,
79        RANGE_EXPLICIT
80    };
81
82    enum AxesFlyMode {
83        FLY_OUTER_EDGES = 0,
84        FLY_CLOSEST_TRIAD,
85        FLY_FURTHEST_TRIAD,
86        FLY_STATIC_EDGES,
87        FLY_STATIC_TRIAD
88    };
89
90    enum AxesTickPosition {
91        TICKS_INSIDE,
92        TICKS_OUTSIDE,
93        TICKS_BOTH
94    };
95
96    enum CameraMode {
97        PERSPECTIVE,
98        ORTHO,
99        IMAGE
100    };
101
102    enum Aspect {
103        ASPECT_NATIVE,
104        ASPECT_SQUARE,
105        ASPECT_WINDOW
106    };
107
108    enum LegendType {
109        LEGEND_SCALAR,
110        LEGEND_VECTOR_MAGNITUDE,
111        LEGEND_VECTOR_X,
112        LEGEND_VECTOR_Y,
113        LEGEND_VECTOR_Z
114    };
115
116    typedef std::string DataSetId;
117    typedef std::string ColorMapId;
118    typedef std::string FieldId;
119
120    // Data sets
121
122    void addDataSet(const DataSetId& id);
123
124    void deleteDataSet(const DataSetId& id);
125
126    DataSet *getDataSet(const DataSetId& id);
127
128    void getDataSetNames(std::vector<std::string>& names);
129
130    bool setData(const DataSetId& id, char *data, int nbytes);
131
132    bool setDataFile(const DataSetId& id, const char *filename);
133
134    bool setDataSetActiveScalars(const DataSetId& id, const char *scalarName);
135
136    bool setDataSetActiveVectors(const DataSetId& id, const char *vectorName);
137
138    bool getScalarValueAtPixel(const DataSetId& id, int x, int y, double *value);
139
140    bool getScalarValue(const DataSetId& id, double x, double y, double z, double *value);
141
142    bool getVectorValueAtPixel(const DataSetId& id, int x, int y, double vector[3]);
143
144    bool getVectorValue(const DataSetId& id, double x, double y, double z, double vector[3]);
145
146    void setDataSetOpacity(const DataSetId& id, double opacity);
147
148    void setDataSetVisibility(const DataSetId& id, bool state);
149
150    void setUseCumulativeDataRange(bool state, bool onlyVisible = false);
151
152    bool getUseCumulativeRange();
153
154    bool setCumulativeDataRange(double *range, const char *name,
155                                DataSet::DataAttributeType type,
156                                int numComponents,
157                                int component = -1);
158
159    bool getCumulativeDataRange(double *range, const char *name,
160                                int numComponents,
161                                int component = -1);
162
163    bool getCumulativeDataRange(double *range, const char *name,
164                                DataSet::DataAttributeType type,
165                                int numComponents,
166                                int component = -1);
167
168    // Render window
169
170    /// Get the VTK render window object this Renderer uses
171    vtkRenderWindow *getRenderWindow()
172    {
173        return _renderWindow;
174    }
175
176    void setWindowSize(int width, int height);
177
178    int getWindowWidth() const;
179
180    int getWindowHeight() const;
181
182    // Lights
183
184    int addLight(float pos[3]);
185
186    vtkLight *getLight(int lightIdx);
187
188    void setLightSwitch(int lightIdx, bool state);
189
190    // Camera controls
191
192    void setViewAngle(int height);
193
194    /// Return the VTK camera object this Renderer uses
195    vtkCamera *getVtkCamera()
196    {
197        if (_renderer != NULL)
198            return _renderer->GetActiveCamera();
199        else
200            return NULL;
201    }
202
203    bool isCameraMaximized()
204    {
205        return (_cameraZoomRatio == 1.0 &&
206                _cameraPan[0] == 0.0 &&
207                _cameraPan[1] == 0.0);
208    }
209
210    void getImageCameraSizes(int *imgWidthPx, int *imgHeightPx,
211                             int *_pxOffsetX = NULL, int *_pxOffsetY = NULL);
212
213    double getImageCameraAspect();
214
215    void setCameraMode(CameraMode mode);
216
217    CameraMode getCameraMode() const;
218
219    void setCameraAspect(Aspect aspect);
220
221    void resetVtkCamera(double *bounds = NULL);
222
223    void resetCamera(bool resetOrientation = true);
224
225    void resetCameraClippingRange();
226
227    bool setCameraZoomRegionPixels(int x, int y, int width, int height);
228
229    bool setCameraZoomRegion(double x, double y, double width, double height);
230
231    void getCameraZoomRegion(double xywh[4]) const;
232
233    void getScreenWorldCoords(double xywh[4]) const;
234
235    void rotateCamera(double yaw, double pitch, double roll);
236
237    void setCameraOrientation(const double quat[4], bool absolute = true);
238
239    void panCamera(double x, double y, bool absolute = true);
240
241    void zoomCamera(double z, bool absolute = true);
242
243    void setCameraOrientationAndPosition(const double position[3],
244                                         const double focalPoint[3],
245                                         const double viewUp[3]);
246
247    void getCameraOrientationAndPosition(double position[3],
248                                         double focalPoint[3],
249                                         double viewUp[3]);
250
251    void eventuallyResetCamera()
252    {
253        _needsCameraReset = true;
254    }
255
256    bool needsCameraReset()
257    {
258        return _needsCameraReset;
259    }
260
261    void eventuallyResetCameraClippingRange()
262    {
263        _needsCameraClippingRangeReset = true;
264    }
265
266    bool needsCameraClippingRangeReset()
267    {
268        return _needsCameraClippingRangeReset;
269    }
270
271    // Rendering an image
272
273    void setBackgroundColor(float color[3]);
274
275    void setClipPlane(Axis axis, double ratio, int direction);
276
277    void setUseTwoSidedLighting(bool state);
278
279    void setUseDepthPeeling(bool state);
280
281    void setDepthPeelingParams(double occlusionRatio = 0.0, int maxPeels = 0);
282
283    void eventuallyRender();
284
285    bool render();
286
287    void getRenderedFrame(vtkUnsignedCharArray *imgData);
288
289    // Axes
290
291    void setAxesOrigin(double x, double y, double z, bool useCustom = true);
292
293    void setAxesAutoBounds(bool state);
294
295    void setAxesBounds(double min, double max);
296
297    void setAxesAutoRange(bool state);
298
299    void setAxisBounds(Axis axis, double min, double max);
300
301    void setAxesScale(double scale);
302
303    void setAxesRange(double min, double max);
304
305    void setAxesLabelPowerScaling(int xPow, int yPow, int zPow, bool useCustom = true);
306
307    void setAxisAutoBounds(Axis axis, bool state);
308
309    void setAxisAutoRange(Axis axis, bool state);
310
311    void setAxisScale(Axis axis, double scale);
312
313    void setAxisRange(Axis axis, double min, double max);
314
315    void setAxesFlyMode(AxesFlyMode mode);
316
317    void setAxesVisibility(bool state);
318
319    void setAxesGridVisibility(bool state);
320
321    void setAxesInnerGridVisibility(bool state);
322
323    void setAxesGridpolysVisibility(bool state);
324
325    void setAxesLabelVisibility(bool state);
326
327    void setAxesTickVisibility(bool state);
328
329    void setAxesMinorTickVisibility(bool state);
330
331    void setAxesTickPosition(AxesTickPosition pos);
332
333    void setAxesColor(double color[3], double opacity = 1.0);
334
335    void setAxesTitleColor(double color[3], double opacity = 1.0);
336
337    void setAxesLabelColor(double color[3], double opacity = 1.0);
338
339    void setAxesLinesColor(double color[3], double opacity = 1.0);
340
341    void setAxesGridlinesColor(double color[3], double opacity = 1.0);
342
343    void setAxesInnerGridlinesColor(double color[3], double opacity = 1.0);
344
345    void setAxesGridpolysColor(double color[3], double opacity = 1.0);
346
347    void setAxesLabelScaling(bool autoScale, int xpow, int ypow, int zpow);
348
349    void setAxesPixelFontSize(double screenSize);
350
351    void setAxesTitleFont(const char *fontName);
352
353    void setAxesTitleFontSize(int sz);
354
355    void setAxesTitleOrientation(double orientation);
356
357    void setAxesLabelFont(const char *fontName);
358
359    void setAxesLabelFontSize(int sz);
360
361    void setAxesLabelOrientation(double orientation);
362
363    void setAxesLabelFormat(const char *format);
364
365    void setAxisVisibility(Axis axis, bool state);
366
367    void setAxisGridVisibility(Axis axis, bool state);
368
369    void setAxisInnerGridVisibility(Axis axis, bool state);
370
371    void setAxisGridpolysVisibility(Axis axis, bool state);
372
373    void setAxisLabelVisibility(Axis axis, bool state);
374
375    void setAxisTickVisibility(Axis axis, bool state);
376
377    void setAxisMinorTickVisibility(Axis axis, bool state);
378
379    void setAxisColor(Axis axis, double color[3], double opacity = 1.0);
380
381    void setAxisTitleColor(Axis axis, double color[3], double opacity = 1.0);
382
383    void setAxisLabelColor(Axis axis, double color[3], double opacity = 1.0);
384
385    void setAxisLinesColor(Axis axis, double color[3], double opacity = 1.0);
386
387    void setAxisGridlinesColor(Axis axis, double color[3], double opacity = 1.0);
388
389    void setAxisInnerGridlinesColor(Axis axis, double color[3], double opacity = 1.0);
390
391    void setAxisGridpolysColor(Axis axis, double color[3], double opacity = 1.0);
392
393    void setAxisTitle(Axis axis, const char *title);
394
395    void setAxisUnits(Axis axis, const char *units);
396
397    void setAxisTitleFont(Axis axis, const char *fontName);
398
399    void setAxisTitleFontSize(Axis axis, int sz);
400
401    void setAxisTitleOrientation(Axis axis, double orientation);
402
403    void setAxisLabelFont(Axis axis, const char *fontName);
404
405    void setAxisLabelFontSize(Axis axis, int sz);
406
407    void setAxisLabelOrientation(Axis axis, double orientation);
408
409    void setAxisLabelFormat(Axis axis, const char *format);
410
411    void eventuallyResetAxes()
412    {
413        _needsAxesReset = true;
414    }
415
416    bool needsAxesReset()
417    {
418        return _needsAxesReset;
419    }
420
421    // Colormaps
422
423    void addColorMap(const ColorMapId& id, ColorMap *colorMap);
424
425    void deleteColorMap(const ColorMapId& id);
426
427    ColorMap *getColorMap(const ColorMapId& id);
428
429    void setColorMapNumberOfTableEntries(const ColorMapId& id, int numEntries);
430
431    bool renderColorMap(const ColorMapId& id,
432                        int width, int height,
433                        bool opaque,
434                        vtkUnsignedCharArray *imgData);
435
436    bool renderColorMap(const ColorMapId& id,
437                        const DataSetId& dataSetID,
438                        LegendType legendType,
439                        const char *fieldName,
440                        DataSet::DataAttributeType type,
441                        std::string& title,
442                        double range[2],
443                        int width, int height,
444                        bool opaque,
445                        int numLabels,
446                        vtkUnsignedCharArray *imgData);
447
448    bool renderColorMap(const ColorMapId& id,
449                        const DataSetId& dataSetID,
450                        LegendType legendType,
451                        const char *fieldName,
452                        std::string& title,
453                        double range[2],
454                        int width, int height,
455                        bool opaque,
456                        int numLabels,
457                        vtkUnsignedCharArray *imgData);
458
459    bool renderColorMap(const ColorMapId& id,
460                        const DataSetId& dataSetID,
461                        LegendType legendType,
462                        std::string& title,
463                        double range[2],
464                        int width, int height,
465                        bool opaque,
466                        int numLabels,
467                        vtkUnsignedCharArray *imgData);
468
469    // Generic GraphicsObject methods
470
471    GraphicsObject *getGenericGraphicsObject(const DataSetId& id);
472
473    template<class T>
474    T *getGraphicsObject(const DataSetId& id);
475
476    template<class T>
477    bool addGraphicsObject(const DataSetId& id);
478
479    template<class T>
480    void deleteGraphicsObject(const DataSetId& id);
481
482    template<class T>
483    void deleteAllGraphicsObjects();
484
485    template<class T>
486    void mergeGraphicsObjectBounds(double *bounds, bool onlyVisible);
487
488    template<class T>
489    void mergeGraphicsObjectUnscaledBounds(double *bounds, bool onlyVisible);
490
491    template<class T>
492    void updateGraphicsObjectFieldRanges();
493
494    template<class T>
495    void setGraphicsObjectClippingPlanes(vtkPlaneCollection *planes);
496
497    template<class T>
498    void setGraphicsObjectAspect(double aspectRatio);
499
500    template<class T>
501    void setGraphicsObjectInterpolateBeforeMapping(const DataSetId& id, bool state);
502
503    template<class T>
504    void setGraphicsObjectColorMap(const DataSetId& id, const ColorMapId& colorMapId);
505
506    template<class T>
507    void updateGraphicsObjectColorMap(ColorMap *cmap);
508
509    template<class T>
510    bool graphicsObjectColorMapUsed(ColorMap *cmap);
511
512    template<class T>
513    void setGraphicsObjectVolumeSlice(const DataSetId& id, Axis axis, double ratio);
514
515    // Prop/Prop3D properties
516
517    template<class T>
518    void setGraphicsObjectOrientation(const DataSetId& id, double quat[4]);
519
520    template<class T>
521    void setGraphicsObjectOrientation(const DataSetId& id, double angle, double axis[3]);
522
523    template<class T>
524    void setGraphicsObjectOrigin(const DataSetId& id, double origin[3]);
525
526    template<class T>
527    void setGraphicsObjectPosition(const DataSetId& id, double pos[3]);
528
529    template<class T>
530    void setGraphicsObjectAspect(const DataSetId& id, double aspect);
531
532    template<class T>
533    void setGraphicsObjectScale(const DataSetId& id, double scale[3]);
534
535    template<class T>
536    void setGraphicsObjectTransform(const DataSetId& id, vtkMatrix4x4 *trans);
537
538    template<class T>
539    void setGraphicsObjectVisibility(const DataSetId& id, bool state);
540
541    // Actor properties
542
543    template<class T>
544    void setGraphicsObjectColor(const DataSetId& id, float color[3]);
545
546    template<class T>
547    void setGraphicsObjectCullFace(const DataSetId& id, GraphicsObject::CullFace state);
548
549    template<class T>
550    void setGraphicsObjectCulling(const DataSetId& id, bool state);
551
552    template<class T>
553    void setGraphicsObjectEdgeVisibility(const DataSetId& id, bool state);
554
555    template<class T>
556    void setGraphicsObjectEdgeColor(const DataSetId& id, float color[3]);
557
558    template<class T>
559    void setGraphicsObjectEdgeWidth(const DataSetId& id, float edgeWidth);
560
561    template<class T>
562    void setGraphicsObjectAmbient(const DataSetId& id, double coeff);
563
564    template<class T>
565    void setGraphicsObjectDiffuse(const DataSetId& id, double coeff);
566
567    template<class T>
568    void setGraphicsObjectShadingModel(const DataSetId& id, GraphicsObject::ShadingModel state);
569
570    template<class T>
571    void setGraphicsObjectSpecular(const DataSetId& id, double coeff, double power);
572
573    template<class T>
574    void setGraphicsObjectLighting(const DataSetId& id, bool state);
575
576    template<class T>
577    void setGraphicsObjectOpacity(const DataSetId& id, double opacity);
578
579    template<class T>
580    void setGraphicsObjectPointSize(const DataSetId& id, float size);
581
582    template<class T>
583    void setGraphicsObjectWireframe(const DataSetId& id, bool state);
584
585    // For Shapes:
586
587    template<class T>
588    void setGraphicsObjectFlipNormals(const DataSetId& id, bool state);
589
590    // Arcs
591
592    bool addArc(const DataSetId& id, double center[3], double pt1[3],
593                double normal[3], double angle);
594
595    void setArcResolution(const DataSetId& id, int res);
596
597    // Arrows
598
599    bool addArrow(const DataSetId& id, double tipRadius, double shaftRadius,
600                  double tipLength, bool flipNormals = false);
601
602    void setArrowResolution(const DataSetId& id, int resTip, int resShaft);
603
604    // Boxes
605
606    bool addBox(const DataSetId& id, double xLen, double yLen, double zLen,
607                bool flipNormals = false);
608
609    // Cones
610
611    bool addCone(const DataSetId& id, double radius, double height, bool cap,
612                 bool flipNormals = false);
613
614    void setConeResolution(const DataSetId& id, int res);
615
616    // 2D Contour plots
617
618    bool addContour2D(const DataSetId& id, int numContours);
619
620    bool addContour2D(const DataSetId& id, const std::vector<double>& contours);
621
622    void setContour2DContourField(const DataSetId& id, const char *fieldName);
623
624    void setContour2DNumContours(const DataSetId& id, int numContours);
625
626    void setContour2DContourList(const DataSetId& id, const std::vector<double>& contours);
627
628    void setContour2DColorMode(const DataSetId& id,
629                               Contour2D::ColorMode mode,
630                               const char *name, double range[2] = NULL);
631
632    void setContour2DColorMode(const DataSetId& id,
633                               Contour2D::ColorMode mode,
634                               DataSet::DataAttributeType type,
635                               const char *name, double range[2] = NULL);
636
637    // 3D Contour (isosurface) plots
638
639    bool addContour3D(const DataSetId& id, int numContours);
640
641    bool addContour3D(const DataSetId& id, const std::vector<double>& contours);
642
643    void setContour3DContourField(const DataSetId& id, const char *fieldName);
644
645    void setContour3DNumContours(const DataSetId& id, int numContours);
646
647    void setContour3DContourList(const DataSetId& id, const std::vector<double>& contours);
648
649    void setContour3DColorMode(const DataSetId& id,
650                               Contour3D::ColorMode mode,
651                               const char *name, double range[2] = NULL);
652
653    void setContour3DColorMode(const DataSetId& id,
654                               Contour3D::ColorMode mode,
655                               DataSet::DataAttributeType type,
656                               const char *name, double range[2] = NULL);
657
658    // Cutplanes
659
660    void setCutplaneCloudStyle(const DataSetId& id,
661                               Cutplane::CloudStyle style);
662
663    void setCutplaneOutlineVisibility(const DataSetId& id, bool state);
664
665    void setCutplaneSliceVisibility(const DataSetId& id, Axis axis, bool state);
666
667    void setCutplaneColorMode(const DataSetId& id,
668                              Cutplane::ColorMode mode,
669                              const char *name, double range[2] = NULL);
670
671    void setCutplaneColorMode(const DataSetId& id,
672                              Cutplane::ColorMode mode,
673                              DataSet::DataAttributeType type,
674                              const char *name, double range[2] = NULL);
675
676    // Cylinders
677
678    bool addCylinder(const DataSetId& id, double radius, double height, bool cap, bool flipNormals = false);
679
680    void setCylinderCapping(const DataSetId& id, bool state);
681
682    void setCylinderResolution(const DataSetId& id, int res);
683
684    // Disks
685
686    bool addDisk(const DataSetId& id, double innerRadius, double outerRadius, bool flipNormals = false);
687
688    void setDiskResolution(const DataSetId& id, int resRadial, int resCircum);
689
690    // Glyphs
691
692    bool addGlyphs(const DataSetId& id, Glyphs::GlyphShape shape);
693
694    void setGlyphsShape(const DataSetId& id, Glyphs::GlyphShape shape);
695
696    void setGlyphsOrientMode(const DataSetId& id, bool state, const char *name);
697
698    void setGlyphsQuality(const DataSetId& id, double quality);
699
700    void setGlyphsColorMode(const DataSetId& id,
701                            Glyphs::ColorMode mode,
702                            const char *name,
703                            double range[2] = NULL);
704
705    void setGlyphsScalingMode(const DataSetId& id,
706                              Glyphs::ScalingMode mode,
707                              const char *name,
708                              double range[2] = NULL);
709
710    void setGlyphsNormalizeScale(const DataSetId& id, bool normalize);
711
712    void setGlyphsScaleFactor(const DataSetId& id, double scale);
713
714    void setGlyphsMaximumNumberOfGlyphs(const DataSetId& id, int max,
715                                        bool random = true,
716                                        int offset = 0, int ratio = 1);
717
718    // Groups
719
720    bool addGroup(const DataSetId& id, const std::vector<Group::NodeId>& nodeList);
721
722    void addChildrenToGroup(const DataSetId& id, const std::vector<Group::NodeId>& nodeList);
723
724    void removeChildrenFromGroup(const DataSetId& id, const std::vector<Group::NodeId>& nodeList);
725
726    // Height maps
727
728    bool addHeightMap(const DataSetId& id, int numContours, double heightScale);
729
730    bool addHeightMap(const DataSetId& id, const std::vector<double>& contours, double heightScale);
731
732    void setHeightMapHeightScale(const DataSetId& id, double scale);
733
734    void setHeightMapCloudStyle(const DataSetId& id,
735                                HeightMap::CloudStyle style);
736
737    void setHeightMapNumContours(const DataSetId& id, int numContours);
738
739    void setHeightMapContourList(const DataSetId& id, const std::vector<double>& contours);
740
741    void setHeightMapContourSurfaceVisibility(const DataSetId& id, bool state);
742
743    void setHeightMapContourLineVisibility(const DataSetId& id, bool state);
744
745    void setHeightMapContourLineColorMapEnabled(const DataSetId& id, bool mode);
746
747    void setHeightMapContourEdgeColor(const DataSetId& id, float color[3]);
748
749    void setHeightMapContourEdgeWidth(const DataSetId& id, float edgeWidth);
750
751    void setHeightMapColorMode(const DataSetId& id,
752                               HeightMap::ColorMode mode,
753                               const char *name, double range[2] = NULL);
754
755    void setHeightMapColorMode(const DataSetId& id,
756                               HeightMap::ColorMode mode,
757                               DataSet::DataAttributeType type,
758                               const char *name, double range[2] = NULL);
759
760    // Images
761
762    void setImageBackground(const DataSetId& id, bool state);
763
764    void setImageBacking(const DataSetId& id, bool state);
765
766    void setImageBorder(const DataSetId& id, bool state);
767
768    // For ImageActor/ImageSliceMapper only
769    void setImageExtents(const DataSetId& id, int extents[6]);
770
771    void setImageLevel(const DataSetId& id, double level);
772
773    void setImageWindow(const DataSetId& id, double window);
774
775    void setImageSlicePlane(const DataSetId& id, double normal[3], double origin[3]);
776
777    void setImageSliceFollowsCamera(const DataSetId& id, bool state);
778
779    // For ImageActor/ImageSliceMapper only
780    void setImageZSlice(const DataSetId& id, int z);
781
782    // ImageCutplanes
783
784    void setImageCutplaneOutlineVisibility(const DataSetId& id, bool state);
785
786    void setImageCutplaneSliceVisibility(const DataSetId& id, Axis axis, bool state);
787
788    void setImageCutplaneLevel(const DataSetId& id, double level);
789
790    void setImageCutplaneWindow(const DataSetId& id, double window);
791
792    // Lines
793
794    bool addLine(const DataSetId& id, double pt1[3], double pt2[3]);
795
796    bool addLine(const DataSetId& id, std::vector<double> points);
797
798    // Molecules
799
800    void setMoleculeAtomQuality(const DataSetId& id, double quality);
801
802    void setMoleculeBondQuality(const DataSetId& id, double quality);
803
804    void setMoleculeAtomRadiusScale(const DataSetId& id, double scale);
805
806    void setMoleculeBondRadiusScale(const DataSetId& id, double scale);
807
808    void setMoleculeAtomScaling(const DataSetId& id, Molecule::AtomScaling scaling);
809
810    void setMoleculeAtomVisibility(const DataSetId& id, bool state);
811
812    void setMoleculeAtomLabelField(const DataSetId& id, const char *fieldName);
813
814    void setMoleculeAtomLabelVisibility(const DataSetId& id, bool state);
815
816    void setMoleculeBondVisibility(const DataSetId& id, bool state);
817
818    void setMoleculeBondStyle(const DataSetId& id, Molecule::BondStyle style);
819
820    void setMoleculeBondColorMode(const DataSetId& id, Molecule::BondColorMode mode);
821
822    void setMoleculeBondColor(const DataSetId& id, float color[3]);
823
824    void setMoleculeColorMode(const DataSetId& id,
825                              Molecule::ColorMode mode,
826                              const char *name, double range[2] = NULL);
827
828    void setMoleculeColorMode(const DataSetId& id,
829                              Molecule::ColorMode mode,
830                              DataSet::DataAttributeType type,
831                              const char *name, double range[2] = NULL);
832
833    // Parallelepipeds
834
835    bool addParallelepiped(const DataSetId& id, double vec1[3], double vec2[3], double vec3[3],
836                           bool flipNormals = false);
837
838    // PolyData meshes
839
840    void setPolyDataCloudStyle(const DataSetId& id,
841                               PolyData::CloudStyle style);
842
843    void setPolyDataColorMode(const DataSetId& id,
844                              PolyData::ColorMode mode,
845                              const char *name, double range[2] = NULL);
846
847    void setPolyDataColorMode(const DataSetId& id,
848                              PolyData::ColorMode mode,
849                              DataSet::DataAttributeType type,
850                              const char *name, double range[2] = NULL);
851
852    // N-sided Regular Polygons
853
854    bool addPolygon(const DataSetId& id, int numSides, double center[3], double normal[3], double radius);
855
856    // Color-mapped surfaces
857
858    void setPseudoColorCloudStyle(const DataSetId& id,
859                                  PseudoColor::CloudStyle style);
860
861    void setPseudoColorColorMode(const DataSetId& id,
862                                 PseudoColor::ColorMode mode,
863                                 const char *name, double range[2] = NULL);
864
865    void setPseudoColorColorMode(const DataSetId& id,
866                                 PseudoColor::ColorMode mode,
867                                 DataSet::DataAttributeType type,
868                                 const char *name, double range[2] = NULL);
869
870    // Spheres
871
872    bool addSphere(const DataSetId& id, double center[3], double radius, bool flipNormals = false);
873
874    void setSphereSection(const DataSetId& id,
875                          double thetaStart, double thetaEnd,
876                          double phiStart, double phiEnd);
877
878    void setSphereResolution(const DataSetId& id, int thetaRes, int phiRes);
879
880    // Streamlines
881
882    void setStreamlinesColorMode(const DataSetId& id,
883                                 Streamlines::ColorMode mode,
884                                 const char *name, double range[2] = NULL);
885
886    void setStreamlinesColorMode(const DataSetId& id,
887                                 Streamlines::ColorMode mode,
888                                 DataSet::DataAttributeType type,
889                                 const char *name, double range[2] = NULL);
890
891    void setStreamlinesLength(const DataSetId& id, double length);
892
893    void setStreamlinesNumberOfSeedPoints(const DataSetId& id, int numPoints);
894
895    void setStreamlinesSeedColor(const DataSetId& id, float color[3]);
896
897    void setStreamlinesSeedPointSize(const DataSetId& id, float size);
898
899    void setStreamlinesSeedToMeshPoints(const DataSetId& id,
900                                        int maxPoints = 500);
901
902    void setStreamlinesSeedToFilledMesh(const DataSetId& id, int numPoints);
903
904    bool setStreamlinesSeedToMeshPoints(const DataSetId& id,
905                                        char *data, size_t nbytes,
906                                        int maxPoints = 500);
907
908    bool setStreamlinesSeedToFilledMesh(const DataSetId& id,
909                                        char *data, size_t nbytes,
910                                        int numPoints);
911
912    void setStreamlinesSeedToRake(const DataSetId& id,
913                                  double start[3], double end[3],
914                                  int numPoints);
915
916    void setStreamlinesSeedToDisk(const DataSetId& id,
917                                  double center[3], double normal[3],
918                                  double radius, double innerRadius,
919                                  int numPoints);
920
921    void setStreamlinesSeedToPolygon(const DataSetId& id,
922                                     double center[3], double normal[3],
923                                     double angle, double radius,
924                                     int numSides);
925
926    void setStreamlinesSeedToFilledPolygon(const DataSetId& id,
927                                           double center[3], double normal[3],
928                                           double angle, double radius,
929                                           int numSides, int numPoints);
930
931    void setStreamlinesSeedVisibility(const DataSetId& id, bool state);
932
933    void setStreamlinesTerminalSpeed(const DataSetId& id, double speed);
934
935    void setStreamlinesTypeToLines(const DataSetId& id);
936
937    void setStreamlinesTypeToTubes(const DataSetId& id, int numSides, double radius);
938
939    void setStreamlinesTypeToRibbons(const DataSetId& id, double width, double angle);
940
941    // Text3Ds
942
943    bool addText3D(const DataSetId& id, const char *string,
944                   const char *fontFamily, int fontSize,
945                   bool bold = false, bool italic = false, bool shadow = false);
946
947    void setText3DBold(const DataSetId& id, bool state);
948
949    void setText3DFollowCamera(const DataSetId& id, bool state);
950
951    void setText3DFont(const DataSetId& id, const char *fontFamily);
952
953    void setText3DFontSize(const DataSetId& id, int size);
954
955    void setText3DItalic(const DataSetId& id, bool state);
956
957    void setText3DShadow(const DataSetId& id, bool state);
958
959    void setText3DText(const DataSetId& id, const char *text);
960
961    // Volumes
962
963    void setVolumeBlendMode(const DataSetId& id, Volume::BlendMode mode);
964
965    void setVolumeSampleDistance(const DataSetId& id, double distance);
966
967    // Warps
968
969    void setWarpCloudStyle(const DataSetId& id,
970                           Warp::CloudStyle style);
971
972    void setWarpColorMode(const DataSetId& id,
973                          Warp::ColorMode mode,
974                          const char *name, double range[2] = NULL);
975
976    void setWarpColorMode(const DataSetId& id,
977                          Warp::ColorMode mode,
978                          DataSet::DataAttributeType type,
979                          const char *name, double range[2] = NULL);
980
981
982    void setWarpWarpScale(const DataSetId& id, double scale);
983
984private:
985    typedef std::tr1::unordered_map<DataSetId, DataSet *> DataSetHashmap;
986    typedef std::tr1::unordered_map<FieldId, double *> FieldRangeHashmap;
987    typedef std::tr1::unordered_map<ColorMapId, ColorMap *> ColorMapHashmap;
988
989    typedef std::tr1::unordered_map<DataSetId, Arc *> ArcHashmap;
990    typedef std::tr1::unordered_map<DataSetId, Arrow *> ArrowHashmap;
991    typedef std::tr1::unordered_map<DataSetId, Box *> BoxHashmap;
992    typedef std::tr1::unordered_map<DataSetId, Cone *> ConeHashmap;
993    typedef std::tr1::unordered_map<DataSetId, Contour2D *> Contour2DHashmap;
994    typedef std::tr1::unordered_map<DataSetId, Contour3D *> Contour3DHashmap;
995    typedef std::tr1::unordered_map<DataSetId, Cutplane *> CutplaneHashmap;
996    typedef std::tr1::unordered_map<DataSetId, Cylinder *> CylinderHashmap;
997    typedef std::tr1::unordered_map<DataSetId, Disk *> DiskHashmap;
998    typedef std::tr1::unordered_map<DataSetId, Glyphs *> GlyphsHashmap;
999    typedef std::tr1::unordered_map<DataSetId, Group *> GroupHashmap;
1000    typedef std::tr1::unordered_map<DataSetId, HeightMap *> HeightMapHashmap;
1001    typedef std::tr1::unordered_map<DataSetId, Image *> ImageHashmap;
1002    typedef std::tr1::unordered_map<DataSetId, ImageCutplane *> ImageCutplaneHashmap;
1003    typedef std::tr1::unordered_map<DataSetId, LIC *> LICHashmap;
1004    typedef std::tr1::unordered_map<DataSetId, Line *> LineHashmap;
1005    typedef std::tr1::unordered_map<DataSetId, Molecule *> MoleculeHashmap;
1006    typedef std::tr1::unordered_map<DataSetId, Outline *> OutlineHashmap;
1007    typedef std::tr1::unordered_map<DataSetId, Parallelepiped *> ParallelepipedHashmap;
1008    typedef std::tr1::unordered_map<DataSetId, PolyData *> PolyDataHashmap;
1009    typedef std::tr1::unordered_map<DataSetId, Polygon *> PolygonHashmap;
1010    typedef std::tr1::unordered_map<DataSetId, PseudoColor *> PseudoColorHashmap;
1011    typedef std::tr1::unordered_map<DataSetId, Sphere *> SphereHashmap;
1012    typedef std::tr1::unordered_map<DataSetId, Streamlines *> StreamlinesHashmap;
1013    typedef std::tr1::unordered_map<DataSetId, Text3D *> Text3DHashmap;
1014    typedef std::tr1::unordered_map<DataSetId, Volume *> VolumeHashmap;
1015    typedef std::tr1::unordered_map<DataSetId, Warp *> WarpHashmap;
1016
1017    void _setCameraZoomRegionPixels(int x, int y, int width, int height);
1018
1019    void _setCameraZoomRegion(double x, double y, double width, double height);
1020
1021    //static void printCameraInfo(vtkCamera *camera);
1022
1023    static void setCameraFromMatrix(vtkCamera *camera, vtkMatrix4x4 &mat);
1024
1025    static void mergeBounds(double *boundsDest, const double *bounds1, const double *bounds2);
1026
1027    template<class T>
1028    std::tr1::unordered_map<DataSetId, T *>& getGraphicsObjectHashmap();
1029
1030    void setObjectAspects(double aspectRatio);
1031
1032    void collectBounds(double *bounds, bool onlyVisible);
1033
1034    void collectUnscaledBounds(double *bounds, bool onlyVisible);
1035
1036    void collectDataRanges();
1037
1038    void collectDataRanges(double *range, const char *name,
1039                           DataSet::DataAttributeType type,
1040                           int component, bool onlyVisible);
1041
1042    void clearFieldRanges();
1043
1044    void clearUserFieldRanges();
1045
1046    void initFieldRanges();
1047
1048    void updateFieldRanges();
1049
1050    void updateColorMap(ColorMap *cmap);
1051
1052    bool colorMapUsed(ColorMap *cmap);
1053
1054    void computeDisplayToWorld(double x, double y, double z, double worldPt[4]);
1055
1056    void computeWorldToDisplay(double x, double y, double z, double displayPt[3]);
1057
1058    void computeScreenWorldCoords();
1059
1060    bool is2D(const double bounds[6],
1061              PrincipalPlane *plane,
1062              double *offset) const;
1063
1064    void initCamera(bool initCameraMode = false);
1065
1066    void sceneBoundsChanged();
1067
1068    void initOrientationMarkers();
1069
1070    void initAxes();
1071
1072    void resetAxes(double bounds[6] = NULL);
1073
1074    void setAxesBounds(double bounds[6] = NULL);
1075
1076    void setAxesRanges();
1077
1078    void computeAxesScale();
1079
1080    void setCameraClippingPlanes();
1081
1082    bool _needsRedraw;
1083    bool _needsAxesReset;
1084    bool _needsCameraClippingRangeReset;
1085    bool _needsCameraReset;
1086
1087    int _windowWidth, _windowHeight;
1088    CameraMode _cameraMode;
1089    Aspect _cameraAspect;
1090    double _imgWorldOrigin[2];
1091    double _imgWorldDims[2];
1092    double _imgWindowWorldDims[2];
1093    double _userImgWorldOrigin[2];
1094    double _userImgWorldDims[2];
1095    PrincipalPlane _imgCameraPlane;
1096    double _imgCameraOffset;
1097    double _screenWorldCoords[4];
1098    double _cameraOrientation[4];
1099    double _cameraZoomRatio;
1100    double _cameraPan[2];
1101    float _bgColor[3];
1102    bool _useCumulativeRange;
1103    bool _cumulativeRangeOnlyVisible;
1104
1105    FieldRangeHashmap _scalarPointDataRange;
1106    FieldRangeHashmap _vectorPointDataRange;
1107    FieldRangeHashmap _vectorCompPointDataRange[3];
1108    FieldRangeHashmap _scalarCellDataRange;
1109    FieldRangeHashmap _vectorCellDataRange;
1110    FieldRangeHashmap _vectorCompCellDataRange[3];
1111    FieldRangeHashmap _scalarFieldDataRange;
1112    FieldRangeHashmap _vectorFieldDataRange;
1113    FieldRangeHashmap _vectorCompFieldDataRange[3];
1114
1115    FieldRangeHashmap _userScalarPointDataRange;
1116    FieldRangeHashmap _userVectorPointDataRange;
1117    FieldRangeHashmap _userVectorCompPointDataRange[3];
1118    FieldRangeHashmap _userScalarCellDataRange;
1119    FieldRangeHashmap _userVectorCellDataRange;
1120    FieldRangeHashmap _userVectorCompCellDataRange[3];
1121    FieldRangeHashmap _userScalarFieldDataRange;
1122    FieldRangeHashmap _userVectorFieldDataRange;
1123    FieldRangeHashmap _userVectorCompFieldDataRange[3];
1124
1125    bool _axesAutoBounds[3];
1126    double _axesUserBounds[6];
1127    AxisRangeMode _axesRangeMode[3];
1128    double _axesScale[3];
1129
1130    ColorMapHashmap _colorMaps;
1131    DataSetHashmap _dataSets;
1132    ArcHashmap _arcs;
1133    ArrowHashmap _arrows;
1134    BoxHashmap _boxes;
1135    ConeHashmap _cones;
1136    Contour2DHashmap _contour2Ds;
1137    Contour3DHashmap _contour3Ds;
1138    CutplaneHashmap _cutplanes;
1139    CylinderHashmap _cylinders;
1140    DiskHashmap _disks;
1141    GlyphsHashmap _glyphs;
1142    GroupHashmap _groups;
1143    HeightMapHashmap _heightMaps;
1144    ImageHashmap _images;
1145    ImageCutplaneHashmap _imageCutplanes;
1146    LICHashmap _lics;
1147    LineHashmap _lines;
1148    MoleculeHashmap _molecules;
1149    OutlineHashmap _outlines;
1150    ParallelepipedHashmap _parallelepipeds;
1151    PolyDataHashmap _polyDatas;
1152    PolygonHashmap _polygons;
1153    PseudoColorHashmap _pseudoColors;
1154    SphereHashmap _spheres;
1155    StreamlinesHashmap _streamlines;
1156    Text3DHashmap _text3Ds;
1157    VolumeHashmap _volumes;
1158    WarpHashmap _warps;
1159
1160    vtkSmartPointer<vtkPlane> _cameraClipPlanes[4];
1161    vtkSmartPointer<vtkPlane> _userClipPlanes[6];
1162    vtkSmartPointer<vtkPlaneCollection> _activeClipPlanes;
1163#ifdef USE_CUSTOM_AXES
1164    vtkSmartPointer<vtkRpCubeAxesActor> _cubeAxesActor;
1165#else
1166    vtkSmartPointer<vtkCubeAxesActor> _cubeAxesActor;
1167#endif
1168    vtkSmartPointer<vtkAxesActor> _axesActor;
1169    vtkSmartPointer<vtkAnnotatedCubeActor> _annotatedCubeActor;
1170    vtkSmartPointer<vtkScalarBarActor> _scalarBarActor;
1171    vtkSmartPointer<vtkRenderer> _renderer;
1172    vtkSmartPointer<vtkRenderer> _legendRenderer;
1173    vtkSmartPointer<vtkRenderWindow> _renderWindow;
1174    vtkSmartPointer<vtkRenderWindow> _legendRenderWindow;
1175};
1176
1177}
1178
1179#endif
Note: See TracBrowser for help on using the repository browser.