Page 1 of 1
Adding labels
Posted: Tue Jul 09, 2019 8:47 am
by alvarofergar
Hi everyone!
I want to use CCLib to display labels at certain points on my cloud. I want to achieve something similar to what happens when you use the
Point picking tool.
- dudaforo.png (914.99 KiB) Viewed 42532 times
As far as I know, the functions related to display labels are connected to the point picking process but I want to establish the labels position after some calculations and not after an user interaction.
In resume, the function I want to create should be similar to
addLabel(Vector3 point_posc, string text) and show the label at the closest point of my cloud to the given position.
Is there a direct way to do this? Can I generate a
PickedItem from a 3D position? Does anybody has a better approach?
Thanks in advance!
Álvaro
Re: Adding labels
Posted: Tue Jul 09, 2019 9:21 pm
by daniel
Well, actually if your algorithm has determined a given point in a cloud (and you know its index), it's really easy to create a cc2DLabel entity and simply 'add' the point (index) associated to the cloud.
(See
https://github.com/CloudCompare/CloudCo ... .cpp#L1021 for instance)
Then you add this label as a child of the cloud, and add it to the database (which is also easy to do in a plugin, or via the main application).
Re: Adding labels
Posted: Wed Jul 10, 2019 8:01 am
by alvarofergar
Hello Daniel! Thanks for your reply.
I'm not using my algorithms directly on the cloud so I think I don't know the point index, just the position.
However, I have made a workaround where we have two clouds: one with the points we analyze and one auxiliary just to display labels.
My function look like this:
Code: Select all
void Viewer3D::addLabel(QVector3D posc, QString text)
{
m_auxcloud = new ccPointCloud();
const CCVector3* P_cc = new CCVector3{ static_cast<float>(posc.x()),
static_cast<float>(posc.y()),
static_cast<float>(posc.z())};
m_auxcloud->addPoint(*P_cc);
cc2DLabel* newLabel = new cc2DLabel();
newLabel->addPickedPoint(m_auxcloud, m_auxcloud->size()-1);
//Params
newLabel->setName(text);
newLabel->setVisible(true);
newLabel->setDisplayedIn2D(false);
newLabel->displayPointLegend(true);
newLabel->setRelativeMarkerScale(1.0);
ccGenericGLDisplay* display = ccviewer->getGLWindow();
if (display)
{
newLabel->setDisplay(display);
QSize size = display->getScreenSize();
newLabel->setPosition(400,400);
}
m_auxcloud->addChild(newLabel);
viewer->addToDB(m_auxcloud);
}
An my results are something like:
- dudaforo.png (13.68 KiB) Viewed 42482 times
It's an advance, but I don't know why my tags don't show the coordinates of the points as in my first post. Also, my labels can't be moved or minimized with the mouse and aren't connected with the marker.
I haven't found what part of the code is responsible for this stuff. Can you (or someone) help me?
Re: Adding labels
Posted: Thu Jul 11, 2019 8:29 pm
by daniel
'Point legend' is the name (title) that appear next to the point.
What you want is actually to display the 2D part of the label:
Re: Adding labels
Posted: Fri Jul 12, 2019 8:40 am
by alvarofergar
The setDisplayedIn2D(true) method didn't make any change.
With a derived class to access the protected members, I have also tried setting the m_showFullBody boolean to true and using the drawMeOnly2D() method, but I always get the same result.
Re: Adding labels
Posted: Sat Jul 13, 2019 7:21 pm
by daniel
Weird.
Can you try to call 'setPosition(0.1, 0.1)' on the label?
And just in case, can you also call 'displayPointLegend(false)'?
Re: Adding labels
Posted: Sun Jul 14, 2019 9:50 pm
by alvarofergar
Hello,
That was it! At one point I started passing the position as an absolute value and not as a relative one.
Thanks for all the answers and thanks also for this great software and code!!
Have a nice week!