Page 1 of 1

Set point clolor in ccPointCloud

Posted: Mon Aug 17, 2020 5:36 am
by kasper
I try to set different color by the point index in pointcloud.
But it always crush.

Code: Select all

for( int i=0; i<cloud->size(); i++)
{
	ccColor::Rgb color;   //same color for example
	color.r = 255;
	color.g = 0;
	color.b = 0;	
	cloud->setPointColor(i, color);   // this line always crush.
}
Could you please offer the correct sample code for this function?

Re: Set point clolor in ccPointCloud

Posted: Mon Aug 17, 2020 9:30 pm
by daniel
Have you 'reserved' some memory for the colors before? (with the 'ccPoinCloud::reserveTheRGBTable' method)

Re: Set point clolor in ccPointCloud

Posted: Tue Aug 18, 2020 1:46 am
by kasper
Sorry for post an incomplete code.

Code: Select all

    BinFilter bin;
    BinFilter::LoadParameters lp;
    BinFilter::SaveParameters sp;
    
    ccHObject *obj = new ccHObject;
    bin.loadFile("origin_cloud.bin", *obj, lp);
    ccPointCloud *cloud = ccHObjectCaster::ToPointCloud(obj->getFirstChild());
    
    if (cloud->resizeTheRGBTable(true))
    {
        for (int i = 0; cloud->size(); i++)
        {
            ccColor::Rgb color;
            color.r = 255;
            color.g = 0;
            color.b = 0;
            cloud->setPointColor(i, color);  // <- crush in this line.
        }
        bin.saveToFile(cloud, "cloud_color.bin", sp);
    }
And the error shows:
erminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 36595) >= this->size() (which is 36595)

Re: Set point clolor in ccPointCloud

Posted: Tue Aug 18, 2020 6:03 pm
by WargodHernandez
for (int i = 0; cloud->size(); i++)

Should be

for (int i = 0; i < cloud->size(); i++)