EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BoundingBox.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BoundingBox.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
14 #include "Acts/Utilities/Ray.hpp"
16 
17 #include <algorithm>
18 #include <array>
19 #include <iostream>
20 #include <limits>
21 #include <ostream>
22 #include <tuple>
23 #include <vector>
24 
25 namespace Acts {
26 
31 template <typename entity_t, typename value_t, size_t DIM>
33  private:
38 
43  template <typename T, typename P>
44  class NamedType {
45  public:
46  explicit NamedType(const T& value) : m_value(value) {}
47  explicit NamedType(T&& value) : m_value(std::move(value)) {}
48  T& get() { return m_value; }
49  const T& get() const { return m_value; }
50 
51  private:
53  };
54 
58  struct SizeParameter {};
59 
60  public:
75  using vertex_array_type = Eigen::Array<value_t, DIM, 1>;
76 
80  using entity_type = entity_t;
81 
85  using transform_type = Eigen::Transform<value_type, DIM, Eigen::Affine>;
86 
90  using Size = NamedType<VertexType, struct SizeParameter>;
91 
95  static const size_t dim = DIM;
96 
101  AxisAlignedBoundingBox(const self_t& other) = default;
102 
109  AxisAlignedBoundingBox(const entity_t* entity, const VertexType& vmin,
110  const VertexType& vmax);
111 
120  AxisAlignedBoundingBox(const entity_t* entity, const VertexType& center,
121  const Size& size);
122 
130  const std::vector<self_t*>& boxes,
131  vertex_array_type envelope = vertex_array_type::Zero());
132 
139  static std::pair<VertexType, VertexType> wrap(
140  const std::vector<const self_t*>& boxes,
141  vertex_array_type envelope = vertex_array_type::Zero());
142 
150  static std::pair<VertexType, VertexType> wrap(
151  const std::vector<self_t*>& boxes,
152  vertex_array_type envelope = vertex_array_type::Zero());
153 
161  static std::pair<VertexType, VertexType> wrap(
162  const std::vector<self_t>& boxes,
163  vertex_array_type envelope = vertex_array_type::Zero());
164 
170  bool intersect(const VertexType& point) const;
171 
187  bool intersect(const Ray<value_type, DIM>& ray) const;
188 
200  template <size_t sides>
201  bool intersect(const Frustum<value_type, DIM, sides>& fr) const;
202 
207  void setSkip(self_t* skip);
208 
213  const self_t* getSkip() const;
214 
220  const self_t* getLeftChild() const;
221 
227  bool hasEntity() const;
228 
234  const entity_t* entity() const;
235 
240  void setEntity(const entity_t* entity);
241 
246  const VertexType& center() const;
247 
252  const VertexType& min() const;
253 
258  const VertexType& max() const;
259 
265  std::ostream& toStream(std::ostream& os) const;
266 
272  void transform(const transform_type& trf);
273 
281  self_t transformed(const transform_type& trf) const;
282 
291  template <size_t D = DIM, std::enable_if_t<D == 3, int> = 0>
292  void draw(IVisualization3D& helper,
293  std::array<int, 3> color = {120, 120, 120},
294  const transform_type& trf = transform_type::Identity()) const;
295 
308  template <size_t D = DIM, std::enable_if_t<D == 2, int> = 0>
309  std::ostream& svg(std::ostream& os, value_type w, value_type h,
310  value_type unit = 10, std::string label = "",
311  std::string fillcolor = "grey") const;
312 
313  private:
314  template <size_t D = DIM, std::enable_if_t<D == 2, int> = 0>
315  std::pair<VertexType, VertexType> transformVertices(
316  const transform_type& trf) const;
317 
318  template <size_t D = DIM, std::enable_if_t<D == 3, int> = 0>
319  std::pair<VertexType, VertexType> transformVertices(
320  const transform_type& trf) const;
321 
322  const entity_t* m_entity;
328 
329  self_t* m_left_child{nullptr};
331  self_t* m_skip{nullptr};
332 };
333 
346 template <typename box_t>
347 box_t* make_octree(std::vector<std::unique_ptr<box_t>>& store,
348  const std::vector<box_t*>& prims, size_t max_depth = 1,
349  typename box_t::value_type envelope1 = 0);
350 
360 template <typename T, typename U, size_t V>
361 std::ostream& operator<<(std::ostream& os,
362  const AxisAlignedBoundingBox<T, U, V>& box);
363 
364 } // namespace Acts
365