Visual Computing Library
Loading...
Searching...
No Matches
box3.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_ALGORITHMS_CORE_BOX_BOX3_H
24#define VCL_ALGORITHMS_CORE_BOX_BOX3_H
25
26#include <vclib/concepts/space/box.h>
27#include <vclib/space/core/box.h>
28#include <vclib/space/core/polygon.h>
29#include <vclib/space/core/segment.h>
30
31#include <stdexcept>
32
75namespace vcl {
76
106template<Box3Concept BoxType>
107auto boxVertex(const BoxType& box, uint i) -> BoxType::PointType
108{
109 using PointType = BoxType::PointType;
110
111 switch (i) {
112 case 0: return box.min();
113 case 1: return PointType(box.max().x(), box.min().y(), box.min().z());
114 case 2: return PointType(box.min().x(), box.max().y(), box.min().z());
115 case 3: return PointType(box.max().x(), box.max().y(), box.min().z());
116 case 4: return PointType(box.min().x(), box.min().y(), box.max().z());
117 case 5: return PointType(box.max().x(), box.min().y(), box.max().z());
118 case 6: return PointType(box.min().x(), box.max().y(), box.max().z());
119 case 7: return box.max();
120 default:
121 throw std::out_of_range("Invalid vertex index");
122 return PointType();
123 }
124}
125
154template<Box3Concept BoxType>
155auto boxEdge(const BoxType& box, uint i) -> Segment<typename BoxType::PointType>
156{
157 using PointType = BoxType::PointType;
158
159 switch (i) {
160 case 0: return Segment<PointType>(boxVertex(box, 1), boxVertex(box, 0));
161 case 1: return Segment<PointType>(boxVertex(box, 0), boxVertex(box, 2));
162 case 2: return Segment<PointType>(boxVertex(box, 2), boxVertex(box, 3));
163 case 3: return Segment<PointType>(boxVertex(box, 3), boxVertex(box, 1));
164 case 4: return Segment<PointType>(boxVertex(box, 4), boxVertex(box, 5));
165 case 5: return Segment<PointType>(boxVertex(box, 5), boxVertex(box, 7));
166 case 6: return Segment<PointType>(boxVertex(box, 7), boxVertex(box, 6));
167 case 7: return Segment<PointType>(boxVertex(box, 6), boxVertex(box, 4));
168 case 8: return Segment<PointType>(boxVertex(box, 0), boxVertex(box, 4));
169 case 9: return Segment<PointType>(boxVertex(box, 1), boxVertex(box, 5));
170 case 10: return Segment<PointType>(boxVertex(box, 2), boxVertex(box, 6));
171 case 11: return Segment<PointType>(boxVertex(box, 3), boxVertex(box, 7));
172 default:
173 throw std::out_of_range("Invalid edge index");
174 return Segment<PointType>();
175 }
176}
177
178} // namespace vcl
179
180#endif // VCL_ALGORITHMS_CORE_BOX_BOX3_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
auto boxVertex(const BoxType &box, uint i) -> BoxType::PointType
Returns the ith vertex of a 3D box.
Definition box3.h:107
auto boxEdge(const BoxType &box, uint i) -> Segment< typename BoxType::PointType >
Returns the ith edge of a 3D box.
Definition box3.h:155