ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ViewControlWithEditing.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 namespace cloudViewer {
11 namespace visualization {
12 
14  if (IsLocked()) return;
15  if (editing_mode_ == EditingMode::FreeMode) {
17  } else {
21  switch (editing_mode_) {
22  case EditingMode::OrthoPositiveX:
23  up_ = Eigen::Vector3d(0.0, 0.0, 1.0);
24  front_ = Eigen::Vector3d(1.0, 0.0, 0.0);
25  break;
26  case EditingMode::OrthoNegativeX:
27  up_ = Eigen::Vector3d(0.0, 0.0, 1.0);
28  front_ = Eigen::Vector3d(-1.0, 0.0, 0.0);
29  break;
30  case EditingMode::OrthoPositiveY:
31  up_ = Eigen::Vector3d(1.0, 0.0, 0.0);
32  front_ = Eigen::Vector3d(0.0, 1.0, 0.0);
33  break;
34  case EditingMode::OrthoNegativeY:
35  up_ = Eigen::Vector3d(1.0, 0.0, 0.0);
36  front_ = Eigen::Vector3d(0.0, -1.0, 0.0);
37  break;
38  case EditingMode::OrthoPositiveZ:
39  up_ = Eigen::Vector3d(0.0, 1.0, 0.0);
40  front_ = Eigen::Vector3d(0.0, 0.0, 1.0);
41  break;
42  case EditingMode::OrthoNegativeZ:
43  up_ = Eigen::Vector3d(0.0, 1.0, 0.0);
44  front_ = Eigen::Vector3d(0.0, 0.0, -1.0);
45  break;
46  default:
47  break;
48  }
50  }
51 }
52 
54  if (IsLocked()) return;
55  if (editing_mode_ == EditingMode::FreeMode) {
57  } else {
58  // Do nothing. Lock field of view if we are in orthogonal editing mode.
59  }
60 }
61 
62 void ViewControlWithEditing::Scale(double scale) {
63  if (IsLocked()) return;
64  if (editing_mode_ == EditingMode::FreeMode) {
65  ViewControl::Scale(scale);
66  } else {
67  ViewControl::Scale(scale);
68  }
69 }
70 
71 void ViewControlWithEditing::Rotate(double x, double y, double xo, double yo) {
72  if (IsLocked()) return;
73  if (editing_mode_ == EditingMode::FreeMode) {
74  ViewControl::Rotate(x, y);
75  } else {
76  // In orthogonal editing mode, lock front, and rotate around it
77  double x0 = xo - (window_width_ / 2.0 - 0.5);
78  double y0 = window_height_ / 2.0 - 0.5 - yo;
79  double x1 = xo + x - (window_width_ / 2.0 - 0.5);
80  double y1 = window_height_ / 2.0 - 0.5 - yo - y;
81  if ((std::abs(x0 * y0) < 0.5) || (std::abs(x1 * y1) < 0.5)) {
82  // Too close to screen center, skip the rotation
83  } else {
84  double theta = std::atan2(y1, x1) - std::atan2(y0, x0);
85  up_ = up_ * std::cos(theta) + right_ * std::sin(theta);
86  }
88  }
89 }
90 
92  double y,
93  double xo,
94  double yo) {
95  if (IsLocked()) return;
96  if (editing_mode_ == EditingMode::FreeMode) {
97  ViewControl::Translate(x, y, xo, yo);
98  } else {
99  ViewControl::Translate(x, y, xo, yo);
100  }
101 }
102 
104  if (IsLocked()) return;
105  if (editing_mode_ == EditingMode::FreeMode) {
107  }
108  editing_mode_ = mode;
109  if (editing_mode_ == EditingMode::FreeMode) {
111  } else {
112  Reset();
113  }
114 }
115 
117  std::string prefix;
118  switch (editing_mode_) {
119  case EditingMode::FreeMode:
120  prefix = "free view";
121  break;
122  case EditingMode::OrthoPositiveX:
123  case EditingMode::OrthoNegativeX:
124  prefix = "orthogonal X asix";
125  break;
126  case EditingMode::OrthoPositiveY:
127  case EditingMode::OrthoNegativeY:
128  prefix = "orthogonal Y asix";
129  break;
130  case EditingMode::OrthoPositiveZ:
131  case EditingMode::OrthoNegativeZ:
132  prefix = "orthogonal Z asix";
133  break;
134  }
135  return prefix + (IsLocked() ? ", lock camera for editing" : "");
136 }
137 
138 } // namespace visualization
139 } // namespace cloudViewer
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: ecvBBox.h:87
void Translate(double x, double y, double xo, double yo) override
Function to process translation.
void Rotate(double x, double y, double xo, double yo) override
Function to process rotation.
bool ConvertFromViewParameters(const ViewParameters &status)
Definition: ViewControl.cpp:97
virtual void Translate(double x, double y, double xo=0.0, double yo=0.0)
Function to process translation.
virtual void Rotate(double x, double y, double xo=0.0, double yo=0.0)
Function to process rotation.
virtual void ChangeFieldOfView(double step)
virtual void Scale(double scale)
bool ConvertToViewParameters(ViewParameters &status) const
Function to get equivalent view parameters (support orthogonal)
Definition: ViewControl.cpp:86
__host__ __device__ int2 abs(int2 v)
Definition: cutil_math.h:1267
Generic file read and write utility for python interface.