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

Definition at line 39 of file example-simplexquiver2d.cxx.

40 {
41  size_t nspin=vtkfig::NSpin();
42 
43  std::vector<double> inpoints;
44  for(double x = -2; x < 2; x+=0.03)
45  {
46  for(double y = -2; y < 2; y+=0.03)
47  {
48  inpoints.push_back(xscale*(x + vtkMath::Random(-.1, .1)));
49  inpoints.push_back(yscale*(y + vtkMath::Random(-.1, .1)));
50  }
51  }
52 
53 
54 
55 
56  std::vector<double>points;
57  std::vector<int>cells;
58 
59  vtkfig::Delaunay2D(inpoints,points,cells);
60 
61 
62  int npoints=points.size()/2;
63 
64  std::vector<double>values(npoints);
65 
66 
67 
68  auto frame=vtkfig::Frame::New();
69 
70  auto colors=vtkfig::RGBTable
71  {
72  {0.0, 0.3, 0.3, 1.0},
73  {0.5, 0.3, 1.0, 0.3},
74  {1.0, 1.0, 0.3, 0.3}
75  };
76  auto qcolors=vtkfig::RGBTable
77  {
78  {0.0, 0.0, 0.0, 0.0},
79  {1.0, 0.0, 0.0, 0.0}
80  };
81 
82  std::vector<double> z(npoints);
83  std::vector<double> u(npoints);
84  std::vector<double> v(npoints);
85 
86 
87  double t=0;
88  double dt=0.1;
89  size_t ii=0;
90  double t0=(double)clock()/(double)CLOCKS_PER_SEC;
91  double i0=ii;
92 
93  auto griddata=vtkfig::DataSet::New();
94  griddata->SetSimplexGrid(2,points,cells);
95  griddata->SetPointScalar(z ,"v");
96  griddata->SetPointVector(u,v ,"grad");
97 
98  auto contour=vtkfig::ScalarView::New();
99  contour->SetData(griddata,"v");
100  contour->SetSurfaceRGBTable(colors,255);
101  contour->ShowIsolines(false);
102 
103  auto quiver=vtkfig::VectorView::New();
104  quiver->SetData(griddata,"grad");
105  quiver->SetQuiverGrid(15,15);
106 
107  contour->KeepXYAspect(false);
108  quiver->KeepXYAspect(false);
109 
110 
111  frame->AddFigure(contour);
112  frame->AddFigure(quiver);
113 
114  while (ii<nspin)
115  {
116 
117  for (size_t ipoint=0, ival=0;ipoint<points.size(); ipoint+=2,ival++)
118  {
119  z[ival]=G(points[ipoint+0],points[ipoint+1],t);
120  u[ival]=dGdx(points[ipoint+0],points[ipoint+1],t);
121  v[ival]=dGdy(points[ipoint+0],points[ipoint+1],t);
122  }
123  griddata->SetPointScalar(z ,"v");
124  griddata->SetPointVector(u,v ,"grad");
125 
126  frame->Show();
127 
128  if (ii==3)
129  frame->WritePNG("example-simplexquiver2d.png");
130 
131  t+=dt;
132  double t1=(double)clock()/(double)CLOCKS_PER_SEC;
133  double i1=ii;
134  if (t1-t0>4.0)
135  {
136  printf("Frame rate: %.2f fps\n",(double)(i1-i0)/4.0);
137  t0=(double)clock()/(double)CLOCKS_PER_SEC;
138  i0=ii;
139  }
140  ii++;
141  }
142 
143 }
size_t NSpin()
Definition: vtkfigTools.cxx:13
static std::shared_ptr< Frame > New()
Create frame with multiple subframes.
Definition: vtkfigFrame.h:54
double xscale
static std::shared_ptr< ScalarView > New()
static std::shared_ptr< DataSet > New()
Static constructor of an empty instance.
Definition: vtkfigDataSet.h:40
std::vector< RGBPoint > RGBTable
Definition: vtkfigTools.h:26
double dGdy(double x, double y, double t)
double G(double x, double y, double t)
double dGdx(double x, double y, double t)
double yscale
void Delaunay2D(const V &points_in, V &points, IV &cells)
Definition: vtkfigTools.h:49
static std::shared_ptr< VectorView > New()

+ Here is the call graph for this function: