mapping.cpp
Go to the documentation of this file.
2 
3 namespace toposens_pointcloud
4 {
5 void Mapping::doTransform(pcl::PointXYZINormal &pt, Vector3f translation, Vector4f quaternion)
6 {
7  Vector4f point_in, point_out;
8  point_in << pt.x, pt.y, pt.z,
9  1; // Assign homogenous co ordinates to the fourth column
10  double qx, qy, qz, qw; // Quaternion x,y,z,w parameters
11  qx = quaternion[0];
12  qy = quaternion[1];
13  qz = quaternion[2];
14  qw = quaternion[3];
15  MatrixXf transform_mat(4, 4);
16 
17  // Assign homogenous coefficients to the 4th column
18  // https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/geometry/transforming-points-and-vectors
19  transform_mat << 1 - 2 * qz * qz - 2 * qy * qy, -2 * qz * qw + 2 * qy * qx,
20  2 * qy * qw + 2 * qz * qx, translation[0], 2 * qx * qy + 2 * qw * qz,
21  1 - 2 * qz * qz - 2 * qx * qx, 2 * qz * qy - 2 * qx * qw, translation[1],
22  2 * qx * qz - 2 * qw * qy, 2 * qy * qz + 2 * qw * qx, 1 - 2 * qy * qy - 2 * qx * qx,
23  translation[2], 0.0, 0.0, 0.0, 1;
24  point_out = transform_mat * point_in;
25 
26  // Update the input PCL point
27  pt.x = point_out[0];
28  pt.y = point_out[1];
29  pt.z = point_out[2];
30 
31  // https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/geometry/transforming-normals
32  Vector4f normal_in, normal_out;
33  normal_in << pt.normal_x, pt.normal_y, pt.normal_z, 1;
34  normal_out = (transform_mat.inverse().transpose()) * normal_in;
35 
36  // Update the input PCL point Normals
37  pt.normal_x = normal_out[0];
38  pt.normal_y = normal_out[1];
39  pt.normal_z = normal_out[2];
40 }
41 
42 pcl::PointXYZINormal Mapping::convertToXYZINormal(toposens_msgs::TsPoint i)
43 {
44  // Fast calculation of inverse of square roots
45  // https://en.wikipedia.org/wiki/Fast_inverse_square_root
46  auto isqrtf = [](float number) {
47  long i;
48  float x2, y;
49  const float threehalfs = 1.5F;
50 
51  x2 = number * 0.5F;
52  y = number;
53  i = *(long *)&y;
54  i = 0x5f3759df - (i >> 1);
55  y = *(float *)&i;
56  y = y * (threehalfs - (x2 * y * y));
57  return y;
58  };
59 
60  pcl::PointXYZINormal o;
61 
62  o.x = i.location.x;
63  o.y = i.location.y;
64  o.z = i.location.z;
65  o.intensity = i.intensity;
66 
67  // Approximation of the inverse of the length of the normal vector
68  float len = isqrtf(i.location.x * i.location.x + i.location.y * i.location.y +
69  i.location.z * i.location.z);
70  // Normalize and store the vector in the PCL point
71  o.normal_x = -i.location.x * len;
72  o.normal_y = -i.location.y * len;
73  o.normal_z = -i.location.z * len;
74 
75  return o;
76 }
77 
78 } // namespace toposens_pointcloud
pcl::PointXYZINormal convertToXYZINormal(toposens_msgs::TsPoint i)
Converts a point from a TsPoint message to a standard PCL point (PointXYZINormal).
Definition: mapping.cpp:42
void doTransform(pcl::PointXYZINormal &pt, Vector3f translation, Vector4f quaternion)
Definition: mapping.cpp:5


toposens_pointcloud
Author(s): Adi Singh, Sebastian Dengler, Christopher Lang, Inshal Uddin
autogenerated on Mon Feb 28 2022 23:57:49