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 */
14#include "transform_space_cartesian.hpp"
15
16#include <algorithm>
17#include "../manager.hpp"
18#include "reader.hpp"
19
20#define PLASK_EXTRUSION_NAME "extrusion"
21
22 namespace plask {
23
24 const char* Extrusion::NAME = PLASK_EXTRUSION_NAME;
25
26std::string Extrusion::getTypeName() const { return NAME; }
27
28 void Extrusion::setLength(double new_length) {
29 if (length == new_length) return;
30 length = new_length;
31 fireChanged(Event::EVENT_RESIZE);
32}
33
34 bool 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
42 shared_ptr<Material> Extrusion::getMaterial(const DVec& p) const {
43 return (this->hasChild() && canBeInside(p)) ? this->_child->getMaterial(childVec(p)) : shared_ptr<Material>();
44}
45
46 Extrusion::Box Extrusion::fromChildCoords(const Extrusion::ChildType::Box& child_bbox) const {
47 return parentBox(child_bbox);
48}
49
50/*std::vector< plask::shared_ptr< const plask::GeometryObject > > Extrusion::getLeafs() const {
51 return getChild()->getLeafs();
52}*/
53
54 shared_ptr<GeometryObject> Extrusion::shallowCopy() const {
55 return shared_ptr<GeometryObjectTransform<3, Extrusion::ChildType>>(new Extrusion(this->_child, length));
56}
57
58 GeometryObject::Subtree Extrusion::getPathsAt(const DVec& point, bool all) const {
59 if (this->hasChild() && canBeInside(point))
60 return GeometryObject::Subtree::extendIfNotEmpty(this, getChild()->getPathsAt(childVec(point), all));
61 else
62 return GeometryObject::Subtree();
63}
64
65 void Extrusion::writeXMLAttr(XMLWriter::Element& dest_xml_object, const AxisNames& axes) const {
66 BaseClass::writeXMLAttr(dest_xml_object, axes);
67 dest_xml_object.attr("length", length);
68}
69
70 void Extrusion::getPositionsToVec(const GeometryObject::Predicate& predicate,
71 std::vector<GeometryObjectTransformSpace::DVec>& dest,
72 const PathHints* path) const {
73 if (predicate(*this)) {
74 dest.push_back(Primitive<3>::ZERO_VEC);
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
93 void Extrusion::addPointsAlongToSet(std::set<double>& points,
94 Primitive<3>::Direction direction,
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
108 void 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
126 shared_ptr<GeometryObject> read_cartesianExtend(GeometryReader& reader) {
127 double length = reader.source.requireAttribute<double>("length");
128 GeometryReader::SetExpectedSuffix suffixSetter(reader, PLASK_GEOMETRY_TYPE_NAME_SUFFIX_2D);
129 return plask::make_shared<Extrusion>(
130 reader.readExactlyOneChild<typename Extrusion::ChildType>(), length);
131}
132
133 static GeometryReader::RegisterObjectReader cartesianExtend2D_reader(PLASK_EXTRUSION_NAME, read_cartesianExtend);
134
135} // namespace plask