ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvPointPickingGenericInterface.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 "MainWindow.h"
12 #include "db_tree/ecvDBRoot.h"
13 
14 // CV_CORE_LIB
15 #include <CVLog.h>
16 
17 // common
18 #include <ecvPickingHub.h>
19 
20 // CV_DB_LIB
21 #include <ecvDisplayTools.h>
22 #include <ecvPointCloud.h>
23 
25  ccPickingHub* pickingHub, QWidget* parent /*=0*/)
26  : ccOverlayDialog(parent), m_pickingHub(pickingHub) {
27  assert(m_pickingHub);
28 }
29 
31  // just in case
32  if (m_pickingHub) {
34  }
35 
36  if (!ccOverlayDialog::linkWith(win)) {
37  return false;
38  }
39 
40  // if the dialog is already linked to a window, we must disconnect the
41  // 'point picked' signal
42  return true;
43 }
44 
46  if (!m_pickingHub) {
47  CVLog::Error("[Point picking] No associated display!");
48  return false;
49  }
50 
51  // activate "point picking mode" in associated GL window
52  if (!m_pickingHub->addListener(this, true, true,
55  "Picking mechanism already in use. Close the tool using it "
56  "first.");
57  return false;
58  }
59 
61  return true;
62 }
63 
65  if (m_pickingHub) {
66  // deactivate "point picking mode" in all GL windows
68  }
69 
70  ccOverlayDialog::stop(state);
71 }
72 
74  if (!m_processing || !pi.entity) return;
75 
77  ccPointCloud* cloud = static_cast<ccPointCloud*>(pi.entity);
78  if (!cloud) {
79  assert(false);
81  "[Item picking] Picked point is not in pickable entities "
82  "DB?!");
83  return;
84  }
85  processPickedPoint(cloud, pi.itemIndex, pi.clickPoint.x(),
86  pi.clickPoint.y());
87  } else if (pi.entity->isKindOf(CV_TYPES::MESH)) {
88  // NOT HANDLED: 'POINT_PICKING' mode only for now
89  CVLog::Warning("[Item picking] 'POINT_PICKING' mode only for now!");
90  return;
91  // assert(false);
92  } else {
93  // unhandled entity
94  assert(false);
95  }
96 }
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
bool isKindOf(CV_CLASS_ENUM type) const
Definition: ecvObject.h:128
Generic overlay dialog interface.
virtual void stop(bool accepted)
Stops process/dialog.
virtual bool start()
Starts process.
bool m_processing
Running/processing state.
virtual bool linkWith(QWidget *win)
Links the overlay dialog with a MDI window.
Point/triangle picking hub.
Definition: ecvPickingHub.h:29
void removeListener(ccPickingListener *listener, bool autoStopPickingIfLast=true)
Removes a listener.
bool addListener(ccPickingListener *listener, bool exclusive=false, bool autoStartPicking=true, ecvDisplayTools::PICKING_MODE mode=ecvDisplayTools::POINT_OR_TRIANGLE_PICKING)
Adds a listener.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void stop(bool state) override
Stops process/dialog.
ccPointPickingGenericInterface(ccPickingHub *pickingHub, QWidget *parent=nullptr)
Default constructor.
virtual void processPickedPoint(ccPointCloud *cloud, unsigned pointIndex, int x, int y)=0
Generic method to process picked points.
bool linkWith(QWidget *win) override
Links the overlay dialog with a MDI window.
void onItemPicked(const PickedItem &pi) override
Inherited from ccPickingListener.
@ MESH
Definition: CVTypes.h:105
@ POINT_CLOUD
Definition: CVTypes.h:104