Page 1 of 1

How to add ScalarValue while adding points?

Posted: Sun Mar 07, 2021 11:45 am
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?

Re: How to add ScalarValue while adding points?

Posted: Sun Mar 07, 2021 12:07 pm
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);

Re: How to add ScalarValue while adding points?

Posted: Sun Mar 07, 2021 2:30 pm
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!