ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
vtkBoxWidgetRestricted.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 #include <vtkDoubleArray.h>
11 #include <vtkMath.h>
12 #include <vtkPoints.h>
13 #include <vtkRenderWindowInteractor.h>
14 #include <vtkRenderer.h>
15 #include <vtkTransform.h>
16 
18 
20  int X, int Y, double *p1, double *p2, double *vpn) {
21  double *pts = static_cast<vtkDoubleArray *>(this->Points->GetData())
22  ->GetPointer(0);
23  double *center = static_cast<vtkDoubleArray *>(this->Points->GetData())
24  ->GetPointer(3 * 14);
25  double v[3]; // vector of motion
26  // double axis[3]; //axis of rotation
27  double theta; // rotation angle
28  int i;
29 
30  v[0] = p2[0] - p1[0];
31  v[1] = p2[1] - p1[1];
32  v[2] = p2[2] - p1[2];
33 
34  // Create axis of rotation and angle of rotation
35  // compute the vector which perpendicular to Y axis in current view
36  double y[3] = {0, 1, 0}; // restrict to y rotation
37  double m[3];
38  vtkMath::Cross(y, vpn, m);
39  if (vtkMath::Normalize(m) == 0.0 || vtkMath::Normalize(v) == 0.0) {
40  return;
41  }
42  // alpha is the angle between the motion vector and vector m
43  double cos_alpha = vtkMath::Dot(m, v);
44  int *size = this->CurrentRenderer->GetSize();
45  double l2 = (X - this->Interactor->GetLastEventPosition()[0]) *
46  (X - this->Interactor->GetLastEventPosition()[0]) +
47  (Y - this->Interactor->GetLastEventPosition()[1]) *
48  (Y - this->Interactor->GetLastEventPosition()[1]);
49  theta = 360.0 * cos_alpha *
50  sqrt(l2 / (size[0] * size[0] + size[1] * size[1]));
51 
52  // Manipulate the transform to reflect the rotation
53  this->Transform->Identity();
54  this->Transform->Translate(center[0], center[1], center[2]);
55  this->Transform->RotateY(theta);
56  this->Transform->Translate(-center[0], -center[1], -center[2]);
57 
58  // Set the corners
59  vtkPoints *newPts = vtkPoints::New(VTK_DOUBLE);
60  this->Transform->TransformPoints(this->Points, newPts);
61 
62  for (i = 0; i < 8; i++, pts += 3) {
63  this->Points->SetPoint(i, newPts->GetPoint(i));
64  }
65 
66  newPts->Delete();
67  this->PositionHandles();
68 }
int size
void * X
Definition: SmallVector.cpp:45
The vtkBoxWidgetRestricted class vtkBoxWidgetRestricted restricts the rotation with Z axis.
virtual void Rotate(int X, int Y, double *p1, double *p2, double *vpn) override
normal_z y
CLOUDVIEWER_HOST_DEVICE float Cross(const Point &a, const Point &b)
Definition: IoUImpl.h:39
void Transform(benchmark::State &state, const core::Device &device)
Definition: PointCloud.cpp:127
std::vector< Eigen::Vector3f > Points
vtkStandardNewMacro(vtkBoxWidgetRestricted)