setPointColor failed

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

setPointColor failed

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

Re: setPointColor failed

Post 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).
Daniel, CloudCompare admin
kasper
Posts: 29
Joined: Thu May 17, 2018 6:13 am

Re: setPointColor failed

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

Re: setPointColor failed

Post 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).
Daniel, CloudCompare admin
kasper
Posts: 29
Joined: Thu May 17, 2018 6:13 am

Re: setPointColor failed

Post by kasper »

i know the problem, Thanks.
Post Reply