Open3D (C++ API)
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 
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
static const double ROTATION_RADIAN_PER_PIXEL
Definition: ViewControl.h:50
GLHelper::GLVector3f GetRight() const
Definition: ViewControl.h:137
double distance_
Definition: ViewControl.h:157
double z_near_
Definition: ViewControl.h:162
Eigen::Matrix< GLfloat, 3, 1, Eigen::ColMajor > GLVector3f
Definition: GLHelper.h:44
int Dimension() const
Returns whether the geometry is 2D or 3D.
Definition: Geometry.h:88
virtual void ChangeFieldOfView(double step)
Definition: ViewControl.cpp:248
The base geometry class.
Definition: Geometry.h:35
GLHelper::GLMatrix4f view_matrix_
Definition: ViewControl.h:167
void SetProjectionParameters()
Definition: ViewControl.cpp:232
int window_width_
Definition: ViewControl.h:149
Eigen::Vector3d lookat_
Definition: ViewControl.h:153
static const double ZOOM_MAX
Definition: ViewControl.h:47
ProjectionType
Definition: ViewControl.h:52
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:130
const geometry::AxisAlignedBoundingBox & GetBoundingBox() const
Definition: ViewControl.h:112
ProjectionType GetProjectionType() const
Definition: ViewControl.cpp:215
bool ConvertFromViewParameters(const ViewParameters &status)
Definition: ViewControl.cpp:114
Definition: ViewControl.h:38
void SetConstantZFar(double z_far)
Definition: ViewControl.h:144
int GetWindowWidth() const
Definition: ViewControl.h:138
static const double FIELD_OF_VIEW_MAX
Definition: ViewControl.h:40
virtual void Scale(double scale)
Definition: ViewControl.cpp:263
GLHelper::GLMatrix4f model_matrix_
Definition: ViewControl.h:168
double z_far_
Definition: ViewControl.h:163
static const double ZOOM_DEFAULT
Definition: ViewControl.h:45
void ResetBoundingBox()
Definition: ViewControl.h:116
static const double FIELD_OF_VIEW_DEFAULT
Definition: ViewControl.h:42
Eigen::Matrix< GLfloat, 4, 4, Eigen::ColMajor > GLMatrix4f
Definition: GLHelper.h:46
GLHelper::GLVector3f GetEye() const
Definition: ViewControl.h:133
double field_of_view_
Definition: ViewControl.h:158
Eigen::Vector3d eye_
Definition: ViewControl.h:152
GLHelper::GLMatrix4f GetProjectionMatrix() const
Definition: ViewControl.h:128
void SetViewMatrices(const Eigen::Matrix4d &model_matrix=Eigen::Matrix4d::Identity())
Definition: ViewControl.cpp:55
void UnsetConstantZNear()
Definition: ViewControl.h:145
GLHelper::GLVector3f GetUp() const
Definition: ViewControl.h:135
virtual ~ViewControl()
Definition: ViewControl.h:58
void UnsetConstantZFar()
Definition: ViewControl.h:146
The base geometry class for 3D geometries.
Definition: Geometry3D.h:46
Eigen::Vector3d right_
Definition: ViewControl.h:156
virtual void Translate(double x, double y, double xo=0.0, double yo=0.0)
Definition: ViewControl.cpp:282
virtual void ChangeWindowSize(int width, int height)
Definition: ViewControl.cpp:256
double GetZFar() const
Definition: ViewControl.h:141
static const double FIELD_OF_VIEW_STEP
Definition: ViewControl.h:43
geometry::AxisAlignedBoundingBox bounding_box_
Definition: ViewControl.h:151
GLHelper::GLVector3f GetLookat() const
Definition: ViewControl.h:134
double GetZNear() const
Definition: ViewControl.h:140
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:161
GLHelper::GLMatrix4f GetMVPMatrix() const
Definition: ViewControl.h:127
Contains both intrinsic and extrinsic pinhole camera parameters.
Definition: PinholeCameraParameters.h:40
void FitInGeometry(const geometry::Geometry &geometry)
Definition: ViewControl.h:118
double constant_z_far_
Definition: ViewControl.h:165
int window_height_
Definition: ViewControl.h:150
GLHelper::GLMatrix4f MVP_matrix_
Definition: ViewControl.h:169
int GetWindowHeight() const
Definition: ViewControl.h:139
Definition: PinholeCameraIntrinsic.cpp:34
double zoom_
Definition: ViewControl.h:159
virtual void Roll(double x)
Definition: ViewControl.cpp:293
void SetConstantZNear(double z_near)
Definition: ViewControl.h:143
double constant_z_near_
Definition: ViewControl.h:164
AxisAlignedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:217
int height
Definition: FilePCD.cpp:69
Eigen::Vector3d up_
Definition: ViewControl.h:154
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: BoundingVolume.cpp:236
Definition: ViewParameters.h:37
double view_ratio_
Definition: ViewControl.h:160
bool ConvertToViewParameters(ViewParameters &status) const
Function to get equivalent view parameters (support orthogonal)
Definition: ViewControl.cpp:103
GLHelper::GLMatrix4f projection_matrix_
Definition: ViewControl.h:166
GLHelper::GLVector3f GetFront() const
Definition: ViewControl.h:136
bool ConvertFromPinholeCameraParameters(const camera::PinholeCameraParameters &parameters)
Definition: ViewControl.cpp:169
virtual void Reset()
Definition: ViewControl.cpp:223
Eigen::Vector3d front_
Definition: ViewControl.h:155
bool ConvertToPinholeCameraParameters(camera::PinholeCameraParameters &parameters)
Definition: ViewControl.cpp:126
virtual void Rotate(double x, double y, double xo=0.0, double yo=0.0)
Definition: ViewControl.cpp:268
GLHelper::GLMatrix4f GetModelMatrix() const
Definition: ViewControl.h:132
double GetFieldOfView() const
Definition: ViewControl.h:126
GLHelper::GLMatrix4f GetViewMatrix() const
Definition: ViewControl.h:131
static const double ZOOM_STEP
Definition: ViewControl.h:48
int width
Definition: FilePCD.cpp:68