ViennaLS
Loading...
Searching...
No Matches
lsGeometries.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cassert>
4#include <vector>
5
7
8#include <vcSmartPointer.hpp>
9#include <vcVectorType.hpp>
10
11namespace viennals {
12using namespace viennacore;
13
15template <class T, int D> class Sphere {
16public:
17 VectorType<T, D> origin;
18 T radius = 0.;
19
20 Sphere(VectorType<T, D> passedOrigin, T passedRadius)
21 : origin(passedOrigin), radius(passedRadius) {}
22
23 Sphere(T *passedOrigin, T passedRadius) : radius(passedRadius) {
24 for (unsigned i = 0; i < D; ++i) {
25 origin[i] = passedOrigin[i];
26 }
27 }
28
29 Sphere(const std::vector<T> &passedOrigin, T passedRadius)
30 : radius(passedRadius) {
31 for (unsigned i = 0; i < D; ++i) {
32 origin[i] = passedOrigin[i];
33 }
34 }
35
36 template <class... Args> static auto New(Args &&...args) {
37 return SmartPointer<Sphere>::New(std::forward<Args>(args)...);
38 }
39};
40
42template <class T, int D> class Plane {
43public:
44 VectorType<T, D> origin;
45 VectorType<T, D> normal;
46
47 Plane(VectorType<T, D> passedOrigin, VectorType<T, D> passedNormal)
48 : origin(passedOrigin), normal(passedNormal) {}
49
50 Plane(const T *passedOrigin, const T *passedNormal) {
51 for (unsigned i = 0; i < D; ++i) {
52 origin[i] = passedOrigin[i];
53 normal[i] = passedNormal[i];
54 }
55 }
56
57 Plane(const std::vector<T> &passedOrigin,
58 const std::vector<T> &passedNormal) {
59 for (unsigned i = 0; i < D; ++i) {
60 origin[i] = passedOrigin[i];
61 normal[i] = passedNormal[i];
62 }
63 }
64
65 template <class... Args> static auto New(Args &&...args) {
66 return SmartPointer<Plane>::New(std::forward<Args>(args)...);
67 }
68};
69
71template <class T, int D> class Box {
72public:
73 VectorType<T, D> minCorner;
74 VectorType<T, D> maxCorner;
75
76 Box(VectorType<T, D> passedMinCorner, VectorType<T, D> passedMaxCorner)
77 : minCorner(passedMinCorner), maxCorner(passedMaxCorner) {}
78
79 Box(const T *passedMinCorner, const T *passedMaxCorner) {
80 for (unsigned i = 0; i < D; ++i) {
81 minCorner[i] = passedMinCorner[i];
82 maxCorner[i] = passedMaxCorner[i];
83 }
84 }
85
86 Box(const std::vector<T> &passedMinCorner,
87 const std::vector<T> &passedMaxCorner) {
88 for (unsigned i = 0; i < D; ++i) {
89 minCorner[i] = passedMinCorner[i];
90 maxCorner[i] = passedMaxCorner[i];
91 }
92 }
93
94 template <class... Args> static auto New(Args &&...args) {
95 return SmartPointer<Box>::New(std::forward<Args>(args)...);
96 }
97};
98
100template <class T, int D> class Cylinder {
101public:
103 VectorType<T, 3> origin;
105 VectorType<T, 3> axisDirection;
107 T height = 0.;
109 T radius = 0.;
112
113 Cylinder(VectorType<T, D> passedOrigin, VectorType<T, D> passedAxisDirection,
114 T passedHeight, T passedRadius, T passedTopRadius = 0)
115 : origin(passedOrigin), axisDirection(passedAxisDirection),
116 height(passedHeight), radius(passedRadius), topRadius(passedTopRadius) {
117 }
118
119 Cylinder(const T *passedOrigin, const T *passedAxisDirection,
120 const T passedHeight, const T passedRadius,
121 const T passedTopRadius = 0)
122 : height(passedHeight), radius(passedRadius), topRadius(passedTopRadius) {
123 for (unsigned i = 0; i < D; ++i) {
124 origin[i] = passedOrigin[i];
125 axisDirection[i] = passedAxisDirection[i];
126 }
127 }
128
129 Cylinder(std::vector<T> passedOrigin, std::vector<T> passedAxisDirection,
130 T passedHeight, T passedRadius, T passedTopRadius = 0)
131 : height(passedHeight), radius(passedRadius), topRadius(passedTopRadius) {
132 for (unsigned i = 0; i < D; ++i) {
133 origin[i] = passedOrigin[i];
134 axisDirection[i] = passedAxisDirection[i];
135 }
136 }
137
138 template <class... Args> static auto New(Args &&...args) {
139 return SmartPointer<Cylinder>::New(std::forward<Args>(args)...);
140 }
141};
142
145template <class T, int D> class PointCloud {
146public:
147 std::vector<VectorType<T, D>> points;
148
149 PointCloud() = default;
150
151 PointCloud(std::vector<VectorType<T, D>> passedPoints)
152 : points(passedPoints) {}
153
154 void insertNextPoint(T *newPoint) {
155 VectorType<T, D> point;
156 for (unsigned i = 0; i < D; ++i) {
157 point[i] = newPoint[i];
158 }
159 points.push_back(std::move(point));
160 }
161
162 void insertNextPoint(const VectorType<T, D> &newPoint) {
163 VectorType<T, D> point(newPoint);
164 points.push_back(std::move(point));
165 }
166
167 std::pair<typename std::vector<VectorType<T, D>>::iterator, bool>
168 insertNextUniquePoint(VectorType<T, D> newPoint) {
169 for (auto it = points.begin(); it != points.end(); ++it) {
170 if (newPoint == *it)
171 return std::make_pair(it, false);
172 }
173 points.push_back(newPoint);
174 return std::make_pair(--points.end(), true);
175 }
176
177 typename std::vector<VectorType<T, D>>::iterator begin() {
178 return points.begin();
179 }
180
181 typename std::vector<VectorType<T, D>>::iterator end() {
182 return points.end();
183 }
184
185 std::size_t size() { return points.size(); }
186
187 VectorType<T, D> &operator[](std::size_t i) { return points[i]; }
188
189 template <class... Args> static auto New(Args &&...args) {
190 return SmartPointer<PointCloud>::New(std::forward<Args>(args)...);
191 }
192};
193
194// add all template specialisations for this class
199
200} // namespace viennals
VectorType< T, D > maxCorner
Definition lsGeometries.hpp:74
Box(VectorType< T, D > passedMinCorner, VectorType< T, D > passedMaxCorner)
Definition lsGeometries.hpp:76
static auto New(Args &&...args)
Definition lsGeometries.hpp:94
Box(const T *passedMinCorner, const T *passedMaxCorner)
Definition lsGeometries.hpp:79
Box(const std::vector< T > &passedMinCorner, const std::vector< T > &passedMaxCorner)
Definition lsGeometries.hpp:86
VectorType< T, D > minCorner
Definition lsGeometries.hpp:73
Cylinder(std::vector< T > passedOrigin, std::vector< T > passedAxisDirection, T passedHeight, T passedRadius, T passedTopRadius=0)
Definition lsGeometries.hpp:129
static auto New(Args &&...args)
Definition lsGeometries.hpp:138
VectorType< T, 3 > axisDirection
This vector will be the main axis of the cylinder.
Definition lsGeometries.hpp:105
Cylinder(const T *passedOrigin, const T *passedAxisDirection, const T passedHeight, const T passedRadius, const T passedTopRadius=0)
Definition lsGeometries.hpp:119
Cylinder(VectorType< T, D > passedOrigin, VectorType< T, D > passedAxisDirection, T passedHeight, T passedRadius, T passedTopRadius=0)
Definition lsGeometries.hpp:113
T radius
radius of the base of the cylinder
Definition lsGeometries.hpp:109
T topRadius
radius of the top of the cylinder
Definition lsGeometries.hpp:111
T height
height of the cylinder
Definition lsGeometries.hpp:107
VectorType< T, 3 > origin
This is the location of the center of the base of the cylinder.
Definition lsGeometries.hpp:103
Plane(VectorType< T, D > passedOrigin, VectorType< T, D > passedNormal)
Definition lsGeometries.hpp:47
static auto New(Args &&...args)
Definition lsGeometries.hpp:65
VectorType< T, D > normal
Definition lsGeometries.hpp:45
VectorType< T, D > origin
Definition lsGeometries.hpp:44
Plane(const std::vector< T > &passedOrigin, const std::vector< T > &passedNormal)
Definition lsGeometries.hpp:57
Plane(const T *passedOrigin, const T *passedNormal)
Definition lsGeometries.hpp:50
void insertNextPoint(const VectorType< T, D > &newPoint)
Definition lsGeometries.hpp:162
std::vector< VectorType< T, D > > points
Definition lsGeometries.hpp:147
std::vector< VectorType< T, D > >::iterator end()
Definition lsGeometries.hpp:181
std::size_t size()
Definition lsGeometries.hpp:185
std::vector< VectorType< T, D > >::iterator begin()
Definition lsGeometries.hpp:177
std::pair< typename std::vector< VectorType< T, D > >::iterator, bool > insertNextUniquePoint(VectorType< T, D > newPoint)
Definition lsGeometries.hpp:168
static auto New(Args &&...args)
Definition lsGeometries.hpp:189
void insertNextPoint(T *newPoint)
Definition lsGeometries.hpp:154
VectorType< T, D > & operator[](std::size_t i)
Definition lsGeometries.hpp:187
PointCloud(std::vector< VectorType< T, D > > passedPoints)
Definition lsGeometries.hpp:151
T radius
Definition lsGeometries.hpp:18
Sphere(T *passedOrigin, T passedRadius)
Definition lsGeometries.hpp:23
Sphere(VectorType< T, D > passedOrigin, T passedRadius)
Definition lsGeometries.hpp:20
Sphere(const std::vector< T > &passedOrigin, T passedRadius)
Definition lsGeometries.hpp:29
VectorType< T, D > origin
Definition lsGeometries.hpp:17
static auto New(Args &&...args)
Definition lsGeometries.hpp:36
#define PRECOMPILE_PRECISION_DIMENSION(className)
Definition lsPreCompileMacros.hpp:24
Definition lsAdvect.hpp:36
constexpr int D
Definition pyWrap.cpp:71
double T
Definition pyWrap.cpp:69