ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccFitPlane.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 "ccFitPlane.h"
9 
10 #include "ccCompass.h"
12  : ccPlane(p->getXWidth(),
13  p->getYWidth(),
14  &p->getTransformation(),
15  p->getName()) // create an identical plane
16 {
17  p->clone();
18 
19  // add metadata tag defining the ccCompass class type
20  QVariantMap* map = new QVariantMap();
21  map->insert("ccCompassType", "FitPlane");
22  setMetaData(*map, true);
23 
24  // update name
25  CCVector3 N(getNormal());
26  // We always consider the normal with a positive 'Z' by default!
27  if (N.z < 0.0) N *= -1.0;
28  // calculate strike/dip/dip direction
29  float dip, dipdir;
31  QString dipAndDipDirStr = QString("%1/%2")
32  .arg((int)dip, 2, 10, QChar('0'))
33  .arg((int)dipdir, 3, 10, QChar('0'));
34 
35  setName(dipAndDipDirStr);
36 
37  // update metadata
38  float rms = -1;
39  float search_r = -1;
40  if (p->hasMetaData("RMS")) {
41  rms = p->getMetaData("RMS").toFloat();
42  }
43  if (p->hasMetaData("Radius")) {
44  search_r = p->getMetaData("Radius").toFloat();
45  }
46  updateAttributes(rms, search_r);
47 
48  // update drawing properties based on ccCompass state
52 }
53 
55 
56 void ccFitPlane::updateAttributes(float rms, float search_r) {
57  // calculate and store plane attributes
58  // get plane normal vector
59  CCVector3 N(getNormal());
60  // We always consider the normal with a positive 'Z' by default!
61  if (N.z < 0.0) N *= -1.0;
62 
63  // calculate strike/dip/dip direction
64  float strike, dip, dipdir;
66  // ccNormalVectors::ConvertNormalToStrikeAndDip(N, strike, dip); //n.b. this
67  // returns result using the british RHR?!?)
68 
69  // calculate strike using American RHR
70  strike = dipdir - 90;
71  while (strike < 0) // ensure strike > 0
72  {
73  strike += 360;
74  }
75  while (strike >= 360) // ensure strike < 360
76  {
77  strike -= 360;
78  }
79 
80  // calculate centroid
81  CCVector3 C = getCenter();
82 
83  // store attributes (centroid, strike, dip, RMS) on plane
84  QVariantMap* map = new QVariantMap();
85  map->insert("Cx", C.x);
86  map->insert("Cy", C.y);
87  map->insert("Cz", C.z); // centroid
88  map->insert("Nx", N.x);
89  map->insert("Ny", N.y);
90  map->insert("Nz", N.z); // normal
91  map->insert("Strike", strike);
92  map->insert("Dip", dip);
93  map->insert("DipDir", dipdir); // strike & dip
94  map->insert("RMS", rms); // rms
95  map->insert("Radius", search_r); // search radius
96  setMetaData(*map, true);
97 }
98 
100  if (object->hasMetaData("ccCompassType")) {
101  return object->getMetaData("ccCompassType")
102  .toString()
103  .contains("FitPlane");
104  }
105  return false;
106  /*return object->isKindOf(CV_TYPES::PLANE) //ensure object is a plane
107  && object->hasMetaData("Cx") //ensure plane has the correct metadata
108  && object->hasMetaData("Cy")
109  && object->hasMetaData("Cz")
110  && object->hasMetaData("Nx")
111  && object->hasMetaData("Ny")
112  && object->hasMetaData("Nz")
113  && object->hasMetaData("Strike")
114  && object->hasMetaData("Dip")
115  && object->hasMetaData("DipDir")
116  && object->hasMetaData("RMS")
117  && object->hasMetaData("Radius");*/
118 }
119 
121  double* rms) {
122  ccPlane* p = ccPlane::Fit(cloud, rms);
123  if (p) // valid plane
124  {
125  ccFitPlane* fp = new ccFitPlane(p);
126  p->transferChildren(*fp);
127  return fp;
128  } else {
129  return nullptr; // return null
130  }
131 }
Type y
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
static bool drawNormals
Definition: ccCompass.h:260
static bool drawName
Definition: ccCompass.h:258
static bool drawStippled
Definition: ccCompass.h:259
virtual void showNameIn3D(bool state)
Sets whether name should be displayed in 3D.
ccFitPlane(ccPlane *p)
Definition: ccFitPlane.cpp:11
static ccFitPlane * Fit(cloudViewer::GenericIndexedCloudPersist *cloud, double *rms)
Definition: ccFitPlane.cpp:120
void updateAttributes(float rms, float search_r)
Definition: ccFitPlane.cpp:56
static bool isFitPlane(ccHObject *object)
Definition: ccFitPlane.cpp:99
void enableStippling(bool state)
Enables polygon stippling.
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
void transferChildren(ccHObject &newParent, bool forceFatherDependent=false)
Transfer all children to another parent.
static void ConvertNormalToDipAndDipDir(const CCVector3 &N, PointCoordinateType &dip_deg, PointCoordinateType &dipDir_deg)
Converts a normal vector to geological 'dip direction & dip' parameters.
void setMetaData(const QString &key, const QVariant &data)
Sets a meta-data element.
QVariant getMetaData(const QString &key) const
Returns a given associated meta data.
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
void showNormalVector(bool state)
Show normal vector.
Plane (primitive)
Definition: ecvPlane.h:18
virtual ccGenericPrimitive * clone() const override
Clones primitive.
static ccPlane * Fit(cloudViewer::GenericIndexedCloudPersist *cloud, double *rms=0)
Fits a plane primitive on a cloud.
CCVector3 getCenter() const
Returns the center.
Definition: ecvPlane.h:56
CCVector3 getNormal() const override
Returns the entity normal.
Definition: ecvPlane.h:73
A generic 3D point cloud with index-based and presistent access to points.