PLaSK library

Loading...
Searching...
No Matches
prism.hpp
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#ifndef PLASK__GEOMETRY_PRISM_H
15#define PLASK__GEOMETRY_PRISM_H
16
21#include "../vector/lateral.hpp"
22
23#include "leaf.hpp"
24
25 namespace plask {
26
31 struct PLASK_API TriangularPrism : public GeometryObjectLeaf<3> {
32 typedef GeometryObjectLeaf<3> BaseClass;
33
35 typedef typename BaseClass::DVec DVec;
36
38 typedef LateralVec<double> Vec2;
39
41 typedef typename BaseClass::Box Box;
42
43 static const char* NAME;
44
45 std::string getTypeName() const override;
46
52 explicit TriangularPrism(const Vec2& p0 = Primitive<2>::ZERO_VEC,
53 const Vec2& p1 = Primitive<2>::ZERO_VEC,
54 double height = 0.,
55 const shared_ptr<Material>& material = shared_ptr<Material>());
56
62 explicit TriangularPrism(const Vec2& p0,
63 const Vec2& p1,
64 double height,
65 shared_ptr<MaterialsDB::MixedCompositionFactory> materialTopBottom);
66
67 // explicit Prism(const DVec& p0, const Vec2& p1, double height,
68 // const std::unique_ptr<MaterialProvider>& materialProvider);
69
70 Box3D getBoundingBox() const override;
71
72 bool contains(const DVec& p) const override;
73
74 shared_ptr<GeometryObject> shallowCopy() const override { return make_shared<TriangularPrism>(*this); }
75
76 void addPointsAlongToSet(std::set<double>& points,
77 Primitive<3>::Direction direction,
78 unsigned max_steps,
79 double min_step_size) const override;
80
81 void addLineSegmentsToSet(std::set<typename GeometryObjectD<3>::LineSegment>& segments,
82 unsigned max_steps,
83 double min_step_size) const override;
84
85 void writeXMLAttr(XMLWriter::Element& dest_xml_object, const AxisNames& axes) const override;
86
88 Vec2 p0, p1;
89
91 double height;
92
97 void setP0(const Vec2& new_p0) {
98 p0 = new_p0;
99 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
100 }
101
106 void setP1(const Vec2& new_p1) {
107 p1 = new_p1;
108 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
109 }
110
115 void setHeight(double new_height) {
116 height = new_height;
117 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
118 }
119};
120
122
123 struct PLASK_API Prism : public GeometryObjectLeaf<3> {
124 protected:
125 double height;
126
127 std::vector<LateralVec<double>> vertices;
128
129 friend shared_ptr<GeometryObject> read_prism(GeometryReader& reader);
130
131 public:
132 typedef GeometryObjectLeaf<3> BaseClass;
133
135 typedef typename BaseClass::DVec DVec;
136
138 typedef typename BaseClass::Box Box;
139
140 static const char* NAME;
141
142 std::string getTypeName() const override;
143
147 Prism() = default;
148
155 explicit Prism(double height,
156 const std::vector<LateralVec<double>>& vertices,
157 const shared_ptr<Material>& material = shared_ptr<Material>());
158
165 explicit Prism(double height,
166 std::vector<LateralVec<double>>&& vertices,
167 const shared_ptr<Material>&& material = shared_ptr<Material>());
168
175 explicit Prism(double height,
176 std::initializer_list<LateralVec<double>> vertices,
177 const shared_ptr<Material>& material = shared_ptr<Material>());
178
185 explicit Prism(double height,
186 const std::vector<LateralVec<double>>& vertices,
187 shared_ptr<MaterialsDB::MixedCompositionFactory> materialTopBottom);
188
195 explicit Prism(double height,
196 std::vector<LateralVec<double>>&& vertices,
197 shared_ptr<MaterialsDB::MixedCompositionFactory> materialTopBottom);
198
205 explicit Prism(double height,
206 std::initializer_list<LateralVec<double>> vertices,
207 shared_ptr<MaterialsDB::MixedCompositionFactory> materialTopBottom);
208
212 explicit Prism(const Prism& src) : BaseClass(src), height(src.height), vertices(src.vertices) {}
213
218 double getHeight() const { return height; }
219
224 void setHeight(double height) {
225 this->height = height;
226 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
227 }
228
233 const std::vector<LateralVec<double>>& getVertices() const { return vertices; }
234
239 std::vector<LateralVec<double>>& getVertices() { return vertices; }
240
245 void setVertices(const std::vector<LateralVec<double>>& vertices) {
246 this->vertices = vertices;
247 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
248 }
249
254 void setVertices(std::vector<LateralVec<double>>&& vertices) {
255 this->vertices = std::move(vertices);
256 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
257 }
258
264 void setVertex(unsigned index, const LateralVec<double>& vertex) {
265 vertices.at(index) = vertex;
266 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
267 }
268
274 void insertVertex(unsigned index, const LateralVec<double>& vertex) {
275 vertices.insert(vertices.begin() + index, vertex);
276 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
277 }
278
283 void addVertex(const LateralVec<double>& vertex) {
284 vertices.push_back(vertex);
285 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
286 }
287
292 void removeVertex(unsigned index) {
293 vertices.erase(vertices.begin() + index);
294 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
295 }
296
300 void clearVertices() {
301 vertices.clear();
302 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
303 }
304
309 unsigned getVertexCount() const { return vertices.size(); }
310
316 const LateralVec<double>& getVertex(unsigned index) const { return vertices.at(index); }
317
318 // /// Validate the prism: check if the lines between vertices do not intersect.
319 // bool checkSegments() const;
320
321 void validate() const override;
322
323 Box getBoundingBox() const override;
324
325 bool contains(const DVec& p) const override;
326
327 shared_ptr<GeometryObject> shallowCopy() const override { return make_shared<Prism>(*this); }
328
329 void addPointsAlongToSet(std::set<double>& points,
330 Primitive<3>::Direction direction,
331 unsigned max_steps,
332 double min_step_size) const override;
333
334 void addLineSegmentsToSet(std::set<typename GeometryObjectD<3>::LineSegment>& segments,
335 unsigned max_steps,
336 double min_step_size) const override;
337
338 void writeXMLAttr(XMLWriter::Element& dest_xml_object, const AxisNames& axes) const override;
339};
340
341} // namespace plask
342
343#endif // PLASK__GEOMETRY_PRISM_H