feat (wip): base visualization technique; Euleriean layer
This commit is contained in:
parent
1c8813de4e
commit
3bc3ffd14f
|
|
@ -5,22 +5,24 @@ project(VtkBase)
|
|||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
find_package(VTK COMPONENTS
|
||||
CommonColor
|
||||
CommonColor
|
||||
CommonCore
|
||||
CommonDataModel
|
||||
FiltersGeneral
|
||||
FiltersGeometry
|
||||
FiltersProgrammable
|
||||
IOImage
|
||||
FiltersSources
|
||||
ImagingSources
|
||||
InteractionStyle
|
||||
IOImage
|
||||
RenderingContextOpenGL2
|
||||
RenderingCore
|
||||
RenderingCore
|
||||
RenderingFreeType
|
||||
RenderingGL2PSOpenGL2
|
||||
RenderingOpenGL2
|
||||
CommonColor
|
||||
RenderingCore)
|
||||
RenderingOpenGL2)
|
||||
|
||||
|
||||
if (NOT VTK_FOUND)
|
||||
message(FATAL_ERROR "VtkBase: Unable to find the VTK build folder.")
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
build/compile_commands.json
|
||||
|
|
@ -1,8 +1,106 @@
|
|||
#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() {
|
||||
this->ren = vtkSmartPointer<vtkRenderer>::New();
|
||||
this->ren->SetLayer(1);
|
||||
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) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,17 @@
|
|||
#define EGLYPHLAYER_H
|
||||
|
||||
#include "Layer.h"
|
||||
|
||||
|
||||
#include <vtkPolyData.h>
|
||||
|
||||
class EGlyphLayer : public Layer {
|
||||
private:
|
||||
vtkSmartPointer<vtkPolyData> data;
|
||||
|
||||
void readCoordinates();
|
||||
|
||||
public:
|
||||
EGlyphLayer();
|
||||
void updateData(short t);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,3 +5,7 @@ LGlyphLayer::LGlyphLayer() {
|
|||
this->ren = vtkSmartPointer<vtkRenderer>::New();
|
||||
this->ren->SetLayer(2);
|
||||
}
|
||||
|
||||
void LGlyphLayer::updateData(short n) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,16 @@
|
|||
#define LGLYPHLAYER_H
|
||||
|
||||
#include "Layer.h"
|
||||
#include <vtkPolyData.h>
|
||||
|
||||
class LGlyphLayer : public Layer {
|
||||
private:
|
||||
vtkSmartPointer<vtkPoints> points;
|
||||
vtkSmartPointer<vtkPolyData> data;
|
||||
|
||||
public:
|
||||
LGlyphLayer();
|
||||
void updateData(short t);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -14,65 +14,6 @@
|
|||
#include "helperClasses/Program.h"
|
||||
|
||||
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() {
|
||||
|
|
@ -82,14 +23,6 @@ int main() {
|
|||
auto program = new Program(*bg, *e, *l);
|
||||
program->render();
|
||||
|
||||
|
||||
// vtkNew<vtkNamedColors> colors;
|
||||
// vtkNew<vtkRenderer> Euler, Background, Lagrange;
|
||||
// Euler->SetBackground(colors->GetColor3d("DarkSlateGray").GetData());
|
||||
|
||||
|
||||
// renderCoordinates(Euler, colors);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 390 KiB |
Loading…
Reference in New Issue