Page 1 of 1
How does the “Trace a polyline by point picking” tool implement line marking in the code?
Posted: Thu May 27, 2021 2:49 am
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~
Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?
Posted: Thu May 27, 2021 7:46 am
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.
Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?
Posted: Thu May 27, 2021 8:28 am
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?
Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?
Posted: Thu May 27, 2021 3:56 pm
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).
Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?
Posted: Fri May 28, 2021 7:05 am
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.
Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?
Posted: Fri May 28, 2021 2:18 pm
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);
Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?
Posted: Mon May 31, 2021 7:38 am
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
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.
Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?
Posted: Tue Jun 01, 2021 9:40 am
by daniel
Ah ok, it could be also 'polyline->setColor(ccColor::Rgb(0, 0, 255));' I guess then.
Have you called showColor(true) afterwards?
Re: How does the “Trace a polyline by point picking” tool implement line marking in the code?
Posted: Wed Jun 02, 2021 1:07 am
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.