Developer documentation
Version 3.0.3-105-gd3941f44
node.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_node_h__
18#define __gui_mrview_tool_connectome_node_h__
19
20#include "image.h"
21
22#include "gui/opengl/gl.h"
23#include "surface/mesh.h"
24
25namespace MR
26{
27 namespace GUI
28 {
29 namespace MRView
30 {
31 namespace Tool
32 {
33
34
35 // Stores all information relating to the drawing of individual nodes, both fixed and variable
36 class Node
37 { MEMALIGN(Node)
38 public:
39 Node (const Eigen::Vector3f&, const size_t, const size_t, const MR::Image<bool>&);
40 Node ();
41
42 void assign_mesh (MR::Surface::Mesh& in) { clear_mesh(); mesh.reset (new Node::Mesh (in)); }
43 void render_mesh() const { if (!mesh) return; mesh->render(); }
44 void clear_mesh() { if (mesh) delete mesh.release(); }
45
46 const Eigen::Vector3f& get_com() const { return centre_of_mass; }
47 size_t get_volume() const { return volume; }
48
49 void set_name (const std::string& i) { name = i; }
50 const std::string& get_name() const { return name; }
51 void set_size (const float i) { size = i; }
52 float get_size() const { return size; }
53 void set_colour (const Eigen::Array3f& i) { colour = i; pixmap.fill (QColor (i[0] * 255.0f, i[1] * 255.0f, i[2] * 255.0f)); }
54 const Eigen::Array3f& get_colour() const { return colour; }
55 const QPixmap get_pixmap() const { return pixmap; }
56 void set_alpha (const float i) { alpha = i; }
57 float get_alpha() const { return alpha; }
58 void set_visible (const bool i) { visible = i; }
59 bool is_visible() const { return visible; }
60
61 bool to_draw() const { return (visible && (alpha > 0.0f) && (size > 0.0f)); }
62
63 private:
64 const Eigen::Vector3f centre_of_mass;
65 const size_t volume;
66 MR::Image<bool> mask;
67
68 std::string name;
69 float size;
70 Eigen::Array3f colour;
71 float alpha;
72 bool visible;
73
74 QPixmap pixmap;
75
76 // Helper class to manage the storage and display of the mesh for each node
77 class Mesh { MEMALIGN(Mesh)
78 public:
79 Mesh (MR::Surface::Mesh&);
80 Mesh (const Mesh&) = delete;
81 Mesh (Mesh&&);
82 Mesh () = delete;
83 ~Mesh();
84 Mesh& operator= (Mesh&&);
85 void render() const;
86 private:
87 GLsizei count;
88 GL::VertexBuffer vertex_buffer, normal_buffer;
89 GL::VertexArrayObject vertex_array_object;
90 GL::IndexBuffer index_buffer;
91 };
92 std::unique_ptr<Mesh> mesh;
93
94 };
95
96
97
98 }
99 }
100 }
101}
102
103#endif
104
105
106
107
Array & operator=(const MR::Helper::ConstRow< ImageType > &row)
Definition: array.h:25
Definition: base.h:24
#define MEMALIGN(...)
Definition: types.h:185