Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.16.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Camera.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018-2021 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <Eigen/Geometry>
30 
31 namespace open3d {
32 
33 namespace geometry {
34 class AxisAlignedBoundingBox;
35 } // namespace geometry
36 
37 namespace visualization {
38 namespace rendering {
39 
40 class Camera {
41 public:
42  enum class FovType { Vertical, Horizontal };
43  enum class Projection { Perspective, Ortho };
44  using Transform = Eigen::Transform<float, 3, Eigen::Affine>;
45  using ProjectionMatrix = Eigen::Transform<float, 3, Eigen::Projective>;
46 
47  virtual ~Camera() = default;
48 
49  virtual void SetProjection(double fov,
50  double aspect,
51  double near,
52  double far,
53  FovType fov_type) = 0;
54 
77  virtual void SetProjection(Projection projection,
78  double left,
79  double right,
80  double bottom,
81  double top,
82  double near,
83  double far) = 0;
84 
85  virtual void SetProjection(const Eigen::Matrix3d& intrinsics,
86  double near,
87  double far,
88  double width,
89  double height) = 0;
90 
91  virtual void LookAt(const Eigen::Vector3f& center,
92  const Eigen::Vector3f& eye,
93  const Eigen::Vector3f& up) = 0;
94  virtual void FromExtrinsics(const Eigen::Matrix4d& extrinsics);
95 
96  virtual void SetModelMatrix(const Transform& view) = 0;
97  virtual void SetModelMatrix(const Eigen::Vector3f& forward,
98  const Eigen::Vector3f& left,
99  const Eigen::Vector3f& up) = 0;
100 
101  virtual double GetNear() const = 0;
102  virtual double GetFar() const = 0;
104  virtual double GetFieldOfView() const = 0;
106  virtual FovType GetFieldOfViewType() const = 0;
107 
108  virtual Eigen::Vector3f GetPosition() const = 0;
109  virtual Eigen::Vector3f GetForwardVector() const = 0;
110  virtual Eigen::Vector3f GetLeftVector() const = 0;
111  virtual Eigen::Vector3f GetUpVector() const = 0;
112  virtual Transform GetModelMatrix() const = 0;
113  virtual Transform GetViewMatrix() const = 0;
114  virtual ProjectionMatrix GetProjectionMatrix() const = 0;
115  virtual Transform GetCullingProjectionMatrix() const = 0;
116 
120  virtual Eigen::Vector3f Unproject(float x,
121  float y,
122  float z,
123  float view_width,
124  float view_height) const = 0;
125 
126  // Returns the normalized device coordinates (NDC) of the specified point
127  // given the view and projection matrices of the camera. The returned point
128  // is in the range [-1, 1] if the point is in view, or outside the range if
129  // the point is out of view.
130  virtual Eigen::Vector2f GetNDC(const Eigen::Vector3f& pt) const = 0;
131 
134  virtual double GetViewZ(float z_buffer) const = 0;
135 
136  struct ProjectionInfo {
137  bool is_ortho;
139  union {
140  struct {
142  double left;
143  double right;
144  double bottom;
145  double top;
146  double near_plane; // Windows #defines "near"
147  double far_plane; // Windows #defines "far"
148  } ortho;
149  struct {
151  double fov;
152  double aspect;
153  double near_plane;
154  double far_plane;
155  } perspective;
156  struct {
157  double fx;
158  double fy;
159  double cx;
160  double cy;
161  double near_plane;
162  double far_plane;
163  double width;
164  double height;
165  } intrinsics;
166  } proj;
167  };
168  virtual const ProjectionInfo& GetProjection() const = 0;
169 
170  virtual void CopyFrom(const Camera* camera) = 0;
171 
176  static void SetupCameraAsPinholeCamera(
177  rendering::Camera& camera,
178  const Eigen::Matrix3d& intrinsic,
179  const Eigen::Matrix4d& extrinsic,
180  int intrinsic_width_px,
181  int intrinsic_height_px,
182  const geometry::AxisAlignedBoundingBox& scene_bounds);
183 
185  static float CalcNearPlane();
186 
189  static float CalcFarPlane(
190  const rendering::Camera& camera,
191  const geometry::AxisAlignedBoundingBox& scene_bounds);
192 };
193 
194 } // namespace rendering
195 } // namespace visualization
196 } // namespace open3d
int height
Definition: FilePCD.cpp:72
Eigen::Transform< float, 3, Eigen::Projective > ProjectionMatrix
Definition: Camera.h:45
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:155
GLMatrix4f LookAt(const Eigen::Vector3d &eye, const Eigen::Vector3d &lookat, const Eigen::Vector3d &up)
Definition: GLHelper.cpp:36
Eigen::Transform< float, 3, Eigen::Affine > Transform
Definition: Camera.h:44
GLMatrix4f Perspective(double field_of_view_, double aspect, double z_near, double z_far)
Definition: GLHelper.cpp:55
Definition: PinholeCameraIntrinsic.cpp:35
void Unproject(const core::Tensor &depth, utility::optional< std::reference_wrapper< const core::Tensor >> image_colors, core::Tensor &points, utility::optional< std::reference_wrapper< core::Tensor >> colors, const core::Tensor &intrinsics, const core::Tensor &extrinsics, float depth_scale, float depth_max, int64_t stride)
Definition: PointCloud.cpp:42
GLMatrix4f Ortho(double left, double right, double bottom, double top, double z_near, double z_far)
Definition: GLHelper.cpp:70
int width
Definition: FilePCD.cpp:71