VTKFIG  0.20.20181114
Easy VTK based in situ visualization
example-surf2d.cxx
Go to the documentation of this file.
1 
7 #include <chrono>
8 #include "vtkfigFrame.h"
9 #include "vtkfigSurf2D.h"
10 #include "vtkfigTools.h"
11 
12 
13 inline double G(double x,double y, double t)
14 {
15 
16  return exp(-(x*x+y*y))*sin(t+x)*cos(y-t);
17 }
18 
19 
20 int main(const int argc, const char *argv[])
21 {
22 
23  size_t nspin=vtkfig::NSpin();
24  vtkfig::Frame frame;
25 
26  const int Nx = 200;
27  const int Ny = 250;
28 
29  std::vector<double> x(Nx);
30  std::vector<double> y(Ny);
31  std::vector<double> z(Nx*Ny);
32 
33  const double x_low = -2.5;
34  const double x_upp = 1.5;
35  const double y_low = -2.5;
36  const double y_upp = 4;
37  const double dx = (x_upp-x_low)/(Nx-1);
38  const double dy = (y_upp-y_low)/(Ny-1);
39 
40 
41 
42 
43 
44  for (int i=0; i<Nx; i++)
45  x[i] = x_low+i*dx;
46 
47  for (int i=0; i<Ny; i++)
48  y[i] = y_low + i*dy;
49 
50 
51  double t=0;
52  double dt=0.1;
53  size_t ii=0;
54  auto t0=std::chrono::system_clock::now();
55  double i0=ii;
56 
57  vtkfig::Surf2D surf;
58 
59  surf.SetGrid(x,y);
60 
61  auto colors=vtkfig::RGBTable
62  {
63  {0.0, 0.0, 0.0, 1.0},
64  {0.5, 0.0, 1.0, 0.0},
65  {1.0, 1.0, 0.0, 0.0}
66  };
67  surf.SetRGBTable(colors,255);
68 
69  frame.AddFigure(surf);
70 
71  while (ii<nspin)
72  {
73 
74  for (int i=0; i<Nx; i++)
75  for (int j=0; j<Ny; j++)
76  z[j*Nx+i] = G(x[i],y[j],t);
77 
78  surf.UpdateValues(z);
79 
80 
81  frame.Show();
82 
83  if (ii==3)
84  frame.WritePNG("example-surf2d.png");
85 
86  t+=dt;
87 
88  auto t1=std::chrono::system_clock::now();
89  double xdt=std::chrono::duration_cast<std::chrono::duration<double>>(t1-t0).count();
90  double i1=ii;
91  if (xdt>4.0)
92  {
93  printf("Frame rate: %.2f fps\n",(double)(i1-i0)/4.0);
94  t0=std::chrono::system_clock::now();
95  i0=ii;
96  fflush(stdout);
97  }
98  ii++;
99  }
100 
101 }
size_t NSpin()
Definition: vtkfigTools.cxx:13
void WritePNG(std::string fname)
Write png image of frame content.
void SetGrid(const V &xcoord, const V &ycoord)
Definition: vtkfigSurf2D.h:115
double G(double x, double y, double t)
int main(const int argc, const char *argv[])
Provide a framework wrapping window+interactor+renderers from vtk.
Definition: vtkfigFrame.h:38
Experimental class for 2D elevation plot - don&#39;t use.
Definition: vtkfigSurf2D.h:19
std::vector< RGBPoint > RGBTable
Definition: vtkfigTools.h:26
void SetRGBTable(RGBTable &tab, int tabsize)
Definition: vtkfigSurf2D.h:35
void AddFigure(Figure *figure)
Add figure at position (0)
Definition: vtkfigFrame.h:88
Define Frame class providing a window for rendering.
void Show()
Show frame content and continue.
Definition: vtkfigFrame.cxx:37
void UpdateValues(const V &values)
Definition: vtkfigSurf2D.h:158