How to Refresh PoinCloud in Plugin?

Questions related to plugins development
Post Reply
CCNewbieL6
Posts: 23
Joined: Wed Jan 27, 2021 11:11 am

How to Refresh PoinCloud in Plugin?

Post 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.
			}
			
WargodHernandez
Posts: 187
Joined: Tue Mar 05, 2019 3:59 pm

Re: How to Refresh PoinCloud in Plugin?

Post 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

Code: Select all

pc->prepareDisplayForRefresh();
CCNewbieL6
Posts: 23
Joined: Wed Jan 27, 2021 11:11 am

Re: How to Refresh PoinCloud in Plugin?

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

Re: How to Refresh PoinCloud in Plugin?

Post 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).
Daniel, CloudCompare admin
CCNewbieL6
Posts: 23
Joined: Wed Jan 27, 2021 11:11 am

Re: How to Refresh PoinCloud in Plugin?

Post 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!
WargodHernandez
Posts: 187
Joined: Tue Mar 05, 2019 3:59 pm

Re: How to Refresh PoinCloud in Plugin?

Post 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
Post Reply