Open3D (C++ API)
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 
38 class ViewControl {
39 public:
40  static const double FIELD_OF_VIEW_MAX;
41  static const double FIELD_OF_VIEW_MIN;
42  static const double FIELD_OF_VIEW_DEFAULT;
43  static const double FIELD_OF_VIEW_STEP;
44 
45  static const double ZOOM_DEFAULT;
46  static const double ZOOM_MIN;
47  static const double ZOOM_MAX;
48  static const double ZOOM_STEP;
49 
50  static const double ROTATION_RADIAN_PER_PIXEL;
51 
55  };
56 
57 public:
58  virtual ~ViewControl() {}
59 
63  void SetViewMatrices(
64  const Eigen::Matrix4d &model_matrix = Eigen::Matrix4d::Identity());
65 
67  bool ConvertToViewParameters(ViewParameters &status) const;
68  bool ConvertFromViewParameters(const ViewParameters &status);
69 
75  const camera::PinholeCameraParameters &parameters);
76 
79  virtual void Reset();
80  virtual void ChangeFieldOfView(double step);
81  virtual void ChangeWindowSize(int width, int height);
82 
83  // Function to process scaling
85  virtual void Scale(double scale);
86 
87  // Function to process rotation
93  virtual void Rotate(double x, double y, double xo = 0.0, double yo = 0.0);
94 
95  // Function to process translation
101  virtual void Translate(double x,
102  double y,
103  double xo = 0.0,
104  double yo = 0.0);
105 
106  // Function to process rolling
110  virtual void Roll(double x);
111 
113  return bounding_box_;
114  }
115 
117 
118  void FitInGeometry(const geometry::Geometry &geometry) {
119  if (geometry.Dimension() == 3) {
120  bounding_box_ += ((const geometry::Geometry3D &)geometry)
122  }
124  }
125 
126  double GetFieldOfView() const { return field_of_view_; }
129  return projection_matrix_;
130  }
133  GLHelper::GLVector3f GetEye() const { return eye_.cast<GLfloat>(); }
134  GLHelper::GLVector3f GetLookat() const { return lookat_.cast<GLfloat>(); }
135  GLHelper::GLVector3f GetUp() const { return up_.cast<GLfloat>(); }
136  GLHelper::GLVector3f GetFront() const { return front_.cast<GLfloat>(); }
137  GLHelper::GLVector3f GetRight() const { return right_.cast<GLfloat>(); }
138  int GetWindowWidth() const { return window_width_; }
139  int GetWindowHeight() const { return window_height_; }
140  double GetZNear() const { return z_near_; }
141  double GetZFar() const { return z_far_; }
142 
143  void SetConstantZNear(double z_near) { constant_z_near_ = z_near; }
144  void SetConstantZFar(double z_far) { constant_z_far_ = z_far; }
147 
148 protected:
149  int window_width_ = 0;
150  int window_height_ = 0;
152  Eigen::Vector3d eye_;
153  Eigen::Vector3d lookat_;
154  Eigen::Vector3d up_;
155  Eigen::Vector3d front_;
156  Eigen::Vector3d right_;
157  double distance_;
159  double zoom_;
160  double view_ratio_;
161  double aspect_;
162  double z_near_;
163  double z_far_;
164  double constant_z_near_ = -1;
165  double constant_z_far_ = -1;
170 };
171 
172 } // namespace visualization
173 } // namespace open3d
int width
Definition: FilePCD.cpp:68
int height
Definition: FilePCD.cpp:69
Contains both intrinsic and extrinsic pinhole camera parameters.
Definition: PinholeCameraParameters.h:40
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:130
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: BoundingVolume.cpp:236
AxisAlignedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:217
The base geometry class for 3D geometries.
Definition: Geometry3D.h:46
The base geometry class.
Definition: Geometry.h:35
int Dimension() const
Returns whether the geometry is 2D or 3D.
Definition: Geometry.h:88
Definition: ViewControl.h:38
GLHelper::GLMatrix4f GetViewMatrix() const
Definition: ViewControl.h:131
GLHelper::GLVector3f GetLookat() const
Definition: ViewControl.h:134
GLHelper::GLMatrix4f GetProjectionMatrix() const
Definition: ViewControl.h:128
void UnsetConstantZNear()
Definition: ViewControl.h:145
double distance_
Definition: ViewControl.h:157
bool ConvertFromViewParameters(const ViewParameters &status)
Definition: ViewControl.cpp:114
Eigen::Vector3d right_
Definition: ViewControl.h:156
double zoom_
Definition: ViewControl.h:159
double z_far_
Definition: ViewControl.h:163
double GetZNear() const
Definition: ViewControl.h:140
Eigen::Vector3d up_
Definition: ViewControl.h:154
Eigen::Vector3d lookat_
Definition: ViewControl.h:153
double aspect_
Definition: ViewControl.h:161
bool ConvertFromPinholeCameraParameters(const camera::PinholeCameraParameters &parameters)
Definition: ViewControl.cpp:169
GLHelper::GLMatrix4f MVP_matrix_
Definition: ViewControl.h:169
Eigen::Vector3d front_
Definition: ViewControl.h:155
void FitInGeometry(const geometry::Geometry &geometry)
Definition: ViewControl.h:118
static const double ROTATION_RADIAN_PER_PIXEL
Definition: ViewControl.h:50
int window_width_
Definition: ViewControl.h:149
static const double ZOOM_MIN
Definition: ViewControl.h:46
virtual ~ViewControl()
Definition: ViewControl.h:58
double view_ratio_
Definition: ViewControl.h:160
static const double FIELD_OF_VIEW_STEP
Definition: ViewControl.h:43
GLHelper::GLVector3f GetRight() const
Definition: ViewControl.h:137
static const double FIELD_OF_VIEW_DEFAULT
Definition: ViewControl.h:42
Eigen::Vector3d eye_
Definition: ViewControl.h:152
GLHelper::GLMatrix4f GetModelMatrix() const
Definition: ViewControl.h:132
double constant_z_near_
Definition: ViewControl.h:164
int window_height_
Definition: ViewControl.h:150
virtual void Translate(double x, double y, double xo=0.0, double yo=0.0)
Definition: ViewControl.cpp:282
void SetViewMatrices(const Eigen::Matrix4d &model_matrix=Eigen::Matrix4d::Identity())
Definition: ViewControl.cpp:55
double constant_z_far_
Definition: ViewControl.h:165
void SetConstantZFar(double z_far)
Definition: ViewControl.h:144
static const double ZOOM_MAX
Definition: ViewControl.h:47
GLHelper::GLVector3f GetEye() const
Definition: ViewControl.h:133
static const double FIELD_OF_VIEW_MAX
Definition: ViewControl.h:40
void SetProjectionParameters()
Definition: ViewControl.cpp:232
bool ConvertToViewParameters(ViewParameters &status) const
Function to get equivalent view parameters (support orthogonal)
Definition: ViewControl.cpp:103
GLHelper::GLVector3f GetUp() const
Definition: ViewControl.h:135
virtual void Roll(double x)
Definition: ViewControl.cpp:293
double GetZFar() const
Definition: ViewControl.h:141
static const double FIELD_OF_VIEW_MIN
Definition: ViewControl.h:41
const geometry::AxisAlignedBoundingBox & GetBoundingBox() const
Definition: ViewControl.h:112
void UnsetConstantZFar()
Definition: ViewControl.h:146
void SetConstantZNear(double z_near)
Definition: ViewControl.h:143
ProjectionType
Definition: ViewControl.h:52
@ Orthogonal
Definition: ViewControl.h:54
@ Perspective
Definition: ViewControl.h:53
virtual void ChangeWindowSize(int width, int height)
Definition: ViewControl.cpp:256
bool ConvertToPinholeCameraParameters(camera::PinholeCameraParameters &parameters)
Definition: ViewControl.cpp:126
virtual void Reset()
Definition: ViewControl.cpp:223
ProjectionType GetProjectionType() const
Definition: ViewControl.cpp:215
GLHelper::GLMatrix4f GetMVPMatrix() const
Definition: ViewControl.h:127
GLHelper::GLMatrix4f model_matrix_
Definition: ViewControl.h:168
GLHelper::GLVector3f GetFront() const
Definition: ViewControl.h:136
double field_of_view_
Definition: ViewControl.h:158
GLHelper::GLMatrix4f view_matrix_
Definition: ViewControl.h:167
double z_near_
Definition: ViewControl.h:162
virtual void Rotate(double x, double y, double xo=0.0, double yo=0.0)
Definition: ViewControl.cpp:268
static const double ZOOM_STEP
Definition: ViewControl.h:48
GLHelper::GLMatrix4f projection_matrix_
Definition: ViewControl.h:166
int GetWindowHeight() const
Definition: ViewControl.h:139
void ResetBoundingBox()
Definition: ViewControl.h:116
geometry::AxisAlignedBoundingBox bounding_box_
Definition: ViewControl.h:151
static const double ZOOM_DEFAULT
Definition: ViewControl.h:45
virtual void ChangeFieldOfView(double step)
Definition: ViewControl.cpp:248
double GetFieldOfView() const
Definition: ViewControl.h:126
int GetWindowWidth() const
Definition: ViewControl.h:138
virtual void Scale(double scale)
Definition: ViewControl.cpp:263
Definition: ViewParameters.h:37
Eigen::Matrix< GLfloat, 4, 4, Eigen::ColMajor > GLMatrix4f
Definition: GLHelper.h:46
Eigen::Matrix< GLfloat, 3, 1, Eigen::ColMajor > GLVector3f
Definition: GLHelper.h:44
Definition: PinholeCameraIntrinsic.cpp:34