PLaSK library
Loading...
Searching...
No Matches
path.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_PATH_H
15
#define PLASK__GEOMETRY_PATH_H
16
17
#include <map>
18
#include <set>
19
#include <plask/config.hpp>
20
#include "
transform.hpp
"
21
22
namespace
plask
{
23
24
struct
GeometryObject;
25
26
//TODO redefine to structure which allow to cast to container and translation
27
typedef
std::pair< shared_ptr<GeometryObject>,
shared_ptr<GeometryObject>
>
Edge
;
28
29
struct
Path
;
30
44
struct
PLASK_API
PathHints
{
45
47
#ifdef PLASK_SHARED_PTR_STD
48
typedef
std::map<weak_ptr<GeometryObject>, std::set<weak_ptr<GeometryObject>, std::owner_less<weak_ptr<GeometryObject>>>,
49
std::owner_less<weak_ptr<GeometryObject>>>
HintMap
;
50
#else
51
typedef
std::map<weak_ptr<GeometryObject>, std::set<weak_ptr<GeometryObject>>>
HintMap
;
52
#endif
53
58
typedef
Edge
Hint
;
59
61
HintMap
hintFor
;
62
66
explicit
PathHints
(
const
Hint
&
hint
) {
67
addHint(
hint
);
68
}
69
73
explicit
PathHints
(
const
Path
& path) {
74
addAllHintsFromPath(path);
75
}
76
81
explicit
PathHints
(
const
std::vector<
shared_ptr<const GeometryObject>
>& path) {
82
addAllHintsFromPath(path);
83
}
84
89
explicit
PathHints
(
const
GeometryObject::Subtree
&
subtree
) {
90
addAllHintsFromSubtree(
subtree
);
91
}
92
96
PathHints
() =
default
;
97
102
void
addHint(
const
Hint
&
hint
);
103
109
bool
includes(
shared_ptr<const GeometryObject>
container,
shared_ptr<const GeometryObject>
child_tran
)
const
;
110
116
bool
includes
(
const
Hint
&
hint
)
const
{
117
return
includes(
hint
.first,
hint
.second);
118
}
119
124
PathHints
&
operator+=
(
const
Hint
&
hint
) {
125
addHint(
hint
);
126
return
*
this
;
127
}
128
130
inline
bool
operator==
(
const
PathHints
& comp)
const
{
131
return
!(hintFor < comp.hintFor || comp.hintFor < hintFor);
132
}
133
135
inline
bool
operator<
(
const
PathHints
& comp)
const
{
136
return
hintFor < comp.hintFor;
137
}
138
143
void
addHint(weak_ptr<GeometryObject> container, weak_ptr<GeometryObject> child);
144
149
void
addAllHintsFromPath(
const
std::vector<
shared_ptr<const GeometryObject>
>&
pathObjects
);
150
155
void
addAllHintsFromPath(
const
Path
& path);
156
161
void
addAllHintsFromSubtree(
const
GeometryObject::Subtree
&
subtree
);
162
167
std::set<shared_ptr<GeometryObject>> getChildren(
shared_ptr<const GeometryObject>
container);
168
173
std::set<shared_ptr<GeometryObject>>
getChildren
(
const
GeometryObject
& container) {
174
return
getChildren(container.shared_from_this());
175
}
176
181
std::set<shared_ptr<GeometryObject>> getChildren(
shared_ptr<const GeometryObject>
container)
const
;
182
187
std::set<shared_ptr<GeometryObject>>
getChildren
(
const
GeometryObject
& container)
const
{
188
return
getChildren(container.shared_from_this());
189
}
190
191
template
<
int
dim>
static
192
std::set<shared_ptr<Translation<dim>>>
castToTranslation
(std::set<
shared_ptr<GeometryObject>
> src) {
193
std::set<shared_ptr<Translation<dim>>>
result
;
194
for
(
auto
&
e
: src)
result
.insert(dynamic_pointer_cast<
Translation<dim>
>(
e
));
195
return
result
;
196
}
197
203
template
<
int
dim> std::set<shared_ptr<Translation<dim>>>
getTranslationChildren
(
shared_ptr<const GeometryObject>
container) {
204
return
castToTranslation<dim>
(getChildren(container));
205
}
206
212
template
<
int
dim> std::set<shared_ptr<Translation<dim>>>
getTranslationChildren
(
const
GeometryObject
& container) {
213
return
getTranslationChildren<dim>
(container.shared_from_this());
214
}
215
221
template
<
int
dim> std::set<shared_ptr<Translation<dim>>>
getTranslationChildren
(
shared_ptr<const GeometryObject>
container)
const
{
222
return
castToTranslation<dim>
(getChildren(container));
223
}
224
230
template
<
int
dim> std::set<shared_ptr<Translation<dim>>>
getTranslationChildren
(
const
GeometryObject
& container)
const
{
231
return
getTranslationChildren<dim>
(container.shared_from_this());
232
}
233
237
void
cleanDeleted();
238
239
};
240
244
struct
PLASK_API
Path
{
245
246
private
:
247
248
bool
completeToFirst(
const
GeometryObject
&
newFirst
,
const
PathHints
*
hints
=
nullptr
);
249
250
bool
completeFromLast(
const
GeometryObject
&
newLast
,
const
PathHints
*
hints
=
nullptr
);
251
252
public
:
253
254
Path
(
const
std::vector<
shared_ptr<const GeometryObject>
>& path)
255
: objects(path) {}
256
257
Path
(std::vector<
shared_ptr<const GeometryObject>
>&& path)
258
: objects(
std
::move(path)) {}
259
260
Path
(
const
GeometryObject::Subtree
&
paths
)
261
: objects(
paths
.toLinearPath().objects) {}
262
263
Path
(
GeometryObject::Subtree
&&
paths
)
264
: objects(
paths
.toLinearPath().objects) {}
265
266
// These are the same as default constructors, so can be skipped:
267
// Path(const Path& path): objects(path.objects) {}
268
// Path(Path&& path): objects(path.objects) {}
269
270
Path
(
const
PathHints::Hint
&
hint
) { append(
hint
); }
271
272
Path
(
const
GeometryObject
&
object
) { append(
object
); }
273
274
Path
(
shared_ptr<const GeometryObject>
object
) { append(*
object
); }
275
277
std::vector< shared_ptr<const GeometryObject> >
objects
;
278
286
void
push_front(
const
std::vector<
shared_ptr<const GeometryObject>
>&
toAdd
);
287
295
void
push_back(
const
std::vector<
shared_ptr<const GeometryObject>
>&
toAdd
);
296
304
Path
& append(
const
std::vector<
shared_ptr<const GeometryObject>
>& path,
const
PathHints
*
hints
=
nullptr
);
305
313
Path
& append(
const
GeometryObject::Subtree
& path,
const
PathHints
*
hints
=
nullptr
);
314
322
Path
& append(
const
Path
& path,
const
PathHints
*
hints
=
nullptr
);
323
331
Path
& append(
const
PathHints::Hint
&
hint
,
const
PathHints
*
hints
=
nullptr
);
332
340
Path
& append(
const
GeometryObject
&
object
,
const
PathHints
*
hints
=
nullptr
);
341
349
Path
& append(
shared_ptr<const GeometryObject>
object
,
const
PathHints
*
hints
=
nullptr
);
350
351
Path
&
operator+=
(
const
std::vector<
shared_ptr<const GeometryObject>
>& path) {
return
append(path); }
352
353
Path
&
operator+=
(
const
GeometryObject::Subtree
&
paths
) {
return
append(
paths
); }
354
355
Path
&
operator+=
(
const
Path
& path) {
return
append(path); }
356
357
Path
&
operator+=
(
const
PathHints::Hint
&
hint
) {
return
append(
hint
); }
358
359
Path
&
operator+=
(
const
GeometryObject
&
object
) {
return
append(
object
); }
360
361
Path
&
operator+=
(
shared_ptr<const GeometryObject>
object
) {
return
append(
object
); }
362
367
PathHints
getPathHints()
const
;
368
370
shared_ptr<const GeometryObject>
front
()
const
{
return
objects.front(); }
371
373
shared_ptr<const GeometryObject>
back
()
const
{
return
objects.back(); }
374
379
operator
PathHints
()
const
{
return
getPathHints(); }
380
};
381
382
}
383
384
#endif
// PLASK__GEOMETRY_PATH_H
plask
geometry
path.hpp
Generated by
1.9.8