VTKFIG  0.25.0
Easy VTK based in situ visualization
example-rectstream2d.cxx

Streamline view for vectors on 2D grid

#include "vtkfigFrame.h"
#include "vtkfigTools.h"
inline double UX(double x, double y, double t)
{
return -y*pow(x*x+y*y,-0.5);
}
inline double UY(double x, double y, double t)
{
return x*pow(x*x+y*y,-0.5);
}
int main(void)
{
size_t nspin=vtkfig::NSpin();
const int Nx = 50;
const int Ny = 50;
std::vector<double> x(Nx);
std::vector<double> y(Ny);
std::vector<double> u(Nx*Ny);
std::vector<double> v(Nx*Ny);
const double x_low = -1.0;
const double x_upp = 1.0;
const double y_low = -1.0;
const double y_upp = 1.0;
const double dx = (x_upp-x_low)/(Nx-1);
const double dy = (y_upp-y_low)/(Ny-1);
auto colors=vtkfig::RGBTable
{
{0.0, 0.3, 0.3, 1.0},
{0.5, 0.3, 1.0, 0.3},
{1.0, 1.0, 0.3, 0.3}
};
auto qcolors=vtkfig::RGBTable
{
{0.0, 0.0, 0.0, 0.0},
{1.0, 0.0, 0.0, 0.0}
};
for (int i=0; i<Nx; i++)
x[i] = x_low+i*dx;
for (int i=0; i<Ny; i++)
y[i] = y_low + i*dy;
double t=0;
double dt=0.1;
size_t ii=0;
double t0=(double)clock()/(double)CLOCKS_PER_SEC;
double i0=ii;
auto frame=vtkfig::Frame::New();
auto dataset=vtkfig::DataSet::New();
dataset->SetRectilinearGrid(x,y);
dataset->SetPointVector(u,v ,"flow");
std::vector<double> seeds=
{
0,0.1,
0,0.3,
0,0.5,
0,0.7,
0,0.9
};
vview->SetData(dataset,"flow");
vview->SetQuiverGrid(5,5);
vview->SetStreamLineSeedPoints(seeds);
vview->SetValueRange(0,2);
vview->ShowStreamLines(true);
frame->AddFigure(vview);
while (ii<nspin)
{
for (int i=0; i<Nx; i++)
for (int j=0; j<Ny; j++)
{
u[j*Nx+i] = UX(x[i],y[j],t);
v[j*Nx+i] = UY(x[i],y[j],t);
}
dataset->SetPointVector(u,v ,"flow");
frame->Show();
if (ii==3)
frame->WritePNG("example-rectstream3.png");
t+=dt;
double t1=(double)clock()/(double)CLOCKS_PER_SEC;
double i1=ii;
if (t1-t0>4.0)
{
printf("Frame rate: %.2f fps\n",(double)(i1-i0)/4.0);
t0=(double)clock()/(double)CLOCKS_PER_SEC;
i0=ii;
}
ii++;
}
}
vtkfig::VectorView::New
static std::shared_ptr< VectorView > New()
Smart pointer constructor.
vtkfig::NSpin
size_t NSpin()
Return content of environment variable VTKFIG_NSPIN or large value.
vtkfig::RGBTable
std::vector< RGBPoint > RGBTable
Color table.
Definition: vtkfigTools.h:43
vtkfigVectorView.h
vtkfigTools.h
vtkfig::DataSet::New
static std::shared_ptr< DataSet > New()
Static constructor of smart pointer to an empty instance.
vtkfigFrame.h
vtkfig::Frame::New
static std::shared_ptr< Frame > New()
Create smart pointer to frame.