Developer documentation
Version 3.0.3-105-gd3941f44
polygon.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_polygon_h__
18#define __surface_polygon_h__
19
20#include <assert.h>
21#include <initializer_list>
22#include <stddef.h>
23#include <stdint.h>
24
25#include "mrtrix.h"
26
27namespace MR
28{
29 namespace Surface
30 {
31
32
33 template <uint32_t vertices = 3>
34 class Polygon
35 { MEMALIGN (Polygon<vertices>)
36
37 public:
38
39 template <typename T>
40 Polygon (const T* const d)
41 {
42 for (size_t i = 0; i != vertices; ++i)
43 indices[i] = d[i];
44 }
45
46 template <class C>
47 Polygon (const C& d)
48 {
49 assert (d.size() == vertices);
50 for (size_t i = 0; i != vertices; ++i)
51 indices[i] = d[i];
52 }
53
54 template <typename T>
55 Polygon (const std::initializer_list<T> l)
56 {
57 assert (l.size() == vertices);
58 size_t counter = 0;
59 for (auto i = l.begin(); i != l.end(); ++i, ++counter)
60 indices[counter] = *i;
61 }
62
63 Polygon()
64 {
65 memset (indices, 0, vertices * sizeof (uint32_t));
66 }
67
68
69 uint32_t& operator[] (const size_t i) { assert (i < vertices); return indices[i]; }
70 uint32_t operator[] (const size_t i) const { assert (i < vertices); return indices[i]; }
71
72 size_t size() const { return vertices; }
73
74 bool shares_edge (const Polygon&) const;
75
76 private:
77 uint32_t indices[vertices];
78
79 };
80
81 template <> bool Polygon<3>::shares_edge (const Polygon<3>&) const;
82
83
84
85 }
86}
87
88#endif
89
Definition: base.h:24