-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgrid_simple.cpp
More file actions
124 lines (104 loc) · 4.85 KB
/
Copy pathgrid_simple.cpp
File metadata and controls
124 lines (104 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* An example mplot::Visual scene, containing a Gridv, and using GridvVisual
*/
#include <iostream>
#include <vector>
#include <cmath>
#include <sm/vec>
#include <sm/grid>
#include <mplot/Visual.h>
#include <mplot/VisualDataModel.h>
#include <mplot/GridVisual.h>
int main()
{
mplot::Visual v(1600, 1000, "mplot::GridVisual");
#ifdef ORTHOGRAPHIC
// Here's how to set your Visual to do an orthographic projection rather than perspective
v.ptype = mplot::perspective_type::orthographic;
#endif
// Create a grid to show in the scene
constexpr unsigned int Nside = 100;
constexpr sm::vec<float, 2> grid_spacing = {0.01f, 0.01f};
// The simplest declaration of Grid is:
// sm::Grid g(size_t n_x, size_t n_y);
// grid_spacing, grid_zero, use of memory, wrapping and ordering are all possible arguments to
// the constructor.
sm::grid grid(Nside, Nside, grid_spacing);
std::cout << "Number of pixels in grid:" << grid.n() << std::endl;
// Make some dummy data (a sine wave) to make an interesting surface
std::vector<float> data(grid.n(), 0.0);
for (unsigned int ri=0; ri<grid.n(); ++ri) {
auto coord = grid[ri];
data[ri] = 0.05f + 0.05f * std::sin(20.0f * coord[0]) * std::sin(10.0f*coord[1]) ; // Range 0->1
}
float step = 0.6f;
// Add a GridVisual to display the Grid within the mplot::Visual scene
sm::vec<float, 3> offset = { -step * grid.width(), -step * grid.width(), 0.0f };
auto gv = std::make_unique<mplot::GridVisual<float>>(&grid, offset);
v.bindmodel (gv);
gv->gridVisMode = mplot::GridVisMode::Triangles;
gv->setScalarData (&data);
gv->cm.setType (mplot::ColourMapType::Cork);
gv->addLabel (std::string("GridVisMode::Triangles, cm: ") + gv->cm.getTypeStr(), sm::vec<float>({0,-0.1,0}), mplot::TextFeatures(0.03f));
gv->finalize();
v.addVisualModel (gv);
offset = { step * grid.width(), -step * grid.width(), 0.0f };
gv = std::make_unique<mplot::GridVisual<float>>(&grid, offset);
v.bindmodel (gv);
gv->gridVisMode = mplot::GridVisMode::RectInterp;
gv->setScalarData (&data);
// To show a grid first set the scaling so that the whole image is flat
//gv->zScale.null_scaling();
// Say you want a grid
//gv->showgrid (true);
// Choose the thickness. This is a proportion of the pixel dimensions
//gv->grid_thickness = 0.1f;
gv->cm.setType (mplot::ColourMapType::Buda);
gv->addLabel (std::string("GridVisMode::RectInterp, cm: ") + gv->cm.getTypeStr(), sm::vec<float>({0,-0.1,0}), mplot::TextFeatures(0.03f));
gv->finalize();
v.addVisualModel (gv);
offset = { -step * grid.width(), step * grid.width(), 0.0f };
gv = std::make_unique<mplot::GridVisual<float>>(&grid, offset);
v.bindmodel (gv);
gv->gridVisMode = mplot::GridVisMode::Columns;
gv->interpolate_colour_sides (true);
gv->setScalarData (&data);
gv->cm.setType (mplot::ColourMapType::Imola);
gv->addLabel (std::string("GridVisMode::Columns, interpolated sides, cm: ") + gv->cm.getTypeStr(), sm::vec<float>({0,-0.1,0}), mplot::TextFeatures(0.03f));
gv->finalize();
v.addVisualModel (gv);
offset = { step * grid.width(), step * grid.width(), 0.0f };
gv = std::make_unique<mplot::GridVisual<float>>(&grid, offset);
v.bindmodel (gv);
gv->gridVisMode = mplot::GridVisMode::Columns;
//gv->interpolate_colour_sides = false; // default
//gv->clr_east_column = mplot::colour::black; // These are defaults but you can change them
//gv->clr_north_column = mplot::colour::black;
gv->setScalarData (&data);
gv->cm.setType (mplot::ColourMapType::Managua);
gv->addLabel (std::string("GridVisMode::Columns, black sides, cm: ") + gv->cm.getTypeStr(), sm::vec<float>({0,-0.1,0}), mplot::TextFeatures(0.03));
gv->finalize();
v.addVisualModel (gv);
offset = { 3 * step * grid.width(), step * grid.width(), 0.0f };
gv = std::make_unique<mplot::GridVisual<float>>(&grid, offset);
v.bindmodel (gv);
gv->gridVisMode = mplot::GridVisMode::Pixels;
gv->setScalarData (&data);
gv->cm.setType (mplot::ColourMapType::Navia);
gv->addLabel (std::string("GridVisMode::Pixels, cm: ") + gv->cm.getTypeStr(), sm::vec<float>({0,-0.1,0}), mplot::TextFeatures(0.03));
gv->finalize();
v.addVisualModel (gv);
offset = { 3 * step * grid.width(), -step * grid.width(), 0.0f };
gv = std::make_unique<mplot::GridVisual<float>>(&grid, offset);
v.bindmodel (gv);
gv->gridVisMode = mplot::GridVisMode::RectInterp;
gv->setScalarData (&data);
gv->cm.setType (mplot::ColourMapType::Navia);
gv->addLabel (std::string("GridVisMode::RectInterp, implygrid=true, cm: ") + gv->cm.getTypeStr(), sm::vec<float>({0,-0.1,0}), mplot::TextFeatures(0.03));
gv->implygrid (true);
gv->grid_thickness = 0.18f; // of a pixel
gv->finalize();
v.addVisualModel (gv);
v.keepOpen();
return 0;
}