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
6#include <hrleVectorType.hpp>
7
9
10namespace viennals {
11
13template <class T, int D> class Sphere {
14public:
15 hrleVectorType<T, D> origin = hrleVectorType<T, D>(T(0));
16 T radius = 0.;
17
18 Sphere() {}
19
20 Sphere(hrleVectorType<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 : origin(passedOrigin), radius(passedRadius) {}
31};
32
34template <class T, int D> class Plane {
35public:
36 hrleVectorType<T, D> origin = hrleVectorType<T, D>(T(0));
37 hrleVectorType<T, D> normal = hrleVectorType<T, D>(T(0));
38
39 Plane() {}
40
41 Plane(hrleVectorType<T, D> passedOrigin, hrleVectorType<T, D> passedNormal)
42 : origin(passedOrigin), normal(passedNormal) {}
43
44 Plane(const T *passedOrigin, const T *passedNormal) {
45 for (unsigned i = 0; i < D; ++i) {
46 origin[i] = passedOrigin[i];
47 normal[i] = passedNormal[i];
48 }
49 }
50
51 Plane(const std::vector<T> &passedOrigin, const std::vector<T> &passedNormal)
52 : origin(passedOrigin), normal(passedNormal) {}
53};
54
56template <class T, int D> class Box {
57public:
58 hrleVectorType<T, D> minCorner = hrleVectorType<T, D>(T(0));
59 hrleVectorType<T, D> maxCorner = hrleVectorType<T, D>(T(0));
60
61 Box() {}
62
63 Box(hrleVectorType<T, D> passedMinCorner,
64 hrleVectorType<T, D> passedMaxCorner)
65 : minCorner(passedMinCorner), maxCorner(passedMaxCorner) {}
66
67 Box(const T *passedMinCorner, const T *passedMaxCorner) {
68 for (unsigned i = 0; i < D; ++i) {
69 minCorner[i] = passedMinCorner[i];
70 maxCorner[i] = passedMaxCorner[i];
71 }
72 }
73
74 Box(const std::vector<T> &passedMinCorner,
75 const std::vector<T> &passedMaxCorner)
76 : minCorner(passedMinCorner), maxCorner(passedMaxCorner) {}
77};
78
80template <class T, int D> class Cylinder {
81public:
83 hrleVectorType<T, 3> origin = hrleVectorType<T, 3>(T(0));
85 hrleVectorType<T, 3> axisDirection = hrleVectorType<T, 3>(T(0));
87 T height = 0.;
89 T radius = 0.;
92
94
95 Cylinder(hrleVectorType<T, D> passedOrigin,
96 hrleVectorType<T, D> passedAxisDirection, T passedHeight,
97 T passedRadius, T passedTopRadius = 0)
98 : origin(passedOrigin), axisDirection(passedAxisDirection),
99 height(passedHeight), radius(passedRadius), topRadius(passedTopRadius) {
100 }
101
102 Cylinder(const T *passedOrigin, const T *passedAxisDirection,
103 const T passedHeight, const T passedRadius,
104 const T passedTopRadius = 0)
105 : height(passedHeight), radius(passedRadius), topRadius(passedTopRadius) {
106 for (unsigned i = 0; i < D; ++i) {
107 origin[i] = passedOrigin[i];
108 axisDirection[i] = passedAxisDirection[i];
109 }
110 }
111
112 Cylinder(std::vector<T> passedOrigin, std::vector<T> passedAxisDirection,
113 T passedHeight, T passedRadius, T passedTopRadius = 0)
114 : origin(passedOrigin), axisDirection(passedAxisDirection),
115 height(passedHeight), radius(passedRadius), topRadius(passedTopRadius) {
116 }
117};
118
121template <class T, int D> class PointCloud {
122public:
123 std::vector<hrleVectorType<T, D>> points;
124
126
127 PointCloud(std::vector<hrleVectorType<T, D>> passedPoints)
128 : points(passedPoints) {}
129
130 PointCloud(const std::vector<std::vector<T>> &passedPoints) {
131 for (auto point : passedPoints) {
132 hrleVectorType<T, D> p(point);
133 points.push_back(p);
134 }
135 }
136
137 void insertNextPoint(hrleVectorType<T, D> newPoint) {
138 points.push_back(newPoint);
139 }
140
141 void insertNextPoint(T *newPoint) {
142 hrleVectorType<T, D> point(newPoint);
143 points.push_back(point);
144 }
145
146 void insertNextPoint(const std::array<T, D> newPoint) {
147 hrleVectorType<T, D> point(newPoint);
148 points.push_back(std::move(point));
149 }
150
151 void insertNextPoint(const std::vector<T> &newPoint) {
152 hrleVectorType<T, D> point(newPoint);
153 points.push_back(point);
154 }
155
156 std::pair<typename std::vector<hrleVectorType<T, D>>::iterator, bool>
157 insertNextUniquePoint(hrleVectorType<T, D> newPoint) {
158 for (auto it = points.begin(); it != points.end(); ++it) {
159 if (newPoint == *it)
160 return std::make_pair(it, false);
161 }
162 points.push_back(newPoint);
163 return std::make_pair(--points.end(), true);
164 }
165
166 typename std::vector<hrleVectorType<T, D>>::iterator begin() {
167 return points.begin();
168 }
169
170 typename std::vector<hrleVectorType<T, D>>::iterator end() {
171 return points.end();
172 }
173
174 std::size_t size() { return points.size(); }
175
176 hrleVectorType<T, D> &operator[](std::size_t i) { return points[i]; }
177};
178
179// add all template specialisations for this class
184
185} // namespace viennals
Class describing a square box from one coordinate to another.
Definition lsGeometries.hpp:56
Box()
Definition lsGeometries.hpp:61
hrleVectorType< T, D > maxCorner
Definition lsGeometries.hpp:59
Box(const T *passedMinCorner, const T *passedMaxCorner)
Definition lsGeometries.hpp:67
Box(hrleVectorType< T, D > passedMinCorner, hrleVectorType< T, D > passedMaxCorner)
Definition lsGeometries.hpp:63
hrleVectorType< T, D > minCorner
Definition lsGeometries.hpp:58
Box(const std::vector< T > &passedMinCorner, const std::vector< T > &passedMaxCorner)
Definition lsGeometries.hpp:74
Class describing a square box from one coordinate to another.
Definition lsGeometries.hpp:80
Cylinder(std::vector< T > passedOrigin, std::vector< T > passedAxisDirection, T passedHeight, T passedRadius, T passedTopRadius=0)
Definition lsGeometries.hpp:112
Cylinder(hrleVectorType< T, D > passedOrigin, hrleVectorType< T, D > passedAxisDirection, T passedHeight, T passedRadius, T passedTopRadius=0)
Definition lsGeometries.hpp:95
Cylinder(const T *passedOrigin, const T *passedAxisDirection, const T passedHeight, const T passedRadius, const T passedTopRadius=0)
Definition lsGeometries.hpp:102
hrleVectorType< T, 3 > axisDirection
This vector will be the main axis of the cylinder.
Definition lsGeometries.hpp:85
Cylinder()
Definition lsGeometries.hpp:93
T radius
radius of the base of the cylinder
Definition lsGeometries.hpp:89
T topRadius
radius of the top of the cylinder
Definition lsGeometries.hpp:91
T height
height of the cylinder
Definition lsGeometries.hpp:87
hrleVectorType< T, 3 > origin
This is the location of the center of the base of the cylinder.
Definition lsGeometries.hpp:83
Class describing a plane via a point in it and the plane normal.
Definition lsGeometries.hpp:34
hrleVectorType< T, D > normal
Definition lsGeometries.hpp:37
hrleVectorType< T, D > origin
Definition lsGeometries.hpp:36
Plane()
Definition lsGeometries.hpp:39
Plane(hrleVectorType< T, D > passedOrigin, hrleVectorType< T, D > passedNormal)
Definition lsGeometries.hpp:41
Plane(const std::vector< T > &passedOrigin, const std::vector< T > &passedNormal)
Definition lsGeometries.hpp:51
Plane(const T *passedOrigin, const T *passedNormal)
Definition lsGeometries.hpp:44
Class describing a point cloud, which can be used to create geometries from its convex hull mesh.
Definition lsGeometries.hpp:121
void insertNextPoint(hrleVectorType< T, D > newPoint)
Definition lsGeometries.hpp:137
std::vector< hrleVectorType< T, D > > points
Definition lsGeometries.hpp:123
std::vector< hrleVectorType< T, D > >::iterator end()
Definition lsGeometries.hpp:170
hrleVectorType< T, D > & operator[](std::size_t i)
Definition lsGeometries.hpp:176
PointCloud(const std::vector< std::vector< T > > &passedPoints)
Definition lsGeometries.hpp:130
void insertNextPoint(const std::array< T, D > newPoint)
Definition lsGeometries.hpp:146
std::size_t size()
Definition lsGeometries.hpp:174
std::vector< hrleVectorType< T, D > >::iterator begin()
Definition lsGeometries.hpp:166
void insertNextPoint(const std::vector< T > &newPoint)
Definition lsGeometries.hpp:151
std::pair< typename std::vector< hrleVectorType< T, D > >::iterator, bool > insertNextUniquePoint(hrleVectorType< T, D > newPoint)
Definition lsGeometries.hpp:157
PointCloud(std::vector< hrleVectorType< T, D > > passedPoints)
Definition lsGeometries.hpp:127
PointCloud()
Definition lsGeometries.hpp:125
void insertNextPoint(T *newPoint)
Definition lsGeometries.hpp:141
Class describing a sphere via origin and radius.
Definition lsGeometries.hpp:13
T radius
Definition lsGeometries.hpp:16
Sphere(hrleVectorType< T, D > passedOrigin, T passedRadius)
Definition lsGeometries.hpp:20
Sphere()
Definition lsGeometries.hpp:18
hrleVectorType< T, D > origin
Definition lsGeometries.hpp:15
Sphere(T *passedOrigin, T passedRadius)
Definition lsGeometries.hpp:23
Sphere(const std::vector< T > &passedOrigin, T passedRadius)
Definition lsGeometries.hpp:29
#define PRECOMPILE_PRECISION_DIMENSION(className)
Definition lsPreCompileMacros.hpp:24
Definition lsAdvect.hpp:46
constexpr int D
Definition pyWrap.cpp:65
double T
Definition pyWrap.cpp:63