VTKFIG  0.20.20181114
Easy VTK based in situ visualization
int main ( void  )

Definition at line 26 of file example-multifig.cxx.

27 {
28  cout.sync_with_stdio(true);
29  size_t nspin=vtkfig::NSpin();
30 
31  const int Nx = 200;
32  const int Ny = 250;
33 
34  std::vector<double> x(Nx);
35  std::vector<double> y(Ny);
36  std::vector<double> u(Nx*Ny);
37  std::vector<double> v(Nx*Ny);
38 
39  std::vector<double> fx(Nx);
40  std::vector<double> fy(Ny);
41 
42  const double x_low = -2.5;
43  const double x_upp = 1.5;
44  const double y_low = -2.5;
45  const double y_upp = 4;
46  const double dx = (x_upp-x_low)/(Nx-1);
47  const double dy = (y_upp-y_low)/(Ny-1);
48 
49  auto colors=vtkfig::RGBTable
50  {
51  {0.0, 0.0, 0.0, 1.0},
52  {0.5, 0.0, 1.0, 0.0},
53  {1.0, 1.0, 0.0, 0.0}
54  };
55 
56  for (int i=0; i<Nx; i++)
57  x[i] = x_low+i*dx;
58 
59  for (int i=0; i<Ny; i++)
60  y[i] = y_low + i*dy;
61 
62  double t=0;
63  double dt=0.1;
64  size_t ii=0;
65  auto t0=std::chrono::system_clock::now();
66  double i0=ii;
67 
68 
69  auto frame=vtkfig::Frame::New();
70  frame->SetLayout(2,2);
71  frame->LinkCamera(1,frame,0);
72 
73  frame->SetSize(800,400);
74  frame->SetWindowTitle("vtkfig");
75  frame->SetFrameTitle("Multiple figures in one frame");
76 
77  auto griddata=vtkfig::DataSet::New();
78  griddata->SetRectilinearGrid(x,y);
79  griddata->SetPointScalar(u ,"u");
80  griddata->SetPointScalar(v ,"v");
81 
82 
83 
84  auto contour_u=vtkfig::ScalarView::New();
85  contour_u->SetData(griddata,"u");
86  contour_u->SetSurfaceRGBTable(colors,255);
87  frame->AddFigure(contour_u,0);
88 
89  auto contour_v=vtkfig::ScalarView::New();
90  contour_v->SetData(griddata,"v");
91  contour_v->SetSurfaceRGBTable(colors,255);
92  frame->AddFigure(contour_v,1);
93 
94  auto xyplot=vtkfig::XYPlot::New();
95  xyplot->SetYRange(-0.5,0.5);
96  frame->AddFigure(xyplot,2);
97 
98  while (ii<nspin)
99  {
100  for (int i=0; i<Nx; i++)
101  for (int j=0; j<Ny; j++)
102  {
103  double f=GU(x[i],y[j],t);
104  u[j*Nx+i] = f;
105  if (i==Nx/2) fy[j]=f;
106  if (j==Ny/2) fx[i]=f;
107 
108  f=GV(x[i],y[j],t);
109  v[j*Nx+i] = f;
110  }
111 
112  griddata->SetPointScalar(u ,"u");
113  griddata->SetPointScalar(v ,"v");
114 
115  xyplot->Clear();
116  xyplot->SetPlotColor(0,0,1);
117  xyplot->SetPlotLineType("-");
118  xyplot->SetPlotLegend("y=0.5");
119  xyplot->AddPlot(x, fx);
120  xyplot->SetPlotColor(1,0,0);
121  xyplot->SetPlotLineType("-");
122  xyplot->SetPlotLegend("x=0.5");
123  xyplot->AddPlot(y, fy);
124  frame->Show();
125 
126  if (ii==3)
127  frame->WritePNG("example-multifig.png");
128 
129  t+=dt;
130  auto t1=std::chrono::system_clock::now();
131  double dt=std::chrono::duration_cast<std::chrono::duration<double>>(t1-t0).count();
132  double i1=ii;
133  if (dt>4.0)
134  {
135  printf("Frame rate: %.2f fps\n",(double)(i1-i0)/4.0);
136  t0=std::chrono::system_clock::now();
137  i0=ii;
138  fflush(stdout);
139  }
140  ii++;
141  }
142 
143 }
double GU(double x, double y, double t)
size_t NSpin()
Definition: vtkfigTools.cxx:13
static std::shared_ptr< Frame > New()
Create frame with multiple subframes.
Definition: vtkfigFrame.h:54
static std::shared_ptr< ScalarView > New()
static std::shared_ptr< XYPlot > New()
static std::shared_ptr< DataSet > New()
Static constructor of an empty instance.
Definition: vtkfigDataSet.h:40
double GV(double x, double y, double t)
std::vector< RGBPoint > RGBTable
Definition: vtkfigTools.h:26

+ Here is the call graph for this function: