Page 1 of 2
getPickedPoints
Posted: Fri Jun 18, 2021 6:28 am
by suyufeng
ccPointListPickingDlg::getPickedPoints()
How do I call it in the plugin to get the coordinates of the point selected by the mouse?
Re: getPickedPoints
Posted: Fri Jun 18, 2021 7:57 am
by suyufeng
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());
}
Re: getPickedPoints
Posted: Fri Jun 18, 2021 7:59 am
by suyufeng
Forgot to mention, I noticed that this function is protected members, and I moved it to public.
Re: getPickedPoints
Posted: Sun Jun 20, 2021 1:34 pm
by daniel
Re: getPickedPoints
Posted: Mon Jun 21, 2021 12:23 pm
by suyufeng
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.
Re: getPickedPoints
Posted: Mon Jun 21, 2021 8:08 pm
by WargodHernandez
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.
Re: getPickedPoints
Posted: Fri Jun 25, 2021 2:09 am
by suyufeng
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.
Re: getPickedPoints
Posted: Sun Jun 27, 2021 9:39 am
by daniel
That's only in debug mode.
Re: getPickedPoints
Posted: Thu Jul 29, 2021 6:21 am
by lxx_13253530485
Code: Select all
ccPickingHub* ph = m_app->pickingHub();
ph->addListener(this, true, true, ccGLWindow::POINT_PICKING);
When I use addListener(),vs does not recognize this external symbol at compile time. Do I need to add a library ?
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 )
And this is error:
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)
A sincere request!
Thanks!
Re: getPickedPoints
Posted: Thu Jul 29, 2021 1:28 pm
by daniel
Do you see the ccPickingHub source files in your plugin project? (and can you open the files?). Maybe the relative path is not right?