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_MESH_COMPONENTS_BOUNDING_BOX_H
24#define VCL_MESH_COMPONENTS_BOUNDING_BOX_H
25
26#include "bases/component.h"
27
28#include <vclib/concepts/mesh/components/bounding_box.h>
29#include <vclib/space/core/box.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 if constexpr (HasBoundingBox<Element>) {
114 using ScalarType = PointType::ScalarType;
115 boundingBox() = e.boundingBox().template cast<ScalarType>();
116 }
117 }
118
119 void serialize(std::ostream& os) const { boundingBox().serialize(os); }
120
121 void deserialize(std::istream& is) { boundingBox().deserialize(is); }
122};
123
124/* Detector function to check if a class has BoundingBox available */
125
138bool isBoundingBoxAvailableOn(const ElementOrMeshConcept auto& element)
139{
140 return isComponentAvailableOn<CompId::BOUNDING_BOX>(element);
141}
142
143/* Specializations */
144
158template<typename S, typename ElementType = void, bool OPT = false>
160
173template<typename ElementType = void, bool OPT = false>
175
188template<typename ElementType = void, bool OPT = false>
190
191} // namespace vcl::comp
192
193#endif // VCL_MESH_COMPONENTS_BOUNDING_BOX_H
The Element class.
Definition element.h:57
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
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.
HasBoundingBox concept is satisfied only if a Element or Mesh class provides the member functions spe...
Definition bounding_box.h:39