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