PLaSK library
Loading...
Searching...
No Matches
lattice.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_LATTICE_H
15#define PLASK__GEOMETRY_LATTICE_H
16
17#include <cmath>
18
19#include "../log/log.hpp"
20#include "transform.hpp"
21
22#include "translation_container.hpp" // used by lattiece
23
24namespace plask {
25
28template <int dim> struct PLASK_API ArrangeContainer : public GeometryObjectTransform<dim> {
30
32 typedef typename BaseClass::DVec DVec;
33
35 typedef typename BaseClass::Box Box;
36
39
40 using BaseClass::getChild;
41
42 protected:
43 using BaseClass::_child;
44
47
49 unsigned repeat_count;
50
52 std::pair<int, int> bounds(const DVec& vec) const;
53
55 void warmOverlaping() const;
56
57 public:
60
62 : GeometryObjectTransform<dim>(shared_ptr<ChildType>()),
63 translation(Primitive<dim>::ZERO_VEC),
64 repeat_count(0),
65 warn_overlapping(true) {}
66
71 ArrangeContainer(const shared_ptr<ChildType>& child, const DVec& step, unsigned repeat, bool warn = true)
72 : GeometryObjectTransform<dim>(child), translation(step), repeat_count(repeat), warn_overlapping(warn) {
73 warmOverlaping();
74 }
75
76 static const char* NAME;
77
78 std::string getTypeName() const override { return NAME; }
79
80 Box getBoundingBox() const override;
81
82 Box getRealBoundingBox() const override;
83
84 void getBoundingBoxesToVec(const GeometryObject::Predicate& predicate,
85 std::vector<Box>& dest,
86 const PathHints* path = 0) const override;
87
88 void getObjectsToVec(const GeometryObject::Predicate& predicate,
90 const PathHints* path = 0) const override;
91
92 void getPositionsToVec(const GeometryObject::Predicate& predicate,
93 std::vector<DVec>& dest,
94 const PathHints* path = 0) const override;
95
96 bool contains(const DVec& p) const override;
97
98 shared_ptr<Material> getMaterial(const DVec& p) const override;
99
100 std::size_t getChildrenCount() const override;
101
102 shared_ptr<GeometryObject> getChildNo(std::size_t child_no) const override;
103
104 std::size_t getRealChildrenCount() const override;
105
106 shared_ptr<GeometryObject> getRealChildNo(std::size_t child_no) const override;
107
108 GeometryObject::Subtree getPathsAt(const DVec& point, bool all = false) const override;
109
110 shared_ptr<GeometryObject> shallowCopy() const override;
111
112 Box fromChildCoords(const typename ChildType::Box& child_bbox) const override;
113
114 unsigned getRepeatCount() const { return repeat_count; }
115
117 if (repeat_count == new_repeat_count) return;
118 repeat_count = new_repeat_count;
119 this->fireChildrenChanged();
120 }
121
122 DVec getTranslation() const { return translation; }
123
125 if (translation == new_translation) return;
126 translation = new_translation;
127 warmOverlaping();
128 this->fireChildrenChanged();
129 }
130
131 void addPointsAlongToSet(std::set<double>& points,
132 Primitive<3>::Direction direction,
133 unsigned max_steps,
134 double min_step_size) const override;
135
136 void addLineSegmentsToSet(std::set<typename GeometryObjectD<dim>::LineSegment>& segments,
137 unsigned max_steps,
138 double min_step_size) const override;
139
140 void writeXMLAttr(XMLWriter::Element& dest_xml_object, const AxisNames& axes) const override;
141};
142
145
148
149
153
156
159
160 using GeometryObjectTransform<3>::getChild;
161
162 static const char* NAME;
163
165 DVec vec0, vec1;
166
168
173 std::vector<std::vector<Vec<2, int>>> segments; // TODO checking somewhere if sides do not cross each other
174
175 std::string getTypeName() const override { return NAME; }
176
182 Lattice(const shared_ptr<ChildType>& child = shared_ptr<ChildType>(),
183 const DVec& vec0 = Primitive<3>::ZERO_VEC,
184 const DVec& vec1 = Primitive<3>::ZERO_VEC)
185 : GeometryObjectTransform<3>(child),
186 vec0(vec0),
187 vec1(vec1),
188 container(plask::make_shared<TranslationContainer<3>>()) {}
189
190 shared_ptr<Material> getMaterial(const DVec& p) const override { return container->getMaterial(p); }
191
192 bool contains(const DVec& p) const override { return container->contains(p); }
193
194 // some methods must be overwrite to invalidate cache:
196 // if (evt.isResize()) invalidateCache();
197 container->onChildChanged(evt); // force early cache rebuilding
199 }
200
201 /*void rebuildCache() {
202 //TODO
203 }*/
204
205 void writeXMLAttr(XMLWriter::Element& dest_xml_object, const AxisNames& axes) const override;
206
207 void writeXMLChildren(XMLWriter::Element& dest_xml_object,
208 WriteXMLCallback& write_cb,
209 const AxisNames& axes) const override;
210
211 Box getBoundingBox() const override { return container->getBoundingBox(); }
212
213 Box getRealBoundingBox() const override { return container->getRealBoundingBox(); }
214
215 // using GeometryObjectTransform<3>::getPathsTo;
216
217 // Box fromChildCoords(const typename ChildType::Box& child_bbox) const override;
218
219 void getBoundingBoxesToVec(const GeometryObject::Predicate& predicate,
220 std::vector<Box>& dest,
221 const PathHints* path = 0) const override;
222
223 void getObjectsToVec(const GeometryObject::Predicate& predicate,
225 const PathHints* path = 0) const override;
226
227 void getPositionsToVec(const GeometryObject::Predicate& predicate,
228 std::vector<DVec>& dest,
229 const PathHints* path = 0) const override;
230
231 GeometryObject::Subtree getPathsTo(const GeometryObject& el, const PathHints* path = 0) const override;
232
233 // GeometryObject::Subtree getPathsAt(const DVec& point, bool all=false) const override;
234
235 GeometryObject::Subtree getPathsAt(const DVec& point, bool all = false) const override {
236 return container->ensureHasCache()->getPathsAt(this->shared_from_this(), point, all);
237 }
238
239 std::size_t getChildrenCount() const override { return container->getChildrenCount(); }
240
241 shared_ptr<GeometryObject> getChildNo(std::size_t child_no) const override {
242 return container->getChildNo(child_no);
243 }
244
246
250
254 return result;
255 }
256
257 shared_ptr<GeometryObject> shallowCopy() const override { return copyShallow(); }
258
259 void addPointsAlongToSet(std::set<double>& points,
260 Primitive<3>::Direction direction,
261 unsigned max_steps,
262 double min_step_size) const override;
263
264 void addLineSegmentsToSet(std::set<typename GeometryObjectD<3>::LineSegment>& segments,
265 unsigned max_steps,
266 double min_step_size) const override;
267
268 // probably unused
269 Box fromChildCoords(const typename ChildType::Box& child_bbox) const override { return child_bbox; }
270
271 void setSegments(std::vector<std::vector<Vec<2, int>>> new_segments);
272
273 // protected:
274
276 void refillContainer();
277};
278
279} // namespace plask
280
281#endif // PLASK__GEOMETRY_LATTICE_H