How to change the color of a point with code?

Feel free to ask any question here
Post Reply
xiaolu
Posts: 36
Joined: Fri Apr 02, 2021 9:42 am

How to change the color of a point with code?

Post by xiaolu »

hi there,

I want to change the color of a point with code.

For example, I want to change the 10th point in the point cloud to red.

thanks~
DA523
Posts: 166
Joined: Mon May 25, 2020 4:02 pm

Re: How to change the color of a point with code?

Post by DA523 »

1- Use text editor or LibreOffice Calc to add 255 in front of your red points and 0 for others
2- Save as csv or txt
3- Open by CC as in pic below
However may be there is beter way directly by CC ?

Remarks:
1- You can ignore label during importing points
2- You can put labels in group to show or hide
3- You can change opacity of label to 0
4- To change points size use properties not (+- ) it is sometimes does not work
.
12.png
12.png (48.57 KiB) Viewed 2295 times
.
123.png
123.png (66.49 KiB) Viewed 2295 times
.
33.png
33.png (93.25 KiB) Viewed 2295 times
.
.
11111111.zip
(409 Bytes) Downloaded 221 times
.
xiaolu
Posts: 36
Joined: Fri Apr 02, 2021 9:42 am

Re: How to change the color of a point with code?

Post by xiaolu »

Thank you for your reply.

But this method doesn't quite work for me.
What I need is a point cloud already loaded and then change the color of one of its points.

But still, thank you very much.

I found a function

Code: Select all

void ccPointCloud::setPointColor(unsigned pointIndex, const ccColor::Rgba& col)
{
	assert(m_rgbaColors && pointIndex < m_rgbaColors->currentSize());

	m_rgbaColors->setValue(pointIndex, col);

	//We must update the VBOs
	colorsHaveChanged();
}
This is how I use it (pc1 is the point cloud already loaded into the dbtree)

Code: Select all

pc1->setPointColor(10, ccColor::red);
But it reports an error.

Code: Select all

 Assertion `m_rgbaColors && pointIndex < m_rgbaColors->currentSize()' failed.
Aborted (core dumped)
xiaolu
Posts: 36
Joined: Fri Apr 02, 2021 9:42 am

Re: How to change the color of a point with code?

Post by xiaolu »

I found my own way

need to set a base color first.

Code: Select all

 pc1->setColor(ccColor::white);
Then change the color of the 10th point

Code: Select all

pc1->setPointColor(10, ccColor::red);
Then

Code: Select all

m_app->addToDB(pc1);
Success
Post Reply