Page 1 of 1

setPointColor failed

Posted: Tue Apr 27, 2021 4:29 am
by kasper
I want to set point cloud but it always failed.
This is my code, is it anything wrong?

My cloudcompare version is 2.9.1

If you can, please give me a resolution for it. Thanks.

Code: Select all

 ccPointCloud *cc_cloud = new ccPointCloud;
    cc_cloud->reserve(100);
    for (int i = 0; i < 100; i++)
    {
        CCvecotr3 p;
        p.x = i;
        p.y = i;
        p.z = i;
        cc_cloud->addPoint(p);
    }

    cc_cloud->enableScalarField();
    cc_cloud->showColors(true);
    if (cc_cloud->resizeTheRGBTable(true))
    {
        srand(static_cast<unsigned int>(time(0)));
        std::vector<unsigned char> colors;
        for (size_t i = 0; i < cc_cloud->size(); i++)
        {
            colors.push_back(static_cast<unsigned char>(rand() % 256));
            colors.push_back(static_cast<unsigned char>(rand() % 256));
            colors.push_back(static_cast<unsigned char>(rand() % 256));
        }

        int next_color = 0;
        for (int i = 0; i < cc_cloud->size(); i++)
        {
            ccColor::Rgb rgb = ccColor::Rgb(colors[3 * next_color], colors[3 * next_color + 1], colors[3 * next_color + 2]);
            cc_cloud->setPointColor(i, rgb);
            next_color++;
        }
    }
 


it can build sucessly, but always gets pointcloud without color.

Re: setPointColor failed

Posted: Tue Apr 27, 2021 8:21 am
by daniel
At least you should remove the call to 'enableScalarField' (as you don't have a scalar field - and if you do, then I believe the SF will have the priority on the RGB colors).

Re: setPointColor failed

Posted: Tue Apr 27, 2021 9:34 am
by kasper
Hi, Daniel.

Even I remove "enableScalarField", it's not working.

I save the result data to bin file and open it in Cloudcompare.
The pointcloud do not have any color and even have no "Color" selection.

Is there any example for adding pointcolor?

I've confused in this issue for a while.

Re: setPointColor failed

Posted: Tue Apr 27, 2021 9:51 am
by daniel
You can look at any I/O filter (such as AsciiFilter.cpp). But in these cases we 'add' the colors one by one.

A good example for the use of 'setPointColor' is ccKdTree::convertCellIndexToRandomColor.

Have you tried to export the cloud to an ASCII file by the way? (this way you'll see directly if the cloud has RGB colors or not).

Re: setPointColor failed

Posted: Tue Apr 27, 2021 9:59 am
by kasper
i know the problem, Thanks.