Open3D (C++ API)  0.17.0+f1a0f3e
ViewControl.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
13 #include "open3d/geometry/Line3D.h"
16 
17 namespace open3d {
18 namespace visualization {
19 
23 class ViewControl {
24 public:
25  static const double FIELD_OF_VIEW_MAX;
26  static const double FIELD_OF_VIEW_MIN;
27  static const double FIELD_OF_VIEW_DEFAULT;
28  static const double FIELD_OF_VIEW_STEP;
29 
30  static const double ZOOM_DEFAULT;
31  static const double ZOOM_MIN;
32  static const double ZOOM_MAX;
33  static const double ZOOM_STEP;
34 
35  static const double ROTATION_RADIAN_PER_PIXEL;
36 
40  };
41 
42 public:
43  virtual ~ViewControl() {}
44 
48  void SetViewMatrices(
49  const Eigen::Matrix4d &model_matrix = Eigen::Matrix4d::Identity());
50 
52  bool ConvertToViewParameters(ViewParameters &status) const;
53  bool ConvertFromViewParameters(const ViewParameters &status);
54 
55  void SetLookat(const Eigen::Vector3d &lookat);
56  void SetUp(const Eigen::Vector3d &up);
57  void SetFront(const Eigen::Vector3d &front);
58  void SetZoom(const double zoom);
59 
66 
74  const camera::PinholeCameraParameters &parameters,
75  bool allow_arbitrary = false);
76 
79  virtual void Reset();
83  virtual void ChangeFieldOfView(double step);
84  virtual void ChangeWindowSize(int width, int height);
85 
91  geometry::Ray3D UnprojectPoint(double x, double y) const;
92 
96  virtual void Scale(double scale);
97 
107  virtual void Rotate(double x, double y, double xo = 0.0, double yo = 0.0);
108 
118  virtual void Translate(double x,
119  double y,
120  double xo = 0.0,
121  double yo = 0.0);
122 
123  virtual void CameraLocalTranslate(double forward, double right, double up);
124  virtual void CameraLocalRotate(double x,
125  double y,
126  double xo = 0.0,
127  double yo = 0.0);
128  virtual void ResetCameraLocalRotate();
129 
130  // Function to process rolling
134  virtual void Roll(double x);
135 
137  return bounding_box_;
138  }
139 
141 
142  void FitInGeometry(const geometry::Geometry &geometry) {
143  if (geometry.Dimension() == 3) {
144  bounding_box_ += ((const geometry::Geometry3D &)geometry)
146  }
148  }
149 
151  double GetFieldOfView() const { return field_of_view_; }
154  return projection_matrix_;
155  }
158  gl_util::GLVector3f GetEye() const { return eye_.cast<GLfloat>(); }
159  gl_util::GLVector3f GetLookat() const { return lookat_.cast<GLfloat>(); }
160  gl_util::GLVector3f GetUp() const { return up_.cast<GLfloat>(); }
161  gl_util::GLVector3f GetFront() const { return front_.cast<GLfloat>(); }
162  gl_util::GLVector3f GetRight() const { return right_.cast<GLfloat>(); }
163  int GetWindowWidth() const { return window_width_; }
164  int GetWindowHeight() const { return window_height_; }
165  double GetZNear() const { return z_near_; }
166  double GetZFar() const { return z_far_; }
167 
172  void SetConstantZNear(double z_near) { constant_z_near_ = z_near; }
177  void SetConstantZFar(double z_far) { constant_z_far_ = z_far; }
186 
187 protected:
188  int window_width_ = 0;
189  int window_height_ = 0;
191  Eigen::Vector3d eye_;
192  Eigen::Vector3d lookat_;
193  Eigen::Vector3d up_;
194  Eigen::Vector3d front_;
195  Eigen::Vector3d right_;
196  double distance_;
198  double zoom_;
199  double view_ratio_;
200  double aspect_;
201  double z_near_;
202  double z_far_;
203  double constant_z_near_ = -1;
204  double constant_z_far_ = -1;
209 
210  Eigen::Vector3d start_local_rotate_up_;
211  Eigen::Vector3d start_local_rotate_right_;
212  Eigen::Vector3d start_local_rotate_front_;
213  Eigen::Vector3d start_local_rotate_eye_;
214  Eigen::Vector3d start_local_rotate_lookat_;
217 };
218 
219 } // namespace visualization
220 } // namespace open3d
Contains both intrinsic and extrinsic pinhole camera parameters.
Definition: PinholeCameraParameters.h:21
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:159
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns the object itself.
Definition: BoundingVolume.cpp:244
AxisAlignedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:224
The base geometry class for 3D geometries.
Definition: Geometry3D.h:28
The base geometry class.
Definition: Geometry.h:18
int Dimension() const
Returns whether the geometry is 2D or 3D.
Definition: Geometry.h:71
A ray is a semantic interpretation of Eigen::ParametrizedLine which has an origin and a direction and...
Definition: Line3D.h:240
View controller for visualizer.
Definition: ViewControl.h:23
Eigen::Vector3d start_local_rotate_right_
Definition: ViewControl.h:211
virtual void ResetCameraLocalRotate()
Definition: ViewControl.cpp:384
double local_rotate_up_accum_
Definition: ViewControl.h:215
void UnsetConstantZNear()
Definition: ViewControl.h:181
double distance_
Definition: ViewControl.h:196
gl_util::GLVector3f GetEye() const
Definition: ViewControl.h:158
bool ConvertFromViewParameters(const ViewParameters &status)
Definition: ViewControl.cpp:97
Eigen::Vector3d right_
Definition: ViewControl.h:195
double zoom_
Definition: ViewControl.h:198
double z_far_
Definition: ViewControl.h:202
double GetZNear() const
Definition: ViewControl.h:165
Eigen::Vector3d up_
Definition: ViewControl.h:193
gl_util::GLVector3f GetRight() const
Definition: ViewControl.h:162
void SetZoom(const double zoom)
Definition: ViewControl.cpp:124
void SetUp(const Eigen::Vector3d &up)
Definition: ViewControl.cpp:114
Eigen::Vector3d lookat_
Definition: ViewControl.h:192
double aspect_
Definition: ViewControl.h:200
gl_util::GLMatrix4f model_matrix_
Definition: ViewControl.h:207
Eigen::Vector3d front_
Definition: ViewControl.h:194
gl_util::GLVector3f GetUp() const
Definition: ViewControl.h:160
Eigen::Vector3d start_local_rotate_up_
Definition: ViewControl.h:210
void FitInGeometry(const geometry::Geometry &geometry)
Definition: ViewControl.h:142
Eigen::Vector3d start_local_rotate_front_
Definition: ViewControl.h:212
static const double ROTATION_RADIAN_PER_PIXEL
Definition: ViewControl.h:35
virtual void CameraLocalTranslate(double forward, double right, double up)
Definition: ViewControl.cpp:333
int window_width_
Definition: ViewControl.h:188
static const double ZOOM_MIN
Definition: ViewControl.h:31
virtual ~ViewControl()
Definition: ViewControl.h:43
double view_ratio_
Definition: ViewControl.h:199
static const double FIELD_OF_VIEW_STEP
Definition: ViewControl.h:28
Eigen::Vector3d start_local_rotate_lookat_
Definition: ViewControl.h:214
gl_util::GLMatrix4f projection_matrix_
Definition: ViewControl.h:205
static const double FIELD_OF_VIEW_DEFAULT
Definition: ViewControl.h:27
Eigen::Vector3d eye_
Definition: ViewControl.h:191
gl_util::GLMatrix4f MVP_matrix_
Definition: ViewControl.h:208
double constant_z_near_
Definition: ViewControl.h:203
geometry::Ray3D UnprojectPoint(double x, double y) const
Definition: ViewControl.cpp:275
int window_height_
Definition: ViewControl.h:189
virtual void Translate(double x, double y, double xo=0.0, double yo=0.0)
Function to process translation.
Definition: ViewControl.cpp:322
void SetViewMatrices(const Eigen::Matrix4d &model_matrix=Eigen::Matrix4d::Identity())
Definition: ViewControl.cpp:38
double constant_z_far_
Definition: ViewControl.h:204
void SetConstantZFar(double z_far)
Definition: ViewControl.h:177
static const double ZOOM_MAX
Definition: ViewControl.h:32
Eigen::Vector3d start_local_rotate_eye_
Definition: ViewControl.h:213
static const double FIELD_OF_VIEW_MAX
Definition: ViewControl.h:25
gl_util::GLMatrix4f GetViewMatrix() const
Definition: ViewControl.h:156
void SetProjectionParameters()
Definition: ViewControl.cpp:243
bool ConvertToViewParameters(ViewParameters &status) const
Function to get equivalent view parameters (support orthogonal)
Definition: ViewControl.cpp:86
virtual void Roll(double x)
Definition: ViewControl.cpp:394
double GetZFar() const
Definition: ViewControl.h:166
virtual void CameraLocalRotate(double x, double y, double xo=0.0, double yo=0.0)
Definition: ViewControl.cpp:341
void SetFront(const Eigen::Vector3d &front)
Definition: ViewControl.cpp:119
gl_util::GLVector3f GetFront() const
Definition: ViewControl.h:161
static const double FIELD_OF_VIEW_MIN
Definition: ViewControl.h:26
const geometry::AxisAlignedBoundingBox & GetBoundingBox() const
Definition: ViewControl.h:136
gl_util::GLMatrix4f view_matrix_
Definition: ViewControl.h:206
gl_util::GLMatrix4f GetModelMatrix() const
Definition: ViewControl.h:157
void UnsetConstantZFar()
Definition: ViewControl.h:185
void SetConstantZNear(double z_near)
Definition: ViewControl.h:172
ProjectionType
Definition: ViewControl.h:37
@ Orthogonal
Definition: ViewControl.h:39
@ Perspective
Definition: ViewControl.h:38
virtual void ChangeWindowSize(int width, int height)
Definition: ViewControl.cpp:268
bool ConvertToPinholeCameraParameters(camera::PinholeCameraParameters &parameters)
Definition: ViewControl.cpp:129
virtual void Reset()
Definition: ViewControl.cpp:234
ProjectionType GetProjectionType() const
Definition: ViewControl.cpp:226
gl_util::GLMatrix4f GetProjectionMatrix() const
Definition: ViewControl.h:153
gl_util::GLVector3f GetLookat() const
Definition: ViewControl.h:159
bool ConvertFromPinholeCameraParameters(const camera::PinholeCameraParameters &parameters, bool allow_arbitrary=false)
Definition: ViewControl.cpp:172
double field_of_view_
Definition: ViewControl.h:197
double z_near_
Definition: ViewControl.h:201
virtual void Rotate(double x, double y, double xo=0.0, double yo=0.0)
Function to process rotation.
Definition: ViewControl.cpp:308
static const double ZOOM_STEP
Definition: ViewControl.h:33
double local_rotate_right_accum_
Definition: ViewControl.h:216
int GetWindowHeight() const
Definition: ViewControl.h:164
void ResetBoundingBox()
Definition: ViewControl.h:140
void SetLookat(const Eigen::Vector3d &lookat)
Definition: ViewControl.cpp:109
geometry::AxisAlignedBoundingBox bounding_box_
Definition: ViewControl.h:190
static const double ZOOM_DEFAULT
Definition: ViewControl.h:30
virtual void ChangeFieldOfView(double step)
Definition: ViewControl.cpp:260
double GetFieldOfView() const
Function to get field of view.
Definition: ViewControl.h:151
gl_util::GLMatrix4f GetMVPMatrix() const
Definition: ViewControl.h:152
int GetWindowWidth() const
Definition: ViewControl.h:163
virtual void Scale(double scale)
Definition: ViewControl.cpp:303
Definition: ViewParameters.h:18
int width
Definition: FilePCD.cpp:52
int height
Definition: FilePCD.cpp:53
Eigen::Matrix< GLfloat, 4, 4, Eigen::ColMajor > GLMatrix4f
Definition: GLHelper.h:34
Eigen::Matrix< GLfloat, 3, 1, Eigen::ColMajor > GLVector3f
Definition: GLHelper.h:32
Definition: PinholeCameraIntrinsic.cpp:16