ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccThickness.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 "ccThickness.h"
9 
10 // pass ctors straight to PointPair
12  : ccPointPair(associatedCloud) {
14 }
15 
18 }
19 
21  QVariantMap* map = new QVariantMap();
22 
23  // add metadata tag defining the ccCompass class type
24  map->insert("ccCompassType", "Thickness");
25 
26  // calculate trace orientation (trend/plunge)
27  if (size() ==
28  2) // can't calculate orientation of something smaller than this...
29  {
30  CCVector3f dir = getDirection();
31  dir.normalize();
32  float trend, plunge;
33 
34  if (dir.x + dir.y + dir.z == 0) // special case: null direction
35  {
36  trend = 0;
37  plunge = 0;
38  } else if (dir.z > 0.9999999 ||
39  dir.z < -0.9999999) // special case: dir is vertical (=
40  // 0,0,1 or 0,0,-1)
41  {
42  trend = 0;
43  if (dir.z < 0)
44  plunge = 90;
45  else
46  plunge = -90;
47  } else // normal cases...
48  {
49  CCVector3f hzComp = CCVector3f(dir.x, dir.y, 0);
50  hzComp.normalize();
51 
52  // calculate plunge: plunge = angle between vector & vector
53  // projected onto horizontal (x,y) plane
54  plunge = std::acos(dir.dot(hzComp)) *
55  (180 /
56  M_PI); // plunge measured from horizontal (in degrees)
57  if (dir.z >
58  0) // lineations pointing towards the sky have negative plunges
59  plunge *= -1;
60 
61  // calculate trend (N.B. I have very little idea how exactly this
62  // code work, it's kinda magic) [c.f.
63  // http://stackoverflow.com/questions/14066933/direct-way-of-computing-clockwise-angle-between-2-vectors
64  //]
65  CCVector3f N(0, 1, 0); // north vector
66  float dot = hzComp.dot(N);
67  float det = CCVector3f(0, 0, 1).dot(hzComp.cross(N));
68  trend = std::atan2(det, dot) *
69  (180 / M_PI); // heading measured clockwise from north (in
70  // degrees)
71  if (trend < 0) trend += 360;
72  }
73 
74  // store trend and plunge info
75  CCVector3 s = *getPoint(0); // start point
76  CCVector3 e = *getPoint(1); // end point
77  float length = (s - e).norm();
78 
79  map->insert("Sx", s.x);
80  map->insert("Sy", s.y);
81  map->insert("Sz", s.z);
82  map->insert("Ex", e.x);
83  map->insert("Ey", e.y);
84  map->insert("Ez", e.z);
85  map->insert("Trend", trend);
86  map->insert("Plunge", plunge);
87  map->insert("Length", length);
88 
89  // store metadata
90  setMetaData(*map, true);
91 
92  // update name
93  setName(QString::asprintf("%.3fT", length));
94  }
95 
96  // store
97  setMetaData(*map, true);
98 }
99 
100 // returns true if object is a lineation
102  if (object->hasMetaData("ccCompassType")) {
103  return object->getMetaData("ccCompassType")
104  .toString()
105  .contains("Thickness");
106  }
107  return false;
108 }
constexpr double M_PI
Pi.
Definition: CVConst.h:19
Vector3Tpl< float > CCVector3f
Float 3D Vector.
Definition: CVGeom.h:801
Type y
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
void normalize()
Sets vector norm to unity.
Definition: CVGeom.h:428
Type dot(const Vector3Tpl &v) const
Dot product.
Definition: CVGeom.h:408
Vector3Tpl cross(const Vector3Tpl &v) const
Cross product.
Definition: CVGeom.h:412
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
void setMetaData(const QString &key, const QVariant &data)
Sets a meta-data element.
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.)
CCVector3 getDirection()
Definition: ccPointPair.cpp:35
Colored polyline.
Definition: ecvPolyline.h:24
ccThickness(ccPointCloud *associatedCloud)
Definition: ccThickness.cpp:11
void updateMetadata() override
Definition: ccThickness.cpp:20
static bool isThickness(ccHObject *obj)
unsigned size() const override
Returns the number of points.
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
__host__ __device__ float length(float2 v)
Definition: cutil_math.h:1162
__host__ __device__ float dot(float2 a, float2 b)
Definition: cutil_math.h:1119