PLaSK library
Loading...
Searching...
No Matches
transform_space_cartesian.cpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
15
16#include <algorithm>
17#include "../manager.hpp"
18#include "reader.hpp"
19
20#define PLASK_EXTRUSION_NAME "extrusion"
21
22namespace plask {
23
25
26std::string Extrusion::getTypeName() const { return NAME; }
27
29 if (length == new_length) return;
30 length = new_length;
31 fireChanged(Event::EVENT_RESIZE);
32}
33
34bool Extrusion::contains(const DVec& p) const {
35 return (this->hasChild() && canBeInside(p)) && this->_child->contains(childVec(p));
36}
37
38/*bool Extrusion::intersects(const Box& area) const {
39 return canIntersect(area) && getChild()->intersects(childBox(area));
40}*/
41
43 return (this->hasChild() && canBeInside(p)) ? this->_child->getMaterial(childVec(p)) : shared_ptr<Material>();
44}
45
49
50/*std::vector< plask::shared_ptr< const plask::GeometryObject > > Extrusion::getLeafs() const {
51 return getChild()->getLeafs();
52}*/
53
57
59 if (this->hasChild() && canBeInside(point))
60 return GeometryObject::Subtree::extendIfNotEmpty(this, getChild()->getPathsAt(childVec(point), all));
61 else
63}
64
69
71 std::vector<GeometryObjectTransformSpace::DVec>& dest,
72 const PathHints* path) const {
73 if (predicate(*this)) {
75 return;
76 }
77 if (!this->hasChild()) return;
78 auto child_pos_vec = this->_child->getPositions(predicate, path);
79 for (const auto& v : child_pos_vec) dest.push_back(parentVec(v, 0.));
80}
81
82// void Extrusion::extractToVec(const GeometryObject::Predicate &predicate, std::vector< shared_ptr<const
83// GeometryObjectD<3> > >&dest, const PathHints *path) const {
84// if (predicate(*this)) {
85// dest.push_back(static_pointer_cast< const GeometryObjectD<3> >(this->shared_from_this()));
86// return;
87// }
88// std::vector< shared_ptr<const GeometryObjectD<2> > > child_res = getChild()->extract(predicate, path);
89// for (shared_ptr<const GeometryObjectD<2>>& c: child_res)
90// dest.emplace_back(new Extrusion(const_pointer_cast<GeometryObjectD<2>>(c), this->length));
91// }
92
93void Extrusion::addPointsAlongToSet(std::set<double>& points,
95 unsigned max_steps,
96 double min_step_size) const {
97 if (!this->hasChild()) return;
98 if (direction == Primitive<3>::DIRECTION_LONG) {
99 points.insert(0);
100 points.insert(length);
101 } else {
102 if (this->max_steps) max_steps = this->max_steps;
103 if (this->min_step_size) min_step_size = this->min_step_size;
104 _child->addPointsAlongToSet(points, direction, max_steps, min_step_size);
105 }
106}
107
108void Extrusion::addLineSegmentsToSet(std::set<typename GeometryObjectD<3>::LineSegment>& segments,
109 unsigned max_steps,
110 double min_step_size) const {
111 if (!this->hasChild()) return;
112 typedef typename GeometryObjectD<3>::LineSegment Segment3;
113 typedef typename GeometryObjectD<2>::LineSegment Segment2;
114 if (this->max_steps) max_steps = this->max_steps;
115 if (this->min_step_size) min_step_size = this->min_step_size;
116 std::set<Segment2> child_segments;
117 _child->addLineSegmentsToSet(child_segments, max_steps, min_step_size);
118 for (const auto& s: child_segments) {
119 segments.insert(Segment3(DVec(0., s.p0().c0, s.p0().c1), DVec(0., s.p1().c0, s.p1().c1)));
120 segments.insert(Segment3(DVec(0., s.p0().c0, s.p0().c1), DVec(length, s.p0().c0, s.p0().c1)));
121 segments.insert(Segment3(DVec(0., s.p1().c0, s.p1().c1), DVec(length, s.p1().c0, s.p1().c1)));
122 segments.insert(Segment3(DVec(length, s.p0().c0, s.p0().c1), DVec(length, s.p1().c0, s.p1().c1)));
123 }
124}
125
132
133static GeometryReader::RegisterObjectReader cartesianExtend2D_reader(PLASK_EXTRUSION_NAME, read_cartesianExtend);
134
135} // namespace plask