ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvGenericDisplayTools.h
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 #pragma once
9 
10 // Local
11 #include "CV_db.h"
12 #include "ecvGLMatrix.h"
13 
14 // CV_CORE_LIB
15 #include <CVConst.h>
16 #include <CVToolbox.h>
17 
18 // SYSTEM
19 #include <algorithm>
20 #include <cmath>
21 #include <iostream>
22 
25 public:
28 
30  static void SetInstance(ecvGenericDisplayTools* tool);
31 
32 public:
33  static int FontSizeModifier(int fontSize, float zoomFactor) {
34  int scaledFontSize =
35  static_cast<int>(std::floor(fontSize * zoomFactor));
36  if (zoomFactor >= 2.0f) scaledFontSize -= static_cast<int>(zoomFactor);
37  if (scaledFontSize < 1) scaledFontSize = 1;
38  return scaledFontSize;
39  }
40 
42  static bool GetPerspectiveState() {
43  assert(GetInstance());
44  return GetInstance()->getPerspectiveState();
45  }
46  inline virtual bool getPerspectiveState(int viewport = 0) const {
47  return false;
48  }
49 
50  template <typename iType, typename oType>
51  static void ToWorldPoint(const Vector3Tpl<iType>& input2D,
52  Vector3Tpl<oType>& output3D) {
53  GetInstance()->toWorldPoint(input2D, output3D);
54  }
55 
56  inline virtual void toWorldPoint(const CCVector3d& input2D,
57  CCVector3d& output3D) { /* do nothing */ }
58  // inline static void ToWorldPoint(CCVector3 & p) {
59  // s_tools->toWorldPoint(p); }
60  inline virtual void toWorldPoint(const CCVector3& input2D,
61  CCVector3d& output3D) { /* do nothing */ }
62 
63  template <typename iType, typename oType>
64  inline static void ToDisplayPoint(const Vector3Tpl<iType>& input3D,
65  Vector3Tpl<oType>& output2D) {
66  GetInstance()->toDisplayPoint(input3D, output2D);
67  }
68  inline virtual void toDisplayPoint(const CCVector3d& input3D,
69  CCVector3d& output2D) { /* do nothing */
70  }
71  // inline static void ToDisplayPoint(const CCVector3 & worldPos, CCVector3d
72  // & displayPos) { s_tools->toDisplayPoint(worldPos, displayPos); }
73  inline virtual void toDisplayPoint(const CCVector3& input3D,
74  CCVector3d& output2D) { /* do nothing */
75  }
76 
78  enum TextAlign {
79  ALIGN_HLEFT = 1,
80  ALIGN_HMIDDLE = 2,
81  ALIGN_HRIGHT = 4,
82  ALIGN_VTOP = 8,
83  ALIGN_VMIDDLE = 16,
84  ALIGN_VBOTTOM = 32,
85  ALIGN_DEFAULT = 1 | 8
86  };
87 
88 public: // GLU equivalent methods
89  static ccGLMatrixd Frustum(double left,
90  double right,
91  double bottom,
92  double top,
93  double znear,
94  double zfar) {
95  // invalid for: n<=0, f<=0, l=r, b=t, or n=f
96  assert(znear > 0);
97  assert(zfar > 0);
98  assert(left != right);
99  assert(bottom != top);
100  assert(znear != zfar);
101 
102  ccGLMatrixd outMatrix;
103  {
104  double* matrix = outMatrix.data();
105 
106  double dX = right - left;
107  double dY = top - bottom;
108  double dZ = znear - zfar;
109 
110  matrix[0] = 2 * znear / dX;
111  matrix[1] = 0.0;
112  matrix[2] = 0.0;
113  matrix[3] = 0.0;
114 
115  matrix[4] = 0.0;
116  matrix[5] = 2 * znear / dY;
117  matrix[6] = 0.0;
118  matrix[7] = 0.0;
119 
120  matrix[8] = (right + left) / dX;
121  matrix[9] = (top + bottom) / dY;
122  matrix[10] = (zfar + znear) / dZ;
123  matrix[11] = -1.0;
124 
125  matrix[12] = 0.0;
126  matrix[13] = 0.0;
127  matrix[14] = 2 * znear * zfar / dZ;
128  matrix[15] = 0.0;
129  }
130 
131  return outMatrix;
132  }
133 
134  // inspired from https://www.opengl.org/wiki/GluPerspective_code and
135  // http://www.songho.ca/opengl/gl_projectionmatrix.html
136  static ccGLMatrixd Perspective(double fovyInDegrees,
137  double aspectRatio,
138  double znear,
139  double zfar) {
140  ccGLMatrixd outMatrix;
141  {
142  double* matrix = outMatrix.data();
143 
144  double ymax =
145  znear *
146  std::tan(cloudViewer::DegreesToRadians(fovyInDegrees / 2));
147  double xmax = ymax * aspectRatio;
148 
149  double dZ = zfar - znear;
150  matrix[0] = znear / xmax;
151  matrix[1] = 0.0;
152  matrix[2] = 0.0;
153  matrix[3] = 0.0;
154 
155  matrix[4] = 0.0;
156  matrix[5] = znear / ymax;
157  matrix[6] = 0.0;
158  matrix[7] = 0.0;
159 
160  matrix[8] = 0.0;
161  matrix[9] = 0.0;
162  matrix[10] = -(zfar + znear) / dZ;
163  matrix[11] = -1.0;
164 
165  matrix[12] = 0.0;
166  matrix[13] = 0.0;
167  matrix[14] = -(2.0 * znear * zfar) / dZ;
168  matrix[15] = 0.0;
169  }
170 
171  return outMatrix;
172  }
173 
174  static ccGLMatrixd Ortho(double left,
175  double right,
176  double bottom,
177  double top,
178  double nearVal,
179  double farVal) {
180  ccGLMatrixd matrix;
181  double dx = (right - left);
182  double dy = (top - bottom);
183  double dz = (farVal - nearVal);
184  if (dx != 0 && dy != 0 && dz != 0) {
185  double* mat = matrix.data();
186  // set OpenGL perspective projection matrix
187  mat[0] = 2.0 / dx;
188  mat[1] = 0;
189  mat[2] = 0;
190  mat[3] = 0;
191 
192  mat[4] = 0;
193  mat[5] = 2.0 / dy;
194  mat[6] = 0;
195  mat[7] = 0;
196 
197  mat[8] = 0;
198  mat[9] = 0;
199  mat[10] = -2.0 / dz;
200  mat[11] = 0;
201 
202  mat[12] = -(right + left) / dx;
203  mat[13] = -(top + bottom) / dy;
204  mat[14] = -(farVal + nearVal) / dz;
205  mat[15] = 1.0;
206  } else {
207  matrix.toIdentity();
208  }
209 
210  return matrix;
211  }
212 
213  // inspired from http://www.songho.ca/opengl/gl_projectionmatrix.html
214  static ccGLMatrixd Ortho(double w, double h, double d) {
215  ccGLMatrixd matrix;
216  if (w != 0 && h != 0 && d != 0) {
217  double* mat = matrix.data();
218  mat[0] = 1.0 / w;
219  mat[1] = 0.0;
220  mat[2] = 0.0;
221  mat[3] = 0.0;
222 
223  mat[4] = 0.0;
224  mat[5] = 1.0 / h;
225  mat[6] = 0.0;
226  mat[7] = 0.0;
227 
228  mat[8] = 0.0;
229  mat[9] = 0.0;
230  mat[10] = -1.0 / d;
231  mat[11] = 0.0;
232 
233  mat[12] = 0.0;
234  mat[13] = 0.0;
235  mat[14] = 0.0;
236  mat[15] = 1.0;
237  } else {
238  matrix.toIdentity();
239  }
240 
241  return matrix;
242  }
243 
244  template <typename iType, typename oType>
245  static bool Project(const Vector3Tpl<iType>& input3D,
246  const oType* modelview,
247  const oType* projection,
248  const int* viewport,
249  Vector3Tpl<oType>& output2D,
250  bool* inFrustum = nullptr) {
251  if (GetInstance() && !GetPerspectiveState()) {
252  ToDisplayPoint<iType, oType>(input3D, output2D);
253  return true;
254  }
255 
256  // Modelview transform
257  Tuple4Tpl<oType> Pm;
258  {
259  Pm.x = static_cast<oType>(modelview[0] * input3D.x +
260  modelview[4] * input3D.y +
261  modelview[8] * input3D.z + modelview[12]);
262  Pm.y = static_cast<oType>(modelview[1] * input3D.x +
263  modelview[5] * input3D.y +
264  modelview[9] * input3D.z + modelview[13]);
265  Pm.z = static_cast<oType>(
266  modelview[2] * input3D.x + modelview[6] * input3D.y +
267  modelview[10] * input3D.z + modelview[14]);
268  Pm.w = static_cast<oType>(
269  modelview[3] * input3D.x + modelview[7] * input3D.y +
270  modelview[11] * input3D.z + modelview[15]);
271  };
272 
273  // Projection transform
274  Tuple4Tpl<oType> Pp;
275  {
276  Pp.x = static_cast<oType>(
277  projection[0] * Pm.x + projection[4] * Pm.y +
278  projection[8] * Pm.z + projection[12] * Pm.w);
279  Pp.y = static_cast<oType>(
280  projection[1] * Pm.x + projection[5] * Pm.y +
281  projection[9] * Pm.z + projection[13] * Pm.w);
282  Pp.z = static_cast<oType>(
283  projection[2] * Pm.x + projection[6] * Pm.y +
284  projection[10] * Pm.z + projection[14] * Pm.w);
285  Pp.w = static_cast<oType>(
286  projection[3] * Pm.x + projection[7] * Pm.y +
287  projection[11] * Pm.z + projection[15] * Pm.w);
288  };
289 
290  // The result normalizes between -1 and 1
291  if (Pp.w == 0.0) {
292  return false;
293  }
294 
295  if (inFrustum) {
296  // Check if the point is inside the frustum
297  *inFrustum = (std::abs(Pp.x) <= Pp.w && std::abs(Pp.y) <= Pp.w &&
298  std::abs(Pp.z) <= Pp.w);
299  }
300 
301  // Perspective division
302  Pp.x /= Pp.w;
303  Pp.y /= Pp.w;
304  Pp.z /= Pp.w;
305  // Window coordinates
306  // Map x, y to range 0-1
307  output2D.x = (1.0 + Pp.x) / 2 * viewport[2] + viewport[0];
308  output2D.y = (1.0 + Pp.y) / 2 * viewport[3] + viewport[1];
309  // This is only correct when glDepthRange(0.0, 1.0)
310  output2D.z = (1.0 + Pp.z) / 2; // Between 0 and 1
311 
312  return true;
313  }
314 
315  inline static double MAT(const double* m, int r, int c) {
316  return m[c * 4 + r];
317  }
318  inline static float MAT(const float* m, int r, int c) {
319  return m[c * 4 + r];
320  }
321 
322  inline static double& MAT(double* m, int r, int c) { return m[c * 4 + r]; }
323  inline static float& MAT(float* m, int r, int c) { return m[c * 4 + r]; }
324 
325  template <typename Type>
326  static bool InvertMatrix(const Type* m, Type* out) {
327  Type wtmp[4][8];
328  Type m0, m1, m2, m3, s;
329  Type *r0, *r1, *r2, *r3;
330  r0 = wtmp[0], r1 = wtmp[1], r2 = wtmp[2], r3 = wtmp[3];
331 
332  r0[0] = MAT(m, 0, 0), r0[1] = MAT(m, 0, 1), r0[2] = MAT(m, 0, 2),
333  r0[3] = MAT(m, 0, 3), r0[4] = 1.0, r0[5] = r0[6] = r0[7] = 0.0,
334  r1[0] = MAT(m, 1, 0), r1[1] = MAT(m, 1, 1), r1[2] = MAT(m, 1, 2),
335  r1[3] = MAT(m, 1, 3), r1[5] = 1.0, r1[4] = r1[6] = r1[7] = 0.0,
336  r2[0] = MAT(m, 2, 0), r2[1] = MAT(m, 2, 1), r2[2] = MAT(m, 2, 2),
337  r2[3] = MAT(m, 2, 3), r2[6] = 1.0, r2[4] = r2[5] = r2[7] = 0.0,
338  r3[0] = MAT(m, 3, 0), r3[1] = MAT(m, 3, 1), r3[2] = MAT(m, 3, 2),
339  r3[3] = MAT(m, 3, 3), r3[7] = 1.0, r3[4] = r3[5] = r3[6] = 0.0;
340 
341  // choose pivot - or die
342  if (std::abs(r3[0]) > std::abs(r2[0])) std::swap(r3, r2);
343  if (std::abs(r2[0]) > std::abs(r1[0])) std::swap(r2, r1);
344  if (std::abs(r1[0]) > std::abs(r0[0])) std::swap(r1, r0);
345  if (0.0 == r0[0]) return false;
346 
347  // eliminate first variable
348  m1 = r1[0] / r0[0];
349  m2 = r2[0] / r0[0];
350  m3 = r3[0] / r0[0];
351  s = r0[1];
352  r1[1] -= m1 * s;
353  r2[1] -= m2 * s;
354  r3[1] -= m3 * s;
355  s = r0[2];
356  r1[2] -= m1 * s;
357  r2[2] -= m2 * s;
358  r3[2] -= m3 * s;
359  s = r0[3];
360  r1[3] -= m1 * s;
361  r2[3] -= m2 * s;
362  r3[3] -= m3 * s;
363  s = r0[4];
364  if (s != 0.0) {
365  r1[4] -= m1 * s;
366  r2[4] -= m2 * s;
367  r3[4] -= m3 * s;
368  }
369  s = r0[5];
370  if (s != 0.0) {
371  r1[5] -= m1 * s;
372  r2[5] -= m2 * s;
373  r3[5] -= m3 * s;
374  }
375  s = r0[6];
376  if (s != 0.0) {
377  r1[6] -= m1 * s;
378  r2[6] -= m2 * s;
379  r3[6] -= m3 * s;
380  }
381  s = r0[7];
382  if (s != 0.0) {
383  r1[7] -= m1 * s;
384  r2[7] -= m2 * s;
385  r3[7] -= m3 * s;
386  }
387 
388  // choose pivot - or die
389  if (std::abs(r3[1]) > std::abs(r2[1])) std::swap(r3, r2);
390  if (std::abs(r2[1]) > std::abs(r1[1])) std::swap(r2, r1);
391  if (0.0 == r1[1]) return false;
392 
393  // eliminate second variable
394  m2 = r2[1] / r1[1];
395  m3 = r3[1] / r1[1];
396  r2[2] -= m2 * r1[2];
397  r3[2] -= m3 * r1[2];
398  r2[3] -= m2 * r1[3];
399  r3[3] -= m3 * r1[3];
400  s = r1[4];
401  if (0.0 != s) {
402  r2[4] -= m2 * s;
403  r3[4] -= m3 * s;
404  }
405  s = r1[5];
406  if (0.0 != s) {
407  r2[5] -= m2 * s;
408  r3[5] -= m3 * s;
409  }
410  s = r1[6];
411  if (0.0 != s) {
412  r2[6] -= m2 * s;
413  r3[6] -= m3 * s;
414  }
415  s = r1[7];
416  if (0.0 != s) {
417  r2[7] -= m2 * s;
418  r3[7] -= m3 * s;
419  }
420 
421  // choose pivot - or die
422  if (std::abs(r3[2]) > std::abs(r2[2])) std::swap(r3, r2);
423  if (0.0 == r2[2]) return false;
424 
425  // eliminate third variable
426  m3 = r3[2] / r2[2];
427  r3[3] -= m3 * r2[3], r3[4] -= m3 * r2[4], r3[5] -= m3 * r2[5],
428  r3[6] -= m3 * r2[6], r3[7] -= m3 * r2[7];
429 
430  // last check
431  if (0.0 == r3[3]) return false;
432 
433  s = 1.0 / r3[3]; // now back substitute row 3
434  r3[4] *= s;
435  r3[5] *= s;
436  r3[6] *= s;
437  r3[7] *= s;
438  m2 = r2[3]; // now back substitute row 2
439  s = 1.0 / r2[2];
440  r2[4] = s * (r2[4] - r3[4] * m2), r2[5] = s * (r2[5] - r3[5] * m2),
441  r2[6] = s * (r2[6] - r3[6] * m2), r2[7] = s * (r2[7] - r3[7] * m2);
442  m1 = r1[3];
443  r1[4] -= r3[4] * m1, r1[5] -= r3[5] * m1, r1[6] -= r3[6] * m1,
444  r1[7] -= r3[7] * m1;
445  m0 = r0[3];
446  r0[4] -= r3[4] * m0, r0[5] -= r3[5] * m0, r0[6] -= r3[6] * m0,
447  r0[7] -= r3[7] * m0;
448  m1 = r1[2]; // now back substitute row 1
449  s = 1.0 / r1[1];
450  r1[4] = s * (r1[4] - r2[4] * m1), r1[5] = s * (r1[5] - r2[5] * m1),
451  r1[6] = s * (r1[6] - r2[6] * m1), r1[7] = s * (r1[7] - r2[7] * m1);
452  m0 = r0[2];
453  r0[4] -= r2[4] * m0, r0[5] -= r2[5] * m0, r0[6] -= r2[6] * m0,
454  r0[7] -= r2[7] * m0;
455  m0 = r0[1]; // now back substitute row 0
456  s = 1.0 / r0[0];
457  r0[4] = s * (r0[4] - r1[4] * m0), r0[5] = s * (r0[5] - r1[5] * m0),
458  r0[6] = s * (r0[6] - r1[6] * m0), r0[7] = s * (r0[7] - r1[7] * m0);
459 
460  MAT(out, 0, 0) = r0[4];
461  MAT(out, 0, 1) = r0[5], MAT(out, 0, 2) = r0[6];
462  MAT(out, 0, 3) = r0[7], MAT(out, 1, 0) = r1[4];
463  MAT(out, 1, 1) = r1[5], MAT(out, 1, 2) = r1[6];
464  MAT(out, 1, 3) = r1[7], MAT(out, 2, 0) = r2[4];
465  MAT(out, 2, 1) = r2[5], MAT(out, 2, 2) = r2[6];
466  MAT(out, 2, 3) = r2[7], MAT(out, 3, 0) = r3[4];
467  MAT(out, 3, 1) = r3[5], MAT(out, 3, 2) = r3[6];
468  MAT(out, 3, 3) = r3[7];
469 
470  return true;
471  }
472 
473  template <typename iType, typename oType>
474  static bool Unproject(const Vector3Tpl<iType>& input2D,
475  const oType* modelview,
476  const oType* projection,
477  const int* viewport,
478  Vector3Tpl<oType>& output3D) {
479  if (GetInstance() && !GetPerspectiveState()) {
480  ToWorldPoint<iType, oType>(input2D, output3D);
481  return true;
482  }
483 
484  // compute projection x modelview
486  ccGLMatrixTpl<oType>(modelview);
488 
489  if (!InvertMatrix(A.data(), m.data())) {
490  return false;
491  }
492 
493  ccGLMatrixTpl<oType> mA = m * A;
494 
495  // Transformation of normalized coordinates between -1 and 1
496  Tuple4Tpl<oType> in;
497  in.x = static_cast<oType>(
498  (input2D.x - static_cast<iType>(viewport[0])) / viewport[2] *
499  2 -
500  1);
501  in.y = static_cast<oType>(
502  (input2D.y - static_cast<iType>(viewport[1])) / viewport[3] *
503  2 -
504  1);
505  in.z = static_cast<oType>(2 * input2D.z - 1);
506  in.w = 1;
507 
508  // Objects coordinates
509  Tuple4Tpl<oType> out = m * in;
510  if (out.w == 0) {
511  return false;
512  }
513 
514  output3D = Vector3Tpl<oType>(out.u) / out.w;
515 
516  return true;
517  }
518 
519  static void PickMatrix(double x,
520  double y,
521  double width,
522  double height,
523  int viewport[4],
524  double m[16]) {
525  double sx = viewport[2] / width;
526  double sy = viewport[3] / height;
527  double tx = (viewport[2] + 2.0 * (viewport[0] - x)) / width;
528  double ty = (viewport[3] + 2.0 * (viewport[1] - y)) / height;
529 
530  MAT(m, 0, 0) = sx;
531  MAT(m, 0, 1) = 0.0;
532  MAT(m, 0, 2) = 0.0;
533  MAT(m, 0, 3) = tx;
534  MAT(m, 1, 0) = 0.0;
535  MAT(m, 1, 1) = sy;
536  MAT(m, 1, 2) = 0.0;
537  MAT(m, 1, 3) = ty;
538  MAT(m, 2, 0) = 0.0;
539  MAT(m, 2, 1) = 0.0;
540  MAT(m, 2, 2) = 1.0;
541  MAT(m, 2, 3) = 0.0;
542  MAT(m, 3, 0) = 0.0;
543  MAT(m, 3, 1) = 0.0;
544  MAT(m, 3, 2) = 0.0;
545  MAT(m, 3, 3) = 1.0;
546  }
547 
548 protected:
551 };
552 
556  : perspective(false), fov_deg(0.0f), pixelSize(0.0f) {
557  memset(viewport, 0, 4 * sizeof(int));
558  }
559 
561  inline bool project(const CCVector3d& input3D,
562  CCVector3d& output2D,
563  bool* inFrustum = nullptr) const {
564  return ecvGenericDisplayTools::Project<double, double>(
565  input3D, modelViewMat.data(), projectionMat.data(), viewport,
566  output2D, inFrustum);
567  }
569  inline bool project(const CCVector3& input3D,
570  CCVector3d& output2D,
571  bool* inFrustum = nullptr) const {
572  return ecvGenericDisplayTools::Project<PointCoordinateType, double>(
573  input3D, modelViewMat.data(), projectionMat.data(), viewport,
574  output2D, inFrustum);
575  }
576 
578  inline bool unproject(const CCVector3d& input2D,
579  CCVector3d& output3D) const {
580  return ecvGenericDisplayTools::Unproject<double, double>(
581  input2D, modelViewMat.data(), projectionMat.data(), viewport,
582  output3D);
583  }
585  inline bool unproject(const CCVector3& input2D,
586  CCVector3d& output3D) const {
587  return ecvGenericDisplayTools::Unproject<PointCoordinateType, double>(
588  input2D, modelViewMat.data(), projectionMat.data(), viewport,
589  output3D);
590  }
591 
597  int viewport[4];
601  float fov_deg;
603  float pixelSize;
604 };
#define CV_DB_LIB_API
Definition: CV_db.h:15
int width
int height
Type y
Definition: CVGeom.h:137
Type * data()
Definition: CVGeom.h:145
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
4-Tuple structure (templated version)
Definition: CVGeom.h:648
Type x
Definition: CVGeom.h:653
Type y
Definition: CVGeom.h:653
Type w
Definition: CVGeom.h:653
Type z
Definition: CVGeom.h:653
3D Vector (templated version)
Definition: CVGeom.h:223
A 4x4 'transformation' matrix (column major order)
T * data()
Returns a pointer to internal data.
virtual void toIdentity()
Sets matrix to identity.
Double version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:56
Empty class - for classification purpose only.
Definition: CVToolbox.h:15
Generic display tools.
static bool InvertMatrix(const Type *m, Type *out)
static double MAT(const double *m, int r, int c)
static ccGLMatrixd Ortho(double left, double right, double bottom, double top, double nearVal, double farVal)
virtual void toDisplayPoint(const CCVector3d &input3D, CCVector3d &output2D)
static void ToWorldPoint(const Vector3Tpl< iType > &input2D, Vector3Tpl< oType > &output3D)
ecvGenericDisplayTools()
Default constructor.
static ccGLMatrixd Ortho(double w, double h, double d)
static int FontSizeModifier(int fontSize, float zoomFactor)
static float & MAT(float *m, int r, int c)
virtual void toWorldPoint(const CCVector3d &input2D, CCVector3d &output3D)
static ccGLMatrixd Perspective(double fovyInDegrees, double aspectRatio, double znear, double zfar)
static void PickMatrix(double x, double y, double width, double height, int viewport[4], double m[16])
static ccGLMatrixd Frustum(double left, double right, double bottom, double top, double znear, double zfar)
static double & MAT(double *m, int r, int c)
virtual void toDisplayPoint(const CCVector3 &input3D, CCVector3d &output2D)
virtual void toWorldPoint(const CCVector3 &input2D, CCVector3d &output3D)
static bool Project(const Vector3Tpl< iType > &input3D, const oType *modelview, const oType *projection, const int *viewport, Vector3Tpl< oType > &output2D, bool *inFrustum=nullptr)
static void ToDisplayPoint(const Vector3Tpl< iType > &input3D, Vector3Tpl< oType > &output2D)
static float MAT(const float *m, int r, int c)
static bool GetPerspectiveState()
Returns perspective mode.
static ecvGenericDisplayTools * GetInstance()
static bool Unproject(const Vector3Tpl< iType > &input2D, const oType *modelview, const oType *projection, const int *viewport, Vector3Tpl< oType > &output3D)
static void SetInstance(ecvGenericDisplayTools *tool)
virtual ~ecvGenericDisplayTools()
Default destructor.
virtual bool getPerspectiveState(int viewport=0) const
__host__ __device__ int2 abs(int2 v)
Definition: cutil_math.h:1267
ccGuiPythonInstance * GetInstance() noexcept
Definition: Runtime.cpp:72
MiniVec< float, N > floor(const MiniVec< float, N > &a)
Definition: MiniVec.h:75
float DegreesToRadians(int degrees)
Convert degrees to radians.
Definition: CVMath.h:98
void swap(cloudViewer::core::SmallVectorImpl< T > &LHS, cloudViewer::core::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Definition: SmallVector.h:1370
OpenGL camera parameters.
float fov_deg
F.O.V. (in degrees) - perspective mode only.
ccGLMatrixd projectionMat
Projection matrix (GL_PROJECTION)
ccGLMatrixd modelViewMat
Model view matrix (GL_MODELVIEW)
bool unproject(const CCVector3d &input2D, CCVector3d &output3D) const
Unprojects a 2D point (+ normalized 'z' coordinate) in 3D.
float pixelSize
Pixel size (i.e. zoom) - non perspective mode only.
bool perspective
Perspective mode.
bool project(const CCVector3d &input3D, CCVector3d &output2D, bool *inFrustum=nullptr) const
Projects a 3D point in 2D (+ normalized 'z' coordinate)
bool unproject(const CCVector3 &input2D, CCVector3d &output3D) const
Unprojects a 2D point (+ normalized 'z' coordinate) in 3D.
bool project(const CCVector3 &input3D, CCVector3d &output2D, bool *inFrustum=nullptr) const
Projects a 3D point in 2D (+ normalized 'z' coordinate)