added new option to modulate brightness for LGlyphLayer
This commit is contained in:
parent
650a245f0a
commit
e53a934212
|
|
@ -33,12 +33,36 @@ vtkSmartPointer<SpawnPointCallback> LGlyphLayer::createSpawnPointCallback() {
|
|||
|
||||
// Further notes; current thinking is to allow tracking a particle's age by using a scalar array in the VtkPolyData. This would be incremented for every tick/updateData function call.
|
||||
|
||||
/**
|
||||
* Build and returns a vtkLookupTable for the given number of colours in grayscale.
|
||||
* @param n : number of colours to add to the SetTableRange
|
||||
* @return : a vtkLookupTable with grayscale colours from [1,1,1,1] to [0.25, 0.25, 0.25, 1] in n steps.
|
||||
*/
|
||||
vtkSmartPointer<vtkLookupTable> buildLutBrightness(int n) {
|
||||
vtkNew<vtkLookupTable> lut;
|
||||
lut->SetNumberOfColors(n);
|
||||
lut->SetTableRange(0, n);
|
||||
lut->SetScaleToLinear();
|
||||
lut->Build();
|
||||
for (int i=0; i < n; i++) {
|
||||
lut->SetTableValue(i, 1-(0.75*i/(n-1)), 1-(0.75*i/(n-1)), 1-(0.75*i/(n-1)), 1);
|
||||
}
|
||||
lut->UseAboveRangeColorOn();
|
||||
lut->SetAboveRangeColor(0.2, 0.2, 0.2, 1);
|
||||
|
||||
// We cheat a little here: any particle with an age of -1 is out of bounds, and thus set invisible.
|
||||
lut->UseBelowRangeColorOn();
|
||||
lut->SetBelowRangeColor(1,1,1,0);
|
||||
|
||||
return lut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and returns a vtkLookupTable for the given number of colours in grayscale.
|
||||
* @param n : number of colours to add to the SetTableRange
|
||||
* @return : a vtkLookupTable with grayscale colours from [1,1,1,1] to [1,1,1,0.25] in n steps.
|
||||
*/
|
||||
vtkSmartPointer<vtkLookupTable> buildLut(int n) {
|
||||
vtkSmartPointer<vtkLookupTable> buildLutOpacity(int n) {
|
||||
vtkNew<vtkLookupTable> lut;
|
||||
lut->SetNumberOfColors(n);
|
||||
lut->SetTableRange(0, n);
|
||||
|
|
@ -58,6 +82,9 @@ vtkSmartPointer<vtkLookupTable> buildLut(int n) {
|
|||
}
|
||||
|
||||
LGlyphLayer::LGlyphLayer(std::shared_ptr<UVGrid> uvGrid, std::unique_ptr<AdvectionKernel> advectionKernel) {
|
||||
this->luts.push(buildLutOpacity(512));
|
||||
this->luts.push(buildLutBrightness(512));
|
||||
|
||||
this->ren = vtkSmartPointer<vtkRenderer>::New();
|
||||
this->ren->SetLayer(2);
|
||||
|
||||
|
|
@ -94,15 +121,20 @@ LGlyphLayer::LGlyphLayer(std::shared_ptr<UVGrid> uvGrid, std::unique_ptr<Advecti
|
|||
glyph2D->SetScaleModeToDataScalingOff();
|
||||
glyph2D->Update();
|
||||
|
||||
vtkNew<vtkPolyDataMapper> mapper;
|
||||
mapper->SetInputConnection(glyph2D->GetOutputPort());
|
||||
mapper->SetColorModeToMapScalars();
|
||||
mapper->SetLookupTable(buildLut(512));
|
||||
mapper->UseLookupTableScalarRangeOn();
|
||||
mapper->Update();
|
||||
this->mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
this->mapper->SetInputConnection(glyph2D->GetOutputPort());
|
||||
this->mapper->SetColorModeToMapScalars();
|
||||
|
||||
auto lut = this->luts.front();
|
||||
mapper->SetLookupTable(lut);
|
||||
this->luts.pop();
|
||||
this->luts.push(lut);
|
||||
|
||||
this->mapper->UseLookupTableScalarRangeOn();
|
||||
this->mapper->Update();
|
||||
|
||||
vtkNew<vtkActor> actor;
|
||||
actor->SetMapper(mapper);
|
||||
actor->SetMapper(this->mapper);
|
||||
|
||||
this->ren->AddActor(actor);
|
||||
}
|
||||
|
|
@ -174,6 +206,13 @@ void LGlyphLayer::addObservers(vtkSmartPointer<vtkRenderWindowInteractor> intera
|
|||
}
|
||||
|
||||
|
||||
void LGlyphLayer::cycleGlyphStyle() {
|
||||
auto lut = this->luts.front();
|
||||
this->mapper->SetLookupTable(lut);
|
||||
this->luts.pop();
|
||||
this->luts.push(lut);
|
||||
}
|
||||
|
||||
void LGlyphLayer::setDt(int dt) {
|
||||
this->dt = dt;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "Layer.h"
|
||||
#include "../advection/kernel/AdvectionKernel.h"
|
||||
#include "../commands/SpawnPointCallback.h"
|
||||
#include <queue>
|
||||
#include <vtkPolyData.h>
|
||||
#include <vtkInteractorStyle.h>
|
||||
|
||||
|
|
@ -16,10 +17,12 @@ private:
|
|||
vtkSmartPointer<vtkPolyData> data;
|
||||
vtkSmartPointer<vtkIntArray> particlesBeached;
|
||||
vtkSmartPointer<vtkIntArray> particlesAge;
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper;
|
||||
std::unique_ptr<AdvectionKernel> advector;
|
||||
std::shared_ptr<UVGrid> uvGrid;
|
||||
int dt = 3600;
|
||||
int beachedAtNumberOfTimes = 20;
|
||||
std::queue<vtkSmartPointer<vtkLookupTable>> luts;
|
||||
|
||||
public:
|
||||
/** Constructor.
|
||||
|
|
@ -41,6 +44,9 @@ public:
|
|||
|
||||
void addObservers(vtkSmartPointer<vtkRenderWindowInteractor> interactor) override;
|
||||
|
||||
/** This function cycles which lut is used for the layer, according to the lookuptables in the luts attribute.
|
||||
*/
|
||||
void cycleGlyphStyle();
|
||||
|
||||
/**
|
||||
* Sets a custom DT value, needed for advect calls to the simulation logic.
|
||||
|
|
|
|||
|
|
@ -33,9 +33,10 @@ int main() {
|
|||
auto l = new LGlyphLayer(uvGrid, std::move(kernelRK4BoundaryChecked));
|
||||
l->spoofPoints();
|
||||
l->setDt(DT);
|
||||
l->cycleGlyphStyle();
|
||||
|
||||
unique_ptr<Program> program = make_unique<Program>(DT);
|
||||
program->addLayer(new BackgroundImage(dataPath + "/map_661-661.png"));
|
||||
program->addLayer(new BackgroundImage(dataPath + "/map_qgis.png"));
|
||||
// program->addLayer(new EGlyphLayer(uvGrid));
|
||||
program->addLayer(new EColLayer(uvGrid));
|
||||
program->addLayer(l);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef TECHNIQUE_H
|
||||
#define TECHNIQUE_H
|
||||
|
||||
#include "layers/Layer.h"
|
||||
#include <vtkPolyData.h>
|
||||
class Technique {
|
||||
private:
|
||||
std::vector<Layer *> layers;
|
||||
vtkSmartPointer<vtkPoints> points;
|
||||
vtkSmartPointer<vtkPolyData> data;
|
||||
|
||||
void setupInteractions();
|
||||
|
||||
public:
|
||||
Technique();
|
||||
void addLayer(Layer *l);
|
||||
void removeLayer(Layer *l);
|
||||
void updateData(int t);
|
||||
int numberOfLayers();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue