-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathadaptor.xyz.h
245 lines (190 loc) · 8.72 KB
/
adaptor.xyz.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#pragma once
/*
MIT License
Copyright (c) 2021 Attila Csikós
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "octree.h"
namespace BasicTypesXYZ // Replaceble with simirarly build geometry types
{
using float_t = float;
struct Point2D
{
float_t x;
float_t y;
};
struct Point3D
{
float_t x;
float_t y;
float_t z;
};
struct BoundingBox2D
{
Point2D Min;
Point2D Max;
};
struct BoundingBox3D
{
Point3D Min;
Point3D Max;
};
struct Ray2D
{
Point2D BasePoint;
Point2D Heading;
};
struct Ray3D
{
Point3D BasePoint;
Point3D Heading;
};
struct Plane2D
{
float_t OrigoDistance;
Point2D Normal;
};
struct Plane3D
{
float_t OrigoDistance;
Point3D Normal;
};
} // namespace BasicTypesXYZ
namespace OrthoTree
{
namespace XYAdaptor2D
{
using xy_geometry_type = BasicTypesXYZ::float_t;
using XYPoint2D = BasicTypesXYZ::Point2D;
using XYBoundingBox2D = BasicTypesXYZ::BoundingBox2D;
using XYRay2D = BasicTypesXYZ::Ray2D;
using XYPlane2D = BasicTypesXYZ::Plane2D;
struct XYAdaptorBasics
{
static constexpr xy_geometry_type GetPointC(XYPoint2D const& pt, dim_t dimensionID)
{
switch (dimensionID)
{
case 0: return pt.x;
case 1: return pt.y;
default: assert(false); std::terminate();
}
}
static constexpr void SetPointC(XYPoint2D& pt, dim_t dimensionID, xy_geometry_type value)
{
switch (dimensionID)
{
case 0: pt.x = value; break;
case 1: pt.y = value; break;
default: assert(false); std::terminate();
}
}
static constexpr void SetBoxMinC(XYBoundingBox2D& box, dim_t dimensionID, xy_geometry_type value) { SetPointC(box.Min, dimensionID, value); }
static constexpr void SetBoxMaxC(XYBoundingBox2D& box, dim_t dimensionID, xy_geometry_type value) { SetPointC(box.Max, dimensionID, value); }
static constexpr xy_geometry_type GetBoxMinC(XYBoundingBox2D const& box, dim_t dimensionID) { return GetPointC(box.Min, dimensionID); }
static constexpr xy_geometry_type GetBoxMaxC(XYBoundingBox2D const& box, dim_t dimensionID) { return GetPointC(box.Max, dimensionID); }
static constexpr XYPoint2D const& GetRayDirection(XYRay2D const& ray) noexcept { return ray.Heading; }
static constexpr XYPoint2D const& GetRayOrigin(XYRay2D const& ray) noexcept { return ray.BasePoint; }
static constexpr XYPoint2D const& GetPlaneNormal(XYPlane2D const& plane) noexcept { return plane.Normal; }
static constexpr xy_geometry_type GetPlaneOrigoDistance(XYPlane2D const& plane) noexcept { return plane.OrigoDistance; }
};
using XYAdaptorGeneral = AdaptorGeneralBase<2, XYPoint2D, XYBoundingBox2D, XYRay2D, XYPlane2D, xy_geometry_type, XYAdaptorBasics>;
} // namespace XYAdaptor2D
namespace XYZAdaptor3D
{
using xyz_geometry_type = BasicTypesXYZ::float_t;
using XYZPoint3D = BasicTypesXYZ::Point3D;
using XYZBoundingBox3D = BasicTypesXYZ::BoundingBox3D;
using XYZRay3D = BasicTypesXYZ::Ray3D;
using XYZPlane3D = BasicTypesXYZ::Plane3D;
struct XYZAdaptorBasics
{
static constexpr xyz_geometry_type GetPointC(XYZPoint3D const& pt, dim_t dimensionID) noexcept
{
switch (dimensionID)
{
case 0: return pt.x;
case 1: return pt.y;
case 2: return pt.z;
default: assert(false); std::terminate();
}
}
static constexpr void SetPointC(XYZPoint3D& pt, dim_t dimensionID, xyz_geometry_type value) noexcept
{
switch (dimensionID)
{
case 0: pt.x = value; break;
case 1: pt.y = value; break;
case 2: pt.z = value; break;
default: assert(false); std::terminate();
}
}
static constexpr void SetBoxMinC(XYZBoundingBox3D& box, dim_t dimensionID, xyz_geometry_type value) { SetPointC(box.Min, dimensionID, value); }
static constexpr void SetBoxMaxC(XYZBoundingBox3D& box, dim_t dimensionID, xyz_geometry_type value) { SetPointC(box.Max, dimensionID, value); }
static constexpr xyz_geometry_type GetBoxMinC(XYZBoundingBox3D const& box, dim_t dimensionID) { return GetPointC(box.Min, dimensionID); }
static constexpr xyz_geometry_type GetBoxMaxC(XYZBoundingBox3D const& box, dim_t dimensionID) { return GetPointC(box.Max, dimensionID); }
static constexpr XYZPoint3D const& GetRayDirection(XYZRay3D const& ray) noexcept { return ray.Heading; }
static constexpr XYZPoint3D const& GetRayOrigin(XYZRay3D const& ray) noexcept { return ray.BasePoint; }
static constexpr XYZPoint3D const& GetPlaneNormal(XYZPlane3D const& plane) noexcept { return plane.Normal; }
static constexpr xyz_geometry_type GetPlaneOrigoDistance(XYZPlane3D const& plane) noexcept { return plane.OrigoDistance; }
};
using XYZAdaptorGeneral = AdaptorGeneralBase<3, XYZPoint3D, XYZBoundingBox3D, XYZRay3D, XYZPlane3D, xyz_geometry_type, XYZAdaptorBasics>;
} // namespace XYZAdaptor3D
} // namespace OrthoTree
namespace XYZ
{
using namespace OrthoTree;
using namespace OrthoTree::XYAdaptor2D;
using namespace OrthoTree::XYZAdaptor3D;
using QuadtreePoint =
OrthoTreePoint<2, XYPoint2D, XYBoundingBox2D, XYRay2D, XYPlane2D, xy_geometry_type, XYAdaptorGeneral, std::span<XYPoint2D const>>;
template<uint32_t SPLIT_DEPTH_INCREASEMENT = 2>
using QuadtreeBox =
OrthoTreeBoundingBox<2, XYPoint2D, XYBoundingBox2D, XYRay2D, XYPlane2D, xy_geometry_type, SPLIT_DEPTH_INCREASEMENT, XYAdaptorGeneral, std::span<XYBoundingBox2D const>>;
using QuadtreePointC = OrthoTreeContainerPoint<QuadtreePoint>;
template<uint32_t SPLIT_DEPTH_INCREASEMENT = 2>
using QuadtreeBoxCs = OrthoTreeContainerBox<QuadtreeBox<SPLIT_DEPTH_INCREASEMENT>>;
using QuadtreeBoxC = QuadtreeBoxCs<2>;
using OctreePoint =
OrthoTreePoint<3, XYZPoint3D, XYZBoundingBox3D, XYZRay3D, XYZPlane3D, xyz_geometry_type, XYZAdaptorGeneral, std::span<XYZPoint3D const>>;
template<uint32_t SPLIT_DEPTH_INCREASEMENT = 2>
using OctreeBox =
OrthoTreeBoundingBox<3, XYZPoint3D, XYZBoundingBox3D, XYZRay3D, XYZPlane3D, xyz_geometry_type, SPLIT_DEPTH_INCREASEMENT, XYZAdaptorGeneral, std::span<XYZPoint3D const>>;
using OcreePointC = OrthoTreeContainerPoint<OctreePoint>;
template<uint32_t SPLIT_DEPTH_INCREASEMENT = 2>
using OctreeBoxCs = OrthoTreeContainerBox<OctreeBox<SPLIT_DEPTH_INCREASEMENT>>;
using OctreeBoxC = OctreeBoxCs<2>;
// Map types
template<typename TEntity>
using Map = std::unordered_map<int, TEntity>;
using QuadtreePointMap = OrthoTreePoint<2, XYPoint2D, XYBoundingBox2D, XYRay2D, XYPlane2D, xy_geometry_type, XYAdaptorGeneral, Map<XYPoint2D>>;
template<uint32_t SPLIT_DEPTH_INCREASEMENT = 2>
using QuadtreeBoxMap =
OrthoTreeBoundingBox<2, XYPoint2D, XYBoundingBox2D, XYRay2D, XYPlane2D, xy_geometry_type, SPLIT_DEPTH_INCREASEMENT, XYAdaptorGeneral, Map<XYBoundingBox2D>>;
using QuadtreePointMapC = OrthoTreeContainerPoint<QuadtreePointMap>;
template<uint32_t SPLIT_DEPTH_INCREASEMENT = 2>
using QuadtreeBoxMapCs = OrthoTreeContainerBox<QuadtreeBoxMap<SPLIT_DEPTH_INCREASEMENT>>;
using QuadtreeBoxMapC = QuadtreeBoxMapCs<2>;
using OctreePointMap = OrthoTreePoint<3, XYZPoint3D, XYZBoundingBox3D, XYZRay3D, XYZPlane3D, xyz_geometry_type, XYZAdaptorGeneral, Map<XYZPoint3D>>;
template<uint32_t SPLIT_DEPTH_INCREASEMENT = 2>
using OctreeBoxMap =
OrthoTreeBoundingBox<3, XYZPoint3D, XYZBoundingBox3D, XYZRay3D, XYZPlane3D, xyz_geometry_type, SPLIT_DEPTH_INCREASEMENT, XYZAdaptorGeneral, Map<XYZBoundingBox3D>>;
using OcreePointMapC = OrthoTreeContainerPoint<OctreePointMap>;
template<uint32_t SPLIT_DEPTH_INCREASEMENT = 2>
using OctreeBoxMapCs = OrthoTreeContainerBox<OctreeBoxMap<SPLIT_DEPTH_INCREASEMENT>>;
using OctreeBoxMapC = OctreeBoxMapCs<2>;
} // namespace XYZ