Developer documentation
Version 3.0.3-105-gd3941f44
edge.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __gui_mrview_tool_connectome_edge_h__
18#define __gui_mrview_tool_connectome_edge_h__
19
20#include <memory>
21
22#include "math/math.h"
23#include "connectome/connectome.h"
25#include "gui/opengl/gl.h"
26
27namespace MR
28{
29 namespace GUI
30 {
31 namespace MRView
32 {
33 namespace Tool
34 {
35
36 class Connectome;
37
38 // Stores all information relating to the drawing of individual edges, both fixed and variable
39 // Try to store more than would otherwise be optimal in here, in order to simplify the drawing process
40 class Edge
41 { MEMALIGN(Edge)
42
44
45 public:
46 Edge (const node_t, const node_t, const Eigen::Vector3f&, const Eigen::Vector3f&);
48 Edge () = delete;
50
51 void render_line() const { assert (line); line->render(); }
52
53 void load_exemplar (const MR::DWI::Tractography::Streamline<float>& data) { assert (!exemplar); exemplar.reset (new Exemplar (*this, data)); }
54 void clear_exemplar() { if (streamtube) delete streamtube.release(); if (streamline) delete streamline.release(); if (exemplar) delete exemplar.release(); }
55
56 void create_streamline() { assert (!streamline); assert (exemplar); streamline.reset (new Streamline (*exemplar)); }
57 void render_streamline() const { assert (streamline); streamline->render(); }
58 void clear_streamline() { if (streamline) delete streamline.release(); }
59
60 void create_streamtube() { assert (!streamtube); assert (exemplar); streamtube.reset (new Streamtube (*exemplar)); }
61 void render_streamtube() const { assert (streamtube); streamtube->render(); }
62 void clear_streamtube() { if (streamtube) delete streamtube.release(); }
63
64 static void set_streamtube_LOD (const size_t lod) { Streamtube::LOD (lod); }
65
66 node_t get_node_index (const size_t i) const { assert (i==0 || i==1); return node_indices[i]; }
67 const Eigen::Vector3f& get_node_centre (const size_t i) const { assert (i==0 || i==1); return node_centres[i]; }
68 Eigen::Vector3f get_com() const { return (node_centres[0] + node_centres[1]) * 0.5; }
69
70 const GLfloat* get_rot_matrix() const { return rot_matrix; }
71
72 const Eigen::Vector3f& get_dir() const { return dir; }
73 void set_size (const float i) { size = i; }
74 float get_size() const { return size; }
75 void set_colour (const Eigen::Array3f& i) { colour = i; }
76 const Eigen::Array3f& get_colour() const { return colour; }
77 void set_alpha (const float i) { alpha = i; }
78 float get_alpha() const { return alpha; }
79 void set_visible (const bool i) { visible = i; }
80 bool is_visible() const { return visible; }
81 bool is_diagonal() const { return (node_indices[0] == node_indices[1]); }
82
83 bool to_draw() const { return (visible && (alpha > 0.0f) && (size > 0.0f)); }
84
85 private:
86 const node_t node_indices[2];
87 const Eigen::Vector3f node_centres[2];
88 const Eigen::Vector3f dir;
89
90 GLfloat* rot_matrix;
91
92 float size;
93 Eigen::Array3f colour;
94 float alpha;
95 bool visible;
96
97 class Line;
98 class Exemplar;
99 class Streamline;
100 class Streamtube;
101
102 class Line
103 { MEMALIGN(Line)
104 public:
105 Line (const Edge& parent);
106 Line (Line&& that) :
107 vertex_buffer (std::move (that.vertex_buffer)),
108 tangent_buffer (std::move (that.tangent_buffer)),
109 vertex_array_object (std::move (that.vertex_array_object)) { }
110 Line () = delete;
111 ~Line();
112 void render() const;
113 private:
114 GL::VertexBuffer vertex_buffer, tangent_buffer;
115 GL::VertexArrayObject vertex_array_object;
116 };
117 std::unique_ptr<Line> line;
118
119 // Raw data for exemplar; need to hold on to this
120 class Exemplar
121 { MEMALIGN(Exemplar)
122 public:
123 Exemplar (const Edge&, const MR::DWI::Tractography::Streamline<float>&);
124 Exemplar (Exemplar&& that) :
125 endpoints { that.endpoints[0], that.endpoints[1] },
126 vertices (std::move (that.vertices)),
127 tangents (std::move (that.tangents)),
128 normals (std::move (that.normals)),
129 binormals (std::move (that.binormals)) { }
130 Exemplar () = delete;
131 private:
132 const Eigen::Vector3f endpoints[2];
133 vector<Eigen::Vector3f> vertices, tangents, normals, binormals;
134 friend class Streamline;
135 friend class Streamtube;
136 };
137 std::unique_ptr<Exemplar> exemplar;
138
139 // Class to store data relating to storing and displaying the exemplar as a streamline
140 class Streamline
141 { MEMALIGN(Streamline)
142 public:
143 Streamline (const Exemplar& exemplar);
144 Streamline (Streamline&& that) :
145 count (that.count),
146 vertex_buffer (std::move (that.vertex_buffer)),
147 tangent_buffer (std::move (that.tangent_buffer)),
148 vertex_array_object (std::move (that.vertex_array_object)) { that.count = 0; }
149 Streamline () = delete;
150 ~Streamline();
151 void render() const;
152 private:
153 // The master thread must assign the VBOs and VAO
154 GLuint count;
155 GL::VertexBuffer vertex_buffer, tangent_buffer;
156 GL::VertexArrayObject vertex_array_object;
157 };
158 std::unique_ptr<Streamline> streamline;
159
160 // Class to store data for plotting each edge exemplar as a streamtube
161 class Streamtube
162 { MEMALIGN(Streamtube)
163 public:
164 Streamtube (const Exemplar&);
165 Streamtube (Streamtube&& that) :
166 count (that.count),
167 vertex_buffer (std::move (that.vertex_buffer)),
168 tangent_buffer (std::move (that.tangent_buffer)),
169 normal_buffer (std::move (that.normal_buffer)),
170 vertex_array_object (std::move (that.vertex_array_object)) { that.count = 0; }
171 ~Streamtube();
172 void render() const;
173 static void LOD (const size_t lod) { shared.set_LOD (lod); }
174 private:
175 GLuint count;
176 GL::VertexBuffer vertex_buffer, tangent_buffer, normal_buffer;
177 GL::VertexArrayObject vertex_array_object;
178
179 class Shared
180 { MEMALIGN(Shared)
181 public:
182 Shared() : max_num_points (0), LOD (0), element_counts (nullptr) { }
183 ~Shared() { clear(); }
184 void check_num_points (const size_t num_points) { if (num_points > max_num_points) { clear(); max_num_points = num_points; regenerate(); } }
185 void set_LOD (const size_t v) { if (LOD != v) { clear(); LOD = v; regenerate(); } }
186 size_t points_per_vertex() const { return Math::pow2 (LOD + 1); }
187 protected:
188 size_t max_num_points;
189 size_t LOD;
190 GLsizei* element_counts;
191 GLuint** element_indices;
192 private:
193 void regenerate();
194 void clear();
195 friend class Streamtube;
196 };
197 static Shared shared;
198
199 };
200 std::unique_ptr<Streamtube> streamtube;
201
202 };
203
204
205
206 }
207 }
208 }
209}
210
211#endif
212
213
214
215
void render_line() const
Definition: edge.h:51
Eigen::Vector3f get_com() const
Definition: edge.h:68
void load_exemplar(const MR::DWI::Tractography::Streamline< float > &data)
Definition: edge.h:53
const Eigen::Array3f & get_colour() const
Definition: edge.h:76
void render_streamtube() const
Definition: edge.h:61
float get_alpha() const
Definition: edge.h:78
void set_size(const float i)
Definition: edge.h:73
void set_alpha(const float i)
Definition: edge.h:77
const Eigen::Vector3f & get_node_centre(const size_t i) const
Definition: edge.h:67
float get_size() const
Definition: edge.h:74
void set_visible(const bool i)
Definition: edge.h:79
static void set_streamtube_LOD(const size_t lod)
Definition: edge.h:64
void set_colour(const Eigen::Array3f &i)
Definition: edge.h:75
node_t get_node_index(const size_t i) const
Definition: edge.h:66
Edge(const node_t, const node_t, const Eigen::Vector3f &, const Eigen::Vector3f &)
void render_streamline() const
Definition: edge.h:57
bool is_diagonal() const
Definition: edge.h:81
const GLfloat * get_rot_matrix() const
Definition: edge.h:70
const Eigen::Vector3f & get_dir() const
Definition: edge.h:72
bool to_draw() const
Definition: edge.h:83
bool is_visible() const
Definition: edge.h:80
constexpr T pow2(const T &v)
Definition: math.h:53
uint32_t node_t
Definition: connectome.h:34
Definition: base.h:24
Definition: types.h:303
#define MEMALIGN(...)
Definition: types.h:185