ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvPointPropertiesDlg.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 
9 
10 // Local
11 #include "ecvCommon.h"
12 #include "ecvGuiParameters.h"
13 
14 // CV_DB_LIB
15 #include <CVLog.h>
16 #include <ecv2DLabel.h>
17 #include <ecv2DViewportLabel.h>
18 #include <ecvDisplayTools.h>
19 #include <ecvPointCloud.h>
20 
21 // cloudViewer
22 #include <ScalarField.h>
23 
24 // Qt
25 #include <QInputDialog>
26 
27 // System
28 #include <assert.h>
29 
31  QWidget* parent)
32  : ccPointPickingGenericInterface(pickingHub, parent),
33  Ui::PointPropertiesDlg(),
34  m_pickingMode(POINT_INFO) {
35  setupUi(this);
36 
37  connect(closeButton, &QToolButton::clicked, this,
39  connect(pointPropertiesButton, &QToolButton::clicked, this,
41  connect(pointPointDistanceButton, &QToolButton::clicked, this,
43  connect(pointsAngleButton, &QToolButton::clicked, this,
45  connect(rectZoneToolButton, &QToolButton::clicked, this,
47  connect(saveLabelButton, &QToolButton::clicked, this,
49  connect(razButton, &QToolButton::clicked, this,
51 
52  // for points picking
53  m_label = new cc2DLabel();
54  m_label->setSelected(true);
55 
56  // for 2D zone picking
58  m_rect2DLabel->setVisible(false); //=invalid
59  m_rect2DLabel->setSelected(true); //=closed
60 }
61 
63  if (m_label) delete m_label;
64  m_label = nullptr;
65 
66  if (m_rect2DLabel) delete m_rect2DLabel;
67  m_rect2DLabel = nullptr;
68 }
69 
70 bool ccPointPropertiesDlg::linkWith(QWidget* win) {
71  assert(m_label && m_rect2DLabel);
72 
74  return false;
75  }
76 
80 
81  m_rect2DLabel->setVisible(false); //=invalid
82  m_rect2DLabel->setSelected(true); //=closed
83  m_label->clear();
84 
85  // new window?
97  }
98 
99  return true;
100 }
101 
105 }
106 
107 void ccPointPropertiesDlg::stop(bool state) {
108  initializeState();
109 
113 
115 }
116 
118 
123 
125  pointPropertiesButton->setDown(true);
126  pointPointDistanceButton->setDown(false);
127  pointsAngleButton->setDown(false);
128  rectZoneToolButton->setDown(false);
129  m_label->setVisible(true);
130  m_rect2DLabel->setVisible(false);
131 }
132 
135  pointPropertiesButton->setDown(false);
136  pointPointDistanceButton->setDown(true);
137  pointsAngleButton->setDown(false);
138  rectZoneToolButton->setDown(false);
139  m_label->setVisible(true);
140  m_rect2DLabel->setVisible(false);
141 
143 }
144 
147  pointPropertiesButton->setDown(false);
148  pointPointDistanceButton->setDown(false);
149  pointsAngleButton->setDown(true);
150  rectZoneToolButton->setDown(false);
151  m_label->setVisible(true);
152  m_rect2DLabel->setVisible(false);
153 
155 }
156 
159  pointPropertiesButton->setDown(false);
160  pointPointDistanceButton->setDown(false);
161  pointsAngleButton->setDown(false);
162  rectZoneToolButton->setDown(true);
163  m_label->setVisible(false);
164  // m_rect2DLabel->setVisible(false);
165 
168 }
169 
171  assert(m_label && m_rect2DLabel);
172  m_label->clear(false, false);
173  m_rect2DLabel->setVisible(false); //=invalid
174  m_rect2DLabel->setSelected(true); //=closed
175 }
176 
178  ccHObject* labelObject = 0;
179  if (m_pickingMode == RECT_ZONE) {
180  labelObject = (m_rect2DLabel->isSelected() && m_rect2DLabel->isVisible()
181  ? m_rect2DLabel
182  : 0);
183  } else {
184  labelObject = (m_label && m_label->size() > 0 ? m_label : 0);
185  if (labelObject && !ecvDisplayTools::USE_2D) {
186  m_label->setDisplayedIn2D(false);
188  }
189  }
190 
191  if (!labelObject) {
192  return;
193  }
194 
195  // detach current label from window
198  labelObject->setSelected(false);
199 
200  ccHObject* newLabelObject = 0;
201  if (m_pickingMode == RECT_ZONE) {
202  newLabelObject = m_rect2DLabel = new cc2DViewportLabel();
203  m_rect2DLabel->setVisible(false); //=invalid
204  m_rect2DLabel->setSelected(true); //=closed
205  } else {
206  // attach old label to first point cloud by default
207  m_label->getPickedPoint(0).cloud->addChild(labelObject);
208  newLabelObject = m_label = new cc2DLabel();
209  m_label->setSelected(true);
210  }
211 
212  emit newLabel(labelObject);
213 
215  ecvDisplayTools::AddToOwnDB(newLabelObject);
217  newLabelObject->setRedraw(true);
219  }
220 }
221 
223  unsigned pointIndex,
224  int x,
225  int y) {
226  assert(cloud);
227  assert(m_label);
228 
229  switch (m_pickingMode) {
230  case POINT_INFO:
231  m_label->clear();
232  break;
234  if (m_label->size() >= 2) m_label->clear();
235  break;
236  case POINTS_ANGLE:
237  if (m_label->size() >= 3) m_label->clear();
238  break;
239  case RECT_ZONE:
240  return; // we don't use this slot for 2D mode
241  }
242 
243  m_label->addPickedPoint(cloud, pointIndex);
244  m_label->setVisible(true);
246  m_label->size() ==
247  3); // we need to display 'A', 'B' and 'C' for 3-points labels
250  static_cast<float>(x + 20) / ecvDisplayTools::GlWidth(),
251  static_cast<float>(y + 20) / ecvDisplayTools::GlWidth());
252  }
253 
254  // output info to Console
255  QStringList body = m_label->getLabelContent(
256  ecvGui::Parameters().displayedNumPrecision);
257  CVLog::Print(QString("[Picked] ") + m_label->getName());
258  for (QString& row : body) {
259  CVLog::Print(QString("[Picked]\t- ") + row);
260  }
261 
263  m_label->setEnabled(true);
264  m_label->updateLabel();
265  }
266 }
267 
269  if (m_pickingMode != RECT_ZONE) {
270  return;
271  }
272 
274  assert(false);
275  return;
276  }
277 
279 
280  if (m_rect2DLabel->isSelected()) // already closed? we start a new label
281  {
282  float roi[4] = {static_cast<float>(pos2D.x),
283  static_cast<float>(pos2D.y), 0, 0};
284 
288  }
289  m_rect2DLabel->setVisible(false); //=invalid
290  m_rect2DLabel->setSelected(false); //=not closed
291  m_rect2DLabel->setRoi(roi);
292  m_rect2DLabel->setName(""); // reset name before display!
293  } else // we close the existing one
294  {
295  float roi[4] = {m_rect2DLabel->roi()[0], m_rect2DLabel->roi()[1],
296  static_cast<float>(pos2D.x),
297  static_cast<float>(pos2D.y)};
298  m_rect2DLabel->setRoi(roi);
299  m_rect2DLabel->setVisible(true); //=valid
300  m_rect2DLabel->setSelected(true); //=closed
301  }
302 
305  }
306 }
307 
309  int y,
310  Qt::MouseButtons buttons) {
311  if (m_pickingMode != RECT_ZONE) {
312  return;
313  }
314 
315  if (m_rect2DLabel->isSelected()) {
316  return;
317  }
318 
320  assert(false);
321  return;
322  }
323 
325 
326  float roi[4] = {m_rect2DLabel->roi()[0], m_rect2DLabel->roi()[1],
327  static_cast<float>(pos2D.x), static_cast<float>(pos2D.y)};
328  m_rect2DLabel->setRoi(roi);
329  m_rect2DLabel->setVisible(true);
330 
333  }
334 }
335 
336 static QString s_last2DLabelComment("");
338  if (m_pickingMode != RECT_ZONE) return;
339 
340  if (m_rect2DLabel->isSelected() || !m_rect2DLabel->isVisible()) return;
341 
342  m_rect2DLabel->setSelected(true);
343 
344  bool ok;
345  QString title = QInputDialog::getText(this, "Set area label title",
346  "Title:", QLineEdit::Normal,
347  s_last2DLabelComment, &ok);
348  if (!ok) {
349  m_rect2DLabel->setVisible(false);
350  } else {
351  m_rect2DLabel->setName(title);
352  s_last2DLabelComment = title;
353  }
354 
357  }
358 }
static bool Print(const char *format,...)
Prints out a formatted message in console.
Definition: CVLog.cpp:113
Type y
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:137
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.
const PickedPoint & getPickedPoint(unsigned index) const
Returns a given point.
Definition: ecv2DLabel.h:194
void clear(bool ignoreDependencies=false, bool ignoreCaption=true)
Clears label.
void updateLabel()
void setDisplayedIn2D(bool state)
Whether to display the label in 2D.
Definition: ecv2DLabel.h:114
unsigned size() const
Returns current size.
Definition: ecv2DLabel.h:74
virtual QString getName() const override
Returns object name.
QStringList getLabelContent(int precision) const
Gets label content (as it will be displayed)
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
2D viewport label
void setRoi(const float *roi)
Sets ROI (relative to screen)
const float * roi() const
Returns ROI (relative to screen)
void setParameters(const ecvViewportParameters &params)
Sets perspective view state.
virtual bool isVisible() const
Returns whether entity is visible or not.
virtual void setVisible(bool state)
Sets entity visibility.
virtual void setRedraw(bool state)
Sets entity redraw mode.
virtual bool isSelected() const
Returns whether entity is selected or not.
virtual void setSelected(bool state)
Selects/Unselects entity.
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
virtual void setName(const QString &name)
Sets object name.
Definition: ecvObject.h:75
virtual void setEnabled(bool state)
Sets the "enabled" property.
Definition: ecvObject.h:102
Point/triangle picking hub.
Definition: ecvPickingHub.h:29
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void stop(bool state) override
Stops process/dialog.
bool linkWith(QWidget *win) override
Links the overlay dialog with a MDI window.
cc2DViewportLabel * m_rect2DLabel
Associated 2D label.
void processPickedPoint(ccPointCloud *cloud, unsigned pointIndex, int x, int y) override
Generic method to process picked points.
cc2DLabel * m_label
Associated 3D label.
virtual void stop(bool state) override
Stops process/dialog.
virtual ~ccPointPropertiesDlg()
Default destructor.
Mode m_pickingMode
Current picking mode.
ccPointPropertiesDlg(ccPickingHub *pickingHub, QWidget *parent)
Default constructor.
void processClickedPoint(int x, int y)
void newLabel(ccHObject *)
Signal emitted when a new label is created.
virtual bool linkWith(QWidget *win) override
Links the overlay dialog with a MDI window.
void update2DZone(int x, int y, Qt::MouseButtons buttons)
virtual bool start() override
Starts process.
static void RemoveFromOwnDB(ccHObject *obj)
Removes an entity from window own DB.
static void AddToOwnDB(ccHObject *obj, bool noDependency=true)
Adds an entity to window own DB.
void leftButtonClicked(int x, int y)
Signal emitted when the left mouse button is cliked on the window.
static const ecvViewportParameters & GetViewportParameters()
static CCVector3d ToVtkCoordinates(int x, int y, int z=0)
static INTERACTION_FLAGS TRANSFORM_CAMERA()
static bool USE_2D
static int GlWidth()
Returns the OpenGL context width.
void mouseMoved(int x, int y, Qt::MouseButtons buttons)
Signal emitted when the mouse is moved.
static ecvDisplayTools * TheInstance()
static void SetInteractionMode(INTERACTION_FLAGS flags)
static QWidget * GetCurrentScreen()
static void SetRedrawRecursive(bool redraw=false)
void buttonReleased()
Signal emitted when a mouse button is released (cursor on the window)
static void RedrawDisplay(bool only2D=false, bool forceRedraw=true)
static const ParamStruct & Parameters()
Returns the stored values of each parameter.
static QString s_last2DLabelComment("")
ccGenericPointCloud * cloud
Cloud.
Definition: ecv2DLabel.h:124