ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
qVoxFallTools.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 
8 #include "qVoxFallTools.h"
9 
10 // qCC_db
11 #include <ecvPointCloud.h>
12 
13 // qCC
14 #include <ecvMainAppInterface.h>
15 #include <ecvQtHelpers.h>
16 
17 // local
18 #include "qVoxFallDialog.h"
19 
20 // Qt
21 #include <QApplication>
22 #include <QMainWindow>
23 #include <QProgressDialog>
24 #include <QtConcurrentMap>
25 #include <QtCore>
26 
27 float qVoxFallTransform::GetRotationAngle(double azimuth) {
28  double azimuthRadians = azimuth * 3.14159 / 180;
29 
30  std::vector<double> direction = {sin(azimuthRadians), cos(azimuthRadians)};
31  std::vector<double> xyView = {0, 1};
32 
33  // compute dot product of unit vectors
34  double dotProduct = 0;
35  for (int i = 0; i < direction.size(); i++) {
36  direction[i] = direction[i] / sqrt(direction[0] * direction[0] +
37  direction[1] * direction[1]);
38  xyView[i] =
39  xyView[i] / sqrt(xyView[0] * xyView[0] + xyView[1] * xyView[1]);
40  dotProduct += direction[i] * xyView[i];
41  }
42 
43  float zRot = acos(std::max(-1.0, std::min(dotProduct, 1.0)));
44 
45  return zRot;
46 }
47 
49  float voxelSize,
50  int voxelIdx) {
51  CCVector3 dims = {voxelSize, voxelSize, voxelSize};
52  QString name = QString("voxel#%1").arg(voxelIdx);
53 
54  const Vector3Tpl<float> X(1, 0, 0);
55  const Vector3Tpl<float> Y(0, 1, 0);
56  const Vector3Tpl<float> Z(0, 0, 1);
57  const ccGLMatrix matrix(X, Y, Z, V);
58 
59  ccBox* voxel = new ccBox(dims, &matrix, name);
61  return voxel;
62 }
63 
64 std::vector<Tuple3i> qVoxFallTools::FindAdjacents(Tuple3i V,
65  CCVector3 steps,
66  bool facetsOnly = false) {
67  std::vector<Tuple3i> set;
68  std::vector<std::vector<int>> adjacencyMatrix;
69 
70  if (!facetsOnly) {
71  adjacencyMatrix = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0},
72  {0, 0, 1}, {0, 0, -1}, {1, 1, 0}, {-1, 1, 0},
73  {1, -1, 0}, {-1, -1, 0}, {0, 1, 1}, {0, 1, -1},
74  {0, -1, 1}, {0, -1, -1}, {1, 0, 1}, {1, 0, -1},
75  {-1, 0, 1}, {-1, 0, -1}, {1, 1, 1}, {-1, -1, -1},
76  {1, 1, -1}, {1, -1, 1}, {-1, 1, 1}, {1, -1, -1},
77  {-1, -1, 1}, {-1, 1, -1}};
78  } else {
79  adjacencyMatrix = {
80  {1, 0, 0}, {-1, 0, 0}, {0, 1, 0},
81  {0, -1, 0}, {0, 0, 1}, {0, 0, -1},
82  };
83  }
84 
85  for (unsigned n = 0; n < adjacencyMatrix.size(); n++) {
86  int x = int(V.x) + adjacencyMatrix[n][0];
87  int y = int(V.y) + adjacencyMatrix[n][1];
88  int z = int(V.z) + adjacencyMatrix[n][2];
89 
90  if (x < 0 || y < 0 || z < 0 || x >= int(steps.x) || y >= int(steps.y) ||
91  z >= int(steps.z)) {
92  continue;
93  }
94 
95  set.push_back({x, y, z});
96  }
97 
98  return set;
99 }
100 
102  int i = n.x;
103  int j = n.y;
104  int k = n.z;
105 
106  int index = (i) + (j * int(steps.x)) + (k * int(steps.x) * int(steps.y));
107  return index;
108 }
109 
111  int k = std::floor(index / (int(steps.y) * int(steps.x)));
112  int remain = index - (int(steps.y) * int(steps.x) * k);
113  int j = std::floor(remain / int(steps.x));
114  int i = remain - (int(steps.x) * j);
115 
116  Tuple3i V(static_cast<int>(i), static_cast<int>(j), static_cast<int>(k));
117  return V;
118 }
std::string name
void * X
Definition: SmallVector.cpp:45
Type y
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
Box (primitive)
Definition: ecvBox.h:16
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
bool computePerTriangleNormals()
Computes per-triangle normals.
static std::vector< Tuple3i > FindAdjacents(Tuple3i V, CCVector3 steps, bool facetsOnly)
static int Grid2Index(Tuple3i n, CCVector3 steps)
static Tuple3i Index2Grid(unsigned index, CCVector3 steps)
ccGLMatrix matrix
Definition: qVoxFallTools.h:30
static ccBox * CreateVoxelMesh(CCVector3 V, float voxelSize, int voxelIdx)
int min(int a, int b)
Definition: cutil_math.h:53
int max(int a, int b)
Definition: cutil_math.h:48
MiniVec< float, N > floor(const MiniVec< float, N > &a)
Definition: MiniVec.h:75