source: trunk/packages/vizservers/vtkvis/Renderer.h @ 3978

Last change on this file since 3978 was 3961, checked in by ldelgass, 11 years ago

Add volume blendmode option for VTK volume renderer. Also, don't change field
active scalar if requested field not found in dataset (previously, active
scalar field would be cleared to NULL if field not found).

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