getPickedPoints

For any question about plugins!
suyufeng
Posts: 47
Joined: Wed May 26, 2021 7:04 am

getPickedPoints

Post by suyufeng »

ccPointListPickingDlg::getPickedPoints()

How do I call it in the plugin to get the coordinates of the point selected by the mouse?
suyufeng
Posts: 47
Joined: Wed May 26, 2021 7:04 am

Re: getPickedPoints

Post 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());
}
suyufeng
Posts: 47
Joined: Wed May 26, 2021 7:04 am

Re: getPickedPoints

Post by suyufeng »

Forgot to mention, I noticed that this function is protected members, and I moved it to public.
daniel
Site Admin
Posts: 7710
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: getPickedPoints

Post by daniel »

No, you should use the ccPickingHub instead: https://github.com/CloudCompare/CloudCo ... ckingHub.h
Daniel, CloudCompare admin
suyufeng
Posts: 47
Joined: Wed May 26, 2021 7:04 am

Re: getPickedPoints

Post 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.
Attachments
Screenshot from 2021-06-21 20-23-02.png
Screenshot from 2021-06-21 20-23-02.png (69.78 KiB) Viewed 6702 times
Screenshot from 2021-06-21 20-21-23.png
Screenshot from 2021-06-21 20-21-23.png (13.47 KiB) Viewed 6702 times
WargodHernandez
Posts: 187
Joined: Tue Mar 05, 2019 3:59 pm

Re: getPickedPoints

Post 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.
suyufeng
Posts: 47
Joined: Wed May 26, 2021 7:04 am

Re: getPickedPoints

Post 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.
daniel
Site Admin
Posts: 7710
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: getPickedPoints

Post by daniel »

That's only in debug mode.
Daniel, CloudCompare admin
lxx_13253530485
Posts: 2
Joined: Thu Jul 22, 2021 11:56 am

Re: getPickedPoints

Post 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!
daniel
Site Admin
Posts: 7710
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: getPickedPoints

Post 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?
Daniel, CloudCompare admin
Post Reply