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_MESH_COMPONENTS_BOUNDING_BOX_H
24#define VCL_MESH_COMPONENTS_BOUNDING_BOX_H
25
26#include "base/component.h"
27#include "base/predicates.h"
28
29#include <vclib/space/core.h>
30
31namespace vcl::comp {
32
60template<
61 PointConcept PointType,
62 typename ParentElemType = void,
63 bool OPT = false>
65 public Component<
66 BoundingBox<PointType, ParentElemType, OPT>,
67 CompId::BOUNDING_BOX,
68 Box<PointType>,
69 ParentElemType,
70 !std::is_same_v<ParentElemType, void>,
71 OPT>
72{
73 using Base = Component<
75 CompId::BOUNDING_BOX,
78 !std::is_same_v<ParentElemType, void>,
79 OPT>;
80
81public:
86
87 /* Constructors */
88
92 BoundingBox() = default;
93
94 /* Member functions */
95
100 const BoundingBoxType& boundingBox() const { return Base::data(); }
101
106 BoundingBoxType& boundingBox() { return Base::data(); }
107
108protected:
109 // Component interface functions
110 template<typename Element>
111 void importFrom(const Element& e, bool = true);
112
113 void serialize(std::ostream& os) const { boundingBox().serialize(os); }
114
115 void deserialize(std::istream& is) { boundingBox().deserialize(is); }
116};
117
118/* concept */
119
131template<typename T>
132concept HasBoundingBox = TTB::IsDerivedFromSpecializationOfV<T, BoundingBox>;
133
134/* importFrom function */
135
136template<PointConcept PointType, typename ParentElemType, bool OPT>
137template<typename Element>
138void BoundingBox<PointType, ParentElemType, OPT>::importFrom(
139 const Element& e,
140 bool)
141{
142 if constexpr (HasBoundingBox<Element>) {
143 using ScalarType = PointType::ScalarType;
144 boundingBox() = e.boundingBox().template cast<ScalarType>();
145 }
146}
147
148/* Detector function to check if a class has BoundingBox available */
149
161bool isBoundingBoxAvailableOn(const auto& element)
162{
164}
165
166/* Specializations */
167
181template<typename S, typename ElementType = void, bool OPT = false>
183
196template<typename ElementType = void, bool OPT = false>
198
211template<typename ElementType = void, bool OPT = false>
213
214} // namespace vcl::comp
215
216#endif // VCL_MESH_COMPONENTS_BOUNDING_BOX_H
A class representing a box in N-dimensional space.
Definition box.h:46
void deserialize(std::istream &is)
Deserializes the box from the given input stream.
Definition box.h:476
void serialize(std::ostream &os) const
Serializes the box to the given output stream.
Definition box.h:466
The Element class.
Definition element.h:75
The BoundingBox component class represents an axis aligned bounding box. This class is usually used a...
Definition bounding_box.h:72
const BoundingBoxType & boundingBox() const
Returns a const reference to the bounding box of this object.
Definition bounding_box.h:100
BoundingBoxType & boundingBox()
Returns a reference to the bounding box of this object.
Definition bounding_box.h:106
BoundingBox()=default
Initilizes the bounding box to an invalid bounding box.
A concept that checks whether a type T (that should be a Mesh) has the BoundingBox component (inherit...
Definition bounding_box.h:132
auto boundingBox(const PointType &p)
Compute the bounding box of a single point.
Definition bounding_box.h:59