Page 1 of 1
How to Refresh PoinCloud in Plugin?
Posted: Sat Mar 06, 2021 6:40 pm
by CCNewbieL6
Hello!
During running my plugin, I add points in a ccPointCloud object. How can I refresh it so that I can get a real-time updated pointcloud view?
Code: Select all
ccMainAppInterface *m_app;
ccHObject *container;
ccPointCloud *pc;
container = new ccHObject("Scan001");
pc = new ccPointCloud("RealScan");
container->addChild(pc);
m_app->addToDB(container, true, true);
for(...){
pc->addPoint(CCVector3(......)); // addPoint here
.......// I try to refresh the view of pc here.
}
Re: How to Refresh PoinCloud in Plugin?
Posted: Sat Mar 06, 2021 9:39 pm
by WargodHernandez
You probably... almost definitely do not want to update point by point you will at a minimum want to have large chunks of points on each refresh.
another option is having 2 clouds and swap between each visibility state, so work on the hidden one then toggle visibility.
But getting back to your question the first thing you need to do is set your point clouds display, and some other display options typically you would do something like this
Code: Select all
pc->setDisplay(m_app->getActiveGLWindow());
pc->showColors(true);
pc->setVisible(true);
Then when you want to refresh the display, I believe the nice way is as follows
Re: How to Refresh PoinCloud in Plugin?
Posted: Sun Mar 07, 2021 8:41 am
by CCNewbieL6
Thank you for your reply, WargodHernandez.
I have tried these, but it does not work:
Code: Select all
ccMainAppInterface *m_app;
ccHObject *container;
ccPointCloud *pc;
container = new ccHObject("Scan001");
pc = new ccPointCloud("RealScan");
container->addChild(pc);
m_app->addToDB(container, true, true);
pc->setDisplay(m_app->getActiveGLWindow());
pc->showColors(true);
pc->setVisible(true);
pc->setEnabled(true);
static_cast<ccGLWindow*>(container->getDisplay())->setVisible(true);
(per 2000ms ...... ){ // per 2000ms a refreash, about 1000 new points
// I try to refresh the view of pc here.
//m_app->removeFromDB(container,false);
//m_app->addToDB(container);
container->prepareDisplayForRefresh();
//container->refreshDisplay();
//static_cast<ccGLWindow*>(container->getDisplay())->zoomGlobal();
pc->prepareDisplayForRefresh();
pc->refreshDisplay();
}
In another thread, program read pointcloud data from a Lidar:
Code: Select all
......
// thread for reading
pc->addPoint(CCVector3(......)); // addPoint here
......
I want it refresh automatically. Per 2000ms a refreash, about 1000 new points. Now, I can only refresh pc manually.
Thank you!
Re: How to Refresh PoinCloud in Plugin?
Posted: Sun Mar 07, 2021 12:01 pm
by daniel
I don't think you need to bother 'preparing for refresh' or 'refreshing' the container, etc.
You should simply call 'pc->redrawDisplay();'
(and in your other thread, make sure you have reserved enough memory to store the added points - what will take the most time is the memory allocation).
Re: How to Refresh PoinCloud in Plugin?
Posted: Sun Mar 07, 2021 3:00 pm
by CCNewbieL6
Thank you, daniel!
My issue has been solved perfectly.
Let me make a Summarize:
To refresh the display of a point cloud, just simply call "pc->redrawDisplay();":
Code: Select all
ccPointCloud *pc;
......
pc->redrawDisplay(); // refresh
Before adding a Point to pc, we should reserve memory first:
Code: Select all
pc->reserve(1); //reserve memory
pc->addPoint(CCVector3(x, y, z)); // add point
It is important to note that: when we refresh pc, it is better to have a large chunk of points on each refresh.
The point-by-point method will consume a lot of computing resources.
Thanks to my best teacher, daniel and WargodHernandez!
Re: How to Refresh PoinCloud in Plugin?
Posted: Mon Mar 08, 2021 5:17 pm
by WargodHernandez
yeah I would think about how long you expect scans to last, at 2000ms 1k points your recording 500 points per second, so if you expect scans to last 1 minute reserve > 30K, if you want an hour then bump it up to 1.8M