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

Multiple figures in one frame

#include <chrono>
#include "vtkfigFrame.h"
#include "vtkfigDataSet.h"
#include "vtkfigXYPlot.h"
#include "vtkfigTools.h"
inline double GU(double x,double y, double t)
{
return exp(-(x*x+y*y))*sin(t+x)*cos(y-t);
}
inline double GV(double x,double y, double t)
{
return exp(-(x*x+y*y))*sin(1.0-(2*t+2*x))*cos(1.0-(2*y-2*t));
}
int main(void)
{
cout.sync_with_stdio(true);
size_t nspin=vtkfig::NSpin();
const int Nx = 200;
const int Ny = 250;
std::vector<double> x(Nx);
std::vector<double> y(Ny);
std::vector<double> u(Nx*Ny);
std::vector<double> v(Nx*Ny);
std::vector<double> fx(Nx);
std::vector<double> fy(Ny);
const double x_low = -2.5;
const double x_upp = 1.5;
const double y_low = -2.5;
const double y_upp = 4;
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.0, 0.0, 1.0},
{0.5, 0.0, 1.0, 0.0},
{1.0, 1.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;
auto t0=std::chrono::system_clock::now();
double i0=ii;
std::shared_ptr<vtkfig::Frame> frame=vtkfig::Frame::New();
std::shared_ptr<vtkfig::DataSet> dataset=vtkfig::DataSet::New();
frame->SetLayout(2,2);
frame->LinkCamera(1,frame,0);
frame->SetSize(800,400);
frame->SetWindowTitle("vtkfig");
frame->SetFrameTitle("Multiple figures in one frame");
dataset->SetRectilinearGrid(x,y);
dataset->SetPointScalar(u ,"u");
dataset->SetPointScalar(v ,"v");
std::shared_ptr<vtkfig::ScalarView> contour_u=vtkfig::ScalarView::New();
contour_u->SetData(dataset,"u");
contour_u->SetSurfaceRGBTable(colors,255);
frame->AddFigure(contour_u,0);
std::shared_ptr<vtkfig::ScalarView> contour_v=vtkfig::ScalarView::New();
contour_v->SetData(dataset,"v");
contour_v->SetSurfaceRGBTable(colors,255);
frame->AddFigure(contour_v,1);
std::shared_ptr<vtkfig::XYPlot> xyplot=vtkfig::XYPlot::New();
xyplot->SetYRange(-0.5,0.5);
frame->AddFigure(xyplot,2);
while (ii<nspin)
{
for (int i=0; i<Nx; i++)
for (int j=0; j<Ny; j++)
{
double f=GU(x[i],y[j],t);
u[j*Nx+i] = f;
if (i==Nx/2) fy[j]=f;
if (j==Ny/2) fx[i]=f;
f=GV(x[i],y[j],t);
v[j*Nx+i] = f;
}
dataset->SetPointScalar(u ,"u");
dataset->SetPointScalar(v ,"v");
xyplot->Clear();
xyplot->SetPlotColor(0,0,1);
xyplot->SetPlotLineType("-");
xyplot->SetPlotLegend("y=0.5");
xyplot->AddPlot(x, fx);
xyplot->SetPlotColor(1,0,0);
xyplot->SetPlotLineType("-");
xyplot->SetPlotLegend("x=0.5");
xyplot->AddPlot(y, fy);
frame->Show();
if (ii==3)
frame->WritePNG("example-multifig.png");
t+=dt;
auto t1=std::chrono::system_clock::now();
double dt=std::chrono::duration_cast<std::chrono::duration<double>>(t1-t0).count();
double i1=ii;
if (dt>4.0)
{
printf("Frame rate: %.2f fps\n",(double)(i1-i0)/4.0);
t0=std::chrono::system_clock::now();
i0=ii;
fflush(stdout);
}
ii++;
}
}
vtkfig::XYPlot::SetPlotLineType
void SetPlotLineType(const std::string type)
Set the line type of the next plot.
vtkfigScalarView.h
vtkfig::XYPlot::SetPlotLegend
void SetPlotLegend(const std::string legend)
Set the information for the legend entry for the next plot.
vtkfig::ScalarView::SetSurfaceRGBTable
void SetSurfaceRGBTable(const V &tab, int lutsize)
Set Surface RGB table from vector.
Definition: vtkfigScalarView.h:119
vtkfig::DataSet::SetRectilinearGrid
void SetRectilinearGrid(const V &x, const V &y)
Enter data of a 2D rectilinear grid.
Definition: vtkfigDataSet.h:469
vtkfig::DataSet::SetPointScalar
void SetPointScalar(const V &f, const std::string name)
Set data of a scalar function defined on the points of the grid.
Definition: vtkfigDataSet.h:703
vtkfig::XYPlot::AddPlot
void AddPlot(const V &x, const V &y)
Add a pair of x/y data to the figure.
Definition: vtkfigXYPlot.h:295
vtkfig::Frame::AddFigure
void AddFigure(std::shared_ptr< Figure > figure)
Add figure at position (0)
vtkfig::Frame::SetLayout
void SetLayout(int nvpx, int nvpy)
Set layout of subframe grid.
vtkfigXYPlot.h
vtkfig::Figure::SetData
void SetData(std::shared_ptr< DataSet > data, const std::string name="")
Add Dataset to figure.
vtkfig::XYPlot::SetYRange
void SetYRange(double y0, double y1)
Set the range of the y values.
vtkfig::Frame::SetFrameTitle
void SetFrameTitle(const std::string title)
Set Frame title.
vtkfig::ScalarView::New
static std::shared_ptr< ScalarView > New()
Create smart pointer to ScalarView instance.
vtkfig::Frame::Show
void Show()
Show frame content and continue.
vtkfig::XYPlot::SetPlotColor
void SetPlotColor(double r, double g, double b)
Set the color of the next plot.
vtkfig::Frame::SetWindowTitle
void SetWindowTitle(const std::string title)
Set window title.
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
vtkfig::Frame::SetSize
void SetSize(int x, int y)
Set frame size in pixels.
vtkfigTools.h
vtkfig::DataSet::New
static std::shared_ptr< DataSet > New()
Static constructor of smart pointer to an empty instance.
vtkfig::Frame::WritePNG
void WritePNG(std::string fname)
Write png image of frame content.
vtkfigDataSet.h
vtkfigFrame.h
vtkfig::XYPlot::New
static std::shared_ptr< XYPlot > New()
Smartpointer construtor.
vtkfig::Frame::LinkCamera
void LinkCamera(int ivp, Frame &frame, int livp)
Link camera to other camera.
vtkfig::Frame::New
static std::shared_ptr< Frame > New()
Create smart pointer to frame.
vtkfig::XYPlot::Clear
void Clear()
Remove all data from plot.