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:
61  void SetViewMatrices(
62  const Eigen::Matrix4d &model_matrix = Eigen::Matrix4d::Identity());
63 
65  bool ConvertToViewParameters(ViewParameters &status) const;
66  bool ConvertFromViewParameters(const ViewParameters &status);
67 
73  const camera::PinholeCameraParameters &parameters);
74 
77  virtual void Reset();
78  virtual void ChangeFieldOfView(double step);
79  virtual void ChangeWindowSize(int width, int height);
80 
81  // Function to process scaling
83  virtual void Scale(double scale);
84 
85  // Function to process rotation
91  virtual void Rotate(double x, double y, double xo = 0.0, double yo = 0.0);
92 
93  // Function to process translation
99  virtual void Translate(double x,
100  double y,
101  double xo = 0.0,
102  double yo = 0.0);
103 
104  // Function to process rolling
108  virtual void Roll(double x);
109 
110  const BoundingBox &GetBoundingBox() const { return bounding_box_; }
111 
113 
114  void FitInGeometry(const geometry::Geometry &geometry) {
115  if (geometry.Dimension() == 3) {
117  }
119  }
120 
121  double GetFieldOfView() const { return field_of_view_; }
124  return projection_matrix_;
125  }
128  GLHelper::GLVector3f GetEye() const { return eye_.cast<GLfloat>(); }
129  GLHelper::GLVector3f GetLookat() const { return lookat_.cast<GLfloat>(); }
130  GLHelper::GLVector3f GetUp() const { return up_.cast<GLfloat>(); }
131  GLHelper::GLVector3f GetFront() const { return front_.cast<GLfloat>(); }
132  GLHelper::GLVector3f GetRight() const { return right_.cast<GLfloat>(); }
133  int GetWindowWidth() const { return window_width_; }
134  int GetWindowHeight() const { return window_height_; }
135  double GetZNear() const { return z_near_; }
136  double GetZFar() const { return z_far_; }
137 
138 protected:
139  int window_width_ = 0;
140  int window_height_ = 0;
142  Eigen::Vector3d eye_;
143  Eigen::Vector3d lookat_;
144  Eigen::Vector3d up_;
145  Eigen::Vector3d front_;
146  Eigen::Vector3d right_;
147  double distance_;
149  double zoom_;
150  double view_ratio_;
151  double aspect_;
152  double z_near_;
153  double z_far_;
158 };
159 
160 } // namespace visualization
161 } // namespace open3d
void Reset()
Definition: BoundingBox.cpp:40
static const double ROTATION_RADIAN_PER_PIXEL
Definition: ViewControl.h:50
GLHelper::GLVector3f GetRight() const
Definition: ViewControl.h:132
double distance_
Definition: ViewControl.h:147
double z_near_
Definition: ViewControl.h:152
Eigen::Matrix< GLfloat, 3, 1, Eigen::ColMajor > GLVector3f
Definition: GLHelper.h:38
int Dimension() const
Definition: Geometry.h:56
virtual void ChangeFieldOfView(double step)
Definition: ViewControl.cpp:232
Definition: Geometry.h:32
GLHelper::GLMatrix4f view_matrix_
Definition: ViewControl.h:155
void SetProjectionParameters()
Definition: ViewControl.cpp:216
int window_width_
Definition: ViewControl.h:139
Eigen::Vector3d lookat_
Definition: ViewControl.h:143
static const double ZOOM_MAX
Definition: ViewControl.h:47
ProjectionType
Definition: ViewControl.h:52
ProjectionType GetProjectionType() const
Definition: ViewControl.cpp:199
bool ConvertFromViewParameters(const ViewParameters &status)
Definition: ViewControl.cpp:98
const BoundingBox & GetBoundingBox() const
Definition: ViewControl.h:110
Definition: ViewControl.h:38
int GetWindowWidth() const
Definition: ViewControl.h:133
static const double FIELD_OF_VIEW_MAX
Definition: ViewControl.h:40
virtual void Scale(double scale)
Definition: ViewControl.cpp:247
GLHelper::GLMatrix4f model_matrix_
Definition: ViewControl.h:156
double z_far_
Definition: ViewControl.h:153
static const double ZOOM_DEFAULT
Definition: ViewControl.h:45
void ResetBoundingBox()
Definition: ViewControl.h:112
static const double FIELD_OF_VIEW_DEFAULT
Definition: ViewControl.h:42
Eigen::Matrix< GLfloat, 4, 4, Eigen::ColMajor > GLMatrix4f
Definition: GLHelper.h:40
GLHelper::GLVector3f GetEye() const
Definition: ViewControl.h:128
double field_of_view_
Definition: ViewControl.h:148
Definition: BoundingBox.h:37
Eigen::Vector3d eye_
Definition: ViewControl.h:142
GLHelper::GLMatrix4f GetProjectionMatrix() const
Definition: ViewControl.h:123
void SetViewMatrices(const Eigen::Matrix4d &model_matrix=Eigen::Matrix4d::Identity())
Definition: ViewControl.cpp:49
GLHelper::GLVector3f GetUp() const
Definition: ViewControl.h:130
Definition: Geometry3D.h:35
Eigen::Vector3d right_
Definition: ViewControl.h:146
virtual void Translate(double x, double y, double xo=0.0, double yo=0.0)
Definition: ViewControl.cpp:266
virtual void ChangeWindowSize(int width, int height)
Definition: ViewControl.cpp:240
double GetZFar() const
Definition: ViewControl.h:136
static const double FIELD_OF_VIEW_STEP
Definition: ViewControl.h:43
GLHelper::GLVector3f GetLookat() const
Definition: ViewControl.h:129
double GetZNear() const
Definition: ViewControl.h:135
static const double FIELD_OF_VIEW_MIN
Definition: ViewControl.h:41
static const double ZOOM_MIN
Definition: ViewControl.h:46
double aspect_
Definition: ViewControl.h:151
GLHelper::GLMatrix4f GetMVPMatrix() const
Definition: ViewControl.h:122
Definition: PinholeCameraParameters.h:37
void FitInGeometry(const geometry::Geometry &geometry)
Definition: ViewControl.h:114
int window_height_
Definition: ViewControl.h:140
GLHelper::GLMatrix4f MVP_matrix_
Definition: ViewControl.h:157
int GetWindowHeight() const
Definition: ViewControl.h:134
Definition: PinholeCameraIntrinsic.cpp:33
double zoom_
Definition: ViewControl.h:149
virtual void Roll(double x)
Definition: ViewControl.cpp:277
int height
Definition: FilePCD.cpp:68
Eigen::Vector3d up_
Definition: ViewControl.h:144
Definition: ViewParameters.h:36
double view_ratio_
Definition: ViewControl.h:150
BoundingBox bounding_box_
Definition: ViewControl.h:141
bool ConvertToViewParameters(ViewParameters &status) const
Function to get equivalent view parameters (support orthogonal)
Definition: ViewControl.cpp:87
GLHelper::GLMatrix4f projection_matrix_
Definition: ViewControl.h:154
GLHelper::GLVector3f GetFront() const
Definition: ViewControl.h:131
bool ConvertFromPinholeCameraParameters(const camera::PinholeCameraParameters &parameters)
Definition: ViewControl.cpp:153
virtual void Reset()
Definition: ViewControl.cpp:207
void FitInGeometry(const geometry::Geometry3D &geometry)
Definition: BoundingBox.cpp:45
Eigen::Vector3d front_
Definition: ViewControl.h:145
bool ConvertToPinholeCameraParameters(camera::PinholeCameraParameters &parameters)
Definition: ViewControl.cpp:110
virtual void Rotate(double x, double y, double xo=0.0, double yo=0.0)
Definition: ViewControl.cpp:252
GLHelper::GLMatrix4f GetModelMatrix() const
Definition: ViewControl.h:127
double GetFieldOfView() const
Definition: ViewControl.h:121
GLHelper::GLMatrix4f GetViewMatrix() const
Definition: ViewControl.h:126
static const double ZOOM_STEP
Definition: ViewControl.h:48
int width
Definition: FilePCD.cpp:67