Analysis Software
Documentation for sPHENIX simulation 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 
13 #include "Acts/Utilities/Ray.hpp"
15 
16 #include <array>
17 #include <memory>
18 #include <tuple>
19 #include <vector>
20 
21 namespace Acts {
22 
27 template <typename entity_t, typename value_t, size_t DIM>
29  private:
34 
39  template <typename T, typename P>
40  class NamedType {
41  public:
42  explicit NamedType(const T& value) : m_value(value) {}
43  explicit NamedType(T&& value) : m_value(std::move(value)) {}
44  T& get() { return m_value; }
45  const T& get() const { return m_value; }
46 
47  private:
49  };
50 
54  struct SizeParameter {};
55 
56  public:
66  using VertexType = Eigen::Matrix<value_t, DIM, 1>;
71  using vertex_array_type = Eigen::Array<value_t, DIM, 1>;
72 
76  using entity_type = entity_t;
77 
81  using transform_type = Eigen::Transform<value_type, DIM, Eigen::Affine>;
82 
86  using Size = NamedType<VertexType, struct SizeParameter>;
87 
91  static const size_t dim = DIM;
92 
97  AxisAlignedBoundingBox(const self_t& other) = default;
98 
103  AxisAlignedBoundingBox& operator=(const self_t& other) = default;
104 
111  AxisAlignedBoundingBox(const entity_t* entity, const VertexType& vmin,
112  const VertexType& vmax);
113 
122  AxisAlignedBoundingBox(const entity_t* entity, const VertexType& center,
123  const Size& size);
124 
132  const std::vector<self_t*>& boxes,
133  vertex_array_type envelope = vertex_array_type::Zero());
134 
141  static std::pair<VertexType, VertexType> wrap(
142  const std::vector<const self_t*>& boxes,
143  vertex_array_type envelope = vertex_array_type::Zero());
144 
152  static std::pair<VertexType, VertexType> wrap(
153  const std::vector<self_t*>& boxes,
154  vertex_array_type envelope = vertex_array_type::Zero());
155 
163  static std::pair<VertexType, VertexType> wrap(
164  const std::vector<self_t>& boxes,
165  vertex_array_type envelope = vertex_array_type::Zero());
166 
172  bool intersect(const VertexType& point) const;
173 
189  bool intersect(const Ray<value_type, DIM>& ray) const;
190 
202  template <size_t sides>
203  bool intersect(const Frustum<value_type, DIM, sides>& fr) const;
204 
209  void setSkip(self_t* skip);
210 
215  const self_t* getSkip() const;
216 
222  const self_t* getLeftChild() const;
223 
229  bool hasEntity() const;
230 
236  const entity_t* entity() const;
237 
242  void setEntity(const entity_t* entity);
243 
248  const VertexType& center() const;
249 
254  const VertexType& min() const;
255 
260  const VertexType& max() const;
261 
267  std::ostream& toStream(std::ostream& os) const;
268 
274  void transform(const transform_type& trf);
275 
283  self_t transformed(const transform_type& trf) const;
284 
293  template <size_t D = DIM, std::enable_if_t<D == 3, int> = 0>
294  void draw(IVisualization3D& helper,
295  std::array<int, 3> color = {120, 120, 120},
296  const transform_type& trf = transform_type::Identity()) const;
297 
310  template <size_t D = DIM, std::enable_if_t<D == 2, int> = 0>
311  std::ostream& svg(std::ostream& os, value_type w, value_type h,
312  value_type unit = 10, const std::string& label = "",
313  const std::string& fillcolor = "grey") const;
314 
315  private:
316  template <size_t D = DIM, std::enable_if_t<D == 2, int> = 0>
317  std::pair<VertexType, VertexType> transformVertices(
318  const transform_type& trf) const;
319 
320  template <size_t D = DIM, std::enable_if_t<D == 3, int> = 0>
321  std::pair<VertexType, VertexType> transformVertices(
322  const transform_type& trf) const;
323 
324  const entity_t* m_entity;
330 
331  self_t* m_left_child{nullptr};
333  self_t* m_skip{nullptr};
334 };
335 
348 template <typename box_t>
349 box_t* make_octree(std::vector<std::unique_ptr<box_t>>& store,
350  const std::vector<box_t*>& prims, size_t max_depth = 1,
351  typename box_t::value_type envelope1 = 0);
352 
362 template <typename T, typename U, size_t V>
363 std::ostream& operator<<(std::ostream& os,
364  const AxisAlignedBoundingBox<T, U, V>& box);
365 
366 } // namespace Acts
367