-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakeMask.hpp
90 lines (74 loc) · 2.96 KB
/
MakeMask.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include <lsSmartPointer.hpp>
template <class T, int D> class MakeMask {
using LSPtrType = lsSmartPointer<lsDomain<T, D>>;
LSPtrType substrate;
LSPtrType mask;
std::array<T, 3> maskOrigin = {};
T maskRadius = 0;
T maskHeight = 2.;
unsigned numberOfHoles = 1;
double scallopSpacing = 1.5;
public:
MakeMask(LSPtrType passedSubstrate, LSPtrType passedMask)
: substrate(passedSubstrate), mask(passedMask) {}
void setMaskOrigin(std::array<T, 3> &origin) { maskOrigin = origin; }
void setMaskRadius(T radius) { maskRadius = radius; }
void apply() {
auto &grid = substrate->getGrid();
auto &boundaryCons = grid.getBoundaryConditions();
auto gridDelta = grid.getGridDelta();
T extent = grid.getGridExtent(0) * gridDelta;
// create mask
{
T normal[3] = {0., (D == 2) ? 1. : 0., (D == 3) ? 1. : 0.};
T origin[3] = {0., (D == 2) ? maskHeight : 0.,
(D == 3) ? maskHeight : 0.};
lsMakeGeometry<T, D>(mask,
lsSmartPointer<lsPlane<T, D>>::New(origin, normal))
.apply();
normal[D - 1] = -1.0;
origin[D - 1] = 0.;
auto maskBottom = lsSmartPointer<lsDomain<T, D>>::New(grid);
lsMakeGeometry<T, D>(maskBottom,
lsSmartPointer<lsPlane<T, D>>::New(origin, normal))
.apply();
lsBooleanOperation<T, D>(mask, maskBottom,
lsBooleanOperationEnum::INTERSECT)
.apply();
// auto mesh = lsSmartPointer<lsMesh<NumericType>>::New();
// lsToMesh<T, D>(mask, mesh).apply();
// lsVTKWriter(mesh, "Plane.vtp").apply();
auto maskHole = lsSmartPointer<lsDomain<T, D>>::New(grid);
if constexpr (D == 3) {
maskOrigin[2] = origin[2] - gridDelta;
// maskRadius = extent / 2.0;
double axis[3] = {0.0, 0.0, 1.0};
lsMakeGeometry<T, D>(maskHole,
lsSmartPointer<lsCylinder<T, D>>::New(
maskOrigin.data(), axis,
maskHeight + 2 * gridDelta, maskRadius))
.apply();
} else {
// double minScalar = origin[D-1] - 2 * gridDelta;
// maskRadius = extent / 2.0;
double min[3] = {-maskRadius, -gridDelta};
double max[3] = {maskRadius, maskHeight + 2 * gridDelta};
lsMakeGeometry<T, D>(maskHole,
lsSmartPointer<lsBox<T, D>>::New(min, max))
.apply();
}
lsBooleanOperation<T, D>(mask, maskHole,
lsBooleanOperationEnum::RELATIVE_COMPLEMENT)
.apply();
// lsToSurfaceMesh<T, D>(mask, mesh).apply();
// lsVTKWriter(mesh, "Mask.vtp").apply();
// make substrate
lsBooleanOperation<T, D>(maskBottom, lsBooleanOperationEnum::INVERT)
.apply();
substrate->deepCopy(maskBottom);
lsBooleanOperation<T, D>(substrate, mask, lsBooleanOperationEnum::UNION)
.apply();
}
}
};