ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvClipBox.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 "ecvClipBox.h"
9 
10 #include "ecvCone.h"
11 #include "ecvCylinder.h"
12 #include "ecvDisplayTools.h"
13 #include "ecvHObjectCaster.h"
14 #include "ecvSphere.h"
15 #include "ecvTorus.h"
16 
17 // system
18 #include <cassert>
19 
20 // Components geometry
21 static QSharedPointer<ccCylinder> c_arrowShaft(nullptr);
22 static QSharedPointer<ccCone> c_arrowHead(nullptr);
23 static QSharedPointer<ccSphere> c_centralSphere(nullptr);
24 static QSharedPointer<ccTorus> c_torus(nullptr);
25 
26 void DrawUnitArrow(int ID,
27  const CCVector3& start,
28  const CCVector3& direction,
29  PointCoordinateType scale,
30  const ecvColor::Rgb& col,
32  // ccGL::Translate(glFunc, start.x, start.y, start.z);
33  context.transformInfo.setTranslationStart(start);
34  // ccGL::Scale(glFunc, scale, scale, scale);
35  context.transformInfo.setScale(CCVector3(scale, scale, scale));
36 
37  // we compute scalar prod between the two vectors
38  CCVector3 Z(0.0, 0.0, 1.0);
39  PointCoordinateType ps = Z.dot(direction);
40 
41  CCVector3 axis(1, 0, 0);
42  PointCoordinateType angle_deg = static_cast<PointCoordinateType>(180.0);
43  if (ps < 1) {
44  if (ps > -1) {
45  // we deduce angle from scalar prod
46  angle_deg = static_cast<PointCoordinateType>(
48 
49  // we compute rotation axis with scalar prod
50  axis = Z.cross(direction);
51  }
52 
53  // ccGL::Rotate(glFunc,angle_deg, axis.x, axis.y, axis.z);
54  context.transformInfo.setRotation(angle_deg, axis.x, axis.y, axis.z);
55  } else {
56  // we deduce angle from scalar prod
57  angle_deg = static_cast<PointCoordinateType>(
59 
60  // we compute rotation axis with scalar prod
61  axis = Z.cross(direction);
62 
63  // ccGL::Rotate(glFunc,angle_deg, axis.x, axis.y, axis.z);
64  context.transformInfo.setRotation(angle_deg, axis.x, axis.y, axis.z);
65  }
66 
67  if (!c_arrowShaft)
68  c_arrowShaft = QSharedPointer<ccCylinder>(
69  new ccCylinder(0.15f, 0.6f, nullptr, "ArrowShaft", 12));
70  if (!c_arrowHead)
71  c_arrowHead = QSharedPointer<ccCone>(
72  new ccCone(0.3f, 0, 0.4f, 0, 0, nullptr, "ArrowHead", 24));
73 
74  // glFunc->glTranslatef(0,0,0.3f);
75  // context.transformInfo.setTranslationEnd(CCVector3(0,0,0.3f));
76 
77  CCVector3 dir = direction;
78  if (ID >= ccClipBox::CROSS * 10) {
79  context.transformInfo.setTranslationEnd(0.3f * 0.5f * dir);
80  } else {
81  context.transformInfo.setTranslationEnd(0.3f * dir);
82  }
83  context.viewID = QString::number(ID, 10) + "-arrowShaft";
84  c_arrowShaft->setTempColor(col);
85  c_arrowShaft->setFixedId(true);
86  c_arrowShaft->draw(context);
87  // glFunc->glTranslatef(0,0,0.3f+0.2f);
88  // context.transformInfo.setTranslationEnd(CCVector3(0, 0, 0.3f+0.2f));
89 
90  if (ID >= ccClipBox::CROSS * 10) {
91  context.transformInfo.setTranslationEnd((0.3f + 0.2f) * 0.5f * dir);
92  } else {
93  context.transformInfo.setTranslationEnd((0.3f + 0.2f) * dir);
94  }
95 
96  context.viewID = QString::number(ID, 10) + "-arrowHead";
97  c_arrowHead->setTempColor(col);
98  c_arrowHead->setFixedId(true);
99  c_arrowHead->draw(context);
100 }
101 
102 static void DrawUnitTorus(int ID,
103  const CCVector3& center,
104  const CCVector3& direction,
105  PointCoordinateType scale,
106  const ecvColor::Rgb& col,
108  // if (ID > 0)
109  // glFunc->glLoadName(ID);
110  //
111  // glFunc->glMatrixMode(GL_MODELVIEW);
112  // glFunc->glPushMatrix();
113 
114  // ccGL::Translate(glFunc, center.x, center.y, center.z);
115  context.transformInfo.setTranslationStart(center);
116  // ccGL::Scale(glFunc, scale, scale, scale);
117  context.transformInfo.setScale(CCVector3(scale, scale, scale));
118 
119  // we compute scalar prod between the two vectors
120  CCVector3 Z(0, 0, 1);
121  PointCoordinateType ps = Z.dot(direction);
122 
123  CCVector3 axis(1, 0, 0);
124  PointCoordinateType angle_deg = 180;
125  if (ps < 1) {
126  if (ps > -1) {
127  // we deduce angle from scalar prod
128  angle_deg = static_cast<PointCoordinateType>(
130 
131  // we compute rotation axis with scalar prod
132  axis = Z.cross(direction);
133  }
134 
135  // ccGL::Rotate(glFunc, angle_deg, axis.x, axis.y, axis.z);
136  context.transformInfo.setRotation(angle_deg, axis.x, axis.y, axis.z);
137  } else {
138  // we deduce angle from scalar prod
139  angle_deg = static_cast<PointCoordinateType>(
141 
142  // we compute rotation axis with scalar prod
143  axis = Z.cross(direction);
144  // ccGL::Rotate(glFunc, angle_deg, axis.x, axis.y, axis.z);
145  context.transformInfo.setRotation(angle_deg, axis.x, axis.y, axis.z);
146  }
147 
148  if (!c_torus)
149  c_torus = QSharedPointer<ccTorus>(new ccTorus(
150  0.2f, 0.4f, 2.0 * M_PI, false, 0, nullptr, "Torus", 12));
151 
152  CCVector3 dir = direction;
153 
154  // glFunc->glTranslatef(0,0,0.3f);
155  // context.transformInfo.setTranslationEnd(CCVector3(0, 0, 0.3f));
156  context.transformInfo.setTranslationEnd(0.3f * dir);
157  context.viewID = QString::number(ID, 10) + "-torus";
158  c_torus->setTempColor(col);
159  c_torus->setFixedId(true);
160  c_torus->draw(context);
161 }
162 
163 // Unused function
164 // static void DrawUnitSphere(int ID, const CCVector3& center,
165 // PointCoordinateType radius, const ecvColor::Rgb& col, CC_DRAW_CONTEXT&
166 // context)
167 //{
168 // //get the set of OpenGL functions (version 2.1)
169 // QOpenGLFunctions_2_1 *glFunc =
170 // context.glFunctions<QOpenGLFunctions_2_1>(); assert(glFunc !=
171 // nullptr);
172 //
173 // if (glFunc == nullptr)
174 // return;
175 //
176 // if (ID > 0)
177 // glFunc->glLoadName(ID);
178 //
179 // glFunc->glMatrixMode(GL_MODELVIEW);
180 // glFunc->glPushMatrix();
181 //
182 // ccGL::Translate(glFunc, center.x, center.y, center.z);
183 // ccGL::Scale(glFunc, radius, radius, radius);
184 //
185 // if (!c_centralSphere)
186 // c_centralSphere = QSharedPointer<ccSphere>(new ccSphere(1, 0,
187 //"CentralSphere", 24));
188 //
189 // c_centralSphere->setTempColor(col);
190 // c_centralSphere->draw(context);
191 //
192 // glFunc->glPopMatrix();
193 // }
194 
195 static void DrawUnitCross(int ID,
196  const CCVector3& center,
197  PointCoordinateType scale,
198  const ecvColor::Rgb& col,
200  // if (glFunc == nullptr)
201  // return;
202 
203  // if (ID > 0)
204  // glFunc->glLoadName(ID);
205 
206  scale /= 2;
207  DrawUnitArrow(10 * ID, center, CCVector3(-1, 0, 0), scale, col, context);
208  DrawUnitArrow(10 * ID + 1, center, CCVector3(1, 0, 0), scale, col, context);
209  DrawUnitArrow(10 * ID + 2, center, CCVector3(0, -1, 0), scale, col,
210  context);
211  DrawUnitArrow(10 * ID + 3, center, CCVector3(0, 1, 0), scale, col, context);
212  DrawUnitArrow(10 * ID + 4, center, CCVector3(0, 0, -1), scale, col,
213  context);
214  DrawUnitArrow(10 * ID + 5, center, CCVector3(0, 0, 1), scale, col, context);
215 }
216 
217 ccClipBox::ccClipBox(QString name /*= QString("clipping box")*/)
218  : ccHObject(name),
219  m_entityContainer("entities"),
220  m_showBox(true),
221  m_activeComponent(NONE) {
223 }
224 
226 
229  return;
230  }
231 
232  // remove any existing clipping plane
233  {
234  for (unsigned ci = 0; ci < m_entityContainer.getChildrenNumber();
235  ++ci) {
237  }
238  }
239 
240  // now add the 6 box clipping planes
241  ccBBox extents;
242  ccGLMatrix transformation;
243  get(extents, transformation);
244 
245  CCVector3 C = transformation * extents.getCenter();
246  CCVector3 halfDim = extents.getDiagVec() / 2;
247 
248  // for each dimension
249  for (unsigned d = 0; d < 3; ++d) {
250  CCVector3 N = transformation.getColumnAsVec3D(d);
251  // positive side
252  {
253  ccClipPlane posPlane;
254  posPlane.equation.x = N.x;
255  posPlane.equation.y = N.y;
256  posPlane.equation.z = N.z;
257 
258  // compute the 'constant' coefficient knowing that P belongs to the
259  // plane if (P - (C - half_dim * N)).N = 0
260  posPlane.equation.w = -static_cast<double>(C.dot(N)) + halfDim.u[d];
261  for (unsigned ci = 0; ci < m_entityContainer.getChildrenNumber();
262  ++ci) {
264  }
265  }
266 
267  // negative side
268  {
269  ccClipPlane negPlane;
270  negPlane.equation.x = -N.x;
271  negPlane.equation.y = -N.y;
272  negPlane.equation.z = -N.z;
273 
274  // compute the 'constant' coefficient knowing that P belongs to the
275  // plane if (P - (C + half_dim * N)).N = 0 negPlane.equation.w =
276  // -(static_cast<double>(C.dot(N)) + halfDim.u[d]);
277  negPlane.equation.w = static_cast<double>(C.dot(N)) + halfDim.u[d];
278  for (unsigned ci = 0; ci < m_entityContainer.getChildrenNumber();
279  ++ci) {
281  }
282  }
283  }
284 }
285 
287  m_box.clear();
289 
292  }
293 
294  update();
295 
296  // send 'modified' signal
297  emit boxModified(&m_box);
298 }
299 
300 void ccClipBox::set(const ccBBox& extents, const ccGLMatrix& transformation) {
301  m_box = extents;
302  setGLTransformation(transformation);
303 
304  update();
305 
306  // send 'modified' signal
307  emit boxModified(&m_box);
308 }
309 
310 void ccClipBox::get(ccBBox& extents, ccGLMatrix& transformation) {
311  extents = m_box;
312 
313  if (isGLTransEnabled()) {
314  transformation = m_glTrans;
315  } else {
316  transformation.toIdentity();
317  }
318 }
319 
321  QStringList removeViewIds;
322  getInteractorIds(removeViewIds);
323 
325 }
326 
327 void ccClipBox::hideShowAllInterators(bool visibility) {
328  QStringList removeViewIds;
329  getInteractorIds(removeViewIds);
330 
332  visibility);
333 }
334 
335 void ccClipBox::getInteractorIds(QStringList& removeViewIds) {
336  removeViewIds.clear();
337  removeViewIds.push_back(QString::number(X_MINUS_ARROW, 10) + "-arrowShaft");
338  removeViewIds.push_back(QString::number(X_MINUS_ARROW, 10) + "-arrowHead");
339  removeViewIds.push_back(QString::number(X_PLUS_ARROW, 10) + "-arrowShaft");
340  removeViewIds.push_back(QString::number(X_PLUS_ARROW, 10) + "-arrowHead");
341  removeViewIds.push_back(QString::number(Y_MINUS_ARROW, 10) + "-arrowShaft");
342  removeViewIds.push_back(QString::number(Y_MINUS_ARROW, 10) + "-arrowHead");
343  removeViewIds.push_back(QString::number(Y_PLUS_ARROW, 10) + "-arrowShaft");
344  removeViewIds.push_back(QString::number(Y_PLUS_ARROW, 10) + "-arrowHead");
345  removeViewIds.push_back(QString::number(Z_MINUS_ARROW, 10) + "-arrowShaft");
346  removeViewIds.push_back(QString::number(Z_MINUS_ARROW, 10) + "-arrowHead");
347  removeViewIds.push_back(QString::number(Z_PLUS_ARROW, 10) + "-arrowShaft");
348  removeViewIds.push_back(QString::number(Z_PLUS_ARROW, 10) + "-arrowHead");
349 
350  for (int i = CROSS * 10; i < CROSS * 10 + 6; ++i) {
351  removeViewIds.push_back(QString::number(i, 10) + "-arrowShaft");
352  removeViewIds.push_back(QString::number(i, 10) + "-arrowHead");
353  }
354 
355  removeViewIds.push_back(QString::number(X_MINUS_TORUS, 10) + "-torus");
356  removeViewIds.push_back(QString::number(Y_MINUS_TORUS, 10) + "-torus");
357  removeViewIds.push_back(QString::number(Z_MINUS_TORUS, 10) + "-torus");
358  removeViewIds.push_back(QString::number(X_PLUS_TORUS, 10) + "-torus");
359  removeViewIds.push_back(QString::number(Y_PLUS_TORUS, 10) + "-torus");
360  removeViewIds.push_back(QString::number(Z_PLUS_TORUS, 10) + "-torus");
361 }
362 
364  for (unsigned ci = 0; ci < m_entityContainer.getChildrenNumber(); ++ci) {
366  }
369 }
370 
372  m_entityContainer.addChild(entity, DP_NONE); // no dependency!
373 
374  // no need to reset the clipping box if the entity has not a valid
375  // bounding-box
376  if (entity->getBB_recursive().isValid()) {
377  reset();
378  }
379 
380  return true;
381 }
382 
384  switch (id) {
385  case 1:
387  break;
388  case 2:
390  break;
391  case 3:
393  break;
394  case 4:
396  break;
397  case 5:
399  break;
400  case 6:
402  break;
403  case 7:
405  break;
406  case 8:
408  break;
409  case 9:
411  break;
412  case 10:
414  break;
415  case 11:
417  break;
418  case 12:
420  break;
421  case 13:
423  break;
424  case 14:
426  break;
427  default:
429  }
430 }
431 
433  int y,
434  int screenWidth,
435  int screenHeight) {
436  // convert mouse position to vector (screen-centered)
437  CCVector3d v(static_cast<double>(2 * std::max(std::min(x, screenWidth - 1),
438  -screenWidth + 1) -
439  screenWidth) /
440  static_cast<double>(screenWidth),
441  static_cast<double>(screenHeight -
442  2 * std::max(std::min(y, screenHeight - 1),
443  -screenHeight + 1)) /
444  static_cast<double>(screenHeight),
445  0);
446 
447  // square 'radius'
448  double d2 = v.x * v.x + v.y * v.y;
449 
450  // projection on the unit sphere
451  if (d2 > 1) {
452  double d = sqrt(d2);
453  v.x /= d;
454  v.y /= d;
455  } else {
456  v.z = sqrt(1 - d2);
457  }
458 
459  return v;
460 }
461 
463  int x, int y, int dx, int dy, int screenWidth, int screenHeight) {
464  if (m_activeComponent != SPHERE || !m_box.isValid()) return false;
465 
466  // convert mouse position to vector (screen-centered)
467  CCVector3d currentOrientation =
468  PointToVector(x, y, screenWidth, screenHeight);
469 
470  ccGLMatrixd rotMat =
471  ccGLMatrixd::FromToRotation(m_lastOrientation, currentOrientation);
472 
473  CCVector3 C = m_box.getCenter();
474 
475  ccGLMatrixd transMat;
476  transMat.setTranslation(-C);
477  transMat = rotMat * transMat;
478  transMat.setTranslation(transMat.getTranslationAsVec3D() +
480 
481  // rotateGL(transMat);
482  m_glTrans = ccGLMatrix(transMat.inverse().data()) * m_glTrans;
484 
485  m_lastOrientation = currentOrientation;
486 
487  update();
488 
489  return true;
490 }
491 
493  int y,
494  int screenWidth,
495  int screenHeight,
496  const ccGLMatrixd& viewMatrix) {
497  m_lastOrientation = PointToVector(x, y, screenWidth, screenHeight);
498  m_viewMatrix = viewMatrix;
499 }
500 
501 bool ccClipBox::move3D(const CCVector3d& uInput) {
502  if (m_activeComponent == NONE || !m_box.isValid()) return false;
503 
504  CCVector3d u = uInput;
505 
506  // Arrows
509 
510  switch (m_activeComponent) {
511  case X_MINUS_ARROW:
512  m_box.minCorner().x += static_cast<PointCoordinateType>(u.x);
513  if (m_box.minCorner().x > m_box.maxCorner().x)
515  break;
516  case X_PLUS_ARROW:
517  m_box.maxCorner().x += static_cast<PointCoordinateType>(u.x);
518  if (m_box.minCorner().x > m_box.maxCorner().x)
520  break;
521  case Y_MINUS_ARROW:
522  m_box.minCorner().y += static_cast<PointCoordinateType>(u.y);
523  if (m_box.minCorner().y > m_box.maxCorner().y)
525  break;
526  case Y_PLUS_ARROW:
527  m_box.maxCorner().y += static_cast<PointCoordinateType>(u.y);
528  if (m_box.minCorner().y > m_box.maxCorner().y)
530  break;
531  case Z_MINUS_ARROW:
532  m_box.minCorner().z += static_cast<PointCoordinateType>(u.z);
533  if (m_box.minCorner().z > m_box.maxCorner().z)
535  break;
536  case Z_PLUS_ARROW:
537  m_box.maxCorner().z += static_cast<PointCoordinateType>(u.z);
538  if (m_box.minCorner().z > m_box.maxCorner().z)
540  break;
541  case CROSS: {
543  } break;
544  default:
545  assert(false);
546  return false;
547  }
548 
549  // send 'modified' signal
550  emit boxModified(&m_box);
551  } else if (m_activeComponent == SPHERE) {
552  // handled by move2D!
553  return false;
554  } else if (m_activeComponent >= X_MINUS_TORUS &&
556  // we guess the rotation order by comparing the current screen 'normal'
557  // and the vector prod of u and the current rotation axis
558  CCVector3d Rb(0, 0, 0);
559  switch (m_activeComponent) {
560  case X_MINUS_TORUS:
561  Rb.x = -1;
562  break;
563  case X_PLUS_TORUS:
564  Rb.x = 1;
565  break;
566  case Y_MINUS_TORUS:
567  Rb.y = -1;
568  break;
569  case Y_PLUS_TORUS:
570  Rb.y = 1;
571  break;
572  case Z_MINUS_TORUS:
573  Rb.z = -1;
574  break;
575  case Z_PLUS_TORUS:
576  Rb.z = 1;
577  break;
578  default:
579  assert(false);
580  return false;
581  }
582 
583  CCVector3d R = Rb;
584  if (m_glTransEnabled) {
586  }
587 
588  CCVector3d RxU = R.cross(u);
589 
590  // look for the most parallel dimension
591  double maxDot = m_viewMatrix.getColumnAsVec3D(0).dot(RxU);
592  for (int i = 1; i < 3; ++i) {
593  double dot = m_viewMatrix.getColumnAsVec3D(i).dot(RxU);
594  if (fabs(dot) > fabs(maxDot)) {
595  maxDot = dot;
596  }
597  }
598 
599  // angle is proportional to absolute displacement
600  double angle_rad = u.norm() / m_box.getDiagNorm() * M_PI;
601  if (maxDot < 0.0) angle_rad = -angle_rad;
602 
603  ccGLMatrixd rotMat;
604  rotMat.initFromParameters(angle_rad, Rb, CCVector3d(0, 0, 0));
605 
606  CCVector3 C = m_box.getCenter();
607  ccGLMatrixd transMat;
608  transMat.setTranslation(-C);
609  transMat = rotMat * transMat;
610  transMat.setTranslation(transMat.getTranslationAsVec3D() +
612 
613  m_glTrans = m_glTrans * ccGLMatrix(transMat.inverse().data());
615  } else {
616  assert(false);
617  return false;
618  }
619 
620  update();
621 
622  return true;
623 }
624 
625 void ccClipBox::setBox(const ccBBox& box) {
626  m_box = box;
627 
628  update();
629 
630  // send 'modified' signal
631  emit boxModified(&m_box);
632 }
633 
634 void ccClipBox::shift(const CCVector3& v) {
635  m_box.minCorner() += v;
636  m_box.maxCorner() += v;
637 
638  update();
639 
640  // send 'modified' signal
641  emit boxModified(&m_box);
642 }
643 
645  ccGenericPointCloud* cloud,
647  bool shrink /*=false*/) const {
648  if (!cloud || !visTable) {
649  // invalid input
650  assert(false);
651  return;
652  }
653  if (cloud->size() != visTable->size()) {
655  assert(false);
656  return;
657  }
658 
659  int count = static_cast<int>(cloud->size());
660 
661  if (m_glTransEnabled) {
662  ccGLMatrix transMat = m_glTrans.inverse();
663 
664 #if defined(_OPENMP)
665 #pragma omp parallel for
666 #endif
667  for (int i = 0; i < count; ++i) {
668  if (!shrink || visTable->at(i) == POINT_VISIBLE) {
669  CCVector3 P = *cloud->getPoint(static_cast<unsigned>(i));
670  transMat.apply(P);
671  visTable->at(i) =
673  }
674  }
675  } else {
676 #if defined(_OPENMP)
677 #pragma omp parallel for
678 #endif
679  for (int i = 0; i < count; ++i) {
680  if (!shrink || visTable->at(i) == POINT_VISIBLE) {
681  const CCVector3* P = cloud->getPoint(static_cast<unsigned>(i));
682  visTable->at(i) =
684  }
685  }
686  }
687 }
688 
689 ccBBox ccClipBox::getOwnBB(bool withGLFeatures /*=false*/) {
690  ccBBox bbox = m_box;
691 
692  if (withGLFeatures) {
694  bbox.minCorner() -= CCVector3(scale, scale, scale);
695  bbox.maxCorner() += CCVector3(scale, scale, scale);
696  }
697 
698  return bbox;
699 }
700 
702  PointCoordinateType scale = m_box.getDiagNorm() / 10;
703 
705  scale = std::max<PointCoordinateType>(scale,
706  getBox().getDiagNorm() / 25);
707  }
708 
709  return scale;
710 }
711 
716 
718  if (!MACRO_Draw3D(context)) return;
719 
720  if (!m_box.isValid()) return;
721 
722  if (m_showBox) {
723  // m_box.draw(m_selected ? context.bbDefaultCol : ecvColor::magenta);
724  context.viewID = this->getViewId();
727  } else {
728  context.viewID = this->getViewId();
730  context.removeViewID = QString("BBox-") + context.viewID;
732  }
733 
734  if (!m_selected) {
735  // nothing to show
736  hideShowAllInterators(false);
737  return;
738  }
739 
740  // standard case: list names pushing (1st level)
741  bool entityPickingMode = MACRO_EntityPicking(context);
742 
743  // draw the interactors
744  {
745  const CCVector3& minC = m_box.minCorner();
746  const CCVector3& maxC = m_box.maxCorner();
747  const CCVector3 center = m_box.getCenter();
748 
750 
751  // custom arrow 'context'
752  CC_DRAW_CONTEXT componentContext = context;
753  // we must remove the 'push name flag' so that the arows don't push
754  // their own!
755  componentContext.drawingFlags &= (~CC_ENTITY_PICKING);
756 
757  entityPickingMode = true;
758  DrawUnitArrow(X_MINUS_ARROW * entityPickingMode,
759  CCVector3(minC.x, center.y, center.z),
760  CCVector3(-1.0, 0.0, 0.0), scale, ecvColor::red,
761  componentContext);
762  DrawUnitArrow(X_PLUS_ARROW * entityPickingMode,
763  CCVector3(maxC.x, center.y, center.z),
764  CCVector3(1.0, 0.0, 0.0), scale, ecvColor::red,
765  componentContext);
766  DrawUnitArrow(Y_MINUS_ARROW * entityPickingMode,
767  CCVector3(center.x, minC.y, center.z),
768  CCVector3(0.0, -1.0, 0.0), scale, ecvColor::green,
769  componentContext);
770  DrawUnitArrow(Y_PLUS_ARROW * entityPickingMode,
771  CCVector3(center.x, maxC.y, center.z),
772  CCVector3(0.0, 1.0, 0.0), scale, ecvColor::green,
773  componentContext);
774  DrawUnitArrow(Z_MINUS_ARROW * entityPickingMode,
775  CCVector3(center.x, center.y, minC.z),
776  CCVector3(0.0, 0.0, -1.0), scale, ecvColor::blue,
777  componentContext);
778  DrawUnitArrow(Z_PLUS_ARROW * entityPickingMode,
779  CCVector3(center.x, center.y, maxC.z),
780  CCVector3(0.0, 0.0, 1.0), scale, ecvColor::blue,
781  componentContext);
782  DrawUnitCross(CROSS * entityPickingMode,
783  minC - CCVector3(scale, scale, scale) / 2.0, scale,
784  ecvColor::yellow, componentContext);
785  // DrawUnitSphere(SPHERE*entityPickingMode, maxC + CCVector3(scale,
786  // scale, scale) / 2.0, scale / 2.0, ecvColor::yellow,
787  // componentContext);
788  DrawUnitTorus(X_MINUS_TORUS * entityPickingMode,
789  CCVector3(minC.x, center.y, center.z),
790  CCVector3(-1.0, 0.0, 0.0), scale, c_lightRed,
791  componentContext);
792  DrawUnitTorus(Y_MINUS_TORUS * entityPickingMode,
793  CCVector3(center.x, minC.y, center.z),
794  CCVector3(0.0, -1.0, 0.0), scale, c_lightGreen,
795  componentContext);
796  DrawUnitTorus(Z_MINUS_TORUS * entityPickingMode,
797  CCVector3(center.x, center.y, minC.z),
798  CCVector3(0.0, 0.0, -1.0), scale, c_lightBlue,
799  componentContext);
800  DrawUnitTorus(X_PLUS_TORUS * entityPickingMode,
801  CCVector3(maxC.x, center.y, center.z),
802  CCVector3(1.0, 0.0, 0.0), scale, c_lightRed,
803  componentContext);
804  DrawUnitTorus(Y_PLUS_TORUS * entityPickingMode,
805  CCVector3(center.x, maxC.y, center.z),
806  CCVector3(0.0, 1.0, 0.0), scale, c_lightGreen,
807  componentContext);
808  DrawUnitTorus(Z_PLUS_TORUS * entityPickingMode,
809  CCVector3(center.x, center.y, maxC.z),
810  CCVector3(0.0, 0.0, 1.0), scale, c_lightBlue,
811  componentContext);
812  }
813 }
constexpr unsigned char POINT_VISIBLE
Definition: CVConst.h:92
constexpr unsigned char POINT_HIDDEN
Definition: CVConst.h:94
constexpr double M_PI
Pi.
Definition: CVConst.h:19
Vector3Tpl< double > CCVector3d
Double 3D Vector.
Definition: CVGeom.h:804
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
Definition: CVGeom.h:798
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
std::string name
int count
Type y
Definition: CVGeom.h:137
Type u[3]
Definition: CVGeom.h:139
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:653
Type y
Definition: CVGeom.h:653
Type w
Definition: CVGeom.h:653
Type z
Definition: CVGeom.h:653
Type dot(const Vector3Tpl &v) const
Dot product.
Definition: CVGeom.h:408
Type norm() const
Returns vector norm.
Definition: CVGeom.h:424
Vector3Tpl cross(const Vector3Tpl &v) const
Cross product.
Definition: CVGeom.h:412
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Definition: CVGeom.h:268
Bounding box structure.
Definition: ecvBBox.h:25
void draw(CC_DRAW_CONTEXT &context) override
Draws entity and its children.
Definition: ecvBBox.cpp:68
void shift(const CCVector3 &v)
Shifts the current box.
Definition: ecvClipBox.cpp:634
@ Y_PLUS_TORUS
Definition: ecvClipBox.h:72
@ X_MINUS_ARROW
Definition: ecvClipBox.h:60
@ Z_MINUS_TORUS
Definition: ecvClipBox.h:70
@ Y_MINUS_ARROW
Definition: ecvClipBox.h:62
@ Z_PLUS_ARROW
Definition: ecvClipBox.h:65
@ Y_MINUS_TORUS
Definition: ecvClipBox.h:69
@ X_PLUS_TORUS
Definition: ecvClipBox.h:71
@ Z_PLUS_TORUS
Definition: ecvClipBox.h:73
@ X_PLUS_ARROW
Definition: ecvClipBox.h:61
@ Z_MINUS_ARROW
Definition: ecvClipBox.h:64
@ X_MINUS_TORUS
Definition: ecvClipBox.h:68
@ Y_PLUS_ARROW
Definition: ecvClipBox.h:63
void getInteractorIds(QStringList &removeViewIds)
Definition: ecvClipBox.cpp:335
void flagPointsInside(ccGenericPointCloud *cloud, ccGenericPointCloud::VisibilityTableType *visTable, bool shrink=false) const
Definition: ecvClipBox.cpp:644
const ccBBox & getBox() const
Returns the box extents.
Definition: ecvClipBox.h:87
bool addAssociatedEntity(ccHObject *associatedEntity)
Adds an associated entity.
Definition: ecvClipBox.cpp:371
void reset()
Resets box.
Definition: ecvClipBox.cpp:286
void setClickedPoint(int x, int y, int screenWidth, int screenHeight, const ccGLMatrixd &viewMatrix)
Sets last clicked point (on screen)
Definition: ecvClipBox.cpp:492
void update()
Updates the associated entity clipping planes.
Definition: ecvClipBox.cpp:227
ccGLMatrixd m_viewMatrix
View matrix.
Definition: ecvClipBox.h:157
ccHObject m_entityContainer
Associated entities container.
Definition: ecvClipBox.h:142
ccClipBox(QString name=QString("Clipping box"))
Default constructor.
Definition: ecvClipBox.cpp:217
bool move2D(int x, int y, int dx, int dy, int screenWidth, int screenHeight) override
Called on mouse move (for 2D interactors)
Definition: ecvClipBox.cpp:462
PointCoordinateType computeArrowsScale()
Computes arrows display scale.
Definition: ecvClipBox.cpp:701
void set(const ccBBox &extents, const ccGLMatrix &transformation)
Manually sets the box parameters.
Definition: ecvClipBox.cpp:300
CCVector3d m_lastOrientation
Last "orientation" vector (corresponding to last clicked point)
Definition: ecvClipBox.h:154
void boxModified(const ccBBox *box)
Signal sent each time the box is modified.
void releaseAssociatedEntities()
Releases all associated entities.
Definition: ecvClipBox.cpp:363
ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
Definition: ecvClipBox.cpp:689
ccBBox m_box
Clipping box.
Definition: ecvClipBox.h:145
void setBox(const ccBBox &box)
Sets the box extents.
Definition: ecvClipBox.cpp:625
Components m_activeComponent
Active component.
Definition: ecvClipBox.h:151
bool m_showBox
Show box.
Definition: ecvClipBox.h:148
~ccClipBox() override
Destructor.
Definition: ecvClipBox.cpp:225
void releaseAllInterators()
Definition: ecvClipBox.cpp:320
void get(ccBBox &extents, ccGLMatrix &transformation)
Returns the box parameters.
Definition: ecvClipBox.cpp:310
void drawMeOnly(CC_DRAW_CONTEXT &context) override
Draws the entity only (not its children)
Definition: ecvClipBox.cpp:717
bool move3D(const CCVector3d &u) override
Called on mouse move (for 3D interactors)
Definition: ecvClipBox.cpp:501
void setActiveComponent(int id)
Sets currently active component.
Definition: ecvClipBox.cpp:383
void hideShowAllInterators(bool visibility)
Definition: ecvClipBox.cpp:327
Cone (primitive)
Definition: ecvCone.h:16
Cylinder (primitive)
Definition: ecvCylinder.h:16
virtual void setGLTransformation(const ccGLMatrix &trans)
Associates entity with a GL transformation (rotation + translation)
virtual bool addClipPlanes(const ccClipPlane &plane)
Registers a new clipping plane.
virtual bool isGLTransEnabled() const
Returns whether a GL transformation is enabled or not.
bool m_glTransEnabled
Current GL transformation activation state.
ccGLMatrix m_glTrans
Current GL transformation.
bool m_selected
Specifies whether the object is selected or not.
virtual void removeAllClipPlanes()
Removes all clipping planes (if any)
virtual void enableGLTransformation(bool state)
Enables/disables associated GL transformation.
virtual void resetGLTransformation()
Resets associated GL transformation.
Vector3Tpl< T > getTranslationAsVec3D() const
Returns a copy of the translation as a CCVector3.
void applyRotation(Vector3Tpl< float > &vec) const
Applies rotation only to a 3D vector (in place) - float version.
static ccGLMatrixTpl< double > FromToRotation(const Vector3Tpl< double > &from, const Vector3Tpl< double > &to)
Creates a transformation matrix that rotates a vector to another.
T * data()
Returns a pointer to internal data.
ccGLMatrixTpl< T > inverse() const
Returns inverse transformation.
void apply(float vec[3]) const
Applies transformation to a 3D vector (in place) - float version.
void setTranslation(const Vector3Tpl< float > &Tr)
Sets translation (float version)
Vector3Tpl< T > getColumnAsVec3D(unsigned index) const
Returns a copy of a given column as a CCVector3.
void initFromParameters(T alpha_rad, const Vector3Tpl< T > &axis3D, const Vector3Tpl< T > &t3D)
Inits transformation from a rotation axis, an angle and a translation.
virtual void toIdentity()
Sets matrix to identity.
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
Double version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:56
A 3D cloud interface with associated features (color, normals, octree, etc.)
std::vector< unsigned char > VisibilityTableType
Array of "visibility" information for each point.
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
virtual ccBBox getBB_recursive(bool withGLFeatures=false, bool onlyEnabledChildren=true)
Returns the bounding-box of this entity and it's children.
Definition: ecvHObject.cpp:759
@ SELECTION_IGNORED
Definition: ecvHObject.h:608
void removeAllChildren()
Removes all children.
QString getViewId() const
Definition: ecvHObject.h:225
unsigned getChildrenNumber() const
Returns the number of children.
Definition: ecvHObject.h:312
virtual void setSelectionBehavior(SelectionBehavior mode)
Sets selection behavior (when displayed)
Definition: ecvHObject.h:616
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
Definition: ecvHObject.cpp:534
ccHObject * getChild(unsigned childPos) const
Returns the ith child.
Definition: ecvHObject.h:325
Torus (primitive)
Definition: ecvTorus.h:16
Vector3Tpl< T > getDiagVec() const
Returns diagonal vector.
Definition: BoundingBox.h:169
Vector3Tpl< T > getCenter() const
Returns center.
Definition: BoundingBox.h:164
bool contains(const Vector3Tpl< T > &P) const
Returns whether a points is inside the box or not.
Definition: BoundingBox.h:231
const Vector3Tpl< T > & maxCorner() const
Returns max corner (const)
Definition: BoundingBox.h:156
T getDiagNorm() const
Returns diagonal length.
Definition: BoundingBox.h:172
void clear()
Resets the bounding box.
Definition: BoundingBox.h:125
const Vector3Tpl< T > & minCorner() const
Returns min corner (const)
Definition: BoundingBox.h:154
bool isValid() const
Returns whether bounding box is valid or not.
Definition: BoundingBox.h:203
virtual unsigned size() const =0
Returns the number of points.
virtual const CCVector3 * getPoint(unsigned index) const =0
Returns the ith point.
RGB color structure.
Definition: ecvColorTypes.h:49
static void RemoveEntities(const ccHObject *obj)
static bool HideShowEntities(const ccHObject *obj, bool visible)
void DrawUnitArrow(int ID, const CCVector3 &start, const CCVector3 &direction, PointCoordinateType scale, const ecvColor::Rgb &col, CC_DRAW_CONTEXT &context)
Definition: ecvClipBox.cpp:26
const ColorCompType c_lightComp
Definition: ecvClipBox.cpp:712
static QSharedPointer< ccTorus > c_torus(nullptr)
static void DrawUnitTorus(int ID, const CCVector3 &center, const CCVector3 &direction, PointCoordinateType scale, const ecvColor::Rgb &col, CC_DRAW_CONTEXT &context)
Definition: ecvClipBox.cpp:102
const ecvColor::Rgb c_lightRed(ecvColor::MAX, c_lightComp, c_lightComp)
static QSharedPointer< ccSphere > c_centralSphere(nullptr)
const ecvColor::Rgb c_lightBlue(c_lightComp, c_lightComp, ecvColor::MAX)
static CCVector3d PointToVector(int x, int y, int screenWidth, int screenHeight)
Definition: ecvClipBox.cpp:432
const ecvColor::Rgb c_lightGreen(c_lightComp, ecvColor::MAX, c_lightComp)
static QSharedPointer< ccCone > c_arrowHead(nullptr)
static QSharedPointer< ccCylinder > c_arrowShaft(nullptr)
static void DrawUnitCross(int ID, const CCVector3 &center, PointCoordinateType scale, const ecvColor::Rgb &col, CC_DRAW_CONTEXT &context)
Definition: ecvClipBox.cpp:195
unsigned char ColorCompType
Default color components type (R,G and B)
Definition: ecvColorTypes.h:29
#define MACRO_Draw3D(context)
@ ECV_WIREFRAME_MODE
#define MACRO_EntityPicking(context)
@ CC_ENTITY_PICKING
@ ECV_MESH
@ ECV_SHAPE
for(size_t i=0;i< 36;++i)
ImGuiContext * context
Definition: Window.cpp:76
normal_z y
normal_z x
float RadiansToDegrees(int radians)
Convert radians to degrees.
Definition: CVMath.h:71
constexpr ColorCompType MAX
Max value of a single color component (default type)
Definition: ecvColorTypes.h:34
constexpr Rgb red(MAX, 0, 0)
constexpr Rgb blue(0, 0, MAX)
constexpr Rgb green(0, MAX, 0)
constexpr Rgb yellow(MAX, MAX, 0)
Simple (clipping) plane equation.
Tuple4Tpl< double > equation
Display context.
int drawingFlags
Drawing options (see below)
ENTITY_TYPE removeEntityType
MESH_RENDERING_MODE meshRenderingMode