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.
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
Adding labels
Re: Adding labels
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).
(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).
Daniel, CloudCompare admin
-
- Posts: 10
- Joined: Wed Mar 13, 2019 12:07 pm
Re: Adding labels
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:
An my results are something like:
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?
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);
}
I haven't found what part of the code is responsible for this stuff. Can you (or someone) help me?
Re: Adding labels
'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:
What you want is actually to display the 2D part of the label:
Code: Select all
newLabel->setDisplayedIn2D(true);
Daniel, CloudCompare admin
-
- Posts: 10
- Joined: Wed Mar 13, 2019 12:07 pm
Re: Adding labels
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.
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
Weird.
Can you try to call 'setPosition(0.1, 0.1)' on the label?
And just in case, can you also call 'displayPointLegend(false)'?
Can you try to call 'setPosition(0.1, 0.1)' on the label?
And just in case, can you also call 'displayPointLegend(false)'?
Daniel, CloudCompare admin
-
- Posts: 10
- Joined: Wed Mar 13, 2019 12:07 pm
Re: Adding labels
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!
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!