PLaSK library

Loading...
Searching...
No Matches
cylinder.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_CYLINDER_H
15#define PLASK__GEOMETRY_CYLINDER_H
16
17#include "leaf.hpp"
18
19 namespace plask {
20
26 struct PLASK_API Cylinder : public GeometryObjectLeaf<3> {
27 double radius, height;
28
29 static const char* NAME;
30
31 std::string getTypeName() const override { return NAME; }
32
33 Cylinder(double radius, double height, const shared_ptr<Material>& material = shared_ptr<Material>());
34
35 Cylinder(double radius, double height, shared_ptr<MaterialsDB::MixedCompositionFactory> materialTopBottom);
36
37 Cylinder(const Cylinder& src);
38
39 Box getBoundingBox() const override;
40
41 bool contains(const DVec& p) const override;
42
43 // virtual bool intersects(const Box& area) const;
44
45 void writeXMLAttr(XMLWriter::Element& dest_xml_object, const AxisNames& axes) const override;
46
47 shared_ptr<GeometryObject> shallowCopy() const override { return make_shared<Cylinder>(*this); }
48
53 void setRadius(double new_radius) {
54 if (new_radius < 0.) new_radius = 0.;
55 this->radius = new_radius;
56 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
57 }
58
63 void setHeight(double new_height) {
64 if (new_height < 0.) new_height = 0.;
65 this->height = new_height;
66 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
67 }
68
74 void resize(double radius, double height) {
75 this->radius = radius;
76 this->height = height;
77 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
78 }
79
80 void addPointsAlongToSet(std::set<double>& points,
81 Primitive<3>::Direction direction,
82 unsigned max_steps,
83 double min_step_size) const override;
84
85 void addLineSegmentsToSet(std::set<typename GeometryObjectD<3>::LineSegment>& segments,
86 unsigned max_steps,
87 double min_step_size) const override;
88};
89
95 struct PLASK_API HollowCylinder : public GeometryObjectLeaf<3> {
96 double inner_radius, outer_radius, height;
97
98 static const char* NAME;
99
100 std::string getTypeName() const override { return NAME; }
101
102 HollowCylinder(double inner_radius,
103 double outer_radius,
104 double height,
105 const shared_ptr<Material>& material = shared_ptr<Material>());
106
107 HollowCylinder(double inner_radius,
108 double outer_radius,
109 double height,
110 shared_ptr<MaterialsDB::MixedCompositionFactory> materialTopBottom);
111
112 HollowCylinder(const HollowCylinder& src);
113
114 Box getBoundingBox() const override;
115
116 bool contains(const DVec& p) const override;
117
118 // virtual bool intersects(const Box& area) const;
119
120 void writeXMLAttr(XMLWriter::Element& dest_xml_object, const AxisNames& axes) const override;
121
122 shared_ptr<GeometryObject> shallowCopy() const override { return make_shared<HollowCylinder>(*this); }
123
128 void setInnerRadius(double new_radius) {
129 if (new_radius < 0.) new_radius = 0.;
130 if (new_radius > this->outer_radius)
131 throw BadInput("Tube", "Inner radius must be less than outer radius");
132 this->inner_radius = new_radius;
133 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
134 }
135
140 void setOuterRadius(double new_radius) {
141 if (new_radius < 0.) new_radius = 0.;
142 if (new_radius < this->inner_radius)
143 throw BadInput("Tube", "Outer radius must be greater than inner radius");
144 this->outer_radius = new_radius;
145 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
146 }
147
152 void setHeight(double new_height) {
153 if (new_height < 0.) new_height = 0.;
154 this->height = new_height;
155 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
156 }
157
163 void resize(double inner_radius, double outer_radius, double height) {
164 if (inner_radius > outer_radius)
165 throw BadInput("Tube", "Inner radius must be less than outer radius");
166 this->inner_radius = inner_radius;
167 this->outer_radius = outer_radius;
168 this->height = height;
169 this->fireChanged(GeometryObject::Event::EVENT_RESIZE);
170 }
171
172 void addPointsAlongToSet(std::set<double>& points,
173 Primitive<3>::Direction direction,
174 unsigned max_steps,
175 double min_step_size) const override;
176
177 void addLineSegmentsToSet(std::set<typename GeometryObjectD<3>::LineSegment>& segments,
178 unsigned max_steps,
179 double min_step_size) const override;
180};
181
182} // namespace plask
183
184#endif // PLASK__GEOMETRY_CYLINDER_H