Visual Computing Library
Loading...
Searching...
No Matches
bounding_box.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_BOUNDING_BOX_H
24#define VCL_ALGORITHMS_CORE_BOUNDING_BOX_H
25
26#include <vclib/concepts/iterators.h>
27#include <vclib/concepts/mesh/elements/edge.h>
28#include <vclib/concepts/range.h>
29#include <vclib/concepts/space/triangle.h>
30#include <vclib/space/core/box.h>
31#include <vclib/space/core/segment.h>
32#include <vclib/space/core/sphere.h>
33
49namespace vcl {
50
64template<PointConcept PointType>
65auto boundingBox(const PointType& p)
66{
67 return Box<PointType>(p);
68}
69
84template<SegmentConcept SegmentType>
86{
87 using PointType = SegmentType::PointType;
88
89 Box<PointType> b(s.p0());
90 b.add(s.p1());
91
92 return b;
93}
94
109template<SphereConcept SphereType>
111{
112 using ScalarType = SphereType::ScalarType;
113
114 Box<Point3<ScalarType>> b(s.center() - s.radius());
115 b.add(s.center() + s.radius());
116
117 return b;
118}
119
133template<TriangleConcept TriangleType>
135{
136 using PointType = TriangleType::PointType;
137
138 Box<PointType> b(t.point(0));
139 b.add(t.point(1));
140 b.add(t.point(2));
141
142 return b;
143}
144
159template<VertexConcept VertexType>
160auto boundingBox(const VertexType& v)
161{
162 return Box<typename VertexType::CoordType>(v.coord());
163}
164
180template<VertexConcept VertexType>
181auto boundingBox(const VertexType* v)
182{
183 return Box<typename VertexType::CoordType>(v->coord());
184}
185
199template<FaceConcept FaceType>
200auto boundingBox(const FaceType& f)
201{
202 using VertexType = FaceType::VertexType;
203
205 for (const VertexType* v : f.vertices())
206 b.add(v->coord());
207 return b;
208}
209
224template<FaceConcept FaceType>
225auto boundingBox(const FaceType* f)
226{
227 using VertexType = FaceType::VertexType;
228
230 for (const VertexType* v : f->vertices())
231 b.add(v->coord());
232 return b;
233}
234
248template<EdgeConcept EdgeType>
249auto boundingBox(const EdgeType& e)
250{
251 using VertexType = EdgeType::VertexType;
252
254 for (const VertexType* v : e.vertices())
255 b.add(v->coord());
256 return b;
257}
258
273template<EdgeConcept EdgeType>
274auto boundingBox(const EdgeType* e)
275{
276 using VertexType = EdgeType::VertexType;
277
279 for (const VertexType* v : e->vertices())
280 b.add(v->coord());
281 return b;
282}
283
305template<IteratorConcept Iterator>
306auto boundingBox(Iterator begin, Iterator end)
307{
308 using BB = decltype(boundingBox(typename Iterator::value_type()));
309
310 BB b;
311
312 for (; begin != end; ++begin)
313 b.add(boundingBox(*begin));
314
315 return b;
316}
317
337template<Range Rng>
339{
340 return boundingBox(std::ranges::begin(r), std::ranges::end(r));
341}
342
343} // namespace vcl
344
345#endif // VCL_ALGORITHMS_CORE_BOUNDING_BOX_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
PointT & p0()
Returns the first endpoint of the segment.
Definition segment.h:83
PointT & p1()
Returns the second endpoint of the segment.
Definition segment.h:97
auto boundingBox(const PointType &p)
Compute the bounding box of a single point.
Definition bounding_box.h:65