16#include "../manager.hpp"
21#define PLASK_CLIP2D_NAME ("clip" PLASK_GEOMETRY_TYPE_NAME_SUFFIX_2D)
22#define PLASK_CLIP3D_NAME ("clip" PLASK_GEOMETRY_TYPE_NAME_SUFFIX_3D)
29 return (this->hasChild() && clipBox.contains(p)) ? this->_child->getMaterial(p) :
shared_ptr<Material>();
33 return this->hasChild() && clipBox.contains(p) && this->_child->contains(p);
38 if (this->hasChild() && clipBox.contains(point))
51 std::vector<DVec>&
dest,
53 this->_getNotChangedPositionsToVec(
this, predicate,
dest, path);
62 double min_step_size)
const {
65 this->_child->addPointsAlongToSet(
child_points, direction, this->max_steps ? this->max_steps : max_steps,
66 this->min_step_size ? this->min_step_size : min_step_size);
67 auto bbox = this->getBoundingBox();
68 points.insert(
bbox.lower[
int(direction) - (3 - dim)]);
70 if (clipBox.lower[
int(direction) - (3 - dim)] <= p && p <= clipBox.upper[
int(direction) - (3 - dim)])
73 points.insert(
bbox.upper[
int(direction) - (3 - dim)]);
80 double min_step_size)
const {
82 std::set<typename GeometryObjectD<dim>::LineSegment>
child_segments;
83 this->_child->addLineSegmentsToSet(
child_segments, this->max_steps ? this->max_steps : max_steps,
84 this->min_step_size ? this->min_step_size : min_step_size);
86 bool in0 = clipBox.contains(s.p0()),
in1 = clipBox.contains(s.p1());
90 addClippedSegment(segments, s.p0(), s.p1());
95inline static void limitT(
double&
t0,
double&
t1,
double tl[],
double th[],
int n,
int x = -1) {
98 for (
size_t i = 0; i <
n; ++i) {
100 double l = tl[i], h =
th[i];
105 if (
t0 > 1.)
t0 = 1.;
106 if (
t1 < 0.)
t1 = 0.;
110void Clip<dim>::addClippedSegment(std::set<
typename GeometryObjectD<dim>::LineSegment>& segments,
115 for (
size_t i = 0;
i < 2; ++
i) {
117 if (clipBox.lower[i] <= p0[i] && p0[0] <= clipBox.upper[i]) {
124 tl[
i] = (clipBox.lower[
i] - p0[
i]) /
dp[i];
125 tu[
i] = (clipBox.upper[
i] - p0[
i]) /
dp[i];
128 for (
size_t i = 0;
i <= dim; ++
i) {
130 limitT(
t0,
t1, tl,
tu, dim, i);
131 if (
t1 <=
t0)
continue;
135 if (p0[i] < clipBox.lower[i]) {
136 q0[
i] =
q1[
i] = clipBox.lower[
i];
137 if (
q0 !=
q1) segments.insert(
typename GeometryObjectD<dim>::LineSegment(
q0,
q1));
138 }
else if (p0[i] > clipBox.upper[i]) {
139 q0[
i] =
q1[
i] = clipBox.upper[
i];
140 if (
q0 !=
q1) segments.insert(
typename GeometryObjectD<dim>::LineSegment(
q0,
q1));
146 if (
q0l !=
q1l) segments.insert(
typename GeometryObjectD<dim>::LineSegment(
q0l,
q1l));
150 if (
q0u !=
q1u) segments.insert(
typename GeometryObjectD<dim>::LineSegment(
q0u,
q1u));
153 if (
q0 !=
q1) segments.insert(
typename GeometryObjectD<dim>::LineSegment(
q0,
q1));
158template <
typename ClipBoxType>
160 if (clipBox.left() > -std::numeric_limits<double>::infinity())
dest_xml_object.attr(
"left", clipBox.left());
161 if (clipBox.right() < std::numeric_limits<double>::infinity())
dest_xml_object.attr(
"right", clipBox.right());
162 if (clipBox.bottom() > -std::numeric_limits<double>::infinity())
dest_xml_object.attr(
"bottom", clipBox.bottom());
163 if (clipBox.top() < std::numeric_limits<double>::infinity())
dest_xml_object.attr(
"top", clipBox.top());
174 if (clipBox.back() > -std::numeric_limits<double>::infinity())
dest_xml_object.attr(
"back", clipBox.back());
175 if (clipBox.front() < std::numeric_limits<double>::infinity())
dest_xml_object.attr(
"front", clipBox.front());
179 clip.clipBox.left() = reader.
source.
getAttribute<
double>(
"left", -std::numeric_limits<double>::infinity());
180 clip.clipBox.right() = reader.
source.
getAttribute<
double>(
"right", std::numeric_limits<double>::infinity());
182 clip.clipBox.bottom() = reader.
source.
getAttribute<
double>(
"bottom", -std::numeric_limits<double>::infinity());
189 setupClip2D3D(reader, *
clip);
196 clip->clipBox.back() = reader.
source.
getAttribute<
double>(
"back", -std::numeric_limits<double>::infinity());
197 clip->clipBox.front() = reader.
source.
getAttribute<
double>(
"front", std::numeric_limits<double>::infinity());
198 setupClip2D3D(reader, *
clip);