ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccItemTree.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 "ccItemTree.h"
9 
10 #include "ccMPlaneErrors.h"
11 
12 // CV_DB_LIB
13 #include <ecvDisplayTools.h>
14 
15 bool compareObjects(QString name,
16  ccHObject *object,
18  if (!object) {
19  return false;
20  }
21  if (object->isKindOf(type) &&
22  (name == nullptr || name != nullptr && (object->getName() == name))) {
23  return true;
24  }
25  return false;
26 }
27 
29  CC_TYPES_MAP itemType,
30  QString itemName) {
31  if (!root) {
32  throw MplaneInvalidArgument("root is not allowed to be nullptr");
33  }
34  auto childrenNumber = root->getChildrenNumber();
35  for (unsigned int i = 0; i < childrenNumber; ++i) {
36  ccHObject *child = root->getChild(i);
37  if (compareObjects(itemName, child, itemType)) {
38  return child;
39  }
40  if (child->getChildrenNumber() > 0) {
41  ccHObject *subChild =
42  findItemInHierarchy(child, itemType, itemName);
43  if (compareObjects(itemName, subChild, itemType)) {
44  return subChild;
45  }
46  }
47  }
48  return nullptr;
49 }
50 
52  const QString &containerName,
53  ecvMainAppInterface *app) {
54  if (!parent) {
55  throw MplaneInvalidArgument("parent is not allowed to be nullptr");
56  }
57  if (!app) {
58  throw MplaneInvalidArgument("app is not allowed to be nullptr");
59  }
60  if (containerName.isEmpty()) {
61  throw MplaneInvalidArgument("containerName is not allowed to be empty");
62  }
65  containerName);
66  if (container) {
67  return container;
68  }
69  container = new ccHObject(containerName);
70  parent->addChild(container);
71  app->addToDB(container, false, true, false, false);
72 
73  return container;
74 }
75 
78  QPoint clickPoint,
79  unsigned int pointIdx) {
80  if (labelText.isEmpty()) {
81  throw MplaneInvalidArgument("labelText is not allowed to be empty");
82  }
83  if (!sourceCloud) {
84  throw MplaneInvalidArgument("sourceCloud is not allowed to be nullptr");
85  }
86  cc2DLabel *newLabel = nullptr;
87  // ccGenericGLDisplay* display = sourceCloud->getDisplay();
89  newLabel = new cc2DLabel();
90  newLabel->addPickedPoint(sourceCloud, pointIdx);
91  newLabel->setName(labelText);
92  newLabel->setVisible(true);
93  newLabel->setDisplayedIn2D(false);
94  newLabel->displayPointLegend(true);
95  newLabel->setCollapsed(true);
96  // newLabel->setDisplay(display);
97 
99  newLabel->setPosition(
100  static_cast<float>(clickPoint.x() + 20) / size.width(),
101  static_cast<float>(clickPoint.y() + 20) / size.height());
102  newLabel->redrawDisplay();
103  }
104  return newLabel;
105 }
int size
std::string name
char type
bool compareObjects(QString name, ccHObject *object, CC_ITEM_TREE::CC_TYPES_MAP type)
Definition: ccItemTree.cpp:15
2D label (typically attached to points)
Definition: ecv2DLabel.h:22
bool addPickedPoint(ccGenericPointCloud *cloud, unsigned pointIndex, bool entityCenter=false)
Adds a point to this label.
void setCollapsed(bool state)
Whether to collapse label or not.
Definition: ecv2DLabel.h:102
void setDisplayedIn2D(bool state)
Whether to display the label in 2D.
Definition: ecv2DLabel.h:114
void setPosition(float x, float y)
Sets relative position.
void displayPointLegend(bool state)
Whether to display the point(s) legend (title only)
Definition: ecv2DLabel.h:108
virtual void setVisible(bool state)
Sets entity visibility.
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
unsigned getChildrenNumber() const
Returns the number of children.
Definition: ecvHObject.h:312
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
virtual void redrawDisplay(bool forceRedraw=true, bool only2D=false)
Redraws associated display.
ccHObject * getChild(unsigned childPos) const
Returns the ith child.
Definition: ecvHObject.h:325
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
virtual void setName(const QString &name)
Sets object name.
Definition: ecvObject.h:75
bool isKindOf(CV_CLASS_ENUM type) const
Definition: ecvObject.h:128
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
static QSize GetScreenSize()
static QWidget * GetCurrentScreen()
Main application interface (for plugins)
virtual void addToDB(ccHObject *obj, bool updateZoom=false, bool autoExpandDBTree=true, bool checkDimensions=false, bool autoRedraw=true)=0
ccHObject * findItemInHierarchy(ccHObject *root, CC_TYPES_MAP itemType, QString itemName=nullptr)
Definition: ccItemTree.cpp:28
ccHObject * findOrCreateContainer(ccHObject *parent, const QString &containerName, ecvMainAppInterface *app)
Definition: ccItemTree.cpp:51
cc2DLabel * createPointLabel2D(QString labelText, ccPointCloud *parentCloud, QPoint clickPoint, unsigned int pointIdx)
Definition: ccItemTree.cpp:76
@ HIERARCHY_OBJECT
Definition: CVTypes.h:103
ccGenericPointCloud * sourceCloud