-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #270 from ABRG-Models/colourmap_browser
Adds a Colourmap browser
- Loading branch information
Showing
7 changed files
with
722 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Make a colourbar tester using a morph::Grid/GridVisual | ||
* | ||
* This shows a min to max gradient of a ColourMap, with a decaying sine wave added to | ||
* the signal. Poor colour maps like Jet show structure in the features that is not part | ||
* of the data. | ||
*/ | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include <cmath> | ||
|
||
#include <morph/Scale.h> | ||
#include <morph/vec.h> | ||
#include <morph/Visual.h> | ||
#include <morph/VisualDataModel.h> | ||
#include <morph/GridVisual.h> | ||
#include <morph/Grid.h> | ||
#include <morph/CyclicColourVisual.h> | ||
|
||
struct myvisual final : public morph::Visual<> | ||
{ | ||
myvisual (int width, int height, const std::string& title) : morph::Visual<> (width, height, title) {} | ||
morph::ColourMapType curr_map_type = morph::ColourMapType::Plasma; | ||
bool forwards = true; | ||
protected: | ||
void key_callback_extra (int key, [[maybe_unused]] int scancode, int action, [[maybe_unused]] int mods) override | ||
{ | ||
if (key == morph::key::right && (action == morph::keyaction::press || action == morph::keyaction::repeat)) { | ||
++this->curr_map_type; | ||
this->forwards = true; | ||
} | ||
if (key == morph::key::left && (action == morph::keyaction::press || action == morph::keyaction::repeat)) { | ||
--this->curr_map_type; | ||
this->forwards = false; | ||
} | ||
if (key == morph::key::h && action == morph::keyaction::press) { std::cout << "left/right switch maps\n"; } | ||
} | ||
}; | ||
|
||
morph::VisualModel<>* addmap (myvisual& v, morph::ColourMapType display_map_type, const morph::Grid<>& grid, const std::vector<float>& data) | ||
{ | ||
morph::VisualModel<>* vmp = nullptr; | ||
morph::ColourMap<float> nextmap (display_map_type); | ||
if ((nextmap.flags & morph::ColourMapFlags::cyclic) == true) { | ||
morph::vec<float, 3> offset = {0,0,0}; | ||
auto cv = std::make_unique<morph::CyclicColourVisual<float>>(offset); | ||
v.bindmodel (cv); | ||
cv->outer_radius = 0.6; | ||
cv->inner_radius = 0.2; | ||
cv->cm = nextmap; | ||
cv->draw_ticks = false; | ||
cv->addLabel (cv->cm.getTypeStr() + std::string(" (") + cv->cm.getFlagsStr() + std::string(")"), | ||
morph::vec<float>({-1.3, -0.4, 0}), morph::TextFeatures(0.05f)); | ||
cv->finalize(); | ||
vmp = v.addVisualModel (cv); | ||
} else { | ||
morph::vec<float, 3> offset = { -0.5f * grid.width(), -0.5f * grid.height(), 0.0f }; | ||
auto gv = std::make_unique<morph::GridVisual<float>>(&grid, offset); | ||
v.bindmodel (gv); | ||
gv->gridVisMode = morph::GridVisMode::Triangles; | ||
gv->setScalarData (&data); | ||
gv->cm = nextmap; | ||
gv->zScale.setParams (0, 0); | ||
gv->addLabel (gv->cm.getTypeStr() + std::string(" (") + gv->cm.getFlagsStr() + std::string(")"), | ||
morph::vec<float>({0,-0.1,0}), morph::TextFeatures(0.05f)); | ||
gv->finalize(); | ||
vmp = v.addVisualModel (gv); | ||
} | ||
return vmp; | ||
} | ||
|
||
int main() | ||
{ | ||
myvisual v(2100, 1100, "Colourbar perceptual uniformity test"); | ||
v.setSceneTrans (morph::vec<float,3>{ float{-0.00636619}, float{0.0518834}, float{-3} }); | ||
|
||
// Create a grid for the colourmaps | ||
constexpr unsigned int Nside_w = 512; | ||
constexpr unsigned int Nside_h = 256; | ||
constexpr float barw = 2.56f; | ||
constexpr float barh = 0.5f; | ||
constexpr morph::vec<float, 2> grid_spacing = {barw/static_cast<float>(Nside_w), barh/static_cast<float>(Nside_h)}; | ||
morph::Grid grid(Nside_w, Nside_h, grid_spacing); | ||
|
||
// Our data is a ramp with a sine wave embossed on it | ||
std::vector<float> data(grid.n, 0.0); | ||
for (unsigned int ri=0; ri<grid.n; ++ri) { | ||
auto x = grid[ri][0]; | ||
auto y = grid[ri][1]; | ||
data[ri] = x / grid.width() + 0.1f * (y / grid.height()) * (y / grid.height()) * std::sin (120.0f * x); | ||
} | ||
|
||
morph::ColourMapType display_map_type = v.curr_map_type; | ||
morph::VisualModel<>* gvp = addmap (v, v.curr_map_type, grid, data); | ||
|
||
while (v.readyToFinish == false) { | ||
v.render(); | ||
v.waitevents (0.017); | ||
if (v.curr_map_type != display_map_type) { | ||
// Change to v.curr_map_type | ||
morph::ColourMap<float> nextmap(v.curr_map_type); | ||
if ((nextmap.flags & morph::ColourMapFlags::one_d) == true) { | ||
// Update the map | ||
v.removeVisualModel (gvp); | ||
gvp = addmap (v, v.curr_map_type, grid, data); | ||
} else { | ||
// The map wasn't 1D, so skip | ||
if (v.forwards) { ++v.curr_map_type; } else { --v.curr_map_type; } | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Use cartgridvisuals to illustrate use of ColourMapType::HSV colourmap. | ||
*/ | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include <cmath> | ||
|
||
#include <morph/Visual.h> | ||
#include <morph/ColourMap.h> | ||
#include <morph/CyclicColourVisual.h> | ||
|
||
int main() | ||
{ | ||
// The main function is simple. Create a morph::Visual, add a single SquareGridVisual and then 'keep it open' | ||
std::string titlestr = "Cyclic colour map"; | ||
morph::Visual v(1600, 1000, titlestr, {-0.8,-0.8}, {.05,.05,.05}, 2.0f, 0.0f); | ||
v.backgroundBlack(); | ||
|
||
morph::vec<float, 3> offset = { 0.0f, 0.0f, 0.0f }; | ||
|
||
// TextFeatures is a nice way to specify font size, colour (and other things) for your addLabel() calls. | ||
morph::TextFeatures tf (0.5f, morph::colour::white); | ||
|
||
// HSVWHeel for Grid1 | ||
morph::vec<float, 3> woffset = offset; | ||
auto hsvw_vis = std::make_unique<morph::CyclicColourVisual<float>>(woffset); | ||
v.bindmodel (hsvw_vis); | ||
hsvw_vis->setColour (morph::colour::white); | ||
hsvw_vis->cm = morph::ColourMapType::CET_C6;// CET_C6 | ||
hsvw_vis->finalize(); | ||
v.addVisualModel (hsvw_vis); | ||
|
||
v.keepOpen(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.