-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTriFrameVisual.cppm
More file actions
86 lines (75 loc) · 2.69 KB
/
Copy pathTriFrameVisual.cppm
File metadata and controls
86 lines (75 loc) · 2.69 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
module;
#include <cstdint>
#include <iostream>
#include <vector>
#include <array>
#include <cmath>
export module mplot.triframevisual;
import sm.vec;
import mplot.tools;
import mplot.visualdatamodel;
import mplot.colourmap;
export namespace mplot
{
/*!
* The template argument Flt is the type of the data which this PointRowsMeshVisual
* will visualize.
*
* Render a triangle made of 3 rods, with spheres at the vertices.
*
* \param sp The shader program
*
* \param _offset The offset within the mplot::Visual scene at which the model will
* be drawn (used when rendering, not when creating the model's vertices)
*/
template <typename Flt, std::int32_t glver = mplot::gl::version_4_1>
class TriFrameVisual : public VisualDataModel<Flt, glver>
{
public:
TriFrameVisual(const sm::vec<float, 3> _offset)
{
this->viewmatrix.translate (_offset);
}
void initializeVertices()
{
this->vertexPositions.clear();
this->vertexNormals.clear();
this->vertexColors.clear();
this->indices.clear();
this->idx = 0;
std::uint32_t ncoords = this->dataCoords->size();
std::uint32_t ndata = this->scalarData->size();
std::vector<Flt> dcopy;
if (ndata) {
dcopy = *(this->scalarData);
this->colourScale.do_autoscale = true;
this->colourScale.transform (*this->scalarData, dcopy);
} // else no scaling required - spheres will be one colour
// Draw spheres
for (std::uint32_t i = 0U; i < ncoords; ++i) {
this->computeSphere ((*this->dataCoords)[i], this->cm.convert ((*this->scalarData)[i]), sradius);
}
// Draw tubes
std::array<float, 3> clr = {0.3f,0.3f,0.3f};
for (std::uint32_t i = 0U; i < ncoords; ++i) {
sm::vec<float> v1 = (*this->dataCoords)[i];
std::uint32_t e = (i < (ncoords-1) ? i+1 : 0);
sm::vec<float> v2 = (*this->dataCoords)[e];
sm::vec<float> _offset = this->viewmatrix.translation();
this->computeTube (_offset + v1, _offset + v2, clr, clr, this->radius, this->tseg);
}
}
//! tube radius
float radius = 0.05f;
//! sphere radius
float sradius = 0.052f;
//! sphere rings
std::int32_t srings = 10;
//! sphere segments
std::int32_t sseg = 12;
//! tube segments
std::int32_t tseg = 12;
//! A colour map for the spheres
mplot::ColourMap<float> cm_sph;
};
} // namespace mplot