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 <vcVectorType.hpp>
9
10namespace viennals {
11using namespace viennacore;
12
14template <class T, int D> class Sphere {
15public:
16 VectorType<T, D> origin;
17 T radius = 0.;
18
19 Sphere(VectorType<T, D> passedOrigin, T passedRadius)
20 : origin(passedOrigin), radius(passedRadius) {}
21
22 Sphere(T *passedOrigin, T passedRadius) : radius(passedRadius) {
23 for (unsigned i = 0; i < D; ++i) {
24 origin[i] = passedOrigin[i];
25 }
26 }
27
28 Sphere(const std::vector<T> &passedOrigin, T passedRadius)
29 : radius(passedRadius) {
30 for (unsigned i = 0; i < D; ++i) {
31 origin[i] = passedOrigin[i];
32 }
33 }
34};
35
37template <class T, int D> class Plane {
38public:
39 VectorType<T, D> origin;
40 VectorType<T, D> normal;
41
42 Plane(VectorType<T, D> passedOrigin, VectorType<T, D> passedNormal)
43 : origin(passedOrigin), normal(passedNormal) {}
44
45 Plane(const T *passedOrigin, const T *passedNormal) {
46 for (unsigned i = 0; i < D; ++i) {
47 origin[i] = passedOrigin[i];
48 normal[i] = passedNormal[i];
49 }
50 }
51
52 Plane(const std::vector<T> &passedOrigin,
53 const std::vector<T> &passedNormal) {
54 for (unsigned i = 0; i < D; ++i) {
55 origin[i] = passedOrigin[i];
56 normal[i] = passedNormal[i];
57 }
58 }
59};
60
62template <class T, int D> class Box {
63public:
64 VectorType<T, D> minCorner;
65 VectorType<T, D> maxCorner;
66
67 Box(VectorType<T, D> passedMinCorner, VectorType<T, D> passedMaxCorner)
68 : minCorner(passedMinCorner), maxCorner(passedMaxCorner) {}
69
70 Box(const T *passedMinCorner, const T *passedMaxCorner) {
71 for (unsigned i = 0; i < D; ++i) {
72 minCorner[i] = passedMinCorner[i];
73 maxCorner[i] = passedMaxCorner[i];
74 }
75 }
76
77 Box(const std::vector<T> &passedMinCorner,
78 const std::vector<T> &passedMaxCorner) {
79 for (unsigned i = 0; i < D; ++i) {
80 minCorner[i] = passedMinCorner[i];
81 maxCorner[i] = passedMaxCorner[i];
82 }
83 }
84};
85
87template <class T, int D> class Cylinder {
88public:
90 VectorType<T, 3> origin;
92 VectorType<T, 3> axisDirection;
94 T height = 0.;
96 T radius = 0.;
99
100 Cylinder(VectorType<T, D> passedOrigin, VectorType<T, D> passedAxisDirection,
101 T passedHeight, T passedRadius, T passedTopRadius = 0)
102 : origin(passedOrigin), axisDirection(passedAxisDirection),
103 height(passedHeight), radius(passedRadius), topRadius(passedTopRadius) {
104 }
105
106 Cylinder(const T *passedOrigin, const T *passedAxisDirection,
107 const T passedHeight, const T passedRadius,
108 const T passedTopRadius = 0)
109 : height(passedHeight), radius(passedRadius), topRadius(passedTopRadius) {
110 for (unsigned i = 0; i < D; ++i) {
111 origin[i] = passedOrigin[i];
112 axisDirection[i] = passedAxisDirection[i];
113 }
114 }
115
116 Cylinder(std::vector<T> passedOrigin, std::vector<T> passedAxisDirection,
117 T passedHeight, T passedRadius, T passedTopRadius = 0)
118 : height(passedHeight), radius(passedRadius), topRadius(passedTopRadius) {
119 for (unsigned i = 0; i < D; ++i) {
120 origin[i] = passedOrigin[i];
121 axisDirection[i] = passedAxisDirection[i];
122 }
123 }
124};
125
128template <class T, int D> class PointCloud {
129public:
130 std::vector<VectorType<T, D>> points;
131
132 PointCloud() = default;
133
134 PointCloud(std::vector<VectorType<T, D>> passedPoints)
135 : points(passedPoints) {}
136
137 void insertNextPoint(T *newPoint) {
138 VectorType<T, D> point;
139 for (unsigned i = 0; i < D; ++i) {
140 point[i] = newPoint[i];
141 }
142 points.push_back(std::move(point));
143 }
144
145 void insertNextPoint(const VectorType<T, D> &newPoint) {
146 VectorType<T, D> point(newPoint);
147 points.push_back(std::move(point));
148 }
149
150 std::pair<typename std::vector<VectorType<T, D>>::iterator, bool>
151 insertNextUniquePoint(VectorType<T, D> newPoint) {
152 for (auto it = points.begin(); it != points.end(); ++it) {
153 if (newPoint == *it)
154 return std::make_pair(it, false);
155 }
156 points.push_back(newPoint);
157 return std::make_pair(--points.end(), true);
158 }
159
160 typename std::vector<VectorType<T, D>>::iterator begin() {
161 return points.begin();
162 }
163
164 typename std::vector<VectorType<T, D>>::iterator end() {
165 return points.end();
166 }
167
168 std::size_t size() { return points.size(); }
169
170 VectorType<T, D> &operator[](std::size_t i) { return points[i]; }
171};
172
173// add all template specialisations for this class
178
179} // namespace viennals
VectorType< T, D > maxCorner
Definition lsGeometries.hpp:65
Box(VectorType< T, D > passedMinCorner, VectorType< T, D > passedMaxCorner)
Definition lsGeometries.hpp:67
Box(const T *passedMinCorner, const T *passedMaxCorner)
Definition lsGeometries.hpp:70
Box(const std::vector< T > &passedMinCorner, const std::vector< T > &passedMaxCorner)
Definition lsGeometries.hpp:77
VectorType< T, D > minCorner
Definition lsGeometries.hpp:64
Cylinder(std::vector< T > passedOrigin, std::vector< T > passedAxisDirection, T passedHeight, T passedRadius, T passedTopRadius=0)
Definition lsGeometries.hpp:116
VectorType< T, 3 > axisDirection
This vector will be the main axis of the cylinder.
Definition lsGeometries.hpp:92
Cylinder(const T *passedOrigin, const T *passedAxisDirection, const T passedHeight, const T passedRadius, const T passedTopRadius=0)
Definition lsGeometries.hpp:106
Cylinder(VectorType< T, D > passedOrigin, VectorType< T, D > passedAxisDirection, T passedHeight, T passedRadius, T passedTopRadius=0)
Definition lsGeometries.hpp:100
T radius
radius of the base of the cylinder
Definition lsGeometries.hpp:96
T topRadius
radius of the top of the cylinder
Definition lsGeometries.hpp:98
T height
height of the cylinder
Definition lsGeometries.hpp:94
VectorType< T, 3 > origin
This is the location of the center of the base of the cylinder.
Definition lsGeometries.hpp:90
Plane(VectorType< T, D > passedOrigin, VectorType< T, D > passedNormal)
Definition lsGeometries.hpp:42
VectorType< T, D > normal
Definition lsGeometries.hpp:40
VectorType< T, D > origin
Definition lsGeometries.hpp:39
Plane(const std::vector< T > &passedOrigin, const std::vector< T > &passedNormal)
Definition lsGeometries.hpp:52
Plane(const T *passedOrigin, const T *passedNormal)
Definition lsGeometries.hpp:45
void insertNextPoint(const VectorType< T, D > &newPoint)
Definition lsGeometries.hpp:145
std::vector< VectorType< T, D > > points
Definition lsGeometries.hpp:130
std::vector< VectorType< T, D > >::iterator end()
Definition lsGeometries.hpp:164
std::size_t size()
Definition lsGeometries.hpp:168
std::vector< VectorType< T, D > >::iterator begin()
Definition lsGeometries.hpp:160
std::pair< typename std::vector< VectorType< T, D > >::iterator, bool > insertNextUniquePoint(VectorType< T, D > newPoint)
Definition lsGeometries.hpp:151
void insertNextPoint(T *newPoint)
Definition lsGeometries.hpp:137
VectorType< T, D > & operator[](std::size_t i)
Definition lsGeometries.hpp:170
PointCloud(std::vector< VectorType< T, D > > passedPoints)
Definition lsGeometries.hpp:134
T radius
Definition lsGeometries.hpp:17
Sphere(T *passedOrigin, T passedRadius)
Definition lsGeometries.hpp:22
Sphere(VectorType< T, D > passedOrigin, T passedRadius)
Definition lsGeometries.hpp:19
Sphere(const std::vector< T > &passedOrigin, T passedRadius)
Definition lsGeometries.hpp:28
VectorType< T, D > origin
Definition lsGeometries.hpp:16
#define PRECOMPILE_PRECISION_DIMENSION(className)
Definition lsPreCompileMacros.hpp:24
Definition lsAdvect.hpp:36
constexpr int D
Definition pyWrap.cpp:70
double T
Definition pyWrap.cpp:68