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

2D Grid visualization with vtkfig::GridView

#include <chrono>
#include <vtkMath.h>
#include "vtkfigFrame.h"
#include "vtkfigDataSet.h"
#include "vtkfigGridView.h"
#include "vtkfigXYPlot.h"
#include "vtkfigTools.h"
int main(void)
{
cout.sync_with_stdio(true);
const int Nx = 20;
const int Ny = 25;
std::vector<double> x(Nx);
std::vector<double> y(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);
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;
std::vector<double> inpoints;
for(double x = -2; x < 2; x+=0.2)
{
for(double y = -2; y < 2; y+=0.2)
{
inpoints.push_back(x + vtkMath::Random(-.1, .1));
inpoints.push_back(y + vtkMath::Random(-.1, .1));
}
}
std::vector<double>points;
std::vector<int>cells;
vtkfig::Delaunay2D(inpoints,points,cells);
int npoints=points.size()/2;
std::vector<double>values(npoints);
std::shared_ptr<vtkfig::Frame> frame=vtkfig::Frame::New();
std::shared_ptr<vtkfig::DataSet> ugriddata=vtkfig::DataSet::New();
frame->SetSize(800,400);
ugriddata->SetSimplexGrid(2,points,cells);
std::shared_ptr<vtkfig::DataSet> rgriddata=vtkfig::DataSet::New();
rgriddata->SetRectilinearGrid(x,y);
std::shared_ptr<vtkfig::GridView> rgview=vtkfig::GridView::New();
rgview->SetData(rgriddata);
std::shared_ptr<vtkfig::GridView> ugview=vtkfig::GridView::New();
ugview->SetData(ugriddata);
ugview->SetTitle("Unstructured Grid");
rgview->SetTitle("Rectilinear Grid");
frame->AddFigure(rgview,0);
frame->AddFigure(ugview,1);
frame->Interact();
}
vtkfig::Delaunay2D
void Delaunay2D(const V0 &points_in, V &points, IV &cells)
Create a 2D Delaunay triangulation from point set.
Definition: vtkfigTools.h:70
vtkfig::GridView::New
static std::shared_ptr< GridView > New()
GridView smart pointer constructor.
vtkfig::DataSet::SetRectilinearGrid
void SetRectilinearGrid(const V &x, const V &y)
Enter data of a 2D rectilinear grid.
Definition: vtkfigDataSet.h:469
vtkfig::Frame::AddFigure
void AddFigure(std::shared_ptr< Figure > figure)
Add figure at position (0)
vtkfigXYPlot.h
vtkfig::Figure::SetData
void SetData(std::shared_ptr< DataSet > data, const std::string name="")
Add Dataset to figure.
vtkfig::Figure::SetTitle
void SetTitle(std::string xtitle)
Set figure title.
Definition: vtkfigFigure.h:103
vtkfig::DataSet::SetSimplexGrid
void SetSimplexGrid(int dim, const V &points, const IV &cells)
Enter data of a simplex grid.
Definition: vtkfigDataSet.h:362
vtkfig::Frame::SetSize
void SetSize(int x, int y)
Set frame size in pixels.
vtkfig::Frame::Interact
void Interact()
Show frame content and wait for interaction.
vtkfigTools.h
vtkfig::DataSet::New
static std::shared_ptr< DataSet > New()
Static constructor of smart pointer to an empty instance.
vtkfigDataSet.h
vtkfigFrame.h
vtkfigGridView.h
vtkfig::Frame::New
static std::shared_ptr< Frame > New()
Create smart pointer to frame.