How does the “Trace a polyline by point picking” tool implement line marking in the code?

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

How does the “Trace a polyline by point picking” tool implement line marking in the code?

Post by xiaolu »

hello,
I want to know how this tool draws lines,
My personal understanding is to select two dots, and there's a function that connects the two dots (similar to pcl's addLine) https://pointclouds.org/documentation/c ... 03550ecab5
But I didn't find anything relevant in the code.
Can you tell me how to draw the line.
thanks~
daniel
Site Admin
Posts: 7711
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?

Post by daniel »

Well, in its basic form, the tool allows you to pick points on a cloud or on a mesh. And then it simply connects two consecutive points by straights segments (= polyline).

But there's an 'oversample' option that will generate intermediate points and try to stick them to the surface as well.

I don't know how the PCL function works, sorry.
Daniel, CloudCompare admin
xiaolu
Posts: 36
Joined: Fri Apr 02, 2021 9:42 am

Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?

Post by xiaolu »

Thank you for your answer,

Which code implements this step?
"It's just a straight line that connects two consecutive points."

I want to choose two points in a cloud of points and connect a line between them. How do I do that in code?
daniel
Site Admin
Posts: 7711
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?

Post by daniel »

Oh that's a 'simple' construction of a ccPolyline instance.

If it's only a few known points, it's especially easy: https://github.com/CloudCompare/CloudCo ... g.cpp#L269

If you want them to add them on the file each time the user picks a point, then you have to manage the memory (by resizing the underlying cloud).
Daniel, CloudCompare admin
xiaolu
Posts: 36
Joined: Fri Apr 02, 2021 9:42 am

Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?

Post by xiaolu »

I'm sorry, I looked at the source code and didn't find the right way,

If there are two dots (-34, 12, 8) and (12, -2, 9) how do I connect them with a red line,

Can you teach me how to write this code?

Thank you very much.
daniel
Site Admin
Posts: 7711
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?

Post by daniel »

Well, it would be something like that:

Code: Select all

ccPointCloud* vertices = new ccPointCloud("vertices");
ccPolyline* polyline = new ccPolyline(vertices);

if (!vertices->reserve(2) || !polyline->reserve(2))
{
	ccLog::Error("Not enough memory!");
	delete vertices;
	delete polyline;
	return;
}

vertices->addPoint(CCVector3(-34, 12, 8));
vertices->addPoint(CCVector3(12, -2, 9));

polyline->addPointIndex(0, 2);
polyline->setVisible(true);
polyline->setColor(0, 0, 255);
vertices->setEnabled(false);
polyline->addChild(vertices);
Daniel, CloudCompare admin
xiaolu
Posts: 36
Joined: Fri Apr 02, 2021 9:42 am

Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?

Post by xiaolu »

Thank you for your help.

I was able to draw a line successfully with your code.

But I need to add at the end

Code: Select all

 MainWindow::TheInstance()->addToDB(polyline);
before it can be displayed.

But there seems to be a problem with the code to set the color.
If I write directly

Code: Select all

polyline->setColor(0, 0, 255);
there is an error

Code: Select all

error: no matching function for call to 'ccPolyline::setColor(int, int, int)'
     polyline->setColor(0, 0, 255);
I wrote it as

Code: Select all

    ccColor::Rgb col = ccColor::Generator::Random();
    polyline->setColor(col);
Or

Code: Select all

 ccColor::Rgb col;
    col.r=0;
    col.g=0;
    col.b=255;
    polyline->setColor(col);
Neither can display the color.
Attachments
DeepinScreenshot_select-area_20210531153432.png
DeepinScreenshot_select-area_20210531153432.png (12.74 KiB) Viewed 3903 times
daniel
Site Admin
Posts: 7711
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?

Post by daniel »

Ah ok, it could be also 'polyline->setColor(ccColor::Rgb(0, 0, 255));' I guess then.

Have you called showColor(true) afterwards?
Daniel, CloudCompare admin
xiaolu
Posts: 36
Joined: Fri Apr 02, 2021 9:42 am

Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?

Post by xiaolu »

Thank you very much.

Perfect solution to my problem

In fact, he's got the color, but he doesn't show it.

polyline->showColors(true);

That's why he shows the color by default.
Post Reply