Developer documentation
Version 3.0.3-105-gd3941f44
tractogram.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_tractogram_h__
18#define __gui_mrview_tool_tractogram_h__
19
23
24
25namespace MR
26{
27
28 namespace GUI
29 {
30 class Projection;
31
32 namespace MRView
33 {
34 class Window;
35
36 namespace Tool
37 {
38 class Tractogram : public Displayable
40 Q_OBJECT
41
42 public:
43 Tractogram (Tractography& tool, const std::string& file_path);
44
45 ~Tractogram ();
46
47 Window& window () const { return *Window::main; }
48
49 void render (const Projection& transform);
50
51 void request_render_colourbar (DisplayableVisitor& visitor) override {
52 if (color_type == TrackColourType::ScalarFile && show_colour_bar)
53 visitor.render_tractogram_colourbar(*this);
54 }
55
56 void load_tracks();
57
58 void load_end_colours();
59 void load_intensity_track_scalars (const std::string&);
60 void load_threshold_track_scalars (const std::string&);
61 void erase_colour_data();
62 void erase_intensity_scalar_data ();
63 void erase_threshold_scalar_data ();
64
65 void set_color_type (const TrackColourType);
66 void set_threshold_type (const TrackThresholdType);
67 void set_geometry_type (const TrackGeometryType);
68 TrackColourType get_color_type() const { return color_type; }
69 TrackThresholdType get_threshold_type() const { return threshold_type; }
70 TrackGeometryType get_geometry_type() const { return geometry_type; }
71
72 void set_colour (float c[3]) { colour = { c[0], c[1], c[2] }; }
73
74 float get_threshold_rate() const {
75 switch (threshold_type) {
76 case TrackThresholdType::None: return NaN;
77 case TrackThresholdType::UseColourFile: return scaling_rate();
78 case TrackThresholdType::SeparateFile: return (1e-3 * (threshold_max - threshold_min));
79 }
80 assert (0);
81 return NaN;
82 }
83 float get_threshold_min() const { return threshold_min; }
84 float get_threshold_max() const { return threshold_max; }
85
86 static TrackGeometryType default_tract_geom;
87 static constexpr float default_line_thickness = 2e-3f;
88 static constexpr float default_point_size = 4e-3f;
89
90 bool scalarfile_by_direction;
91 bool show_colour_bar;
92 bool should_update_stride;
93 Eigen::Array3f colour;
94 float original_fov;
95 float line_thickness;
96 std::string intensity_scalar_filename;
97 std::string threshold_scalar_filename;
98
99 class Shader : public Displayable::Shader { MEMALIGN(Shader)
100 public:
101 Shader () :
102 do_crop_to_slab (false),
103 use_lighting (false),
104 color_type (TrackColourType::Direction),
105 threshold_type (TrackThresholdType::None),
106 geometry_type (Tractogram::default_tract_geom) { }
107 std::string vertex_shader_source (const Displayable&) override;
108 std::string fragment_shader_source (const Displayable&) override;
109 std::string geometry_shader_source (const Displayable&) override;
110 virtual bool need_update (const Displayable&) const override;
111 virtual void update (const Displayable&) override;
112 protected:
113 bool do_crop_to_slab, use_lighting;
114 TrackColourType color_type;
115 TrackThresholdType threshold_type;
116 TrackGeometryType geometry_type;
117
118 } track_shader;
119
120 signals:
122
123 private:
124 static const int track_padding = 6;
125 Tractography& tractography_tool;
126
127 const std::string filename;
128
129 TrackColourType color_type;
130 TrackThresholdType threshold_type;
131 TrackGeometryType geometry_type;
132
133 // Instead of tracking the file path, pre-calculate the
134 // streamline tangents and store them; then, if colour by
135 // endpoint is requested, generate the buffer based on these
136 // and the known track sizes
137 vector<Eigen::Vector3f> endpoint_tangents;
138
139 vector<GLuint> vertex_buffers;
140 vector<GLuint> vertex_array_objects;
141 vector<GLuint> colour_buffers;
142 vector<GLuint> intensity_scalar_buffers;
143 vector<GLuint> threshold_scalar_buffers;
145 vector<vector<GLint> > track_starts;
146 vector<vector<GLint> > track_sizes;
147 vector<vector<GLint> > original_track_sizes;
148 vector<vector<GLint> > original_track_starts;
149 vector<size_t> num_tracks_per_buffer;
150 GLint sample_stride;
151 bool vao_dirty;
152
153 // Extra members now required since different scalar files
154 // may be used for streamline colouring and thresholding
155 float threshold_min, threshold_max;
156
157
158 void load_tracks_onto_GPU (vector<Eigen::Vector3f>& buffer,
159 vector<GLint>& starts,
160 vector<GLint>& sizes,
161 size_t& tck_count);
162
163 void load_end_colours_onto_GPU (vector<Eigen::Vector3f>&);
164
165 void load_intensity_scalars_onto_GPU (vector<float>& buffer, size_t& tck_count);
166 void load_threshold_scalars_onto_GPU (vector<float>& buffer, size_t& tck_count);
167
168 void render_streamlines ();
169
170 void update_stride ();
171
172 private slots:
173 void on_FOV_changed() {
174 should_update_stride = true;
175 }
176 };
177 }
178 }
179 }
180}
181
182#endif
183
virtual void render_tractogram_colourbar(const Tool::Tractogram &)
Definition: displayable.h:59
static Window * main
Definition: window.h:160
constexpr double e
Definition: math.h:39
Definition: base.h:24
constexpr default_type NaN
Definition: types.h:230
#define MEMALIGN(...)
Definition: types.h:185