Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ViewControl.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 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 
34 
35 namespace open3d {
36 namespace visualization {
37 
41 class ViewControl {
42 public:
43  static const double FIELD_OF_VIEW_MAX;
44  static const double FIELD_OF_VIEW_MIN;
45  static const double FIELD_OF_VIEW_DEFAULT;
46  static const double FIELD_OF_VIEW_STEP;
47 
48  static const double ZOOM_DEFAULT;
49  static const double ZOOM_MIN;
50  static const double ZOOM_MAX;
51  static const double ZOOM_STEP;
52 
53  static const double ROTATION_RADIAN_PER_PIXEL;
54 
58  };
59 
60 public:
61  virtual ~ViewControl() {}
62 
66  void SetViewMatrices(
67  const Eigen::Matrix4d &model_matrix = Eigen::Matrix4d::Identity());
68 
70  bool ConvertToViewParameters(ViewParameters &status) const;
71  bool ConvertFromViewParameters(const ViewParameters &status);
72 
73  void SetLookat(const Eigen::Vector3d &lookat);
74  void SetUp(const Eigen::Vector3d &up);
75  void SetFront(const Eigen::Vector3d &front);
76  void SetZoom(const double zoom);
77 
84 
92  const camera::PinholeCameraParameters &parameters,
93  bool allow_arbitrary = false);
94 
97  virtual void Reset();
101  virtual void ChangeFieldOfView(double step);
102  virtual void ChangeWindowSize(int width, int height);
103 
107  virtual void Scale(double scale);
108 
118  virtual void Rotate(double x, double y, double xo = 0.0, double yo = 0.0);
119 
129  virtual void Translate(double x,
130  double y,
131  double xo = 0.0,
132  double yo = 0.0);
133 
134  virtual void CameraLocalTranslate(double forward, double right, double up);
135  virtual void CameraLocalRotate(double x,
136  double y,
137  double xo = 0.0,
138  double yo = 0.0);
139  virtual void ResetCameraLocalRotate();
140 
141  // Function to process rolling
145  virtual void Roll(double x);
146 
148  return bounding_box_;
149  }
150 
152 
153  void FitInGeometry(const geometry::Geometry &geometry) {
154  if (geometry.Dimension() == 3) {
155  bounding_box_ += ((const geometry::Geometry3D &)geometry)
157  }
159  }
160 
162  double GetFieldOfView() const { return field_of_view_; }
165  return projection_matrix_;
166  }
169  gl_util::GLVector3f GetEye() const { return eye_.cast<GLfloat>(); }
170  gl_util::GLVector3f GetLookat() const { return lookat_.cast<GLfloat>(); }
171  gl_util::GLVector3f GetUp() const { return up_.cast<GLfloat>(); }
172  gl_util::GLVector3f GetFront() const { return front_.cast<GLfloat>(); }
173  gl_util::GLVector3f GetRight() const { return right_.cast<GLfloat>(); }
174  int GetWindowWidth() const { return window_width_; }
175  int GetWindowHeight() const { return window_height_; }
176  double GetZNear() const { return z_near_; }
177  double GetZFar() const { return z_far_; }
178 
183  void SetConstantZNear(double z_near) { constant_z_near_ = z_near; }
188  void SetConstantZFar(double z_far) { constant_z_far_ = z_far; }
197 
198 protected:
199  int window_width_ = 0;
200  int window_height_ = 0;
202  Eigen::Vector3d eye_;
203  Eigen::Vector3d lookat_;
204  Eigen::Vector3d up_;
205  Eigen::Vector3d front_;
206  Eigen::Vector3d right_;
207  double distance_;
209  double zoom_;
210  double view_ratio_;
211  double aspect_;
212  double z_near_;
213  double z_far_;
214  double constant_z_near_ = -1;
215  double constant_z_far_ = -1;
220 
221  Eigen::Vector3d start_local_rotate_up_;
222  Eigen::Vector3d start_local_rotate_right_;
223  Eigen::Vector3d start_local_rotate_front_;
224  Eigen::Vector3d start_local_rotate_eye_;
225  Eigen::Vector3d start_local_rotate_lookat_;
228 };
229 
230 } // namespace visualization
231 } // namespace open3d
gl_util::GLMatrix4f projection_matrix_
Definition: ViewControl.h:216
gl_util::GLMatrix4f GetMVPMatrix() const
Definition: ViewControl.h:163
static const double ROTATION_RADIAN_PER_PIXEL
Definition: ViewControl.h:53
double distance_
Definition: ViewControl.h:207
double z_near_
Definition: ViewControl.h:212
int Dimension() const
Returns whether the geometry is 2D or 3D.
Definition: Geometry.h:90
Eigen::Vector3d start_local_rotate_lookat_
Definition: ViewControl.h:225
virtual void ChangeFieldOfView(double step)
Definition: ViewControl.cpp:279
The base geometry class.
Definition: Geometry.h:37
void SetProjectionParameters()
Definition: ViewControl.cpp:262
void SetZoom(const double zoom)
Definition: ViewControl.cpp:143
gl_util::GLVector3f GetUp() const
Definition: ViewControl.h:171
void SetUp(const Eigen::Vector3d &up)
Definition: ViewControl.cpp:133
Eigen::Matrix< GLfloat, 4, 4, Eigen::ColMajor > GLMatrix4f
Definition: GLHelper.h:53
int window_width_
Definition: ViewControl.h:199
Eigen::Vector3d lookat_
Definition: ViewControl.h:203
Eigen::Vector3d start_local_rotate_up_
Definition: ViewControl.h:221
static const double ZOOM_MAX
Definition: ViewControl.h:50
ProjectionType
Definition: ViewControl.h:55
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:150
const geometry::AxisAlignedBoundingBox & GetBoundingBox() const
Definition: ViewControl.h:147
ProjectionType GetProjectionType() const
Definition: ViewControl.cpp:245
bool ConvertFromViewParameters(const ViewParameters &status)
Definition: ViewControl.cpp:116
virtual void ResetCameraLocalRotate()
Definition: ViewControl.cpp:375
View controller for visualizer.
Definition: ViewControl.h:41
void SetConstantZFar(double z_far)
Definition: ViewControl.h:188
int GetWindowWidth() const
Definition: ViewControl.h:174
void SetFront(const Eigen::Vector3d &front)
Definition: ViewControl.cpp:138
static const double FIELD_OF_VIEW_MAX
Definition: ViewControl.h:43
virtual void Scale(double scale)
Definition: ViewControl.cpp:294
gl_util::GLVector3f GetLookat() const
Definition: ViewControl.h:170
double z_far_
Definition: ViewControl.h:213
static const double ZOOM_DEFAULT
Definition: ViewControl.h:48
void ResetBoundingBox()
Definition: ViewControl.h:151
static const double FIELD_OF_VIEW_DEFAULT
Definition: ViewControl.h:45
gl_util::GLVector3f GetFront() const
Definition: ViewControl.h:172
gl_util::GLMatrix4f view_matrix_
Definition: ViewControl.h:217
double field_of_view_
Definition: ViewControl.h:208
Eigen::Vector3d start_local_rotate_front_
Definition: ViewControl.h:223
Eigen::Vector3d eye_
Definition: ViewControl.h:202
void SetViewMatrices(const Eigen::Matrix4d &model_matrix=Eigen::Matrix4d::Identity())
Definition: ViewControl.cpp:57
void UnsetConstantZNear()
Definition: ViewControl.h:192
virtual ~ViewControl()
Definition: ViewControl.h:61
gl_util::GLMatrix4f GetProjectionMatrix() const
Definition: ViewControl.h:164
Eigen::Vector3d start_local_rotate_right_
Definition: ViewControl.h:222
gl_util::GLMatrix4f MVP_matrix_
Definition: ViewControl.h:219
Eigen::Matrix< GLfloat, 3, 1, Eigen::ColMajor > GLVector3f
Definition: GLHelper.h:51
void UnsetConstantZFar()
Definition: ViewControl.h:196
The base geometry class for 3D geometries.
Definition: Geometry3D.h:46
Eigen::Vector3d right_
Definition: ViewControl.h:206
virtual void Translate(double x, double y, double xo=0.0, double yo=0.0)
Function to process translation.
Definition: ViewControl.cpp:313
virtual void ChangeWindowSize(int width, int height)
Definition: ViewControl.cpp:287
double GetZFar() const
Definition: ViewControl.h:177
bool ConvertFromPinholeCameraParameters(const camera::PinholeCameraParameters &parameters, bool allow_arbitrary=false)
Definition: ViewControl.cpp:191
static const double FIELD_OF_VIEW_STEP
Definition: ViewControl.h:46
gl_util::GLMatrix4f GetViewMatrix() const
Definition: ViewControl.h:167
geometry::AxisAlignedBoundingBox bounding_box_
Definition: ViewControl.h:201
double GetZNear() const
Definition: ViewControl.h:176
static const double FIELD_OF_VIEW_MIN
Definition: ViewControl.h:44
static const double ZOOM_MIN
Definition: ViewControl.h:49
double aspect_
Definition: ViewControl.h:211
Contains both intrinsic and extrinsic pinhole camera parameters.
Definition: PinholeCameraParameters.h:40
void FitInGeometry(const geometry::Geometry &geometry)
Definition: ViewControl.h:153
double constant_z_far_
Definition: ViewControl.h:215
int window_height_
Definition: ViewControl.h:200
double local_rotate_up_accum_
Definition: ViewControl.h:226
int GetWindowHeight() const
Definition: ViewControl.h:175
Definition: PinholeCameraIntrinsic.cpp:35
double zoom_
Definition: ViewControl.h:209
virtual void Roll(double x)
Definition: ViewControl.cpp:385
void SetConstantZNear(double z_near)
Definition: ViewControl.h:183
double constant_z_near_
Definition: ViewControl.h:214
AxisAlignedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:196
int height
Definition: FilePCD.cpp:72
Eigen::Vector3d start_local_rotate_eye_
Definition: ViewControl.h:224
Eigen::Vector3d up_
Definition: ViewControl.h:204
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: BoundingVolume.cpp:216
Definition: ViewParameters.h:37
gl_util::GLMatrix4f GetModelMatrix() const
Definition: ViewControl.h:168
double view_ratio_
Definition: ViewControl.h:210
void SetLookat(const Eigen::Vector3d &lookat)
Definition: ViewControl.cpp:128
bool ConvertToViewParameters(ViewParameters &status) const
Function to get equivalent view parameters (support orthogonal)
Definition: ViewControl.cpp:105
gl_util::GLVector3f GetEye() const
Definition: ViewControl.h:169
virtual void Reset()
Definition: ViewControl.cpp:253
gl_util::GLMatrix4f model_matrix_
Definition: ViewControl.h:218
virtual void CameraLocalRotate(double x, double y, double xo=0.0, double yo=0.0)
Definition: ViewControl.cpp:332
Eigen::Vector3d front_
Definition: ViewControl.h:205
bool ConvertToPinholeCameraParameters(camera::PinholeCameraParameters &parameters)
Definition: ViewControl.cpp:148
virtual void Rotate(double x, double y, double xo=0.0, double yo=0.0)
Function to process rotation.
Definition: ViewControl.cpp:299
double GetFieldOfView() const
Function to get field of view.
Definition: ViewControl.h:162
static const double ZOOM_STEP
Definition: ViewControl.h:51
double local_rotate_right_accum_
Definition: ViewControl.h:227
gl_util::GLVector3f GetRight() const
Definition: ViewControl.h:173
virtual void CameraLocalTranslate(double forward, double right, double up)
Definition: ViewControl.cpp:324
int width
Definition: FilePCD.cpp:71