Set point clolor in ccPointCloud

Feel free to ask any question here
Post Reply
kasper
Posts: 29
Joined: Thu May 17, 2018 6:13 am

Set point clolor in ccPointCloud

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

Re: Set point clolor in ccPointCloud

Post by daniel »

Have you 'reserved' some memory for the colors before? (with the 'ccPoinCloud::reserveTheRGBTable' method)
Daniel, CloudCompare admin
kasper
Posts: 29
Joined: Thu May 17, 2018 6:13 am

Re: Set point clolor in ccPointCloud

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

Re: Set point clolor in ccPointCloud

Post by WargodHernandez »

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

Should be

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