ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvPlanarEntityInterface.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 // Local
11 #include "ecvCone.h"
12 #include "ecvCylinder.h"
13 #include "ecvDisplayTools.h"
14 
15 // Qt
16 #include <QSharedPointer>
17 
19  : m_showNormalVector(false), m_uniqueId(0) {}
20 
21 // unit normal representation
22 static QSharedPointer<ccCylinder> c_unitNormalSymbol(0);
23 static QSharedPointer<ccCone> c_unitNormalHeadSymbol(0);
24 static const QString SEPARATOR = "_";
25 
27  : m_showNormalVector(false), m_uniqueId(id) {}
28 
30  const CCVector3& pos,
31  float scale,
32  const ecvColor::Rgb* color /*=0*/) {
33  // get the set of OpenGL functions (version 2.1)
34 
35  if (ecvDisplayTools::GetCurrentScreen() == nullptr) return;
36 
37  // delete history
39 
40  if (!normalVectorIsShown()) {
41  return;
42  }
43 
44  if (!c_unitNormalSymbol) {
45  c_unitNormalSymbol = QSharedPointer<ccCylinder>(
46  new ccCylinder(0.02f, 0.9f, 0, "UnitNormal", 12));
47  c_unitNormalSymbol->showColors(true);
48  c_unitNormalSymbol->setVisible(true);
49  c_unitNormalSymbol->setEnabled(true);
50  c_unitNormalSymbol->setTempColor(ecvColor::green);
51  c_unitNormalSymbol->setFixedId(true);
52  }
54  c_unitNormalHeadSymbol = QSharedPointer<ccCone>(
55  new ccCone(0.05f, 0.0f, 0.1f, 0, 0, 0, "UnitNormalHead", 12));
56  c_unitNormalHeadSymbol->showColors(true);
57  c_unitNormalHeadSymbol->setVisible(true);
58  c_unitNormalHeadSymbol->setEnabled(true);
60  c_unitNormalHeadSymbol->setFixedId(true);
61  }
62 
64  m_headId = QString::number(m_uniqueId) + SEPARATOR +
65  c_unitNormalHeadSymbol->getViewId();
66  }
67 
68  if (c_unitNormalSymbol) {
69  m_bodyId = QString::number(m_uniqueId) + SEPARATOR +
70  c_unitNormalSymbol->getViewId();
71  }
72 
73  // build-up the normal representation own 'context'
74  CC_DRAW_CONTEXT normalContext = context;
75  // we must remove the 'push name flag' so that the primitives don't push
76  // their own!
77  normalContext.drawingFlags &= (~CC_ENTITY_PICKING);
78 
79  if (color) {
80  c_unitNormalSymbol->setTempColor(*color, true);
81  c_unitNormalHeadSymbol->setTempColor(*color, true);
82  } else {
83  c_unitNormalSymbol->enableTempColor(false);
84  c_unitNormalHeadSymbol->enableTempColor(false);
85  }
86 
87  c_unitNormalSymbol->setRedraw(true);
88  c_unitNormalHeadSymbol->setRedraw(true);
89 
90  CCVector3 posVec(pos.x, pos.y, pos.z);
91  normalContext.transformInfo.setTranslationStart(posVec);
92  CCVector3 direction(0, 0, PC_ONE * scale);
93 
96  .data());
97  mat.applyRotation(direction);
98  normalContext.transformInfo.setTransformation(mat, false, false);
99 
100  // ccGL::Scale(glFunc, scale, scale, scale);
101  normalContext.transformInfo.setScale(CCVector3(scale, scale, scale));
102 
103  // glFunc->glTranslatef(0, 0, 0.45f);
104  normalContext.transformInfo.setTranslationEnd(0.45f * direction);
105  normalContext.viewID = m_bodyId;
106  c_unitNormalSymbol->draw(normalContext);
107 
108  // glFunc->glTranslatef(0, 0, 0.45f);
109  normalContext.transformInfo.setTranslationEnd(0.9f * direction);
110  normalContext.viewID = m_headId;
111  c_unitNormalHeadSymbol->draw(normalContext);
112 }
113 
115  context.removeEntityType = ENTITY_TYPE::ECV_MESH;
116  if (c_unitNormalSymbol) {
117  context.removeViewID = m_bodyId;
119  }
121  context.removeViewID = m_headId;
123  }
124 }
constexpr PointCoordinateType PC_ONE
'1' as a PointCoordinateType value
Definition: CVConst.h:67
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
Definition: CVGeom.h:798
math::float4 color
Type y
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
Cone (primitive)
Definition: ecvCone.h:16
Cylinder (primitive)
Definition: ecvCylinder.h:16
void applyRotation(Vector3Tpl< float > &vec) const
Applies rotation only to a 3D vector (in place) - float version.
static ccGLMatrixTpl< float > FromToRotation(const Vector3Tpl< float > &from, const Vector3Tpl< float > &to)
Creates a transformation matrix that rotates a vector to another.
Double version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:56
void glDrawNormal(CC_DRAW_CONTEXT &context, const CCVector3 &pos, float scale, const ecvColor::Rgb *color=0)
Draws a normal vector (OpenGL)
void clearNormalVector(CC_DRAW_CONTEXT &context)
bool normalVectorIsShown() const
Whether normal vector is shown or not.
ccPlanarEntityInterface()
Default constructor.
virtual CCVector3 getNormal() const =0
Returns the entity normal.
RGB color structure.
Definition: ecvColorTypes.h:49
static void RemoveEntities(const ccHObject *obj)
static QWidget * GetCurrentScreen()
@ CC_ENTITY_PICKING
@ ECV_MESH
static QSharedPointer< ccCylinder > c_unitNormalSymbol(0)
static QSharedPointer< ccCone > c_unitNormalHeadSymbol(0)
static const QString SEPARATOR
GraphType data
Definition: graph_cut.cc:138
ImGuiContext * context
Definition: Window.cpp:76
constexpr Rgb green(0, MAX, 0)
void setScale(const CCVector3 &scale)
void setTranslationEnd(const CCVector3 &trans)
void setTranslationStart(const CCVector3 &trans)
void setTransformation(const ccGLMatrixd &transform, bool updateTranslation=true, bool useEuler=false)
Display context.
int drawingFlags
Drawing options (see below)
TransformInfo transformInfo