ECCE @ 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 
11 #include <algorithm>
12 #include <array>
13 #include <iostream>
14 #include <limits>
15 #include <ostream>
16 #include <tuple>
17 #include <vector>
21 #include "Acts/Utilities/Ray.hpp"
23 
24 namespace Acts {
25 
30 template <typename entity_t, typename value_t, size_t DIM>
32  private:
37 
42  template <typename T, typename P>
43  class NamedType {
44  public:
45  explicit NamedType(const T& value) : m_value(value) {}
46  explicit NamedType(T&& value) : m_value(std::move(value)) {}
47  T& get() { return m_value; }
48  const T& get() const { return m_value; }
49 
50  private:
52  };
53 
57  struct SizeParameter {};
58 
59  public:
74  using vertex_array_type = Eigen::Array<value_t, DIM, 1>;
75 
79  using entity_type = entity_t;
80 
84  using transform_type = Eigen::Transform<value_type, DIM, Eigen::Affine>;
85 
89  using Size = NamedType<VertexType, struct SizeParameter>;
90 
94  static const size_t dim = DIM;
95 
100  AxisAlignedBoundingBox(const self_t& other) = default;
101 
108  AxisAlignedBoundingBox(const entity_t* entity, const VertexType& vmin,
109  const VertexType& vmax);
110 
119  AxisAlignedBoundingBox(const entity_t* entity, const VertexType& center,
120  const Size& size);
121 
129  const std::vector<self_t*>& boxes,
130  vertex_array_type envelope = vertex_array_type::Zero());
131 
138  static std::pair<VertexType, VertexType> wrap(
139  const std::vector<const self_t*>& boxes,
140  vertex_array_type envelope = vertex_array_type::Zero());
141 
149  static std::pair<VertexType, VertexType> wrap(
150  const std::vector<self_t*>& boxes,
151  vertex_array_type envelope = vertex_array_type::Zero());
152 
160  static std::pair<VertexType, VertexType> wrap(
161  const std::vector<self_t>& boxes,
162  vertex_array_type envelope = vertex_array_type::Zero());
163 
169  bool intersect(const VertexType& point) const;
170 
186  bool intersect(const Ray<value_type, DIM>& ray) const;
187 
199  template <size_t sides>
200  bool intersect(const Frustum<value_type, DIM, sides>& fr) const;
201 
206  void setSkip(self_t* skip);
207 
212  const self_t* getSkip() const;
213 
219  const self_t* getLeftChild() const;
220 
226  bool hasEntity() const;
227 
233  const entity_t* entity() const;
234 
239  void setEntity(const entity_t* entity);
240 
245  const VertexType& center() const;
246 
251  const VertexType& min() const;
252 
257  const VertexType& max() const;
258 
264  std::ostream& toStream(std::ostream& os) const;
265 
271  void transform(const transform_type& trf);
272 
280  self_t transformed(const transform_type& trf) const;
281 
290  template <size_t D = DIM, std::enable_if_t<D == 3, int> = 0>
291  void draw(IVisualization& helper, std::array<int, 3> color = {120, 120, 120},
292  const transform_type& trf = transform_type::Identity()) const;
293 
306  template <size_t D = DIM, std::enable_if_t<D == 2, int> = 0>
307  std::ostream& svg(std::ostream& os, value_type w, value_type h,
308  value_type unit = 10, std::string label = "",
309  std::string fillcolor = "grey") const;
310 
311  private:
312  template <size_t D = DIM, std::enable_if_t<D == 2, int> = 0>
313  std::pair<VertexType, VertexType> transformVertices(
314  const transform_type& trf) const;
315 
316  template <size_t D = DIM, std::enable_if_t<D == 3, int> = 0>
317  std::pair<VertexType, VertexType> transformVertices(
318  const transform_type& trf) const;
319 
320  const entity_t* m_entity;
326 
327  self_t* m_left_child{nullptr};
329  self_t* m_skip{nullptr};
330 };
331 
344 template <typename box_t>
345 box_t* make_octree(std::vector<std::unique_ptr<box_t>>& store,
346  const std::vector<box_t*>& prims, size_t max_depth = 1,
347  typename box_t::value_type envelope1 = 0);
348 
358 template <typename T, typename U, size_t V>
359 std::ostream& operator<<(std::ostream& os,
360  const AxisAlignedBoundingBox<T, U, V>& box);
361 
362 } // namespace Acts
363