Developer documentation
Version 3.0.3-105-gd3941f44
mesh.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 __surface_mesh_h__
18#define __surface_mesh_h__
19
20
21#include <cstdint>
22#include <fstream>
23
24#include "header.h"
25#include "image.h"
26#include "transform.h"
27
28#include "algo/copy.h"
29#include "algo/loop.h"
30
31#include "surface/types.h"
32
33
34
35namespace MR
36{
37 namespace Surface
38 {
39
40
41 namespace Filter
42 {
43 class Smooth;
44 }
45
46
47
49
50 public:
51 Mesh (const std::string&);
52
53 Mesh (const Mesh& that) = default;
54
55 Mesh (Mesh&& that) :
56 vertices (std::move (that.vertices)),
57 normals (std::move (that.normals)),
58 triangles (std::move (that.triangles)),
59 quads (std::move (that.quads)) { }
60
61 Mesh() { }
62
63 Mesh& operator= (Mesh&& that) {
64 vertices = std::move (that.vertices);
65 normals = std::move (that.normals);
66 triangles = std::move (that.triangles);
67 quads = std::move (that.quads);
68 return *this;
69 }
70
71 Mesh& operator= (const Mesh& that) {
72 vertices = that.vertices;
73 normals = that.normals;
74 triangles = that.triangles;
75 quads = that.quads;
76 return *this;
77 }
78
79
80 void load (VertexList&& v, TriangleList&& p) {
81 vertices = std::move (v);
82 normals.clear();
83 triangles = std::move (p);
84 quads.clear();
85 }
86 void load (const VertexList& v, const TriangleList& p) {
87 vertices = v;
88 normals.clear();
89 triangles = p;
90 quads.clear();
91 }
92
93 void load (VertexList&& v, QuadList&& p) {
94 vertices = std::move (v);
95 normals.clear();
96 triangles.clear();
97 quads = std::move (p);
98 }
99 void load (const VertexList& v, const QuadList& p) {
100 vertices = v;
101 normals.clear();
102 triangles.clear();
103 quads = p;
104 }
105
106 void load (VertexList&& v, TriangleList&& p, QuadList&& q) {
107 vertices = std::move (v);
108 normals.clear();
109 triangles = std::move (p);
110 quads = std::move (q);
111 }
112 void load (const VertexList& v, const TriangleList& p, const QuadList& q) {
113 vertices = v;
114 normals.clear();
115 triangles = p;
116 quads = q;
117 }
118
119 void load (VertexList&& v, VertexList&& n, TriangleList&& p, QuadList&& q) {
120 vertices = std::move (v);
121 normals = std::move (n);
122 triangles = std::move (p);
123 quads = std::move (q);
124 }
125 void load (const VertexList& v, const VertexList& n, const TriangleList& p, const QuadList& q) {
126 vertices = v;
127 normals = n;
128 triangles = p;
129 quads = q;
130 }
131
132 void clear() {
133 vertices.clear();
134 normals.clear();
135 triangles.clear();
136 quads.clear();
137 }
138
139
140 void save (const std::string&, const bool binary = false) const;
141
142 size_t num_vertices() const { return vertices.size(); }
143 size_t num_triangles() const { return triangles.size(); }
144 size_t num_quads() const { return quads.size(); }
145 size_t num_polygons() const { return triangles.size() + quads.size(); }
146
147 bool have_normals() const { return normals.size(); }
148 void calculate_normals();
149
150 const std::string& get_name() const { return name; }
151 void set_name (const std::string& s) { name = s; }
152
153 const Vertex& vert (const size_t i) const { assert (i < vertices .size()); return vertices[i]; }
154 const Vertex& norm (const size_t i) const { assert (i < normals .size()); return normals[i]; }
155 const Triangle& tri (const size_t i) const { assert (i < triangles.size()); return triangles[i]; }
156 const Quad& quad (const size_t i) const { assert (i < quads .size()); return quads[i]; }
157
158 const VertexList& get_vertices() const { return vertices; }
159 const VertexList& get_normals() const { return normals; }
160 const TriangleList& get_triangles() const { return triangles; }
161 const QuadList& get_quads() const { return quads; }
162
163 void load_triangle_vertices (VertexList&, const size_t) const;
164 void load_quad_vertices (VertexList&, const size_t) const;
165
166
167 protected:
172
173
174 private:
175 std::string name;
176
177 void load_vtk (const std::string&);
178 void load_stl (const std::string&);
179 void load_obj (const std::string&);
180 void load_fs (const std::string&);
181 void save_vtk (const std::string&, const bool) const;
182 void save_stl (const std::string&, const bool) const;
183 void save_obj (const std::string&) const;
184
185 void verify_data() const;
186
187 friend class MeshMulti;
188 friend class Filter::Smooth;
189 template <class ImageType>
190 void mesh2image (const ImageType&, Mesh&, const default_type);
191
192 };
193
194
195
196 }
197}
198
199#endif
200
VertexList normals
Definition: mesh.h:169
QuadList quads
Definition: mesh.h:171
TriangleList triangles
Definition: mesh.h:170
VertexList vertices
Definition: mesh.h:168
void mesh2image(const Mesh &, Image< float > &)
Eigen::Vector3d Vertex
Definition: types.h:32
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228
#define MEMALIGN(...)
Definition: types.h:185