VTKFIG  0.20.20181114
Easy VTK based in situ visualization
vtkfigFigure.cxx
Go to the documentation of this file.
1 #include <vtkTransform.h>
2 #include <vtkCamera.h>
3 #include <vtkProperty2D.h>
4 #include <vtkTextProperty.h>
5 #include <vtkCommand.h>
6 #include <vtkDataSetSurfaceFilter.h>
7 #include <vtkTransformFilter.h>
8 #include <vtkOutlineFilter.h>
9 #include <vtkCubeAxesActor2D.h>
10 #include <vtkMapper.h>
11 #include <vtkMapper2D.h>
12 #include <vtkContextScene.h>
13 
14 
15 #include "vtkfigFigure.h"
16 #include "config.h"
17 
18 namespace vtkfig
19 {
22  {
23 
24 
25  data_producer=vtkSmartPointer<vtkTrivialProducer>::New();
26  boundary_data_producer=vtkSmartPointer<vtkTrivialProducer>::New();
27 
28  surface_lut=BuildLookupTable(surface_rgbtab,state.surface_rgbtab_size);
29  //contour_lut=BuildLookupTable(contour_rgbtab,state.contour_rgbtab_size);
31  quiver_lut=BuildLookupTable(quiver_rgbtab,state.quiver_rgbtab_size);
32  stream_lut=BuildLookupTable(stream_rgbtab,state.stream_rgbtab_size);
33 
36 
37 
38 
39  isoline_filter = vtkSmartPointer<vtkContourFilter>::New();
40  isoline_filter->SetNumberOfContours(11);
41  isosurface_filter = vtkSmartPointer<vtkContourFilter>::New();
42 
43 
44  isosurface_plot = vtkSmartPointer<vtkActor>::New();
45  isoline_plot = vtkSmartPointer<vtkActor>::New();
46  elevation_plot = vtkSmartPointer<vtkActor>::New();
47  surface_plot = vtkSmartPointer<vtkActor>::New();
48 
49 
50 
51  planecutX= vtkSmartPointer<vtkCutter>::New();
52  planecutY= vtkSmartPointer<vtkCutter>::New();
53  planecutZ= vtkSmartPointer<vtkCutter>::New();
54 
55  arrow2d = vtkSmartPointer<vtkGlyphSource2D>::New();
56  arrow2d->SetGlyphTypeToArrow();
57 
58  arrow3ds= vtkSmartPointer<vtkArrowSource>::New();
59  arrow3ds->SetTipResolution(16);
60  arrow3ds->SetTipLength(0.4);
61  arrow3ds->SetTipRadius(0.2);
62  arrow3ds->SetShaftRadius(0.1);
63 
64  arrow3dt=vtkSmartPointer<vtkTransform>::New();
65  arrow3d=vtkSmartPointer<vtkTransformPolyDataFilter>::New();
66  arrow3d->SetTransform(arrow3dt);
67  arrow3d->SetInputConnection(arrow3ds->GetOutputPort());
68 
69 
70  warp_transform = vtkSmartPointer<vtkTransform>::New();
71  warp_transform->Translate(0,0,state.warp_ztran);
72 
73 
74 
75 
76  planeX= vtkSmartPointer<vtkPlane>::New();
77  planeX->SetNormal(1,0,0);
78  planeY= vtkSmartPointer<vtkPlane>::New();
79  planeY->SetNormal(0,1,0);
80  planeZ= vtkSmartPointer<vtkPlane>::New();
81  planeZ->SetNormal(0,0,1);
82 
83 
84  };
85 
86 
88  {
89 
90  if (SubClassName()=="GridView") return;
91  if (SubClassName()=="XYPlot") return;
92  if (SubClassName()=="ChartXY") return;
93  if (SubClassName()=="FigureBase") return;
94  if (SubClassName()=="Surf2D") return;
95 
96  auto data=vtkDataSet::SafeDownCast(data_producer->GetOutputDataObject(0));
97 
98  auto values=vtkDoubleArray::SafeDownCast(data->GetPointData()->GetAbstractArray(dataname.c_str()));
99 
100  if (!values) return;
101 
102  double vrange[2];
103  // If comp (2nd argument) is -1, the range of the magnitude (L2 norm) over all
104  // components will be provided. The range is computed and then
105  // cached, and will not be re-computed on subsequent calls to
106  // GetRange() unless the array is modified or the requested component
107  // changes. THIS METHOD IS NOT THREAD SAFE.
108  values->GetRange(vrange,-1);
109  state.data_vmin=vrange[0];
110  state.data_vmax=vrange[1];
111  }
112 
113 
114  void Figure::SetData(DataSet& vtkfig_data, const std::string name)
115  {
116 
117  this->state.spacedim=vtkfig_data.GetSpaceDimension();
118 
119  this->data_producer->SetOutput(0);
120  this->data_producer->SetOutput(vtkfig_data.GetVTKDataSet());
121  this->data_producer->Modified();
122 
123  this->boundary_data_producer->SetOutput(0);
124  this->boundary_data_producer->SetOutput(vtkfig_data.GetVTKBoundaryDataSet());
125  this->boundary_data_producer->Modified();
126 
128 
129  state.datatype=vtkfig_data.GetDataType();
130 
131  this->dataname=name;
132  this->celllist=0;
133  this->title=name;
134  this->state.coordinate_scale_factor_xyz[0]=vtkfig_data.coordinate_scale_factor*vtkfig_data.coordinate_scale_factor_xyz[0];
135  this->state.coordinate_scale_factor_xyz[1]=vtkfig_data.coordinate_scale_factor*vtkfig_data.coordinate_scale_factor_xyz[1];
136  this->state.coordinate_scale_factor_xyz[2]=vtkfig_data.coordinate_scale_factor*vtkfig_data.coordinate_scale_factor_xyz[2];
137 
138  // We have to inquire properties of data (ranges etc.) here because
139  // in the rendering pipelines they can be used only once
140  // In fact, we should find a way to move these things to the
141  // corresponding derived classes. Idea:
142  // virtual method ExploreData()
143 
144  // Data for scalar/vector stuff
145  SetVMinMax();
146 
147  // Data for grid visualization
148  auto cr=vtkDoubleArray::SafeDownCast(vtkfig_data.GetVTKDataSet()->GetCellData()->GetAbstractArray("cellregions"));
149  if (cr)
150  {
151  double range[2];
152  cr->GetRange(range);
153  cell_lut->SetTableRange(range[0],range[1]);
154  cell_lut->Modified();
155  if (cbar)
156  {
157  cbar->SetNumberOfLabels((int)(range[1]-range[0]+1));
158  cbar->Modified();
159  }
160  }
161 
162  // Data for grid visualization
163  auto boundary_data=vtkfig_data.GetVTKBoundaryDataSet();
164  if (boundary_data)
165  {
166  auto bcr=vtkDoubleArray::SafeDownCast(boundary_data->GetCellData()->GetAbstractArray("boundarycellregions"));
167  if (bcr)
168  {
169  double range[2];
170  bcr->GetRange(range);
171  bface_lut->SetTableRange(range[0],range[1]);
172  bface_lut->Modified();
173  if (bcbar)
174  {
175  bcbar->SetNumberOfLabels((int)(range[1]-range[0]+1));
176  bcbar->Modified();
177  }
178  }
179  }
180 
181  }
182 
183 
184 
185  void Figure::SetMaskedData(DataSet& vtkfig_data, const std::string name,const std::string maskname)
186  {
187  SetData(vtkfig_data,name);
188  celllist=vtkfig_data.GetCellList(maskname);
189  }
190 
191  void Figure::SetData(std::shared_ptr<DataSet> vtkfig_data, const std::string name)
192  {
193  SetData(*vtkfig_data,name);
194  }
195 
196 
197 
198  void Figure::SetMaskedData(std::shared_ptr<DataSet> vtkfig_data, const std::string name,const std::string maskname)
199  {
200  SetMaskedData(*vtkfig_data,name,maskname);
201  }
202 
203 
204  void Figure::SendRGBTable(vtkSmartPointer<internals::Communicator> communicator, RGBTable & rgbtab)
205  {
206  communicator->SendInt(rgbtab.size());
207  communicator->SendDoubleBuffer((double*)rgbtab.data(),rgbtab.size()*sizeof(RGBPoint)/sizeof(double));
208  }
209 
210  void Figure::ReceiveRGBTable(vtkSmartPointer<internals::Communicator> communicator, RGBTable & rgbtab)
211  {
212  int tabsize;
213  communicator->ReceiveInt(tabsize);
214  rgbtab.resize(tabsize);
215  communicator->ReceiveDoubleBuffer((double*)rgbtab.data(),rgbtab.size()*sizeof(RGBPoint)/sizeof(double));
216  }
217 
218 
219 
220 
221 
222 
223  void Figure::RTAddActor(vtkSmartPointer<vtkActor> prop) {actors.push_back(prop);}
224  void Figure::RTAddActor2D(vtkSmartPointer<vtkActor2D> prop) {actors2d.push_back(prop);}
225  void Figure::RTAddContextActor(vtkSmartPointer<vtkContextActor> prop) {ctxactors.push_back(prop);}
226  bool Figure::IsEmpty(void) {return (actors.size()==0 && actors2d.size()==0 && ctxactors.size()==0);}
227 
228 
229 
230 
231  void Figure::RTShowPlanePos(vtkSmartPointer<vtkCutter> planecut, const std::string plane, int idim)
232  {
233  //if (this->SubClassName()!="ScalarView") return;
234  int i=planecut->GetNumberOfContours();
235  if (i>0)
236  {
237  double planepos=data_bounds[2*idim]+ (data_bounds[2*idim+1]-data_bounds[2*idim])*(planecut->GetValue(i-1)+trans_center[idim]-trans_bounds[2*idim]);
238  RTMessage("plane_" + plane +"[" + std::to_string(i-1) + "]=" + std::to_string(planepos));
239  }
240  else
241  {
242  double planepos=data_bounds[2*idim]+ (data_bounds[2*idim+1]-data_bounds[2*idim])*(trans_center[idim]-trans_bounds[2*idim]);
243  RTMessage("[Return] for plane_"+plane+"[0]="+std::to_string(planepos));
244  }
245  }
246 
247 
249  {
250  //if (this->SubClassName()!="ScalarView") return;
251 
252  int i=isoline_filter->GetNumberOfContours();
253  if (i>0)
254  {
255  double isolevel=isoline_filter->GetValue(i-1);
256  RTMessage("isolevel["+ std::to_string(i-1)+ "]="+std::to_string(isolevel));
257  }
258  else
259  {
260  RTMessage("[Return] for isolevel[0]="+std::to_string(0.5*(state.real_vmin+state.real_vmax)));
261  }
262  }
263 
265  {
266  // if (this->SubClassName()!="VectorView") return;
267 
268  RTMessage("arrow_scale="+std::to_string(state.quiver_arrowscale_user));
269  }
270 
271 
273  const std::string plane,
274  int idim,
275  const std::string key,
276  bool & edit,
277  vtkSmartPointer<vtkCutter> planecut)
278  {
279 
280  if (!edit && key==plane)
281  {
282  edit=true;
283  RTShowPlanePos(planecut,plane,idim);
284  return 1;
285  }
286 
287  if (edit && key=="Return")
288  {
289  double planepos;
290  int i=planecut->GetNumberOfContours();
291  if (i>0)
292  planepos=planecut->GetValue(i-1);
293  else
294  planepos=0.0;
295  planecut->SetValue(i,planepos);
296  RTShowPlanePos(planecut,plane,idim);
297  return 1;
298  }
299 
300  if (edit&& key=="Delete")
301  {
302  int i=planecut->GetNumberOfContours();
303  if (i>0)
304  planecut->SetNumberOfContours(i-1);
305 
306  RTShowPlanePos(planecut,plane,idim);
307  return 1;
308  }
309 
310  if (edit&& key=="Escape")
311  {
312  edit=false;
313  return 1;
314  }
315 
316  return 0;
317  }
318 
319  int Figure::RTProcessIsoKey(const std::string key,bool & edit)
320  {
321  if (!edit && key=="l")
322  {
323  edit=true;
324  state.isolevels_locked=true;
325  RTShowIsolevel();
326  return 1;
327  }
328 
329  if (edit && key=="Return")
330  {
331  double isolevel;
332  int i=isoline_filter->GetNumberOfContours();
333  if (i>0)
334  isolevel=isoline_filter->GetValue(i);
335  else
336  isolevel=0.5*(state.real_vmin+state.real_vmax);
337 
338  isoline_filter->SetValue(i,isolevel);
339  RTShowIsolevel();
341  return 1;
342  }
343 
344  if (edit&& key=="Delete")
345  {
346  int i=isoline_filter->GetNumberOfContours();
347  if (i>0)
348  isoline_filter->SetNumberOfContours(i-1);
349  RTShowIsolevel();
351  return 1;
352  }
353 
354  if (edit&& key=="Escape")
355  {
356  edit=false;
357  return 1;
358  }
359 
360  return 0;
361  }
362 
363 
364  int Figure::RTProcessArrowKey(const std::string key,bool & edit)
365  {
366  if (!edit && key=="a")
367  {
368  edit=true;
370  return 1;
371  }
372 
373  if (edit&& key=="Escape")
374  {
375  edit=false;
376  return 1;
377  }
378 
379  return 0;
380  }
381 
382 
383  void Figure::RTProcessKey(const std::string key)
384  {
385 
386  if (key=="I" && state.spacedim==3)
387  {
388 // state.show_isolines=!state.show_isolines;
389  state.show_isosurfaces=!state.show_isosurfaces;
390  // isoline_plot->SetVisibility(state.show_isolines);
391  isosurface_plot->SetVisibility(state.show_isosurfaces);
393  isosurface_plot->Modified();
394  return;
395  }
396 
397  if (key=="S" && state.spacedim==2)
398  {
399  state.show_surface=!state.show_surface;
400  state.show_isolines=!state.show_isolines;
401  isoline_plot->SetVisibility(state.show_isolines);
402  surface_plot->SetVisibility(state.show_surface);
403  isoline_plot->Modified();
404  surface_plot->Modified();
405  return;
406  }
407 
408  if (key=="E" && state.spacedim==2)
409  {
410  state.show_elevation=!state.show_elevation;
411  elevation_plot->SetVisibility(state.show_elevation);
412  elevation_plot->Modified();
413  return;
414  }
415 
416  if (key=="A")
417  {
418  if (axes)
419  {
420  int vis=axes->GetVisibility();
421  vis=!vis;
422  axes->SetVisibility(vis);
423  if (outline)
424  outline->SetVisibility(vis);
425  }
426  return;
427  }
428 
429  if (key=="O")
430  {
431  if (splot)
432  {
433  int vis=splot->GetVisibility();
434  vis=!vis;
435  splot->SetVisibility(vis);
436  }
437  return;
438  }
439 
440 
441 
442 
443  if (key=="L")
444  {
445  isoline_filter->SetNumberOfContours(11);
446  state.isolevels_locked=false;
447  GenIsolevels();
448  if (edit.l_iso)
449  {
450  state.isolevels_locked=true;
451  RTShowIsolevel();
452  }
453  return;
454  }
455 
456  if (
457  (edit.x_plane||edit.y_plane|| edit.z_plane|| edit.l_iso || edit.a_scale)
458  &&(key=="x"|| key=="y"|| key=="z"|| key=="l" || key=="a")
459  )
460  {
461  edit.x_plane=false;
462  edit.y_plane=false;
463  edit.z_plane=false;
464  edit.l_iso=false;
465  edit.a_scale=false;
466  }
467 
468  if (RTProcessArrowKey(key,edit.a_scale)) return;
469  if (RTProcessIsoKey(key,edit.l_iso)) return;
470  if (RTProcessPlaneKey("x",0,key,edit.x_plane, planecutX)) return;
471  if (RTProcessPlaneKey("y",1,key,edit.y_plane, planecutY)) return;
472  if (RTProcessPlaneKey("z",2,key,edit.z_plane, planecutZ)) return;
473  }
474 
475 
476  int Figure::RTProcessPlaneMove(const std::string plane,int idim, int dx, int dy, bool & edit,
477  vtkSmartPointer<vtkCutter> planecut )
478  {
479  if (edit)
480  {
481  int i=planecut->GetNumberOfContours()-1;
482  if (i>=0)
483  {
484  double planepos=planecut->GetValue(i)+trans_center[idim];
485  planepos+=(0.01)*((double)dx)*(trans_bounds[2*idim+1]-trans_bounds[2*idim+0]);
486  planepos=std::min(planepos,trans_bounds[2*idim+1]);
487  planepos=std::max(planepos,trans_bounds[2*idim+0]);
488  planecut->SetValue(i,planepos-trans_center[idim+0]);
489  RTShowPlanePos(planecut,plane,idim);
490  planecut->Modified();
491  }
492  return 1;
493  }
494  return 0;
495  }
496 
497  int Figure::RTProcessIsoMove(int dx, int dy, bool & edit)
498  {
499  if (edit)
500  {
501  int i=isoline_filter->GetNumberOfContours()-1;
502  if (i>=0)
503  {
504  double isolevel=isoline_filter->GetValue(i);
505  isolevel+=(0.01)*((double)dx)*(state.real_vmax-state.real_vmin);
506  isolevel=std::min(isolevel,state.real_vmax);
507  isolevel=std::max(isolevel,state.real_vmin);
508  isoline_filter->SetValue(i,isolevel);
509  isoline_filter->Modified();
510  RTShowIsolevel();
512  }
513  return 1;
514  }
515  return 0;
516  }
517 
518  int Figure::RTProcessArrowMove(int dx, int dy, bool & edit)
519  {
520  if (edit)
521  {
522  double ascale=state.quiver_arrowscale_user;
523  ascale*=pow(10.0,((double)dy)/100.0);
524  ascale=std::min(ascale,1.0e20);
525  ascale=std::max(ascale,1.0e-20);
526  state.quiver_arrowscale_user=ascale;
528  arrow3dt->Identity();
529  double scalefac=state.quiver_arrowscale_geometry*state.quiver_arrowscale_user/state.real_vmax;
530  arrow3dt->Scale(scalefac,scalefac,scalefac);
531  arrow2d->SetScale(scalefac);
532  return 1;
533  }
534  return 0;
535  }
536 
538  {
539  if (state.spacedim==3)
540  {
541  int n=isoline_filter->GetNumberOfContours();
542  isosurface_filter->SetNumberOfContours(n);
543  for (int i=0;i<n;i++)
544  isosurface_filter->SetValue(i,isoline_filter->GetValue(i));
545  }
546  }
547 
548  void Figure::RTProcessMove(int dx, int dy)
549  {
550  if (RTProcessArrowMove(dx,dy,edit.a_scale)) return;
551  if (RTProcessIsoMove(dx,dy,edit.l_iso)) return;
552  if (RTProcessPlaneMove("x",0,dx,dy,edit.x_plane, planecutX)) return;
553  if (RTProcessPlaneMove("y",1,dx,dy,edit.y_plane, planecutY)) return;
554  if (RTProcessPlaneMove("z",2,dx,dy,edit.z_plane, planecutZ)) return;
555  }
556 
557 
558 
559 
560  void Figure::SetContourRGBTable(RGBTable & tab, int tabsize)
561  {
562  state.contour_rgbtab_size=tabsize;
563  state.contour_rgbtab_modified=true;
564  //contour_rgbtab=tab;
565  //contour_lut=BuildLookupTable(tab,tabsize);
566  }
567 
569  {
570  if (!transform_dirty) return;
571  auto data=vtkDataSet::SafeDownCast(data_producer->GetOutputDataObject(0));
572 
573  if ( state.xmin<state.xmax
574  &&state.ymin<state.ymax
575  &&(state.spacedim==2 || state.zmin<state.zmax))
576  {
577  data_bounds[0]=state.xmin;
578  data_bounds[1]=state.xmax;
579  data_bounds[2]=state.ymin;
580  data_bounds[3]=state.ymax;
581  data_bounds[4]=state.zmin;
582  data_bounds[5]=state.zmax;
583  data_center[0]=0.5*(data_bounds[0]+data_bounds[1]);
584  data_center[1]=0.5*(data_bounds[2]+data_bounds[3]);
585  data_center[2]=0.5*(data_bounds[4]+data_bounds[5]);
586  }
587  else if (data)
588  {
589  data->GetBounds(data_bounds);
590  data->GetCenter(data_center);
591  }
592  else
593  {
594  throw std::runtime_error("Specify either view volume or dataset for figure\n");
595  }
596  if (!transform)
597  transform = vtkSmartPointer<vtkTransform>::New();
598  transform->Identity();
599  double xsize=data_bounds[1]-data_bounds[0];
600  double ysize=data_bounds[3]-data_bounds[2];
601  double zsize=data_bounds[5]-data_bounds[4];
602  if (state.spacedim==2) zsize=0;
603  double xysize=std::max(xsize,ysize);
604  double xyzsize=std::max(xysize,zsize);
605 
606  // we don't need this if we prevent vectors from being
607  // transformed
608  //state.quiver_arrowscale_geometry=1.0/xyzsize;
609 
610  // transform everything to [0,1]x[0,1]x[0,1]
611  if (state.keep_aspect)
612  {
613  if (xsize>ysize)
614  transform->Translate(0,0.5*(xsize-ysize)/xyzsize,0);
615  else
616  transform->Translate(0.5*(ysize-xsize)/xyzsize,0,0);
617 
618  transform->Scale(1.0/xyzsize, 1.0/xyzsize,1.0/xyzsize);
619  }
620  else
621  {
622  if (state.aspect>1.0)
623  {
624  transform->Translate(0,0.5-0.5/state.aspect,0);
625  transform->Scale(1.0/xsize, 1.0/(state.aspect*ysize),1);
626  }
627  else
628  {
629  transform->Translate(0.5-0.5*state.aspect,0,0);
630  transform->Scale(state.aspect/xsize, 1.0/ysize,1);
631  }
632  }
633 
634  transform->Translate(-data_bounds[0],-data_bounds[2],-data_bounds[4]);
635 
636  double p0[3]={data_bounds[0],data_bounds[2],data_bounds[4]};
637  double p1[3]={data_bounds[1],data_bounds[3],data_bounds[5]};
638  double tp0[3],tp1[3];
639 
640  transform->TransformPoint(p0,tp0);
641  transform->TransformPoint(p1,tp1);
642  trans_bounds[0]=tp0[0];
643  trans_bounds[1]=tp1[0];
644  trans_bounds[2]=tp0[1];
645  trans_bounds[3]=tp1[1];
646  trans_bounds[4]=tp0[2];
647  trans_bounds[5]=tp1[2];
648 
649  transform->TransformPoint(data_center,trans_center);
650 
651  transform_dirty=false;
652  }
653 
655  {
656  if (
657  SubClassName()!="ScalarView"
658  &&
659  SubClassName()!="VectorView"
660  ) return;
661 
662  this->SetRange();
663 
664  if (state.vmin_set<state.vmax_set)
665  {
666  state.real_vmin=state.vmin_set;
667  state.real_vmax=state.vmax_set;
668  }
669  else if (state.accumulate_range)
670  {
671  state.real_vmin=std::min(state.real_vmin,state.data_vmin);
672  state.real_vmax=std::max(state.real_vmax,state.data_vmax);
673  }
674  else
675  {
676  state.real_vmin=state.data_vmin;
677  state.real_vmax=state.data_vmax;
678  }
679  // cout << SubClassName() << endl;
680  // cout << state.data_vmin << " " << state.data_vmax << endl;
681  // cout << state.real_vmin << " " << state.real_vmax << endl << endl;
682 
683  arrow3dt->Identity();
684  double scalefac=state.quiver_arrowscale_geometry*state.quiver_arrowscale_user/(state.real_vmax);
685  arrow3dt->Scale(scalefac,scalefac,scalefac);
686  arrow3dt->Modified();
687  arrow2d->SetScale(scalefac);
688  arrow2d->Modified();
689 
690  double lut_min=state.real_vmin;
691  double lut_max=state.real_vmax;
692 
693 
694  if (SubClassName()=="ScalarView")
695  {
696  surface_lut->SetTableRange(lut_min,lut_max);
697  surface_lut->Modified();
698  GenIsolevels();
699  }
700 
701  if (SubClassName()=="VectorView")
702  {
703  quiver_lut->SetTableRange(lut_min,lut_max);
704  quiver_lut->Modified();
705 
706  stream_lut->SetTableRange(lut_min,lut_max);
707  stream_lut->Modified();
708  }
709 
710 
711 
712  // contour_lut->SetTableRange(state.real_vmin,state.real_vmax);
713  // contour_lut->Modified();
714  }
715 
717  {
718  if (!state.isolevels_locked)
719  {
720  double eps = this->state.eps_geom*(state.real_vmax-state.real_vmin)/(isoline_filter->GetNumberOfContours());
721  isoline_filter->GenerateValues(isoline_filter->GetNumberOfContours(), state.real_vmin+eps, state.real_vmax-eps);
722  isoline_filter->Modified();
723  }
725  }
726 
727  // this will see the right text size
729  {
730  if (!annot)
731  {
732 
733  annot= vtkSmartPointer<vtkCornerAnnotation>::New();
734  auto textprop=annot->GetTextProperty();
735  annot->SetMinimumFontSize(8);
736  annot->SetMaximumFontSize(20);
737  textprop->ItalicOff();
738  textprop->BoldOn();
739  textprop->SetFontSize(8);
740  textprop->SetFontFamilyToCourier();
741  textprop->SetColor(0,0,0);
742  }
743 
744  }
746  {
748  annot->SetText(7,title.c_str());
749  annot->SetText(4,"");
750  annot->SetText(3,"[ ]");
752  }
753 
754 
756  {
758  annot->SetText(3,"[X]");
759  annot->Modified();
760  }
761 
762 
764  {
766  annot->SetText(3,"[ ]");
767  annot->Modified();
768  }
769 
770  void Figure::RTMessage(std::string msg)
771  {
773  annot->SetText(4,msg.c_str());
774  annot->Modified();
775  }
776 
777 
779  {
780  SetVMinMax();
781  if (SubClassName()!="XYPlot")
782  RTCalcTransform();
783 
784  for (auto actor: actors) {auto m=actor->GetMapper(); if (m) m->Update();}
785  for (auto actor: ctxactors) {auto m=actor->GetScene(); if (m) m->SetDirty(true);}
786  for (auto actor: actors2d){auto m=actor->GetMapper(); if (m) m->Update();}
787  }
788 
789 
790  void Figure::ServerRTSendData(vtkSmartPointer<internals::Communicator> communicator)
791  {
792  auto data=vtkDataSet::SafeDownCast(data_producer->GetOutputDataObject(0));
793 
794  if (SubClassName()!="XYPlot")
795  {
796  communicator->SendCharBuffer((char*)&state,sizeof(state));
797  communicator->SendString(dataname);
798  communicator->Send(data,1,1);
799  }
800  ServerRTSend(communicator);
801  };
802 
803  void Figure::ClientMTReceiveData(vtkSmartPointer<internals::Communicator> communicator)
804  {
805  //auto data=vtkDataSet::SafeDownCast(data_producer->GetOutputDataObject(0));
806 
807  if (SubClassName()!="XYPlot")
808  {
809 
810  communicator->ReceiveCharBuffer((char*)&state,sizeof(state));
811  communicator->ReceiveString(dataname);
812 
813  vtkSmartPointer<vtkDataSet> data;
815  data=vtkSmartPointer<vtkRectilinearGrid>::New();
816  else if (state.datatype==DataSet::DataType::UnstructuredGrid)
817  data=vtkSmartPointer<vtkUnstructuredGrid>::New();
818  communicator->Receive(data,1,1);
819  data_producer->SetOutput(data);
820  }
821  ClientMTReceive(communicator);
822  }
823 
824 
825 
826 
828  template <class DATA>
829  void Figure::RTBuildDomainPipeline0(vtkSmartPointer<vtkRenderer> renderer)
830  {
831  RTCalcTransform();
832 
833  auto geometry=vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
834  geometry->SetInputConnection(data_producer->GetOutputPort());
835 
836  auto transgeometry=vtkSmartPointer<vtkTransformFilter>::New();
837  transgeometry->SetInputConnection(geometry->GetOutputPort());
838  transgeometry->SetTransform(transform);
839 
840 
842  if (state.show_domain_boundary && state.spacedim==3)
843  {
844  vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
845  mapper->SetInputConnection(transgeometry->GetOutputPort());
846  splot=vtkSmartPointer<vtkActor>::New();
847  if (state.spacedim==3)
848  {
849  splot->GetProperty()->SetOpacity(state.domain_opacity);
850  splot->GetProperty()->SetColor(state.domain_surface_color);
851  }
852  else // TODO add filter to extract boundary edges
853  {
854  splot->GetProperty()->SetOpacity(1.0);
855  splot->GetProperty()->SetColor(0,0,0);
856  }
857 
858  splot->SetMapper(mapper);
860  }
861 
862 
863  if (state.show_domain_box&& state.spacedim==3)
864  {
865  // create outline
866  vtkSmartPointer<vtkOutlineFilter>outlinefilter = vtkSmartPointer<vtkOutlineFilter>::New();
867  outlinefilter->SetInputConnection(transgeometry->GetOutputPort());
868  vtkSmartPointer<vtkPolyDataMapper> outlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
869  outlineMapper->SetInputConnection(outlinefilter->GetOutputPort());
870  outline = vtkSmartPointer<vtkActor>::New();
871  outline->SetMapper(outlineMapper);
872  outline->GetProperty()->SetColor(0, 0, 0);
874  }
875 
876 
877  if (state.show_domain_axes)
878  {
879  axes=vtkSmartPointer<vtkCubeAxesActor2D>::New();
880  double unscaled_data_bounds[6];
881  unscaled_data_bounds[0]=data_bounds[0]/this->state.coordinate_scale_factor_xyz[0];
882  unscaled_data_bounds[1]=data_bounds[1]/this->state.coordinate_scale_factor_xyz[0];
883  unscaled_data_bounds[2]=data_bounds[2]/this->state.coordinate_scale_factor_xyz[1];
884  unscaled_data_bounds[3]=data_bounds[3]/this->state.coordinate_scale_factor_xyz[1];
885  unscaled_data_bounds[4]=data_bounds[4]/this->state.coordinate_scale_factor_xyz[2];
886  unscaled_data_bounds[5]=data_bounds[5]/this->state.coordinate_scale_factor_xyz[2];
887  axes->SetRanges(unscaled_data_bounds);
888  axes->SetUseRanges(1);
889  axes->SetInputConnection(transgeometry->GetOutputPort());
890  axes->GetProperty()->SetColor(0, 0, 0);
891  axes->SetFontFactor(1.5);
892  axes->SetCornerOffset(0);
893  axes->SetNumberOfLabels(3);
894  axes->SetInertia(100);
895  axes->SetLabelFormat("%6.2g");
896 
898  axes->SetCamera(renderer->GetActiveCamera());
899 
900  if (state.spacedim==2)
901  {
902  axes->SetXLabel("");
903  axes->SetYLabel("");
904  axes->ZAxisVisibilityOff();
905  }
906  else
907  {
908  axes->SetXLabel("x");
909  axes->SetYLabel("y");
910  axes->SetZLabel("z");
911  }
912  auto textprop=axes->GetAxisLabelTextProperty();
913  textprop->ItalicOff();
914  textprop->BoldOn();
915  textprop->SetFontFamilyToCourier();
916  textprop->SetColor(0,0,0);
917 
918  textprop=axes->GetAxisTitleTextProperty();
919  textprop->ItalicOff();
920  textprop->BoldOn();
921  textprop->SetFontFamilyToCourier();
922  textprop->SetColor(0,0,0);
923 
925  }
926  }
927 
928 
931  void Figure::RTBuildDomainPipeline(vtkSmartPointer<vtkRenderer> renderer)
932  {
934  this->RTBuildDomainPipeline0<vtkUnstructuredGrid>(renderer);
935  else if (state.datatype==DataSet::DataType::RectilinearGrid)
936  this->RTBuildDomainPipeline0<vtkRectilinearGrid>(renderer);
937  }
938 
939 
940 
941 }
void RTShowActive()
Show figure is active [x].
vtkSmartPointer< vtkLookupTable > quiver_lut
Definition: vtkfigFigure.h:268
vtkSmartPointer< vtkActor > outline
Definition: vtkfigFigure.h:237
std::string dataname
Name of data item in data set.
Definition: vtkfigFigure.h:256
RGBTable cell_rgbtab
Definition: vtkfigFigure.h:277
double trans_bounds[6]
Definition: vtkfigFigure.h:532
RGBTable quiver_rgbtab
Definition: vtkfigFigure.h:269
void ServerRTSendData(vtkSmartPointer< internals::Communicator > communicator)
void RTMessage(std::string msg)
Show string in message field.
void RTBuildDomainPipeline(vtkSmartPointer< vtkRenderer > renderer)
Build domain pipeline for 2D/3D figures (outline, suface, axes)
vtkSmartPointer< vtkCutter > planecutY
Definition: vtkfigFigure.h:204
virtual void RTProcessMove(int dx, int dy)
double scalefac
void RTAddActor2D(vtkSmartPointer< vtkActor2D > prop)
Add vtk Actor to renderer showing figure.
vtkSmartPointer< vtkScalarBarActor > bcbar
Definition: vtkfigFigure.h:294
double coordinate_scale_factor
coordinate scale
Definition: vtkfigFigure.h:253
vtkSmartPointer< vtkDataSet > GetVTKBoundaryDataSet()
Request boundary dataset.
vtkSmartPointer< vtkIdList > celllist
Cell mask.
Definition: vtkfigFigure.h:259
Class to collect all data given on one grid.
Definition: vtkfigDataSet.h:31
vtkSmartPointer< vtkLookupTable > stream_lut
Definition: vtkfigFigure.h:271
vtkSmartPointer< vtkCutter > planecutX
Cutters for plane sections.
Definition: vtkfigFigure.h:203
void SetRange()
Obtain the data range from the relevant dataset.
void RTShowInActive()
Show figure is inactive [ ].
int RTProcessArrowKey(const std::string key, bool &edit)
Process keyboard events for quiver arrow editing etc.
void SetContourRGBTable(RGBTable &tab, int lutsize)
Set contour RGB table from RGBtable.
std::vector< vtkSmartPointer< vtkActor > > actors
Definition: vtkfigFigure.h:539
vtkSmartPointer< vtkCornerAnnotation > annot
The following items are declared in the base class in order to allow easy coding of interaction...
Definition: vtkfigFigure.h:199
vtkSmartPointer< vtkActor > splot
Definition: vtkfigFigure.h:238
vtkSmartPointer< vtkCubeAxesActor2D > axes
Definition: vtkfigFigure.h:236
void SetVMinMax()
Set minmax values from data.
vtkSmartPointer< vtkContourFilter > isoline_filter
Definition: vtkfigFigure.h:224
vtkSmartPointer< vtkActor > surface_plot
Items for surface plot.
Definition: vtkfigFigure.h:230
struct vtkfig::Figure::@1 edit
edit state
static void ReceiveRGBTable(vtkSmartPointer< internals::Communicator > communicator, RGBTable &rgbtab)
Receive rgb table from client.
vtkSmartPointer< vtkLookupTable > bface_lut
Definition: vtkfigFigure.h:276
RGBTable surface_rgbtab
Definition: vtkfigFigure.h:266
void SetMaskedData(std::shared_ptr< DataSet > data, const std::string name, const std::string maskname)
Add Dataset with mask to figure.
vtkSmartPointer< vtkTrivialProducer > data_producer
Data producer for grid dataset.
Definition: vtkfigFigure.h:247
std::string title
Title of figure.
Definition: vtkfigFigure.h:262
vtkSmartPointer< vtkTransform > transform
Definition: vtkfigFigure.h:200
bool IsEmpty()
Check if figure is empty (== no actors added)
void RTCalcTransform()
Calculate transformation to unit cube This shall be applied to all data.
vtkSmartPointer< vtkActor > isoline_plot
Items for isoline plot.
Definition: vtkfigFigure.h:223
void ClientMTReceiveData(vtkSmartPointer< internals::Communicator > communicator)
RGBTable bface_rgbtab
Definition: vtkfigFigure.h:285
RGBTable stream_rgbtab
Definition: vtkfigFigure.h:272
vtkSmartPointer< vtkLookupTable > surface_lut
Color lookup table for surface plots.
Definition: vtkfigFigure.h:265
vtkSmartPointer< vtkLookupTable > elevation_lut
Color lookup table for contour plots vtkSmartPointer<vtkLookupTable> contour_lut; RGBTable contour_rg...
Definition: vtkfigFigure.h:303
vtkSmartPointer< vtkLookupTable > BuildLookupTable(RGBTable &xrgb, size_t size)
DataType GetDataType()
Request the data type of the dataset.
void GenIsolevels()
Generate isolevels after minmax data known.
struct vtkfig::Figure::@0 state
figure state
static void SendRGBTable(vtkSmartPointer< internals::Communicator > communicator, RGBTable &rgbtab)
Send rgb table to client.
void RTInitAnnotations()
Init annotations.
vtkSmartPointer< vtkActor > isosurface_plot
Items for isosurface plot.
Definition: vtkfigFigure.h:219
vtkSmartPointer< vtkIdList > GetCellList(std::string name)
Request celllist.
double coordinate_scale_factor_xyz[3]
Figure()
Construct empty figure.
int RTProcessPlaneKey(const std::string plane, int idim, const std::string key, bool &edit, vtkSmartPointer< vtkCutter > planecut)
Process keyboard and mouse move events for plane section editing.
int RTProcessPlaneMove(const std::string plane, int idim, int dx, int dy, bool &edit, vtkSmartPointer< vtkCutter > planecut)
vtkSmartPointer< vtkPlane > planeY
Definition: vtkfigFigure.h:209
std::vector< vtkSmartPointer< vtkContextActor > > ctxactors
The different actor lists.
Definition: vtkfigFigure.h:538
void RTAddAnnotations()
Add annotations.
RGBTable elevation_rgbtab
Definition: vtkfigFigure.h:304
int RTProcessIsoMove(int dx, int dy, bool &edit)
vtkSmartPointer< vtkTransformPolyDataFilter > arrow3d
Definition: vtkfigFigure.h:214
double data_center[3]
Definition: vtkfigFigure.h:530
int GetSpaceDimension()
Request the space dimension of the dataset.
std::vector< RGBPoint > RGBTable
Definition: vtkfigTools.h:26
virtual void ClientMTReceive(vtkSmartPointer< internals::Communicator > communicator)
Receive data from server.
Definition: vtkfigFigure.h:343
void RTUpdateIsoSurfaceFilter()
vtkSmartPointer< vtkTrivialProducer > boundary_data_producer
Data producer for boundary grid dataset.
Definition: vtkfigFigure.h:250
vtkSmartPointer< vtkTransform > arrow3dt
Definition: vtkfigFigure.h:215
virtual void ServerRTSend(vtkSmartPointer< internals::Communicator > communicator)
Send data to client.
Definition: vtkfigFigure.h:340
vtkSmartPointer< vtkLookupTable > cell_lut
Definition: vtkfigFigure.h:275
vtkSmartPointer< vtkGlyphSource2D > arrow2d
Arrow glyph source.
Definition: vtkfigFigure.h:213
void RTAddActor(vtkSmartPointer< vtkActor > prop)
Add vtk Actor to renderer showing figure.
vtkSmartPointer< vtkPlane > planeX
Plane equations for plane sections.
Definition: vtkfigFigure.h:208
vtkSmartPointer< vtkScalarBarActor > cbar
Definition: vtkfigFigure.h:293
vtkSmartPointer< vtkDataSet > GetVTKDataSet()
Request vtkDataset which contains all the data.
vtkSmartPointer< vtkCutter > planecutZ
Definition: vtkfigFigure.h:205
void RTBuildDomainPipeline0(vtkSmartPointer< vtkRenderer > renderer)
Duck typing interface allowing to handle different VTK datatypes with the same code.
vtkSmartPointer< vtkPlane > planeZ
Definition: vtkfigFigure.h:210
std::vector< vtkSmartPointer< vtkActor2D > > actors2d
Definition: vtkfigFigure.h:540
double trans_center[3]
Definition: vtkfigFigure.h:533
virtual void RTProcessKey(const std::string key)
Process keyboard and mouse move events.
int RTProcessIsoKey(const std::string key, bool &edit)
Process keyboard and mouse move events for isolevel editing.
void SetData(std::shared_ptr< DataSet > data, const std::string name="")
Add Dataset to figure.
vtkSmartPointer< vtkActor > elevation_plot
Items for elevation plot.
Definition: vtkfigFigure.h:227
vtkSmartPointer< vtkContourFilter > isosurface_filter
Definition: vtkfigFigure.h:220
void RTAddContextActor(vtkSmartPointer< vtkContextActor > prop)
Add vtk Actor to renderer showing figure.
double coordinate_scale_factor
virtual std::string SubClassName()
Get subclass name (for s-c communication, should be replaced by tag.
Definition: vtkfigFigure.h:384
void RTUpdateActors()
Update all actors belonging to figure.
int RTProcessArrowMove(int dx, int dy, bool &edit)
Process mouse move events for quiver arrow editing etc.
vtkSmartPointer< vtkArrowSource > arrow3ds
Definition: vtkfigFigure.h:216
void RTShowPlanePos(vtkSmartPointer< vtkCutter > planecut, const std::string plane, int idim)
vtkSmartPointer< vtkTransform > warp_transform
Items for elevation plot.
Definition: vtkfigFigure.h:233
void RTShowArrowScale()
Show arrow scale informtion.
double data_bounds[6]
Definition: vtkfigFigure.h:529
RGB point for color tables.
Definition: vtkfigTools.h:24