Developer documentation
Version 3.0.3-105-gd3941f44
utils.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_utils_h__
18#define __surface_utils_h__
19
20#include "surface/mesh.h"
21#include "surface/polygon.h"
22#include "surface/types.h"
23
24
25namespace MR
26{
27 namespace Surface
28 {
29
30
31
32 inline Vertex normal (const Vertex& one, const Vertex& two, const Vertex& three)
33 {
34 return (two - one).cross (three - two).normalized();
35 }
36 inline Vertex normal (const Mesh& mesh, const Triangle& tri)
37 {
38 return normal (mesh.vert(tri[0]), mesh.vert(tri[1]), mesh.vert(tri[2]));
39 }
40
41 inline Vertex normal (const Vertex& one, const Vertex& two, const Vertex& three, const Vertex& four)
42 {
43 return (normal (one, two, three) + normal (one, three, four)).normalized();
44 }
45
46 inline Vertex normal (const Mesh& mesh, const Quad& quad)
47 {
48 return normal (mesh.vert(quad[0]), mesh.vert(quad[1]), mesh.vert(quad[2]), mesh.vert(quad[3]));
49 }
50
51
52
53 inline default_type area (const Vertex& one, const Vertex& two, const Vertex& three)
54 {
55 return 0.5 * ((two - one).cross (three - two).norm());
56 }
57
58 inline default_type area (const Mesh& mesh, const Triangle& tri)
59 {
60 return area (mesh.vert(tri[0]), mesh.vert(tri[1]), mesh.vert(tri[2]));
61 }
62
63 inline default_type area (const Vertex& one, const Vertex& two, const Vertex& three, const Vertex& four)
64 {
65 return area (one, two, three) + area (one, three, four);
66 }
67
68 inline default_type area (const Mesh& mesh, const Quad& quad)
69 {
70 return area (mesh.vert(quad[0]), mesh.vert(quad[1]), mesh.vert(quad[2]), mesh.vert(quad[3]));
71 }
72
73
74
75 }
76}
77
78#endif
79
Vertex normal(const Vertex &one, const Vertex &two, const Vertex &three)
Definition: utils.h:32
default_type area(const Vertex &one, const Vertex &two, const Vertex &three)
Definition: utils.h:53
Eigen::Vector3d Vertex
Definition: types.h:32
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228