Lagrange
AABB.h
1/*
2 * Copyright 2020 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/ui/api.h>
15#include <lagrange/ui/utils/math.h>
16#include <array>
17
18
19namespace lagrange {
20namespace ui {
21
22class Frustum;
23
24class LA_UI_API AABB : public Eigen::AlignedBox3f
25{
26public:
27 using Super = Eigen::AlignedBox3f;
28 using Super::Super;
29
30 AABB() = default;
31 AABB(Eigen::AlignedBox3f box)
32 : Super(std::move(box))
33 {}
34
36 template <typename Derived>
37 Eigen::Vector3f normalize_point(const Eigen::MatrixBase<Derived>& pt) const
38 {
39 const auto d = diagonal();
40 return Eigen::Vector3f(
41 (float(pt.x()) - min().x()) / d.x(),
42 (float(pt.y()) - min().y()) / d.y(),
43 (float(pt.z()) - min().z()) / d.z());
44 }
45
47 template <typename Scalar>
48 Eigen::Vector3f normalize_point(const Eigen::Matrix<Scalar, 2, 1>& pt) const
49 {
50 const auto d = diagonal();
51 return Eigen::Vector3f(
52 (float(pt.x()) - min().x()) / d.x(),
53 (float(pt.y()) - min().y()) / d.y(),
54 0);
55 }
56
57 Eigen::Affine3f get_cube_transform() const;
58
59 Eigen::Affine3f get_normalization_transform(bool preserve_aspect = true) const;
60
61 AABB transformed(const Eigen::Affine3f& transform) const;
62
63 bool intersects_ray(
64 Eigen::Vector3f origin,
65 Eigen::Vector3f dir,
66 float* tmin_out = nullptr,
67 float* tmax_out = nullptr) const;
68
69 bool intersects_frustum(const Frustum& f) const;
70};
71
72} // namespace ui
73} // namespace lagrange
Definition: AABB.h:25
Eigen::Vector3f normalize_point(const Eigen::MatrixBase< Derived > &pt) const
Normalizes point to [0.0f,1.0f]^3 in AABB's bounds.
Definition: AABB.h:37
Eigen::Vector3f normalize_point(const Eigen::Matrix< Scalar, 2, 1 > &pt) const
Overload for 2D mesh.
Definition: AABB.h:48
Frustum defined using 6 planes.
Definition: Frustum.h:43
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
Main namespace for Lagrange.
Definition: AABBIGL.h:30