feat (wip): base visualization technique; Euleriean layer

This commit is contained in:
Djairo Hougee 2024-04-29 11:43:50 +02:00
parent 1c8813de4e
commit 3bc3ffd14f
8 changed files with 122 additions and 73 deletions

View File

@ -5,22 +5,24 @@ project(VtkBase)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(VTK COMPONENTS find_package(VTK COMPONENTS
CommonColor
CommonColor CommonColor
CommonCore CommonCore
CommonDataModel CommonDataModel
FiltersGeneral FiltersGeneral
FiltersGeometry FiltersGeometry
FiltersProgrammable FiltersProgrammable
IOImage FiltersSources
ImagingSources ImagingSources
InteractionStyle InteractionStyle
IOImage
RenderingContextOpenGL2 RenderingContextOpenGL2
RenderingCore RenderingCore
RenderingCore
RenderingFreeType RenderingFreeType
RenderingGL2PSOpenGL2 RenderingGL2PSOpenGL2
RenderingOpenGL2 RenderingOpenGL2)
CommonColor
RenderingCore)
if (NOT VTK_FOUND) if (NOT VTK_FOUND)
message(FATAL_ERROR "VtkBase: Unable to find the VTK build folder.") message(FATAL_ERROR "VtkBase: Unable to find the VTK build folder.")

View File

@ -0,0 +1 @@
build/compile_commands.json

View File

@ -1,8 +1,106 @@
#include "EGlyphLayer.h" #include "EGlyphLayer.h"
#include <vtkRegularPolygonSource.h>
#include <vtkGlyph2D.h>
#include <vtkActor2D.h>
#include <vtkNamedColors.h>
#include <vtkPolyDataMapper2D.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkProperty2D.h>
#include <vtkVertexGlyphFilter.h>
#include <netcdf>
#include <vtkArrowSource.h>
using namespace netCDF;
using namespace std;
template <typename T>
vector<T> getVarVector(const NcVar &var) {
int length = 1;
for (NcDim dim : var.getDims()) {
length *= dim.getSize();
}
vector<T> vec(length);
var.getVar(vec.data());
return vec;
}
tuple<vector<int>, vector<double>, vector<double>> readGrid() {
netCDF::NcFile data("../../../../data/grid.h5", netCDF::NcFile::read);
multimap< string, NcVar > vars = data.getVars();
vector<int> time = getVarVector<int>(vars.find("times")->second);
vector<double> longitude = getVarVector<double>(vars.find("longitude")->second);
vector<double> latitude = getVarVector<double>(vars.find("latitude")->second);
return {time, latitude, longitude};
}
EGlyphLayer::EGlyphLayer() { EGlyphLayer::EGlyphLayer() {
this->ren = vtkSmartPointer<vtkRenderer>::New(); this->ren = vtkSmartPointer<vtkRenderer>::New();
this->ren->SetLayer(1); this->ren->SetLayer(1);
this->ren->InteractiveOff(); this->ren->InteractiveOff();
this->data = vtkSmartPointer<vtkPolyData>::New();
readCoordinates();
}
void EGlyphLayer::readCoordinates() {
vtkNew<vtkPoints> points;
auto [times, lats, lons] = readGrid(); // FIXME: import Robin's readData function and use it
double i = 0;
for (double lat : lats) {
for (double lon : lons) {
//FIXME: hard-coded values; should update with window geometry.
points->InsertNextPoint((lat*1000-46125)*661/16500, (lon*1000+15875)*661/28750, 0);
}
}
this->data->SetPoints(points);
// vtkNew<vtkArrowSource> arrowSource;
vtkNew<vtkRegularPolygonSource> arrowSource;
vtkNew<vtkGlyph2D> glyph2D;
glyph2D->SetSourceConnection(arrowSource->GetOutputPort());
glyph2D->SetInputData(this->data);
glyph2D->Update();
vtkNew<vtkPolyDataMapper>(mapper);
mapper->SetInputConnection(glyph2D->GetOutputPort());
mapper->Update();
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
vtkNew<vtkNamedColors> colors;
actor->GetProperty()->SetColor(colors->GetColor3d("Salmon").GetData());
this->ren->AddActor(actor);
// vtkNew<vtkVertexGlyphFilter> glyphFilter;
// glyphFilter->SetInputData(this->data);
// glyphFilter->Update();
//
// vtkNew<vtkPolyDataMapper2D> mapper;
// mapper->SetInputConnection(glyphFilter->GetOutputPort());
// mapper->Update();
//
// vtkNew<vtkNamedColors> colors;
// vtkNew<vtkActor2D> actor;
// actor->SetMapper(mapper);
// actor->GetProperty()->SetColor(colors->GetColor3d("Gold").GetData());
// actor->GetProperty()->SetPointSize(3);
//
// this->ren->AddActor(actor);
}
void EGlyphLayer::updateData(short t) {
} }

View File

@ -2,12 +2,17 @@
#define EGLYPHLAYER_H #define EGLYPHLAYER_H
#include "Layer.h" #include "Layer.h"
#include <vtkPolyData.h>
class EGlyphLayer : public Layer { class EGlyphLayer : public Layer {
private:
vtkSmartPointer<vtkPolyData> data;
void readCoordinates();
public: public:
EGlyphLayer(); EGlyphLayer();
void updateData(short t);
}; };

View File

@ -5,3 +5,7 @@ LGlyphLayer::LGlyphLayer() {
this->ren = vtkSmartPointer<vtkRenderer>::New(); this->ren = vtkSmartPointer<vtkRenderer>::New();
this->ren->SetLayer(2); this->ren->SetLayer(2);
} }
void LGlyphLayer::updateData(short n) {
}

View File

@ -2,10 +2,16 @@
#define LGLYPHLAYER_H #define LGLYPHLAYER_H
#include "Layer.h" #include "Layer.h"
#include <vtkPolyData.h>
class LGlyphLayer : public Layer { class LGlyphLayer : public Layer {
private:
vtkSmartPointer<vtkPoints> points;
vtkSmartPointer<vtkPolyData> data;
public: public:
LGlyphLayer(); LGlyphLayer();
void updateData(short t);
}; };

View File

@ -14,65 +14,6 @@
#include "helperClasses/Program.h" #include "helperClasses/Program.h"
using namespace std; using namespace std;
using namespace netCDF;
template <typename T>
vector<T> getVarVector(const NcVar &var) {
int length = 1;
for (NcDim dim : var.getDims()) {
length *= dim.getSize();
}
vector<T> vec(length);
var.getVar(vec.data());
return vec;
}
tuple<vector<int>, vector<double>, vector<double>> readGrid() {
netCDF::NcFile data("../../../../data/grid.h5", netCDF::NcFile::read);
multimap< string, NcVar > vars = data.getVars();
vector<int> time = getVarVector<int>(vars.find("times")->second);
vector<double> longitude = getVarVector<double>(vars.find("longitude")->second);
vector<double> latitude = getVarVector<double>(vars.find("latitude")->second);
return {time, latitude, longitude};
}
void renderCoordinates(vtkRenderer *ren, vtkNamedColors *colors) {
vtkNew<vtkPoints> points;
auto [times, lats, lons] = readGrid();
double i = 0;
for (double lat : lats) {
for (double lon : lons) {
cout << "lat: " << (lat*1000-46125)*661/16500 << "\t lon: " << (lon*1000+15875)*661/28750 << endl;
points->InsertNextPoint((lat*1000-46125)*661/16500, (lon*1000+15875)*661/28750, 0);
}
}
vtkNew<vtkPolyData> polydata;
polydata->SetPoints(points);
vtkNew<vtkVertexGlyphFilter> glyphFilter;
glyphFilter->SetInputData(polydata);
glyphFilter->Update();
vtkNew<vtkPolyDataMapper2D> mapper;
mapper->SetInputConnection(glyphFilter->GetOutputPort());
mapper->Update();
vtkNew<vtkActor2D> actor;
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(colors->GetColor3d("Gold").GetData());
actor->GetProperty()->SetPointSize(3);
ren->AddActor(actor);
}
int main() { int main() {
@ -82,14 +23,6 @@ int main() {
auto program = new Program(*bg, *e, *l); auto program = new Program(*bg, *e, *l);
program->render(); program->render();
// vtkNew<vtkNamedColors> colors;
// vtkNew<vtkRenderer> Euler, Background, Lagrange;
// Euler->SetBackground(colors->GetColor3d("DarkSlateGray").GetData());
// renderCoordinates(Euler, colors);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 390 KiB