|
@@ -0,0 +1,700 @@
|
|
1
|
+#ifdef LEMMAUSEVTK
|
|
2
|
+
|
|
3
|
+#include "matplot.h"
|
|
4
|
+
|
|
5
|
+#include "vtkActor.h"
|
|
6
|
+#include "vtkAxesActor.h"
|
|
7
|
+#include "vtkCamera.h"
|
|
8
|
+#include "vtkCaptionActor2D.h"
|
|
9
|
+#include "vtkContourFilter.h"
|
|
10
|
+#include "vtkDataSetMapper.h"
|
|
11
|
+#include "vtkGlyph3D.h"
|
|
12
|
+#include "vtkGlyphSource2D.h"
|
|
13
|
+#include "vtkOutlineFilter.h"
|
|
14
|
+#include "vtkPolyData.h"
|
|
15
|
+#include "vtkPolyDataMapper.h"
|
|
16
|
+#include "vtkPNGWriter.h"
|
|
17
|
+#include "vtkProperty.h"
|
|
18
|
+#include "vtkProperty2D.h"
|
|
19
|
+#include "vtkRectilinearGridGeometryFilter.h"
|
|
20
|
+#include "vtkRenderWindow.h"
|
|
21
|
+#include "vtkRenderWindowInteractor.h"
|
|
22
|
+#include "vtkStructuredGridGeometryFilter.h"
|
|
23
|
+#include "vtkScalarBarActor.h"
|
|
24
|
+#include "vtkTextProperty.h"
|
|
25
|
+#include "vtkTubeFilter.h"
|
|
26
|
+#include "vtkWarpScalar.h"
|
|
27
|
+#include "vtkWindowToImageFilter.h"
|
|
28
|
+#include "vtkRenderLargeImage.h"
|
|
29
|
+
|
|
30
|
+#include "vtkTextActor.h"
|
|
31
|
+#include "vtkVectorText.h"
|
|
32
|
+#include "vtkTransformPolyDataFilter.h"
|
|
33
|
+#include "vtkTransform.h"
|
|
34
|
+#include "vtkFollower.h"
|
|
35
|
+
|
|
36
|
+#include "vtkAxisActor2D.h"
|
|
37
|
+//#include "vtkCubeAxesActor.h"
|
|
38
|
+#include "vtkCubeAxesActor2D.h"
|
|
39
|
+
|
|
40
|
+using namespace matplot;
|
|
41
|
+
|
|
42
|
+/// Default constructor
|
|
43
|
+Plot2D_VTK::Plot2D_VTK(std::string x_label, std::string y_label,
|
|
44
|
+ int xpix, int ypix, bool semilogX)
|
|
45
|
+{
|
|
46
|
+ semilogx = semilogX;
|
|
47
|
+ xPix = xpix;
|
|
48
|
+ yPix = ypix;
|
|
49
|
+
|
|
50
|
+ plot_no = 0;
|
|
51
|
+
|
|
52
|
+ // set up the renderer
|
|
53
|
+ rend = vtkRenderer::New();
|
|
54
|
+ rend->SetBackground(1., 1., 1.);
|
|
55
|
+
|
|
56
|
+ // set up the xy plot
|
|
57
|
+ xyplot = vtkXYPlotActor::New();
|
|
58
|
+
|
|
59
|
+ xyplot->GetProperty()->SetColor(0.0, 0.0, 0.0);
|
|
60
|
+
|
|
61
|
+ xyplot->SetBorder(10);
|
|
62
|
+ xyplot->GetPositionCoordinate()->SetValue(0.0, 0.0, 0);
|
|
63
|
+ xyplot->GetPosition2Coordinate()->SetValue(1.0, 1.0, 0);
|
|
64
|
+
|
|
65
|
+ xyplot->GetProperty()->SetLineWidth(1);
|
|
66
|
+ xyplot->GetProperty()->SetPointSize(5);
|
|
67
|
+
|
|
68
|
+ xyplot->PlotPointsOff();
|
|
69
|
+ xyplot->PlotLinesOff();
|
|
70
|
+ xyplot->PlotCurvePointsOn();
|
|
71
|
+ xyplot->PlotCurveLinesOn();
|
|
72
|
+
|
|
73
|
+ xyplot->SetXValuesToArcLength();
|
|
74
|
+
|
|
75
|
+ xyplot->SetLabelFormat("%2.1f");
|
|
76
|
+ xyplot->SetTitle("");
|
|
77
|
+ xyplot->SetXTitle(x_label.c_str());
|
|
78
|
+ xyplot->SetYTitle(y_label.c_str());
|
|
79
|
+
|
|
80
|
+ if (semilogx) {
|
|
81
|
+ xyplot->LogxOn();
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ vtkTextProperty* text_prop = xyplot->GetTitleTextProperty();
|
|
85
|
+ text_prop->SetColor(0.0, 0.0, 0.0);
|
|
86
|
+ text_prop->SetFontFamilyToArial();
|
|
87
|
+ xyplot->SetAxisTitleTextProperty(text_prop);
|
|
88
|
+ xyplot->SetAxisLabelTextProperty(text_prop);
|
|
89
|
+ xyplot->SetTitleTextProperty(text_prop);
|
|
90
|
+}
|
|
91
|
+
|
|
92
|
+/// Destructor
|
|
93
|
+Plot2D_VTK::~Plot2D_VTK()
|
|
94
|
+{
|
|
95
|
+ xyplot->Delete();
|
|
96
|
+ rend->Delete();
|
|
97
|
+}
|
|
98
|
+
|
|
99
|
+/// Render current figure to screen
|
|
100
|
+void Plot2D_VTK::show()
|
|
101
|
+{
|
|
102
|
+ rend->AddActor(xyplot);
|
|
103
|
+ render_interactive(rend,xPix,yPix);
|
|
104
|
+}
|
|
105
|
+
|
|
106
|
+/// Render current figure to file
|
|
107
|
+void Plot2D_VTK::draw_to_png(std::string filename)
|
|
108
|
+{
|
|
109
|
+ rend->AddActor(xyplot);
|
|
110
|
+ render_to_png(rend,xPix,yPix,filename);
|
|
111
|
+}
|
|
112
|
+//==============================================================================
|
|
113
|
+
|
|
114
|
+Surf_VTK::Surf_VTK(int px, int py)
|
|
115
|
+{
|
|
116
|
+ has_data = false;
|
|
117
|
+ Lxy = -1;
|
|
118
|
+ Lz = -1;
|
|
119
|
+ xPix = px;
|
|
120
|
+ yPix = py;
|
|
121
|
+
|
|
122
|
+ gridfunc = vtkStructuredGrid::New();
|
|
123
|
+ rend = vtkRenderer::New();
|
|
124
|
+}
|
|
125
|
+
|
|
126
|
+/// Destructor
|
|
127
|
+Surf_VTK::~Surf_VTK()
|
|
128
|
+{
|
|
129
|
+ gridfunc->Delete();
|
|
130
|
+ rend->Delete();
|
|
131
|
+}
|
|
132
|
+
|
|
133
|
+/// Clear plot data before reuse
|
|
134
|
+void Surf_VTK::purge()
|
|
135
|
+{
|
|
136
|
+ assert(has_data);
|
|
137
|
+ gridfunc->Delete();
|
|
138
|
+ rend->Delete();
|
|
139
|
+ gridfunc = vtkStructuredGrid::New();
|
|
140
|
+ rend = vtkRenderer::New();
|
|
141
|
+ has_data = false;
|
|
142
|
+ Lxy = -1;
|
|
143
|
+ Lz = -1;
|
|
144
|
+}
|
|
145
|
+
|
|
146
|
+void Surf_VTK::renderer(bool draw_axes, bool draw_colorbar, bool draw_box,
|
|
147
|
+ bool do_warp)
|
|
148
|
+{
|
|
149
|
+ assert(has_data);
|
|
150
|
+
|
|
151
|
+ // filter to geometry primitive
|
|
152
|
+ vtkStructuredGridGeometryFilter *geometry =
|
|
153
|
+ vtkStructuredGridGeometryFilter::New();
|
|
154
|
+ geometry->SetInputData(gridfunc);
|
|
155
|
+
|
|
156
|
+ // warp to fit in box
|
|
157
|
+ vtkWarpScalar *warp = vtkWarpScalar::New();
|
|
158
|
+ if (do_warp)
|
|
159
|
+ {
|
|
160
|
+ double scale = Lxy/Lz;
|
|
161
|
+ warp->SetInputConnection(geometry->GetOutputPort());
|
|
162
|
+ warp->XYPlaneOn();
|
|
163
|
+ warp->SetScaleFactor(scale);
|
|
164
|
+ }
|
|
165
|
+
|
|
166
|
+ // map gridfunction
|
|
167
|
+ vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
|
|
168
|
+ if (do_warp)
|
|
169
|
+ mapper->SetInputConnection(warp->GetOutputPort());
|
|
170
|
+ else
|
|
171
|
+ mapper->SetInputConnection(geometry->GetOutputPort());
|
|
172
|
+
|
|
173
|
+ double tmp[2];
|
|
174
|
+ gridfunc->GetScalarRange(tmp);
|
|
175
|
+ mapper->SetScalarRange(tmp[0], tmp[1]);
|
|
176
|
+
|
|
177
|
+ // create plot surface actor
|
|
178
|
+ vtkActor *surfplot = vtkActor::New();
|
|
179
|
+ surfplot->SetMapper(mapper);
|
|
180
|
+
|
|
181
|
+ // create outline
|
|
182
|
+ vtkOutlineFilter *outlinefilter = vtkOutlineFilter::New();
|
|
183
|
+ if (do_warp)
|
|
184
|
+ outlinefilter->SetInputConnection(warp->GetOutputPort());
|
|
185
|
+ else
|
|
186
|
+ outlinefilter->SetInputConnection(geometry->GetOutputPort());
|
|
187
|
+ vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
|
|
188
|
+ outlineMapper->SetInputConnection(outlinefilter->GetOutputPort());
|
|
189
|
+ vtkActor *outline = vtkActor::New();
|
|
190
|
+ outline->SetMapper(outlineMapper);
|
|
191
|
+ outline->GetProperty()->SetColor(0, 0, 0);
|
|
192
|
+
|
|
193
|
+ // create axes
|
|
194
|
+ vtkAxesActor* axes = vtkAxesActor::New();
|
|
195
|
+ axes->SetShaftTypeToCylinder();
|
|
196
|
+ axes->SetNormalizedShaftLength( 0.85, 0.85, 0.85);
|
|
197
|
+ axes->SetNormalizedTipLength( 0.15, 0.15, 0.15);
|
|
198
|
+ axes->SetCylinderRadius( 0.500 * axes->GetCylinderRadius() );
|
|
199
|
+ axes->SetConeRadius( 1.025 * axes->GetConeRadius() );
|
|
200
|
+ axes->SetSphereRadius( 1.500 * axes->GetSphereRadius() );
|
|
201
|
+ vtkTextProperty* text_prop_ax = axes->GetXAxisCaptionActor2D()->
|
|
202
|
+ GetCaptionTextProperty();
|
|
203
|
+ text_prop_ax->SetColor(0.0, 0.0, 0.0);
|
|
204
|
+ text_prop_ax->SetFontFamilyToArial();
|
|
205
|
+ text_prop_ax->SetFontSize(8);
|
|
206
|
+ axes->GetYAxisCaptionActor2D()->GetCaptionTextProperty()->
|
|
207
|
+ ShallowCopy(text_prop_ax);
|
|
208
|
+ axes->GetZAxisCaptionActor2D()->GetCaptionTextProperty()->
|
|
209
|
+ ShallowCopy(text_prop_ax);
|
|
210
|
+
|
|
211
|
+ // create colorbar
|
|
212
|
+ vtkScalarBarActor *colorbar = vtkScalarBarActor::New();
|
|
213
|
+ colorbar->SetLookupTable(mapper->GetLookupTable());
|
|
214
|
+ colorbar->SetWidth(0.085);
|
|
215
|
+ colorbar->SetHeight(0.9);
|
|
216
|
+ colorbar->SetPosition(0.9, 0.1);
|
|
217
|
+ vtkTextProperty* text_prop_cb = colorbar->GetLabelTextProperty();
|
|
218
|
+ text_prop_cb->SetColor(1.0, 1.0, 1.0);
|
|
219
|
+ colorbar->SetLabelTextProperty(text_prop_cb);
|
|
220
|
+
|
|
221
|
+ // renderer
|
|
222
|
+ rend->AddActor(surfplot);
|
|
223
|
+ if (draw_box)
|
|
224
|
+ rend->AddActor(outline);
|
|
225
|
+ if (draw_axes)
|
|
226
|
+ rend->AddActor(axes);
|
|
227
|
+ if (draw_colorbar)
|
|
228
|
+ rend->AddActor(colorbar);
|
|
229
|
+
|
|
230
|
+ rend->SetBackground(0.25, 0.25, 0.25);
|
|
231
|
+
|
|
232
|
+ // renderer is now set up!
|
|
233
|
+
|
|
234
|
+ // clean up
|
|
235
|
+ colorbar->Delete();
|
|
236
|
+ warp->Delete();
|
|
237
|
+ axes->Delete();
|
|
238
|
+ outline->Delete();
|
|
239
|
+ outlinefilter->Delete();
|
|
240
|
+ outlineMapper->Delete();
|
|
241
|
+ surfplot->Delete();
|
|
242
|
+ mapper->Delete();
|
|
243
|
+ geometry->Delete();
|
|
244
|
+}
|
|
245
|
+//==============================================================================
|
|
246
|
+
|
|
247
|
+/// Default constructor
|
|
248
|
+Contour_VTK::Contour_VTK(int px, int py)
|
|
249
|
+{
|
|
250
|
+ XScale = LINEAR;
|
|
251
|
+ YScale = LINEAR;
|
|
252
|
+
|
|
253
|
+ has_data = false;
|
|
254
|
+ xPix = px;
|
|
255
|
+ yPix = py;
|
|
256
|
+
|
|
257
|
+ gridfunc = vtkRectilinearGrid::New();
|
|
258
|
+ rend = vtkRenderer::New();
|
|
259
|
+}
|
|
260
|
+
|
|
261
|
+/// Default constructor
|
|
262
|
+Contour_VTK::Contour_VTK(int px, int py, SCALE xsc, SCALE ysc)
|
|
263
|
+{
|
|
264
|
+ XScale = xsc;
|
|
265
|
+ YScale = ysc;
|
|
266
|
+
|
|
267
|
+ xlabel = "x";
|
|
268
|
+ ylabel = "y";
|
|
269
|
+
|
|
270
|
+ has_data = false;
|
|
271
|
+ xPix = px;
|
|
272
|
+ yPix = py;
|
|
273
|
+
|
|
274
|
+ gridfunc = vtkRectilinearGrid::New();
|
|
275
|
+ rend = vtkRenderer::New();
|
|
276
|
+}
|
|
277
|
+
|
|
278
|
+/// Destructor
|
|
279
|
+Contour_VTK::~Contour_VTK()
|
|
280
|
+{
|
|
281
|
+ gridfunc->Delete();
|
|
282
|
+ rend->Delete();
|
|
283
|
+}
|
|
284
|
+
|
|
285
|
+/// Clear plot data before reuse
|
|
286
|
+void Contour_VTK::purge()
|
|
287
|
+{
|
|
288
|
+ assert(has_data);
|
|
289
|
+ gridfunc->Delete();
|
|
290
|
+ rend->Delete();
|
|
291
|
+ gridfunc = vtkRectilinearGrid::New();
|
|
292
|
+ rend = vtkRenderer::New();
|
|
293
|
+ has_data = false;
|
|
294
|
+}
|
|
295
|
+
|
|
296
|
+/// Set labels for contour plots
|
|
297
|
+void Contour_VTK::SetXLabel(const std::string &xlab) {
|
|
298
|
+ xlabel = xlab;
|
|
299
|
+}
|
|
300
|
+
|
|
301
|
+void Contour_VTK::SetYLabel(const std::string &ylab ) {
|
|
302
|
+ ylabel = ylab;
|
|
303
|
+}
|
|
304
|
+
|
|
305
|
+void Contour_VTK::renderer(bool draw_colorbar, bool draw_surf, int lines)
|
|
306
|
+{
|
|
307
|
+ assert(has_data);
|
|
308
|
+
|
|
309
|
+ // filter to geometry primitive
|
|
310
|
+ vtkRectilinearGridGeometryFilter *geometry =
|
|
311
|
+ vtkRectilinearGridGeometryFilter::New();
|
|
312
|
+ geometry->SetInputData(gridfunc);
|
|
313
|
+
|
|
314
|
+ // map gridfunction
|
|
315
|
+ vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
|
|
316
|
+ mapper->SetInputConnection(geometry->GetOutputPort());
|
|
317
|
+
|
|
318
|
+ double tmp[2];
|
|
319
|
+ gridfunc->GetScalarRange(tmp);
|
|
320
|
+ mapper->SetScalarRange(tmp[0], tmp[1]);
|
|
321
|
+
|
|
322
|
+ // create plot surface actor
|
|
323
|
+ vtkActor *surfplot = vtkActor::New();
|
|
324
|
+ surfplot->SetMapper(mapper);
|
|
325
|
+
|
|
326
|
+ // create contour lines (10 lines)
|
|
327
|
+ vtkContourFilter *contlines = vtkContourFilter::New();
|
|
328
|
+ contlines->SetInputConnection(geometry->GetOutputPort());
|
|
329
|
+ double tempdiff = (tmp[1]-tmp[0])/(10*lines);
|
|
330
|
+ contlines->GenerateValues(lines, tmp[0]+tempdiff, tmp[1]-tempdiff);
|
|
331
|
+ vtkPolyDataMapper *contourMapper = vtkPolyDataMapper::New();
|
|
332
|
+ contourMapper->SetInputConnection(contlines->GetOutputPort());
|
|
333
|
+ if (draw_surf)
|
|
334
|
+ contourMapper->ScalarVisibilityOff();
|
|
335
|
+ else
|
|
336
|
+ contourMapper->SetScalarRange(tmp[0], tmp[1]);
|
|
337
|
+ vtkActor *contours = vtkActor::New();
|
|
338
|
+ contours->SetMapper(contourMapper);
|
|
339
|
+ contours->GetProperty()->SetOpacity(.25);
|
|
340
|
+ contours->GetProperty()->SetColor(0.5,0.5,0.5);
|
|
341
|
+
|
|
342
|
+ // create outline
|
|
343
|
+ vtkOutlineFilter *outlinefilter = vtkOutlineFilter::New();
|
|
344
|
+ outlinefilter->SetInputConnection(geometry->GetOutputPort());
|
|
345
|
+ vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
|
|
346
|
+ outlineMapper->SetInputConnection(outlinefilter->GetOutputPort());
|
|
347
|
+ vtkActor *outline = vtkActor::New();
|
|
348
|
+ outline->SetMapper(outlineMapper);
|
|
349
|
+ outline->GetProperty()->SetColor(0, 0, 0);
|
|
350
|
+
|
|
351
|
+ // create colorbar
|
|
352
|
+ vtkScalarBarActor *colorbar = vtkScalarBarActor::New();
|
|
353
|
+ if (draw_surf)
|
|
354
|
+ colorbar->SetLookupTable(mapper->GetLookupTable());
|
|
355
|
+ else
|
|
356
|
+ colorbar->SetLookupTable(contourMapper->GetLookupTable());
|
|
357
|
+//
|
|
358
|
+ colorbar->SetWidth(0.085);
|
|
359
|
+ colorbar->SetHeight(0.9);
|
|
360
|
+ colorbar->SetPosition(0.9, 0.1);
|
|
361
|
+ vtkTextProperty* text_prop_cb = colorbar->GetLabelTextProperty();
|
|
362
|
+ text_prop_cb->SetColor(1.0, 1.0, 1.0);
|
|
363
|
+ colorbar->SetLabelTextProperty(text_prop_cb);
|
|
364
|
+
|
|
365
|
+ double xrange[2];
|
|
366
|
+ double yrange[2];
|
|
367
|
+ gridfunc->GetXCoordinates()->GetRange(xrange);
|
|
368
|
+ gridfunc->GetYCoordinates()->GetRange(yrange);
|
|
369
|
+ vtkCubeAxesActor2D *caxis = vtkCubeAxesActor2D::New();
|
|
370
|
+
|
|
371
|
+ caxis->ZAxisVisibilityOff();
|
|
372
|
+ caxis->SetXLabel(xlabel.c_str());
|
|
373
|
+ caxis->SetYLabel(ylabel.c_str());
|
|
374
|
+
|
|
375
|
+ vtkCamera* mycam = rend->MakeCamera(); // vtkCamera::New();
|
|
376
|
+ //rend->SetActiveCamera(mycam);
|
|
377
|
+ caxis->SetBounds( xrange[0], xrange[1], yrange[0], yrange[1], 0, 0);
|
|
378
|
+ caxis->SetRanges( xrange[0], xrange[1], ymin, ymax, 0, 0);
|
|
379
|
+ caxis->SetUseRanges(1);
|
|
380
|
+
|
|
381
|
+ caxis->SetCamera( mycam );
|
|
382
|
+ caxis->SetNumberOfLabels(6);
|
|
383
|
+ // doesn't work, rotate y label 90 degrees
|
|
384
|
+ caxis->GetYAxisActor2D()->GetTitleTextProperty()->SetOrientation(90.);
|
|
385
|
+ rend->AddActor(caxis);
|
|
386
|
+
|
|
387
|
+ mycam->Delete();
|
|
388
|
+ caxis->Delete();
|
|
389
|
+
|
|
390
|
+ // handdrwan label
|
|
391
|
+// // X label
|
|
392
|
+// vtkVectorText *xlabel = vtkVectorText::New();
|
|
393
|
+// vtkTransformPolyDataFilter *transxlabel = vtkTransformPolyDataFilter::New();
|
|
394
|
+// vtkTransform *trans = vtkTransform::New();
|
|
395
|
+// vtkPolyDataMapper *xlabmap = vtkPolyDataMapper::New();
|
|
396
|
+// vtkFollower *xlabact = vtkFollower::New();
|
|
397
|
+ // locate and rotate as needed
|
|
398
|
+ //double yranget = std::abs(yrange[1]-yrange[0]);
|
|
399
|
+ //double xranget = std::abs(xrange[1]-xrange[0]);
|
|
400
|
+// trans->Identity();
|
|
401
|
+// trans->Scale(5,5,5); // TODO, is 5 always OK???
|
|
402
|
+// transxlabel->SetTransform(trans);
|
|
403
|
+// transxlabel->SetInputConnection(xlabel->GetOutputPort());
|
|
404
|
+// // TODO input name
|
|
405
|
+// xlabel->SetText("Frequency [Hz]");
|
|
406
|
+// transxlabel->SetInputConnection(xlabel->GetOutputPort());
|
|
407
|
+// xlabmap->SetInputConnection(transxlabel->GetOutputPort());
|
|
408
|
+// xlabact->SetMapper(xlabmap);
|
|
409
|
+// // centre between axis
|
|
410
|
+// xlabact->SetPosition( (xrange[0]+xrange[1])/2 - xlabact->GetCenter()[0],
|
|
411
|
+// yrange[0]-.2*yranget, 0 );
|
|
412
|
+// //rend->AddActor(xlabact);
|
|
413
|
+// // Y label
|
|
414
|
+// vtkVectorText *ylabel = vtkVectorText::New();
|
|
415
|
+// vtkTransformPolyDataFilter *transylabel = vtkTransformPolyDataFilter::New();
|
|
416
|
+// vtkTransform *ytrans = vtkTransform::New();
|
|
417
|
+// vtkPolyDataMapper *ylabmap = vtkPolyDataMapper::New();
|
|
418
|
+// vtkFollower *ylabact = vtkFollower::New();
|
|
419
|
+// // locate and rotate as needed
|
|
420
|
+// ytrans->Identity();
|
|
421
|
+// ytrans->Scale(5,5,5); // TODO don't hard code, calc from window size maybe??
|
|
422
|
+// ytrans->RotateZ(90);
|
|
423
|
+// transylabel->SetTransform(ytrans);
|
|
424
|
+// transylabel->SetInputConnection(ylabel->GetOutputPort());
|
|
425
|
+//
|
|
426
|
+// ylabel->SetText("Pulse moment [A sec]");
|
|
427
|
+// transylabel->SetInputConnection(ylabel->GetOutputPort());
|
|
428
|
+// ylabmap->SetInputConnection(transylabel->GetOutputPort());
|
|
429
|
+// ylabact->SetMapper(ylabmap);
|
|
430
|
+// ylabact->SetPosition( xrange[0]-.2*xranget,
|
|
431
|
+// (yrange[0]+yrange[1])/2 - ylabact->GetCenter()[1],
|
|
432
|
+// 0 );
|
|
433
|
+// //rend->AddActor(ylabact);
|
|
434
|
+
|
|
435
|
+ if (draw_surf)
|
|
436
|
+ rend->AddActor(surfplot);
|
|
437
|
+
|
|
438
|
+ rend->AddActor(contours);
|
|
439
|
+ rend->AddActor(outline);
|
|
440
|
+ if (draw_colorbar) {
|
|
441
|
+ rend->AddActor(colorbar);
|
|
442
|
+ }
|
|
443
|
+
|
|
444
|
+ rend->SetBackground(0.25, 0.25, 0.25);
|
|
445
|
+
|
|
446
|
+// double xrange[2];
|
|
447
|
+// double yrange[2];
|
|
448
|
+// gridfunc->GetXCoordinates()->GetRange(xrange);
|
|
449
|
+// gridfunc->GetYCoordinates()->GetRange(yrange);
|
|
450
|
+// vtkCubeAxesActor *caxis = vtkCubeAxesActor::New();
|
|
451
|
+// caxis->ZAxisVisibilityOff();
|
|
452
|
+// caxis->SetCamera(rend->GetActiveCamera());
|
|
453
|
+// caxis->SetBounds( xrange[0], xrange[1], yrange[0], yrange[1], 0, 1 );
|
|
454
|
+// rend->AddActor(caxis);
|
|
455
|
+
|
|
456
|
+ //rend->AddActor(yaxis);
|
|
457
|
+// // clean up
|
|
458
|
+// xlabel->Delete();
|
|
459
|
+// transxlabel->Delete();
|
|
460
|
+// trans->Delete();
|
|
461
|
+// xlabmap->Delete();
|
|
462
|
+// xlabact->Delete();
|
|
463
|
+//
|
|
464
|
+// ylabel->Delete();
|
|
465
|
+// transylabel->Delete();
|
|
466
|
+// ytrans->Delete();
|
|
467
|
+// ylabmap->Delete();
|
|
468
|
+// ylabact->Delete();
|
|
469
|
+
|
|
470
|
+ // renderer is now set up!
|
|
471
|
+ //caxis->Delete();
|
|
472
|
+ //yaxis->Delete();
|
|
473
|
+
|
|
474
|
+ contours->Delete();
|
|
475
|
+ contlines->Delete();
|
|
476
|
+ contourMapper->Delete();
|
|
477
|
+ outline->Delete();
|
|
478
|
+ outlinefilter->Delete();
|
|
479
|
+ outlineMapper->Delete();
|
|
480
|
+ colorbar->Delete();
|
|
481
|
+ surfplot->Delete();
|
|
482
|
+ mapper->Delete();
|
|
483
|
+ geometry->Delete();
|
|
484
|
+
|
|
485
|
+}
|
|
486
|
+//==============================================================================
|
|
487
|
+
|
|
488
|
+/// Default constructor
|
|
489
|
+Quiver_VTK::Quiver_VTK(int px, int py)
|
|
490
|
+{
|
|
491
|
+ has_data = false;
|
|
492
|
+ xPix = px;
|
|
493
|
+ yPix = py;
|
|
494
|
+
|
|
495
|
+ gridfunc = vtkRectilinearGrid::New();
|
|
496
|
+ rend = vtkRenderer::New();
|
|
497
|
+}
|
|
498
|
+
|
|
499
|
+/// Destructor
|
|
500
|
+Quiver_VTK::~Quiver_VTK()
|
|
501
|
+{
|
|
502
|
+ gridfunc->Delete();
|
|
503
|
+ rend->Delete();
|
|
504
|
+}
|
|
505
|
+
|
|
506
|
+/// Clear plot data before reuse
|
|
507
|
+void Quiver_VTK::purge()
|
|
508
|
+{
|
|
509
|
+ assert(has_data);
|
|
510
|
+ gridfunc->Delete();
|
|
511
|
+ rend->Delete();
|
|
512
|
+ gridfunc = vtkRectilinearGrid::New();
|
|
513
|
+ rend = vtkRenderer::New();
|
|
514
|
+ has_data = false;
|
|
515
|
+}
|
|
516
|
+
|
|
517
|
+void Quiver_VTK::renderer(double s)
|
|
518
|
+{
|
|
519
|
+ assert(has_data);
|
|
520
|
+
|
|
521
|
+ // filter to geometry primitive
|
|
522
|
+ vtkRectilinearGridGeometryFilter *geometry =
|
|
523
|
+ vtkRectilinearGridGeometryFilter::New();
|
|
524
|
+ geometry->SetInputData(gridfunc);
|
|
525
|
+
|
|
526
|
+ // make a vector glyph
|
|
527
|
+ vtkGlyphSource2D* vec = vtkGlyphSource2D::New();
|
|
528
|
+ vec->SetGlyphTypeToArrow();
|
|
529
|
+ vec->SetScale(s);
|
|
530
|
+ vec->FilledOff();
|
|
531
|
+
|
|
532
|
+ vtkGlyph3D* glyph = vtkGlyph3D::New();
|
|
533
|
+ glyph->SetInputConnection(geometry->GetOutputPort());
|
|
534
|
+ glyph->SetSourceConnection(vec->GetOutputPort());
|
|
535
|
+ glyph->SetColorModeToColorByScalar();
|
|
536
|
+
|
|
537
|
+ // map gridfunction
|
|
538
|
+ vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
|
|
539
|
+ mapper->SetInputConnection(glyph->GetOutputPort());
|
|
540
|
+
|
|
541
|
+ double tmp[2];
|
|
542
|
+ gridfunc->GetScalarRange(tmp);
|
|
543
|
+ mapper->SetScalarRange(tmp[0], tmp[1]);
|
|
544
|
+
|
|
545
|
+ // create plot quiver actor
|
|
546
|
+ vtkActor *quiver_actor = vtkActor::New();
|
|
547
|
+ quiver_actor->SetMapper(mapper);
|
|
548
|
+
|
|
549
|
+ // create colorbar
|
|
550
|
+ vtkScalarBarActor *colorbar = vtkScalarBarActor::New();
|
|
551
|
+ colorbar->SetLookupTable(mapper->GetLookupTable());
|
|
552
|
+ colorbar->SetWidth(0.085);
|
|
553
|
+ colorbar->SetHeight(0.9);
|
|
554
|
+ colorbar->SetPosition(0.9, 0.1);
|
|
555
|
+ vtkTextProperty* text_prop_cb = colorbar->GetLabelTextProperty();
|
|
556
|
+ text_prop_cb->SetColor(1.0, 1.0, 1.0);
|
|
557
|
+ colorbar->SetLabelTextProperty(text_prop_cb);
|
|
558
|
+
|
|
559
|
+ // create outline
|
|
560
|
+ vtkOutlineFilter *outlinefilter = vtkOutlineFilter::New();
|
|
561
|
+ outlinefilter->SetInputConnection(geometry->GetOutputPort());
|
|
562
|
+ vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
|
|
563
|
+ outlineMapper->SetInputConnection(outlinefilter->GetOutputPort());
|
|
564
|
+ vtkActor *outline = vtkActor::New();
|
|
565
|
+ outline->SetMapper(outlineMapper);
|
|
566
|
+ outline->GetProperty()->SetColor(0, 0, 0);
|
|
567
|
+
|
|
568
|
+ // add actors to renderer
|
|
569
|
+ rend->AddActor(quiver_actor);
|
|
570
|
+ rend->AddActor(colorbar);
|
|
571
|
+ rend->AddActor(outline);
|
|
572
|
+ rend->SetBackground(0.25, 0.25, 0.25);
|
|
573
|
+
|
|
574
|
+ // renderer is now set up!
|
|
575
|
+
|
|
576
|
+ // clean up
|
|
577
|
+ outline->Delete();
|
|
578
|
+ outlinefilter->Delete();
|
|
579
|
+ outlineMapper->Delete();
|
|
580
|
+ vec->Delete();
|
|
581
|
+ glyph->Delete();
|
|
582
|
+ colorbar->Delete();
|
|
583
|
+ quiver_actor->Delete();
|
|
584
|
+ mapper->Delete();
|
|
585
|
+
|
|
586
|
+}
|
|
587
|
+
|
|
588
|
+//==============================================================================
|
|
589
|
+
|
|
590
|
+/** Start interactive rendereing (default camera).
|
|
591
|
+ * Sets resolution to (xPix,yPix)
|
|
592
|
+ */
|
|
593
|
+void matplot::render_interactive(vtkRenderer *rend, int xPix, int yPix)
|
|
594
|
+{
|
|
595
|
+ vtkRenderWindow *renWin = vtkRenderWindow::New();
|
|
596
|
+ vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
|
|
597
|
+ renWin->AddRenderer(rend);
|
|
598
|
+ iren->SetRenderWindow(renWin);
|
|
599
|
+ renWin->SetSize(xPix, yPix);
|
|
600
|
+
|
|
601
|
+ // makes first frame look reasonable interactive
|
|
602
|
+ renWin->Render();
|
|
603
|
+ renWin->Start();
|
|
604
|
+
|
|
605
|
+ // Start interactive rendering
|
|
606
|
+ iren->Initialize();
|
|
607
|
+ iren->Start();
|
|
608
|
+ iren->Disable();
|
|
609
|
+ iren->Delete();
|
|
610
|
+ renWin->Delete();
|
|
611
|
+}
|
|
612
|
+
|
|
613
|
+/** Start interactive rendereing (manual camera placement).
|
|
614
|
+ * Sets resolution to (xPix,yPix)
|
|
615
|
+ */
|
|
616
|
+void matplot::render_interactive_cam(vtkRenderer *rend, int xPix, int yPix,
|
|
617
|
+ double cam[3], double focal[3])
|
|
618
|
+{
|
|
619
|
+ rend->GetActiveCamera()->SetViewUp(0, 0, 1);
|
|
620
|
+ rend->GetActiveCamera()->SetPosition(cam);
|
|
621
|
+ rend->GetActiveCamera()->SetFocalPoint(focal);
|
|
622
|
+
|
|
623
|
+ vtkRenderWindow *renWin = vtkRenderWindow::New();
|
|
624
|
+ vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
|
|
625
|
+ renWin->AddRenderer(rend);
|
|
626
|
+ iren->SetRenderWindow(renWin);
|
|
627
|
+ renWin->SetSize(xPix, yPix);
|
|
628
|
+
|
|
629
|
+ // Start interactive rendering
|
|
630
|
+ iren->Initialize();
|
|
631
|
+ iren->Start();
|
|
632
|
+
|
|
633
|
+ iren->Delete();
|
|
634
|
+ renWin->Delete();
|
|
635
|
+}
|
|
636
|
+
|
|
637
|
+/// Renders scene to PNG (default camera)
|
|
638
|
+void matplot::render_to_png(vtkRenderer *rend, int xPix, int yPix,
|
|
639
|
+ std::string fname)
|
|
640
|
+{
|
|
641
|
+ vtkRenderWindow *renWin = vtkRenderWindow::New();
|
|
642
|
+ renWin->AddRenderer(rend);
|
|
643
|
+ renWin->SetSize(xPix, yPix);
|
|
644
|
+ renWin->Render();
|
|
645
|
+ rend->Render();
|
|
646
|
+
|
|
647
|
+ vtkRenderLargeImage* renderLarge = vtkRenderLargeImage::New();
|
|
648
|
+ renderLarge->SetInput(rend);
|
|
649
|
+ renderLarge->SetMagnification(1);
|
|
650
|
+
|
|
651
|
+ vtkPNGWriter *pngfile = vtkPNGWriter::New();
|
|
652
|
+ pngfile->SetFileName(fname.c_str());
|
|
653
|
+ pngfile->SetInputConnection(renderLarge->GetOutputPort());
|
|
654
|
+ pngfile->Update();
|
|
655
|
+ pngfile->Update();
|
|
656
|
+
|
|
657
|
+ pngfile->Update();
|
|
658
|
+ pngfile->Write();
|
|
659
|
+
|
|
660
|
+ renderLarge->Delete();
|
|
661
|
+ pngfile->Delete();
|
|
662
|
+ renWin->Delete();
|
|
663
|
+}
|
|
664
|
+
|
|
665
|
+/// Renders scene to PNG (manual camera placement)
|
|
666
|
+void matplot::render_to_png_cam(vtkRenderer *rend, int xPix, int yPix,
|
|
667
|
+ std::string fname, double cam[3],
|
|
668
|
+ double focal[3])
|
|
669
|
+{
|
|
670
|
+ rend->GetActiveCamera()->SetViewUp(0, 0, 1);
|
|
671
|
+ rend->GetActiveCamera()->SetPosition(cam);
|
|
672
|
+ rend->GetActiveCamera()->SetFocalPoint(focal);
|
|
673
|
+
|
|
674
|
+ vtkRenderWindow *renWin = vtkRenderWindow::New();
|
|
675
|
+ renWin->AddRenderer(rend);
|
|
676
|
+ renWin->SetSize(xPix, yPix);
|
|
677
|
+
|
|
678
|
+ vtkRenderLargeImage* renderLarge = vtkRenderLargeImage::New();
|
|
679
|
+ renderLarge->SetInput(rend);
|
|
680
|
+ renderLarge->SetMagnification(1);
|
|
681
|
+
|
|
682
|
+ //vtkWindowToImageFilter *w2i = vtkWindowToImageFilter::New();
|
|
683
|
+ vtkPNGWriter *pngfile = vtkPNGWriter::New();
|
|
684
|
+ //pngfile->SetInputConnection(w2i->GetOutputPort());
|
|
685
|
+ pngfile->SetInputConnection(renderLarge->GetOutputPort());
|
|
686
|
+ pngfile->SetFileName(fname.c_str());
|
|
687
|
+
|
|
688
|
+ //w2i->SetInput(renWin);
|
|
689
|
+ //w2i->Update();
|
|
690
|
+
|
|
691
|
+ renWin->Render();
|
|
692
|
+ pngfile->Write();
|
|
693
|
+
|
|
694
|
+ //w2i->Delete();
|
|
695
|
+ renderLarge->Delete();
|
|
696
|
+ pngfile->Delete();
|
|
697
|
+ renWin->Delete();
|
|
698
|
+}
|
|
699
|
+
|
|
700
|
+#endif
|