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 setCutplaneCloudStyle(const DataSetId& id, |
---|
613 | Cutplane::CloudStyle style); |
---|
614 | |
---|
615 | void setCutplaneOutlineVisibility(const DataSetId& id, bool state); |
---|
616 | |
---|
617 | void setCutplaneSliceVisibility(const DataSetId& id, Axis axis, bool state); |
---|
618 | |
---|
619 | void setCutplaneColorMode(const DataSetId& id, |
---|
620 | Cutplane::ColorMode mode, |
---|
621 | const char *name, double range[2] = NULL); |
---|
622 | |
---|
623 | void setCutplaneColorMode(const DataSetId& id, |
---|
624 | Cutplane::ColorMode mode, |
---|
625 | DataSet::DataAttributeType type, |
---|
626 | const char *name, double range[2] = NULL); |
---|
627 | |
---|
628 | // Cylinders |
---|
629 | |
---|
630 | bool addCylinder(const DataSetId& id, double radius, double height, bool cap); |
---|
631 | |
---|
632 | void setCylinderResolution(const DataSetId& id, int res); |
---|
633 | |
---|
634 | // Disks |
---|
635 | |
---|
636 | bool addDisk(const DataSetId& id, double innerRadius, double outerRadius); |
---|
637 | |
---|
638 | void setDiskResolution(const DataSetId& id, int resRadial, int resCircum); |
---|
639 | |
---|
640 | // Glyphs |
---|
641 | |
---|
642 | bool addGlyphs(const DataSetId& id, Glyphs::GlyphShape shape); |
---|
643 | |
---|
644 | void setGlyphsShape(const DataSetId& id, Glyphs::GlyphShape shape); |
---|
645 | |
---|
646 | void setGlyphsOrientMode(const DataSetId& id, bool state, const char *name); |
---|
647 | |
---|
648 | void setGlyphsColorMode(const DataSetId& id, |
---|
649 | Glyphs::ColorMode mode, |
---|
650 | const char *name, |
---|
651 | double range[2] = NULL); |
---|
652 | |
---|
653 | void setGlyphsScalingMode(const DataSetId& id, |
---|
654 | Glyphs::ScalingMode mode, |
---|
655 | const char *name, |
---|
656 | double range[2] = NULL); |
---|
657 | |
---|
658 | void setGlyphsNormalizeScale(const DataSetId& id, bool normalize); |
---|
659 | |
---|
660 | void setGlyphsScaleFactor(const DataSetId& id, double scale); |
---|
661 | |
---|
662 | // Height maps |
---|
663 | |
---|
664 | bool addHeightMap(const DataSetId& id, int numContours, double heightScale); |
---|
665 | |
---|
666 | bool addHeightMap(const DataSetId& id, const std::vector<double>& contours, double heightScale); |
---|
667 | |
---|
668 | void setHeightMapHeightScale(const DataSetId& id, double scale); |
---|
669 | |
---|
670 | void setHeightMapCloudStyle(const DataSetId& id, |
---|
671 | HeightMap::CloudStyle style); |
---|
672 | |
---|
673 | void setHeightMapNumContours(const DataSetId& id, int numContours); |
---|
674 | |
---|
675 | void setHeightMapContourList(const DataSetId& id, const std::vector<double>& contours); |
---|
676 | |
---|
677 | void setHeightMapContourSurfaceVisibility(const DataSetId& id, bool state); |
---|
678 | |
---|
679 | void setHeightMapContourLineVisibility(const DataSetId& id, bool state); |
---|
680 | |
---|
681 | void setHeightMapContourLineColorMapEnabled(const DataSetId& id, bool mode); |
---|
682 | |
---|
683 | void setHeightMapContourEdgeColor(const DataSetId& id, float color[3]); |
---|
684 | |
---|
685 | void setHeightMapContourEdgeWidth(const DataSetId& id, float edgeWidth); |
---|
686 | |
---|
687 | void setHeightMapColorMode(const DataSetId& id, |
---|
688 | HeightMap::ColorMode mode, |
---|
689 | const char *name, double range[2] = NULL); |
---|
690 | |
---|
691 | void setHeightMapColorMode(const DataSetId& id, |
---|
692 | HeightMap::ColorMode mode, |
---|
693 | DataSet::DataAttributeType type, |
---|
694 | const char *name, double range[2] = NULL); |
---|
695 | |
---|
696 | |
---|
697 | // Lines |
---|
698 | |
---|
699 | bool addLine(const DataSetId& id, double pt1[3], double pt2[3]); |
---|
700 | |
---|
701 | // Molecules |
---|
702 | |
---|
703 | void setMoleculeAtomRadiusScale(const DataSetId& id, double scale); |
---|
704 | |
---|
705 | void setMoleculeBondRadiusScale(const DataSetId& id, double scale); |
---|
706 | |
---|
707 | void setMoleculeAtomScaling(const DataSetId& id, Molecule::AtomScaling scaling); |
---|
708 | |
---|
709 | void setMoleculeAtomVisibility(const DataSetId& id, bool state); |
---|
710 | |
---|
711 | void setMoleculeAtomLabelField(const DataSetId& id, const char *fieldName); |
---|
712 | |
---|
713 | void setMoleculeAtomLabelVisibility(const DataSetId& id, bool state); |
---|
714 | |
---|
715 | void setMoleculeBondVisibility(const DataSetId& id, bool state); |
---|
716 | |
---|
717 | void setMoleculeBondStyle(const DataSetId& id, Molecule::BondStyle style); |
---|
718 | |
---|
719 | void setMoleculeBondColorMode(const DataSetId& id, Molecule::BondColorMode mode); |
---|
720 | |
---|
721 | void setMoleculeBondColor(const DataSetId& id, float color[3]); |
---|
722 | |
---|
723 | void setMoleculeColorMode(const DataSetId& id, |
---|
724 | Molecule::ColorMode mode, |
---|
725 | const char *name, double range[2] = NULL); |
---|
726 | |
---|
727 | void setMoleculeColorMode(const DataSetId& id, |
---|
728 | Molecule::ColorMode mode, |
---|
729 | DataSet::DataAttributeType type, |
---|
730 | const char *name, double range[2] = NULL); |
---|
731 | |
---|
732 | // N-sided Regular Polygons |
---|
733 | |
---|
734 | bool addPolygon(const DataSetId& id, int numSides); |
---|
735 | |
---|
736 | // PolyData meshes |
---|
737 | |
---|
738 | void setPolyDataCloudStyle(const DataSetId& id, |
---|
739 | PolyData::CloudStyle style); |
---|
740 | |
---|
741 | // Color-mapped surfaces |
---|
742 | |
---|
743 | void setPseudoColorCloudStyle(const DataSetId& id, |
---|
744 | PseudoColor::CloudStyle style); |
---|
745 | |
---|
746 | void setPseudoColorColorMode(const DataSetId& id, |
---|
747 | PseudoColor::ColorMode mode, |
---|
748 | const char *name, double range[2] = NULL); |
---|
749 | |
---|
750 | void setPseudoColorColorMode(const DataSetId& id, |
---|
751 | PseudoColor::ColorMode mode, |
---|
752 | DataSet::DataAttributeType type, |
---|
753 | const char *name, double range[2] = NULL); |
---|
754 | |
---|
755 | // Spheres |
---|
756 | |
---|
757 | void setSphereSection(const DataSetId& id, double thetaStart, double thetaEnd, |
---|
758 | double phiStart, double phiEnd); |
---|
759 | |
---|
760 | void setSphereResolution(const DataSetId& id, int thetaRes, int phiRes); |
---|
761 | |
---|
762 | // Streamlines |
---|
763 | |
---|
764 | void setStreamlinesColorMode(const DataSetId& id, |
---|
765 | Streamlines::ColorMode mode, |
---|
766 | const char *name, double range[2] = NULL); |
---|
767 | |
---|
768 | void setStreamlinesColorMode(const DataSetId& id, |
---|
769 | Streamlines::ColorMode mode, |
---|
770 | DataSet::DataAttributeType type, |
---|
771 | const char *name, double range[2] = NULL); |
---|
772 | |
---|
773 | void setStreamlinesLength(const DataSetId& id, double length); |
---|
774 | |
---|
775 | void setStreamlinesNumberOfSeedPoints(const DataSetId& id, int numPoints); |
---|
776 | |
---|
777 | void setStreamlinesSeedColor(const DataSetId& id, float color[3]); |
---|
778 | |
---|
779 | void setStreamlinesSeedPointSize(const DataSetId& id, float size); |
---|
780 | |
---|
781 | void setStreamlinesSeedToMeshPoints(const DataSetId& id, |
---|
782 | int maxPoints = 500); |
---|
783 | |
---|
784 | void setStreamlinesSeedToFilledMesh(const DataSetId& id, int numPoints); |
---|
785 | |
---|
786 | bool setStreamlinesSeedToMeshPoints(const DataSetId& id, |
---|
787 | char *data, size_t nbytes, |
---|
788 | int maxPoints = 500); |
---|
789 | |
---|
790 | bool setStreamlinesSeedToFilledMesh(const DataSetId& id, |
---|
791 | char *data, size_t nbytes, |
---|
792 | int numPoints); |
---|
793 | |
---|
794 | void setStreamlinesSeedToRake(const DataSetId& id, |
---|
795 | double start[3], double end[3], |
---|
796 | int numPoints); |
---|
797 | |
---|
798 | void setStreamlinesSeedToDisk(const DataSetId& id, |
---|
799 | double center[3], double normal[3], |
---|
800 | double radius, double innerRadius, |
---|
801 | int numPoints); |
---|
802 | |
---|
803 | void setStreamlinesSeedToPolygon(const DataSetId& id, |
---|
804 | double center[3], double normal[3], |
---|
805 | double angle, double radius, |
---|
806 | int numSides); |
---|
807 | |
---|
808 | void setStreamlinesSeedToFilledPolygon(const DataSetId& id, |
---|
809 | double center[3], double normal[3], |
---|
810 | double angle, double radius, |
---|
811 | int numSides, int numPoints); |
---|
812 | |
---|
813 | void setStreamlinesSeedVisibility(const DataSetId& id, bool state); |
---|
814 | |
---|
815 | void setStreamlinesTerminalSpeed(const DataSetId& id, double speed); |
---|
816 | |
---|
817 | void setStreamlinesTypeToLines(const DataSetId& id); |
---|
818 | |
---|
819 | void setStreamlinesTypeToTubes(const DataSetId& id, int numSides, double radius); |
---|
820 | |
---|
821 | void setStreamlinesTypeToRibbons(const DataSetId& id, double width, double angle); |
---|
822 | |
---|
823 | // Volumes |
---|
824 | |
---|
825 | void setVolumeSampleDistance(const DataSetId& id, double distance); |
---|
826 | |
---|
827 | // Warps |
---|
828 | |
---|
829 | void setWarpCloudStyle(const DataSetId& id, |
---|
830 | Warp::CloudStyle style); |
---|
831 | |
---|
832 | void setWarpColorMode(const DataSetId& id, |
---|
833 | Warp::ColorMode mode, |
---|
834 | const char *name, double range[2] = NULL); |
---|
835 | |
---|
836 | void setWarpColorMode(const DataSetId& id, |
---|
837 | Warp::ColorMode mode, |
---|
838 | DataSet::DataAttributeType type, |
---|
839 | const char *name, double range[2] = NULL); |
---|
840 | |
---|
841 | |
---|
842 | void setWarpWarpScale(const DataSetId& id, double scale); |
---|
843 | |
---|
844 | private: |
---|
845 | typedef std::tr1::unordered_map<DataSetId, DataSet *> DataSetHashmap; |
---|
846 | typedef std::tr1::unordered_map<FieldId, double *> FieldRangeHashmap; |
---|
847 | typedef std::tr1::unordered_map<ColorMapId, ColorMap *> ColorMapHashmap; |
---|
848 | |
---|
849 | typedef std::tr1::unordered_map<DataSetId, Arc *> ArcHashmap; |
---|
850 | typedef std::tr1::unordered_map<DataSetId, Arrow *> ArrowHashmap; |
---|
851 | typedef std::tr1::unordered_map<DataSetId, Box *> BoxHashmap; |
---|
852 | typedef std::tr1::unordered_map<DataSetId, Cone *> ConeHashmap; |
---|
853 | typedef std::tr1::unordered_map<DataSetId, Contour2D *> Contour2DHashmap; |
---|
854 | typedef std::tr1::unordered_map<DataSetId, Contour3D *> Contour3DHashmap; |
---|
855 | typedef std::tr1::unordered_map<DataSetId, Cutplane *> CutplaneHashmap; |
---|
856 | typedef std::tr1::unordered_map<DataSetId, Cylinder *> CylinderHashmap; |
---|
857 | typedef std::tr1::unordered_map<DataSetId, Disk *> DiskHashmap; |
---|
858 | typedef std::tr1::unordered_map<DataSetId, Glyphs *> GlyphsHashmap; |
---|
859 | typedef std::tr1::unordered_map<DataSetId, Group *> GroupHashmap; |
---|
860 | typedef std::tr1::unordered_map<DataSetId, HeightMap *> HeightMapHashmap; |
---|
861 | typedef std::tr1::unordered_map<DataSetId, LIC *> LICHashmap; |
---|
862 | typedef std::tr1::unordered_map<DataSetId, Line *> LineHashmap; |
---|
863 | typedef std::tr1::unordered_map<DataSetId, Molecule *> MoleculeHashmap; |
---|
864 | typedef std::tr1::unordered_map<DataSetId, Outline *> OutlineHashmap; |
---|
865 | typedef std::tr1::unordered_map<DataSetId, PolyData *> PolyDataHashmap; |
---|
866 | typedef std::tr1::unordered_map<DataSetId, Polygon *> PolygonHashmap; |
---|
867 | typedef std::tr1::unordered_map<DataSetId, PseudoColor *> PseudoColorHashmap; |
---|
868 | typedef std::tr1::unordered_map<DataSetId, Sphere *> SphereHashmap; |
---|
869 | typedef std::tr1::unordered_map<DataSetId, Streamlines *> StreamlinesHashmap; |
---|
870 | typedef std::tr1::unordered_map<DataSetId, Volume *> VolumeHashmap; |
---|
871 | typedef std::tr1::unordered_map<DataSetId, Warp *> WarpHashmap; |
---|
872 | |
---|
873 | void _setCameraZoomRegionPixels(int x, int y, int width, int height); |
---|
874 | |
---|
875 | void _setCameraZoomRegion(double x, double y, double width, double height); |
---|
876 | |
---|
877 | //static void printCameraInfo(vtkCamera *camera); |
---|
878 | |
---|
879 | static void setCameraFromMatrix(vtkCamera *camera, vtkMatrix4x4 &mat); |
---|
880 | |
---|
881 | static void mergeBounds(double *boundsDest, const double *bounds1, const double *bounds2); |
---|
882 | |
---|
883 | template<class T> |
---|
884 | std::tr1::unordered_map<DataSetId, T *>& getGraphicsObjectHashmap(); |
---|
885 | |
---|
886 | void setObjectAspects(double aspectRatio); |
---|
887 | |
---|
888 | void collectBounds(double *bounds, bool onlyVisible); |
---|
889 | |
---|
890 | void collectUnscaledBounds(double *bounds, bool onlyVisible); |
---|
891 | |
---|
892 | void collectDataRanges(); |
---|
893 | |
---|
894 | void collectDataRanges(double *range, const char *name, |
---|
895 | DataSet::DataAttributeType type, |
---|
896 | int component, bool onlyVisible); |
---|
897 | |
---|
898 | void clearFieldRanges(); |
---|
899 | |
---|
900 | void clearUserFieldRanges(); |
---|
901 | |
---|
902 | void initFieldRanges(); |
---|
903 | |
---|
904 | void updateFieldRanges(); |
---|
905 | |
---|
906 | void updateColorMap(ColorMap *cmap); |
---|
907 | |
---|
908 | bool colorMapUsed(ColorMap *cmap); |
---|
909 | |
---|
910 | void computeDisplayToWorld(double x, double y, double z, double worldPt[4]); |
---|
911 | |
---|
912 | void computeWorldToDisplay(double x, double y, double z, double displayPt[3]); |
---|
913 | |
---|
914 | void computeScreenWorldCoords(); |
---|
915 | |
---|
916 | bool is2D(const double bounds[6], |
---|
917 | PrincipalPlane *plane, |
---|
918 | double *offset) const; |
---|
919 | |
---|
920 | void initCamera(bool initCameraMode = false); |
---|
921 | |
---|
922 | void sceneBoundsChanged(); |
---|
923 | |
---|
924 | void initAxes(); |
---|
925 | |
---|
926 | void resetAxes(double bounds[6] = NULL); |
---|
927 | |
---|
928 | void setAxesBounds(double bounds[6] = NULL); |
---|
929 | |
---|
930 | void setAxesRanges(); |
---|
931 | |
---|
932 | void computeAxesScale(); |
---|
933 | |
---|
934 | void setCameraClippingPlanes(); |
---|
935 | |
---|
936 | bool _needsRedraw; |
---|
937 | bool _needsAxesReset; |
---|
938 | bool _needsCameraClippingRangeReset; |
---|
939 | bool _needsCameraReset; |
---|
940 | |
---|
941 | int _windowWidth, _windowHeight; |
---|
942 | CameraMode _cameraMode; |
---|
943 | Aspect _cameraAspect; |
---|
944 | double _imgWorldOrigin[2]; |
---|
945 | double _imgWorldDims[2]; |
---|
946 | double _imgWindowWorldDims[2]; |
---|
947 | double _userImgWorldOrigin[2]; |
---|
948 | double _userImgWorldDims[2]; |
---|
949 | PrincipalPlane _imgCameraPlane; |
---|
950 | double _imgCameraOffset; |
---|
951 | double _screenWorldCoords[4]; |
---|
952 | double _cameraOrientation[4]; |
---|
953 | double _cameraZoomRatio; |
---|
954 | double _cameraPan[2]; |
---|
955 | float _bgColor[3]; |
---|
956 | bool _useCumulativeRange; |
---|
957 | bool _cumulativeRangeOnlyVisible; |
---|
958 | |
---|
959 | FieldRangeHashmap _scalarPointDataRange; |
---|
960 | FieldRangeHashmap _vectorPointDataRange; |
---|
961 | FieldRangeHashmap _vectorCompPointDataRange[3]; |
---|
962 | FieldRangeHashmap _scalarCellDataRange; |
---|
963 | FieldRangeHashmap _vectorCellDataRange; |
---|
964 | FieldRangeHashmap _vectorCompCellDataRange[3]; |
---|
965 | |
---|
966 | FieldRangeHashmap _userScalarPointDataRange; |
---|
967 | FieldRangeHashmap _userVectorPointDataRange; |
---|
968 | FieldRangeHashmap _userVectorCompPointDataRange[3]; |
---|
969 | FieldRangeHashmap _userScalarCellDataRange; |
---|
970 | FieldRangeHashmap _userVectorCellDataRange; |
---|
971 | FieldRangeHashmap _userVectorCompCellDataRange[3]; |
---|
972 | |
---|
973 | bool _axesAutoBounds[3]; |
---|
974 | double _axesUserBounds[6]; |
---|
975 | AxisRangeMode _axesRangeMode[3]; |
---|
976 | double _axesScale[3]; |
---|
977 | |
---|
978 | ColorMapHashmap _colorMaps; |
---|
979 | DataSetHashmap _dataSets; |
---|
980 | ArcHashmap _arcs; |
---|
981 | ArrowHashmap _arrows; |
---|
982 | BoxHashmap _boxes; |
---|
983 | ConeHashmap _cones; |
---|
984 | Contour2DHashmap _contour2Ds; |
---|
985 | Contour3DHashmap _contour3Ds; |
---|
986 | CutplaneHashmap _cutplanes; |
---|
987 | CylinderHashmap _cylinders; |
---|
988 | DiskHashmap _disks; |
---|
989 | GlyphsHashmap _glyphs; |
---|
990 | GroupHashmap _groups; |
---|
991 | HeightMapHashmap _heightMaps; |
---|
992 | LICHashmap _lics; |
---|
993 | LineHashmap _lines; |
---|
994 | MoleculeHashmap _molecules; |
---|
995 | OutlineHashmap _outlines; |
---|
996 | PolyDataHashmap _polyDatas; |
---|
997 | PolygonHashmap _polygons; |
---|
998 | PseudoColorHashmap _pseudoColors; |
---|
999 | SphereHashmap _spheres; |
---|
1000 | StreamlinesHashmap _streamlines; |
---|
1001 | VolumeHashmap _volumes; |
---|
1002 | WarpHashmap _warps; |
---|
1003 | |
---|
1004 | vtkSmartPointer<vtkPlane> _cameraClipPlanes[4]; |
---|
1005 | vtkSmartPointer<vtkPlane> _userClipPlanes[6]; |
---|
1006 | vtkSmartPointer<vtkPlaneCollection> _activeClipPlanes; |
---|
1007 | #ifdef USE_CUSTOM_AXES |
---|
1008 | vtkSmartPointer<vtkRpCubeAxesActor> _cubeAxesActor; |
---|
1009 | #else |
---|
1010 | vtkSmartPointer<vtkCubeAxesActor> _cubeAxesActor; |
---|
1011 | #endif |
---|
1012 | vtkSmartPointer<vtkScalarBarActor> _scalarBarActor; |
---|
1013 | vtkSmartPointer<vtkRenderer> _renderer; |
---|
1014 | vtkSmartPointer<vtkRenderer> _legendRenderer; |
---|
1015 | vtkSmartPointer<vtkRenderWindow> _renderWindow; |
---|
1016 | vtkSmartPointer<vtkRenderWindow> _legendRenderWindow; |
---|
1017 | }; |
---|
1018 | |
---|
1019 | } |
---|
1020 | |
---|
1021 | #endif |
---|