hemocell
Loading...
Searching...
No Matches
geometry.h
Go to the documentation of this file.
1#include "palabos3D.h"
2#include "palabos3D.hh"
3#include <cmath>
4#include <limits>
5
6#ifndef GEOMETRY_H
7#define GEOMETRY_H
8
9namespace geom {
10
14class BoxDomain : public plb::DomainFunctional3D {
15public:
16 explicit BoxDomain(plb::Box3D box) : box{box} {}
17
19 bool operator()(plb::plint x, plb::plint y, plb::plint z) const override {
20 return plb::contained(x, y, z, box);
21 }
22
24 const plb::Box3D& bounding_box() const { return box; }
25
26 BoxDomain *clone() const override { return new BoxDomain(*this); }
27private:
28 plb::Box3D box;
29};
30
36class EllipseDomain : public plb::DomainFunctional3D {
37public:
42 EllipseDomain(double x, double y, double rx, double ry)
43 : EllipseDomain(x, y, 0, rx, ry, std::numeric_limits<double>::max())
44 {}
45
47 EllipseDomain(double cx, double cy, double cz, double rx, double ry, double rz)
48 : cx{ cx },
49 cy{ cy },
50 cz{ cz },
51 rx{ rx },
52 ry{ ry },
53 rz{ rz }
54 {}
55
59 bool operator()(plb::plint x, plb::plint y, plb::plint z) const override {
60 auto dx = x - cx;
61 auto dy = y - cy;
62 auto dz = z - cz;
63 return (dx*dx)/(rx*rx) + (dy*dy)/(ry*ry) + (dz*dz)/(rz*rz) < 1;
64 }
65
66 EllipseDomain *clone() const override { return new EllipseDomain(*this); }
67
68private:
69 double cx = 0;
70 double cy = 0;
71 double cz = 0;
72 double rx = 0;
73 double ry = 0;
74 double rz = 0;
75};
76
81class Union : public plb::DomainFunctional3D {
82public:
83 Union(std::initializer_list<std::reference_wrapper<plb::DomainFunctional3D>>
84 domains)
86 {}
87
89 bool operator()(plb::plint x, plb::plint y, plb::plint z) const override {
90 auto predicate = [x, y, z](const plb::DomainFunctional3D &domain) {
91 return domain(x, y, z);
92 };
93 return std::any_of(domains.begin(), domains.end(), predicate);
94 }
95
96 Union *clone() const override { return new Union(*this); };
97
98private:
99 std::vector<std::reference_wrapper<plb::DomainFunctional3D>> domains;
100};
101
108class Difference : public plb::DomainFunctional3D {
109public:
111 std::initializer_list<std::reference_wrapper<plb::DomainFunctional3D>> domains)
112 : domains{ domains } {}
113
115 bool operator()(plb::plint x, plb::plint y, plb::plint z) const override {
116 if (domains.empty())
117 return false;
118
119 if (!domains.front()(x, y, z))
120 // No need to subtract subsequent domains if the first domain is empty.
121 return false;
122
123 auto predicate = [x, y, z](const plb::DomainFunctional3D& domain) {
124 return domain(x, y, z);
125 };
126 return std::none_of(std::next(domains.begin()), domains.end(), predicate);
127 }
128
129 Difference *clone() const override { return new Difference(*this); }
130
131private:
132 std::vector<std::reference_wrapper<plb::DomainFunctional3D>> domains;
133};
134
140class Intersection : public plb::DomainFunctional3D {
141public:
143 std::initializer_list<std::reference_wrapper<plb::DomainFunctional3D>>
144 domains)
145 : domains{domains} {}
146
148 bool operator()(plb::plint x, plb::plint y, plb::plint z) const override {
149 if (domains.empty())
150 // No domains have an empty intersection, whereas std::all_of returns
151 // true for emtpy ranges.
152 return false;
153
154 auto predicate = [x, y, z](const plb::DomainFunctional3D &domain) {
155 return domain(x, y, z);
156 };
157 return std::all_of(domains.begin(), domains.end(), predicate);
158 }
159
160 Intersection *clone() const override { return new Intersection(*this); }
161
162private:
163 std::vector<std::reference_wrapper<plb::DomainFunctional3D>> domains;
164};
165
166} // namespace geom
167
168#endif /* GEOMETRY_H */
A domain functional indicating true inside a rectangular box. The BoxDomain functional evaluates to t...
Definition geometry.h:14
plb::Box3D box
Definition geometry.h:28
const plb::Box3D & bounding_box() const
The relevant bounding box of the BoxDomain functional is known.
Definition geometry.h:24
BoxDomain(plb::Box3D box)
Definition geometry.h:16
BoxDomain * clone() const override
Definition geometry.h:26
bool operator()(plb::plint x, plb::plint y, plb::plint z) const override
Returns true inside the rectangular box (inclusive edges).
Definition geometry.h:19
Create the boolean difference of the first and subsequent domains. This creates the boolean differenc...
Definition geometry.h:108
Difference * clone() const override
Definition geometry.h:129
bool operator()(plb::plint x, plb::plint y, plb::plint z) const override
Return true if the first domain is true and none of the others.
Definition geometry.h:115
std::vector< std::reference_wrapper< plb::DomainFunctional3D > > domains
Definition geometry.h:132
Difference(std::initializer_list< std::reference_wrapper< plb::DomainFunctional3D > > domains)
Definition geometry.h:110
An ellipsoidal domain functional returning true inside the ellipsoid. The EllipseDomain represents an...
Definition geometry.h:36
EllipseDomain(double x, double y, double rx, double ry)
Definition geometry.h:42
double rz
Definition geometry.h:74
bool operator()(plb::plint x, plb::plint y, plb::plint z) const override
Definition geometry.h:59
double cz
Definition geometry.h:71
double ry
Definition geometry.h:73
double cx
Definition geometry.h:69
double cy
Definition geometry.h:70
EllipseDomain(double cx, double cy, double cz, double rx, double ry, double rz)
Default constructor specifying the x, y, z coordinates and radii.
Definition geometry.h:47
EllipseDomain * clone() const override
Definition geometry.h:66
double rx
Definition geometry.h:72
The boolean intersection of a number of domain functionals. This creates the boolean intersection bet...
Definition geometry.h:140
Intersection * clone() const override
Definition geometry.h:160
bool operator()(plb::plint x, plb::plint y, plb::plint z) const override
Returns true only if all domains are true.
Definition geometry.h:148
std::vector< std::reference_wrapper< plb::DomainFunctional3D > > domains
Definition geometry.h:163
Intersection(std::initializer_list< std::reference_wrapper< plb::DomainFunctional3D > > domains)
Definition geometry.h:142
The union of multiple domain functionals. This domain functional builds the union of any number of do...
Definition geometry.h:81
bool operator()(plb::plint x, plb::plint y, plb::plint z) const override
Return true if any of the included domains is true.
Definition geometry.h:89
std::vector< std::reference_wrapper< plb::DomainFunctional3D > > domains
Definition geometry.h:99
Union(std::initializer_list< std::reference_wrapper< plb::DomainFunctional3D > > domains)
Definition geometry.h:83
Union * clone() const override
Definition geometry.h:96
Definition geometry.h:9