ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccFitPlaneTool.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 "ccFitPlaneTool.h"
9 
10 // CV_DB_LIB
11 // #include <ecvPointCloud.h>
12 
14 
16  if (m_mouseCircle) {
17  assert(false); // we should never end up here...
19  delete m_mouseCircle;
20  m_mouseCircle = nullptr;
21  }
22 }
23 
24 // called when the tool is set to active (for initialization)
28 
29  // set orthographic view (as this tool doesn't work in perspective mode)
31 }
32 
33 // called when the tool is set to disactive (for cleanup)
35  if (m_mouseCircle) {
36  m_mouseCircle->setVisible(false);
37  delete m_mouseCircle;
38  m_mouseCircle = nullptr;
39  }
40 }
41 
42 // called when a point in a point cloud gets picked while this tool is active
44  unsigned itemIdx,
45  ccPointCloud* cloud,
46  const CCVector3& P) {
47  // get or generate octree
48  ccOctree::Shared oct = cloud->getOctree();
49  if (!oct) {
50  oct = cloud->computeOctree(); // if the user clicked "no" when asked to
51  // compute the octree then tough....
52  }
53 
54  // nearest neighbour search
55  float r = m_mouseCircle->getRadiusWorld();
56  unsigned char level =
57  oct->findBestLevelForAGivenNeighbourhoodSizeExtraction(r);
59  int n = oct->getPointsInSphericalNeighbourhood(P, PointCoordinateType(r),
60  set, level);
61  // Put data in a point cloud class and encapsulate as a "neighbourhood"
63  cloudViewer::Neighbourhood Z(&nCloud);
64 
65  // Fit plane!
66  double rms = 0.0; // output for rms
67  ccFitPlane* pPlane = ccFitPlane::Fit(&nCloud, &rms);
68 
69  if (pPlane) // valid fit
70  {
72 
73  // make plane to add to display
74  pPlane->setVisible(true);
76 
77  // add plane to scene graph
78  insertPoint->addChild(pPlane);
79  // pPlane->setDisplay(m_app->getActiveWindow());
80  // pPlane->prepareDisplayForRefresh_recursive(); //not sure what this
81  // does, but it looks like fun
82 
83  // add plane to TOC
84  m_app->addToDB(pPlane, false, false, false, false);
85 
86  // report orientation to console for convenience
88  QString("[ccCompass] Surface orientation estimate = " +
89  pPlane->getName()),
91  }
92 }
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
virtual void setVisible(bool state)
Sets entity visibility.
virtual ~ccFitPlaneTool()
void toolActivated() override
void toolDisactivated() override
ccMouseCircle * m_mouseCircle
void pointPicked(ccHObject *insertPoint, unsigned itemIdx, ccPointCloud *cloud, const CCVector3 &P) override
static ccFitPlane * Fit(cloudViewer::GenericIndexedCloudPersist *cloud, double *rms)
Definition: ccFitPlane.cpp:120
void updateAttributes(float rms, float search_r)
Definition: ccFitPlane.cpp:56
virtual ccOctree::Shared computeOctree(cloudViewer::GenericProgressCallback *progressCb=nullptr, bool autoAddChild=true)
Computes the cloud octree.
virtual ccOctree::Shared getOctree() const
Returns the associated octree (if any)
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
@ SELECTION_IGNORED
Definition: ecvHObject.h:608
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
virtual void setSelectionBehavior(SelectionBehavior mode)
Sets selection behavior (when displayed)
Definition: ecvHObject.h:616
void ownerIsDead()
Definition: ccMouseCircle.h:41
float getRadiusWorld()
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
QSharedPointer< ccOctree > Shared
Shared pointer.
Definition: ecvOctree.h:32
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Definition: ccTool.h:18
ecvMainAppInterface * m_app
Definition: ccTool.h:67
A kind of ReferenceCloud based on the DgmOctree::NeighboursSet structure.
std::vector< PointDescriptor > NeighboursSet
A set of neighbours.
Definition: DgmOctree.h:133
static QWidget * GetCurrentScreen()
static void SetPerspectiveState(bool state, bool objectCenteredView)
Set perspective state/mode.
virtual void addToDB(ccHObject *obj, bool updateZoom=false, bool autoExpandDBTree=true, bool checkDimensions=false, bool autoRedraw=true)=0
virtual void dispToConsole(QString message, ConsoleMessageLevel level=STD_CONSOLE_MESSAGE)=0