Visual Computing Library  devel
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/space/core.h>
27
28#include <stdexcept>
29
72namespace vcl {
73
103template<Box3Concept BoxType>
104auto boxVertex(const BoxType& box, uint i) -> BoxType::PointType
105{
106 using PointType = BoxType::PointType;
107
108 switch (i) {
109 case 0: return box.min();
110 case 1: return PointType(box.max().x(), box.min().y(), box.min().z());
111 case 2: return PointType(box.min().x(), box.max().y(), box.min().z());
112 case 3: return PointType(box.max().x(), box.max().y(), box.min().z());
113 case 4: return PointType(box.min().x(), box.min().y(), box.max().z());
114 case 5: return PointType(box.max().x(), box.min().y(), box.max().z());
115 case 6: return PointType(box.min().x(), box.max().y(), box.max().z());
116 case 7: return box.max();
117 default:
118 throw std::out_of_range("Invalid vertex index");
119 return PointType();
120 }
121}
122
151template<Box3Concept BoxType>
153{
154 using PointType = BoxType::PointType;
155
156 switch (i) {
157 case 0: return Segment<PointType>(boxVertex(box, 1), boxVertex(box, 0));
158 case 1: return Segment<PointType>(boxVertex(box, 0), boxVertex(box, 2));
159 case 2: return Segment<PointType>(boxVertex(box, 2), boxVertex(box, 3));
160 case 3: return Segment<PointType>(boxVertex(box, 3), boxVertex(box, 1));
161 case 4: return Segment<PointType>(boxVertex(box, 4), boxVertex(box, 5));
162 case 5: return Segment<PointType>(boxVertex(box, 5), boxVertex(box, 7));
163 case 6: return Segment<PointType>(boxVertex(box, 7), boxVertex(box, 6));
164 case 7: return Segment<PointType>(boxVertex(box, 6), boxVertex(box, 4));
165 case 8: return Segment<PointType>(boxVertex(box, 0), boxVertex(box, 4));
166 case 9: return Segment<PointType>(boxVertex(box, 1), boxVertex(box, 5));
167 case 10: return Segment<PointType>(boxVertex(box, 2), boxVertex(box, 6));
168 case 11: return Segment<PointType>(boxVertex(box, 3), boxVertex(box, 7));
169 default:
170 throw std::out_of_range("Invalid edge index");
171 return Segment<PointType>();
172 }
173}
174
175} // namespace vcl
176
177#endif // VCL_ALGORITHMS_CORE_BOX_BOX3_H
A class representing a box in N-dimensional space.
Definition box.h:46
PointT & max()
Returns a reference to the maximum point of the box.
Definition box.h:104
PointT & min()
Returns a reference to the minimum point of the box.
Definition box.h:90
auto boxVertex(const BoxType &box, uint i) -> BoxType::PointType
Returns the ith vertex of a 3D box.
Definition box3.h:104
auto boxEdge(const BoxType &box, uint i) -> Segment< typename BoxType::PointType >
Returns the ith edge of a 3D box.
Definition box3.h:152