Open3D (C++ API)  0.12.0
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) 2019 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 namespace visualization {
33 namespace rendering {
34 
35 class Camera {
36 public:
37  enum class FovType { Vertical, Horizontal };
38  enum class Projection { Perspective, Ortho };
39  using Transform = Eigen::Transform<float, 3, Eigen::Affine>;
40 
41  virtual ~Camera() = default;
42 
43  virtual void SetProjection(double fov,
44  double aspect,
45  double near,
46  double far,
47  FovType fov_type) = 0;
48 
71  virtual void SetProjection(Projection projection,
72  double left,
73  double right,
74  double bottom,
75  double top,
76  double near,
77  double far) = 0;
78 
79  virtual void SetProjection(const Eigen::Matrix3d& intrinsics,
80  double near,
81  double far,
82  double width,
83  double height) = 0;
84 
85  virtual void LookAt(const Eigen::Vector3f& center,
86  const Eigen::Vector3f& eye,
87  const Eigen::Vector3f& up) = 0;
88 
89  virtual void SetModelMatrix(const Transform& view) = 0;
90  virtual void SetModelMatrix(const Eigen::Vector3f& forward,
91  const Eigen::Vector3f& left,
92  const Eigen::Vector3f& up) = 0;
93 
94  virtual double GetNear() const = 0;
95  virtual double GetFar() const = 0;
97  virtual double GetFieldOfView() const = 0;
99  virtual FovType GetFieldOfViewType() const = 0;
100 
101  virtual Eigen::Vector3f GetPosition() const = 0;
102  virtual Eigen::Vector3f GetForwardVector() const = 0;
103  virtual Eigen::Vector3f GetLeftVector() const = 0;
104  virtual Eigen::Vector3f GetUpVector() const = 0;
105  virtual Transform GetModelMatrix() const = 0;
106  virtual Transform GetViewMatrix() const = 0;
107  virtual Transform GetProjectionMatrix() const = 0;
108 
109  // Returns the normalized device coordinates (NDC) of the specified point
110  // given the view and projection matrices of the camera. The returned point
111  // is in the range [-1, 1] if the point is in view, or outside the range if
112  // the point is out of view.
113  virtual Eigen::Vector2f GetNDC(const Eigen::Vector3f& pt) const = 0;
114 
115  struct ProjectionInfo {
116  bool is_ortho;
118  union {
119  struct {
121  double left;
122  double right;
123  double bottom;
124  double top;
125  double near_plane; // Windows #defines "near"
126  double far_plane; // Windows #defines "far"
127  } ortho;
128  struct {
130  double fov;
131  double aspect;
132  double near_plane;
133  double far_plane;
134  } perspective;
135  struct {
136  double fx;
137  double fy;
138  double cx;
139  double cy;
140  double near_plane;
141  double far_plane;
142  double width;
143  double height;
144  } intrinsics;
145  } proj;
146  };
147  virtual const ProjectionInfo& GetProjection() const = 0;
148 
149  virtual void CopyFrom(const Camera* camera) = 0;
150 };
151 
152 } // namespace rendering
153 } // namespace visualization
154 } // namespace open3d
virtual Eigen::Vector3f GetUpVector() const =0
virtual double GetFieldOfView() const =0
only valid if fov was passed to SetProjection()
virtual const ProjectionInfo & GetProjection() const =0
virtual FovType GetFieldOfViewType() const =0
only valid if fov was passed to SetProjection()
virtual Eigen::Vector3f GetLeftVector() const =0
virtual void LookAt(const Eigen::Vector3f &center, const Eigen::Vector3f &eye, const Eigen::Vector3f &up)=0
virtual Transform GetModelMatrix() const =0
Eigen::Transform< float, 3, Eigen::Affine > Transform
Definition: Camera.h:39
virtual void SetModelMatrix(const Transform &view)=0
Definition: PinholeCameraIntrinsic.cpp:35
virtual Eigen::Vector3f GetForwardVector() const =0
virtual void CopyFrom(const Camera *camera)=0
int height
Definition: FilePCD.cpp:72
virtual Eigen::Vector2f GetNDC(const Eigen::Vector3f &pt) const =0
virtual Eigen::Vector3f GetPosition() const =0
virtual Transform GetProjectionMatrix() const =0
virtual double GetFar() const =0
virtual double GetNear() const =0
virtual Transform GetViewMatrix() const =0
virtual void SetProjection(double fov, double aspect, double near, double far, FovType fov_type)=0
int width
Definition: FilePCD.cpp:71