ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccLineation.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 "ccLineation.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", "Lineation");
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  // CCVector3d Pg = cloud->toGlobal3d(*P);
76  CCVector3d s = toGlobal3d(*getPoint(0)); // start point
77  CCVector3d e = toGlobal3d(*getPoint(1)); // end point
78  float length = (s - e).norm();
79 
80  map->insert("Sx", s.x);
81  map->insert("Sy", s.y);
82  map->insert("Sz", s.z);
83  map->insert("Ex", e.x);
84  map->insert("Ey", e.y);
85  map->insert("Ez", e.z);
86  map->insert("Trend", trend);
87  map->insert("Plunge", plunge);
88  map->insert("Length", length * getGlobalScale());
89 
90  // store metadata
91  setMetaData(*map, true);
92 
93  // update name
94  QString lengthstr = QString("").asprintf("%.1f on ", length);
95  QString trendAndPlungeStr = QString("%2->%3")
96  .arg((int)plunge, 2, 10, QChar('0'))
97  .arg((int)trend, 3, 10, QChar('0'));
98  QString namestr = lengthstr + trendAndPlungeStr;
99  setName(namestr);
100  }
101 }
102 
103 // returns true if object is a lineation
105  if (object->hasMetaData("ccCompassType")) {
106  return object->getMetaData("ccCompassType")
107  .toString()
108  .contains("Lineation");
109  }
110  return false;
111 }
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 updateMetadata() override
Definition: ccLineation.cpp:20
ccLineation(ccPointCloud *associatedCloud)
Definition: ccLineation.cpp:11
static bool isLineation(ccHObject *obj)
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
CCVector3d toGlobal3d(const Vector3Tpl< T > &Plocal) const
Returns the point back-projected into the original coordinates system.
virtual double getGlobalScale() const
Returns the scale applied to original coordinates.
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