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