How to add ScalarValue while adding points?

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

How to add ScalarValue while adding points?

Post by CCNewbieL6 »

Hello,
I try to add ScalarValue while adding points.

I tried these codes, but nothing happened.

Code: Select all

	ccPointCloud *pc;
	......
	pc->setDisplay(m_app->getActiveGLWindow());
	pc->addScalarField("DefaultScalarField");
	pc->enableScalarField();
	pc->setCurrentScalarField(0);
	pc->showColors(true);
	pc->setVisible(true);
	pc->setEnabled(true);
	......
	pc->reserve(1);
	pc->addPoint(CCVector3(ppoint_data->x, ppoint_data->y, ppoint_data->z)); //ppoint_data is from Lidar
	pc->getScalarField(0)->addElement(ppoint_data->reflectivity);// Try to add ScalarValue
	pc->getScalarField(0)->computeMinAndMax();
	
What is the right option?
daniel
Site Admin
Posts: 7709
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: How to add ScalarValue while adding points?

Post by daniel »

It's not 'pc->showColors(true);' but 'pc->showSF(true); that you should call.

And technically you shouldn't need to call the following lines:

Code: Select all

	pc->setCurrentScalarField(0);
	pc->setVisible(true);
	pc->setEnabled(true);
Daniel, CloudCompare admin
CCNewbieL6
Posts: 23
Joined: Wed Jan 27, 2021 11:11 am

Re: How to add ScalarValue while adding points?

Post by CCNewbieL6 »

Thank you, daniel!

Your suggestion have solved my issue perfectly.
What needs to be added is “pc->setCurrentDisplayedScalarField(0); ”

This is the modified code:

Code: Select all

	ccPointCloud *pc;
	......
	pc->setDisplay(m_app->getActiveGLWindow());
	pc->addScalarField("DefaultScalarField");
	pc->enableScalarField();
	
	// modified here
	pc->showSF(true);
	pc->setCurrentDisplayedScalarField(0); // After several attempts, must setCurrentDisplayedScalarField.

	......
	pc->reserve(1); // reserve memory to store a new point.
	pc->addPoint(CCVector3(ppoint_data->x, ppoint_data->y, ppoint_data->z)); //ppoint_data is from Lidar
	pc->getScalarField(0)->addElement(ppoint_data->reflectivity);// add ScalarValue
	pc->getScalarField(0)->computeMinAndMax();
	
Thank you again!
Post Reply