Visual Computing Library  devel
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/space/core.h>
27
43namespace vcl {
44
58template<PointConcept PointType>
59auto boundingBox(const PointType& p)
60{
61 return Box<PointType>(p);
62}
63
78template<SegmentConcept SegmentType>
80{
81 using PointType = SegmentType::PointType;
82
83 Box<PointType> b(s.p0());
84 b.add(s.p1());
85
86 return b;
87}
88
103template<SphereConcept SphereType>
105{
106 using ScalarType = SphereType::ScalarType;
107
108 Box<Point3<ScalarType>> b(s.center() - s.radius());
109 b.add(s.center() + s.radius());
110
111 return b;
112}
113
127template<TriangleConcept TriangleType>
129{
130 using PointType = TriangleType::PointType;
131
132 Box<PointType> b(t.point(0));
133 b.add(t.point(1));
134 b.add(t.point(2));
135
136 return b;
137}
138
160template<IteratorConcept Iterator>
161auto boundingBox(Iterator begin, Iterator end)
162{
163 using BB = decltype(boundingBox(typename Iterator::value_type()));
164
165 BB b;
166
167 for (; begin != end; ++begin)
168 b.add(boundingBox(*begin));
169
170 return b;
171}
172
192template<Range Rng>
194{
195 return boundingBox(std::ranges::begin(r), std::ranges::end(r));
196}
197
198} // namespace vcl
199
200#endif // VCL_ALGORITHMS_CORE_BOUNDING_BOX_H
A class representing a box in N-dimensional space.
Definition box.h:46
void add(const PointT &p)
Adds the given point to the current box, expanding this box in order to contain also the values of th...
Definition box.h:385
PointT center() const
Calculates the center point of the box.
Definition box.h:259
auto boundingBox(const PointType &p)
Compute the bounding box of a single point.
Definition bounding_box.h:59