getPickedPoints
getPickedPoints
ccPointListPickingDlg::getPickedPoints()
How do I call it in the plugin to get the coordinates of the point selected by the mouse?
How do I call it in the plugin to get the coordinates of the point selected by the mouse?
Re: getPickedPoints
ccPointListPickingDlg *point_list_picking;
std::vector<cc2DLabel*> labels;
const int count = static_cast<int>(point_list_picking->getPickedPoints(labels)); //Crashes here
for ( int i = 0; i < count; ++i )
{
cc2DLabel* label = labels[static_cast<unsigned int>( i )];
const cc2DLabel::PickedPoint& PP = label->getPickedPoint(0);
CCVector3 P = PP.getPointPosition();
CCVector3d Pd = CCVector3d::fromArray(P.u);
for(int j = 0 ; j < 5; ++j)
{
tablewidget->insertRow(i);
tablewidget->setItem(i, j, new QTableWidgetItem(QStringLiteral( "%1" ).arg( Pd.u[j], 0, 'f', 0 )));
}
}
I want to use it in my plug-in. But it fell apart.I marked the breakdown.
unsigned ccPointListPickingDlg::getPickedPoints(std::vector<cc2DLabel*>& pickedPoints)
{
pickedPoints.clear();
if (m_orderedLabelsContainer) // Do not enter if,The debug message crashes here.
{
//get all labels
ccHObject::Container labels;
unsigned count = m_orderedLabelsContainer->filterChildren(labels, false, CC_TYPES::LABEL_2D);
try
{
pickedPoints.reserve(count);
}
catch (const std::bad_alloc&)
{
ccLog::Error("Not enough memory!");
return 0;
}
for (unsigned i = 0; i < count; ++i)
{
if (labels->isA(CC_TYPES::LABEL_2D)) //Warning: cc2DViewportLabel is also a kind of 'CC_TYPES::LABEL_2D'!
{
cc2DLabel* label = static_cast<cc2DLabel*>(labels);
if (label->isVisible() && label->size() == 1)
{
pickedPoints.push_back(label);
}
}
}
}
return static_cast<unsigned>(pickedPoints.size());
}
std::vector<cc2DLabel*> labels;
const int count = static_cast<int>(point_list_picking->getPickedPoints(labels)); //Crashes here
for ( int i = 0; i < count; ++i )
{
cc2DLabel* label = labels[static_cast<unsigned int>( i )];
const cc2DLabel::PickedPoint& PP = label->getPickedPoint(0);
CCVector3 P = PP.getPointPosition();
CCVector3d Pd = CCVector3d::fromArray(P.u);
for(int j = 0 ; j < 5; ++j)
{
tablewidget->insertRow(i);
tablewidget->setItem(i, j, new QTableWidgetItem(QStringLiteral( "%1" ).arg( Pd.u[j], 0, 'f', 0 )));
}
}
I want to use it in my plug-in. But it fell apart.I marked the breakdown.
unsigned ccPointListPickingDlg::getPickedPoints(std::vector<cc2DLabel*>& pickedPoints)
{
pickedPoints.clear();
if (m_orderedLabelsContainer) // Do not enter if,The debug message crashes here.
{
//get all labels
ccHObject::Container labels;
unsigned count = m_orderedLabelsContainer->filterChildren(labels, false, CC_TYPES::LABEL_2D);
try
{
pickedPoints.reserve(count);
}
catch (const std::bad_alloc&)
{
ccLog::Error("Not enough memory!");
return 0;
}
for (unsigned i = 0; i < count; ++i)
{
if (labels->isA(CC_TYPES::LABEL_2D)) //Warning: cc2DViewportLabel is also a kind of 'CC_TYPES::LABEL_2D'!
{
cc2DLabel* label = static_cast<cc2DLabel*>(labels);
if (label->isVisible() && label->size() == 1)
{
pickedPoints.push_back(label);
}
}
}
}
return static_cast<unsigned>(pickedPoints.size());
}
Re: getPickedPoints
Forgot to mention, I noticed that this function is protected members, and I moved it to public.
Re: getPickedPoints
No, you should use the ccPickingHub instead: https://github.com/CloudCompare/CloudCo ... ckingHub.h
Daniel, CloudCompare admin
Re: getPickedPoints
Thank you very much.
I did my job with these functions.
if (!m_app->pickingHub()) //no valid picking hub
{
m_app->dispToConsole("[ccCompass] Could not retrieve valid picking hub. Measurement aborted.", ccMainAppInterface::ERR_CONSOLE_MESSAGE);
}
if (!m_app->pickingHub()->addListener(this, true, true))
{
m_app->dispToConsole("Another tool is already using the picking mechanism. Stop it first", ccMainAppInterface::ERR_CONSOLE_MESSAGE);
}
onItemPicked()
I did my job of getting coordinates in onitemoicked, but I ran into a problem.
When I adjust the scalar, click on my plug-in to select the mouse point function, an exception occurs, the point cloud color disappears! The scalar is still the one I set. When I set the scalar again, the scalar will not be abnormal again.
I did my job with these functions.
if (!m_app->pickingHub()) //no valid picking hub
{
m_app->dispToConsole("[ccCompass] Could not retrieve valid picking hub. Measurement aborted.", ccMainAppInterface::ERR_CONSOLE_MESSAGE);
}
if (!m_app->pickingHub()->addListener(this, true, true))
{
m_app->dispToConsole("Another tool is already using the picking mechanism. Stop it first", ccMainAppInterface::ERR_CONSOLE_MESSAGE);
}
onItemPicked()
I did my job of getting coordinates in onitemoicked, but I ran into a problem.
When I adjust the scalar, click on my plug-in to select the mouse point function, an exception occurs, the point cloud color disappears! The scalar is still the one I set. When I set the scalar again, the scalar will not be abnormal again.
- Attachments
-
- Screenshot from 2021-06-21 20-23-02.png (69.78 KiB) Viewed 6641 times
-
- Screenshot from 2021-06-21 20-21-23.png (13.47 KiB) Viewed 6641 times
-
- Posts: 187
- Joined: Tue Mar 05, 2019 3:59 pm
Re: getPickedPoints
we would need a lot more context to help track down the exception, what your showing has a risk that it would try to use an invalid picking hub since your valid picking hub check doesn't bail out of the function early.
but beyond that, we need information.
but beyond that, we need information.
Re: getPickedPoints
Thank you for your answer, we solved this problem, and we found that on the first click, cc created a scalar called "octree_picking" for the point cloud.
-
- Posts: 2
- Joined: Thu Jul 22, 2021 11:56 am
Re: getPickedPoints
Code: Select all
ccPickingHub* ph = m_app->pickingHub();
ph->addListener(this, true, true, ccGLWindow::POINT_PICKING);
This is a part of my cmakeList:
Code: Select all
# we need includes from the main CC source dir
include_directories( ${CloudCompare_SOURCE_DIR} )
#we need ccOverlay classes
file( GLOB CC_PLUGIN_CUSTOM_HEADER_LIST ${CloudCompare_SOURCE_DIR}/../common/ccOverlayDialog*.h )
file( GLOB CC_PLUGIN_CUSTOM_SOURCE_LIST ${CloudCompare_SOURCE_DIR}/../common/ccOverlayDialog*.cpp )
#we also need picking hub classes
list( APPEND CC_PLUGIN_CUSTOM_HEADER_LIST ${CloudCompare_SOURCE_DIR}/../common/ccPickingListener.h )
list( APPEND CC_PLUGIN_CUSTOM_HEADER_LIST ${CloudCompare_SOURCE_DIR}/../common/ccPickingHub.h )
list( APPEND CC_PLUGIN_CUSTOM_SOURCE_LIST ${CloudCompare_SOURCE_DIR}/../common/ccPickingHub.cpp )
Code: Select all
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: bool __cdecl ccPickingHub::addListener(class ccPickingListener *,bool,bool,enum ccGLWindow::PICKING_MODE)" (?addListener@ccPickingHub@@QEAA_NPEAVccPickingListener@@_N1W4PICKING_MODE@ccGLWindow@@@Z) referenced in function "protected: void __cdecl TestPlugin::doAction(void)" (?doAction@TestPlugin@@IEAAXXZ)
Thanks!
Re: getPickedPoints
Do you see the ccPickingHub source files in your plugin project? (and can you open the files?). Maybe the relative path is not right?
Daniel, CloudCompare admin