ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccPointPair.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 "ccPointPair.h"
9 
10 #include <ecvDisplayTools.h>
11 
12 // static sphere for drawing with
13 static QSharedPointer<ccSphere> c_unitPointMarker(nullptr);
14 static QSharedPointer<ccCylinder> c_bodyMarker(nullptr);
15 static QSharedPointer<ccCone> c_headMarker(nullptr);
16 
17 // ctor
19  : ccPolyline(associatedCloud) {
20  // do nothing
21 }
22 
24  : ccPolyline(obj->getAssociatedCloud()) {
25  // load points
26  for (unsigned i = 0; i < obj->size(); i++) {
27  int pId = obj->getPointGlobalIndex(i); // get global point ID
28  addPointIndex(pId); // add point to this polyline
29  }
30 
31  // copy name
32  setName(obj->getName());
33 }
34 
36  if (size() != 2) {
37  return CCVector3(); // null vector
38  } else {
39  const CCVector3 start = *getPoint(0);
40  const CCVector3 end = *getPoint(1);
41  return end - start;
42  }
43 }
44 
45 // overidden from ccHObject
47  if (!MACRO_Foreground(context)) // 2D foreground only
48  return; // do nothing
49 
50  if (MACRO_Draw3D(context)) {
51  if (size() == 0) // no points -> bail!
52  return;
53 
54  // get the set of OpenGL functions (version 2.1)
55  if (ecvDisplayTools::GetCurrentScreen() == nullptr) {
56  assert(false);
57  return;
58  }
59 
60  // push name for picking
61  bool entityPickingMode = MACRO_EntityPicking(context);
62 
63  // check sphere exists
64  if (!c_unitPointMarker) {
65  c_unitPointMarker = QSharedPointer<ccSphere>(
66  new ccSphere(1.0f, 0, "PointMarker", 6));
67 
68  c_unitPointMarker->showColors(true);
69  c_unitPointMarker->setVisible(true);
70  c_unitPointMarker->setEnabled(true);
71  }
72 
73  // check arrow parts exist
74  if (!c_bodyMarker) {
75  c_bodyMarker = QSharedPointer<ccCylinder>(
76  new ccCylinder(1.0f, 0.9f, 0, "UnitNormal", 12));
77  c_bodyMarker->showColors(true);
78  c_bodyMarker->setVisible(true);
79  c_bodyMarker->setEnabled(true);
80  c_bodyMarker->setTempColor(ecvColor::green);
81  c_bodyMarker->showNormals(false);
82  }
83  if (!c_headMarker) {
84  c_headMarker = QSharedPointer<ccCone>(new ccCone(
85  2.5f, 0.0f, 0.1f, 0, 0, 0, "UnitNormalHead", 12));
86  c_headMarker->showColors(true);
87  c_headMarker->setVisible(true);
88  c_headMarker->setEnabled(true);
89  c_headMarker->setTempColor(ecvColor::green);
90  c_headMarker->showNormals(false);
91  }
92 
93  // not sure what this does, but it looks like fun
94  CC_DRAW_CONTEXT markerContext =
95  context; // build-up point maker own 'context'
96  markerContext.drawingFlags &=
97  (~CC_ENTITY_PICKING); // we must remove the 'push name flag'
98  // so that the sphere doesn't push its
99  // own!
100 
101  // get camera info
102  ccGLCameraParameters camera;
104 
105  // set draw colour
106  c_unitPointMarker->setTempColor(getMeasurementColour());
107 
108  // get point size for drawing
109  float pSize = markerContext.defaultPointSize;
110 
111  // draw points
112  const ecvViewportParameters& viewportParams =
114  for (unsigned i = 0; i < size(); i++) {
115  const CCVector3* P = getPoint(i);
116  // glFunc->glMatrixMode(GL_MODELVIEW);
117  // glFunc->glPushMatrix();
118  // ccGL::Translate(glFunc, P->x, P->y, P->z);
119  markerContext.transformInfo.setTranslationStart(
120  CCVector3(P->x, P->y, P->z));
121  float scale = context.labelMarkerSize * m_relMarkerScale * 0.2 *
122  fmin(pSize, 4);
123  if (viewportParams.perspectiveView && viewportParams.zFar > 0) {
124  // in perspective view, the actual scale depends on the distance
125  // to the camera!
126  const double* M = camera.modelViewMat.data();
127  double d = (camera.modelViewMat * CCVector3d::fromArray(P->u))
128  .norm();
129  double unitD = viewportParams.zFar /
130  2; // we consider that the 'standard' scale is
131  // at half the depth
132  scale = static_cast<float>(
133  scale *
134  sqrt(d /
135  unitD)); // sqrt = empirical (probably because the
136  // marker size is already partly
137  // compensated by
138  // ecvDisplayTools::computeActualPixelSize())
139  }
140  // glFunc->glScalef(scale, scale, scale);
141  markerContext.transformInfo.setScale(
142  CCVector3(scale, scale, scale));
143  c_unitPointMarker->draw(markerContext);
144  // glFunc->glPopMatrix();
145  }
146 
147  // draw arrow
148  c_bodyMarker->setTempColor(getMeasurementColour());
149  c_headMarker->setTempColor(getMeasurementColour());
150  if (size() == 2) // two points
151  {
152  const CCVector3 start = *getPoint(0);
153  const CCVector3 end = *getPoint(1);
154 
155  CCVector3 disp = end - start;
156  float length = disp.norm();
157  float width = context.labelMarkerSize * m_relMarkerScale * 0.05 *
158  std::fmin(pSize, 5);
159  CCVector3 dir = disp / length;
160 
161  // transform into coord space with origin at start and arrow head at
162  // 0,0,1 (unashamedly pilfered from
163  // ccPlanarEntityInterface::glDrawNormal(...)
164  // glFunc->glMatrixMode(GL_MODELVIEW);
165  markerContext.transformInfo.setTranslationStart(
166  CCVector3(start.x, start.y, start.z));
167 
169  CCVector3(0, 0, PC_ONE),
170  CCVector3(dir.x, dir.y, dir.z)); // end = 0,0,1
171  markerContext.transformInfo.setTransformation(mat, false);
172  markerContext.transformInfo.setScale(
174 
175  // draw arrow body
176  markerContext.transformInfo.setTranslationEnd(
177  CCVector3(0, 0, 0.45f));
178  c_bodyMarker->draw(markerContext);
179 
180  // draw arrow head
181  markerContext.transformInfo.setTranslationEnd(
182  CCVector3(0, 0, 0.45f));
183  c_headMarker->draw(markerContext);
184  }
185 
186  // finish picking name
187  }
188 }
189 
190 // returns true if object is a pointPair
192  if (object->hasMetaData("ccCompassType")) {
193  return object->getMetaData("ccCompassType")
194  .toString()
195  .contains("PointPair") |
196  object->getMetaData("ccCompassType")
197  .toString()
198  .contains("Lineation") |
199  object->getMetaData("ccCompassType")
200  .toString()
201  .contains("Thickness") |
202  object->getMetaData("ccCompassType")
203  .toString()
204  .contains("PinchNode") |
205  object->getMetaData("ccCompassType")
206  .toString()
207  .contains("Relationship");
208  }
209  return false;
210 }
constexpr PointCoordinateType PC_ONE
'1' as a PointCoordinateType value
Definition: CVConst.h:67
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
Definition: CVGeom.h:798
int width
static QSharedPointer< ccCone > c_headMarker(nullptr)
static QSharedPointer< ccSphere > c_unitPointMarker(nullptr)
static QSharedPointer< ccCylinder > c_bodyMarker(nullptr)
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 norm() const
Returns vector norm.
Definition: CVGeom.h:424
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Definition: CVGeom.h:268
Cone (primitive)
Definition: ecvCone.h:16
Cylinder (primitive)
Definition: ecvCylinder.h:16
static ccGLMatrixTpl< float > FromToRotation(const Vector3Tpl< float > &from, const Vector3Tpl< float > &to)
Creates a transformation matrix that rotates a vector to another.
T * data()
Returns a pointer to internal data.
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
ecvColor::Rgb getMeasurementColour() const
Definition: ccMeasurement.h:36
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
bool hasMetaData(const QString &key) const
Returns whether a meta-data element with the given key exists or not.
virtual void setName(const QString &name)
Sets object name.
Definition: ecvObject.h:75
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
ccPointPair(ccPointCloud *associatedCloud)
Definition: ccPointPair.cpp:18
virtual void drawMeOnly(CC_DRAW_CONTEXT &context) override
Draws the entity only (not its children)
Definition: ccPointPair.cpp:46
float m_relMarkerScale
Definition: ccPointPair.h:38
CCVector3 getDirection()
Definition: ccPointPair.cpp:35
static bool isPointPair(ccHObject *object)
Colored polyline.
Definition: ecvPolyline.h:24
Sphere (primitive)
Definition: ecvSphere.h:16
virtual bool addPointIndex(unsigned globalIndex)
Point global index insertion mechanism.
unsigned size() const override
Returns the number of points.
virtual unsigned getPointGlobalIndex(unsigned localIndex) const
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
static void GetGLCameraParameters(ccGLCameraParameters &params)
Returns the current OpenGL camera parameters.
static const ecvViewportParameters & GetViewportParameters()
static QWidget * GetCurrentScreen()
Standard parameters for GL displays/viewports.
bool perspectiveView
Perspective view state.
double zFar
Actual perspective 'zFar' value.
__host__ __device__ float length(float2 v)
Definition: cutil_math.h:1162
#define MACRO_Draw3D(context)
#define MACRO_Foreground(context)
#define MACRO_EntityPicking(context)
@ CC_ENTITY_PICKING
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)
OpenGL camera parameters.
ccGLMatrixd modelViewMat
Model view matrix (GL_MODELVIEW)
Display context.
int drawingFlags
Drawing options (see below)
TransformInfo transformInfo
unsigned char defaultPointSize