tmontaigu / CloudCompare-PythonRuntime

Python plugin for CloudCompare
55 stars 15 forks source link

pycc.cc2DLabel how to show label text #123

Closed eglrp closed 2 months ago

eglrp commented 2 months ago

Can pycc.cc2DLabel achieve the following effect,text label image

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);

}

(See https://github.com/CloudCompare/CloudCo ... .cpp#L1021 for instance)

reference https://www.danielgm.net/cc/forum/viewtopic.php?t=3826#

tmontaigu commented 2 months ago

Yes, something like this

import pycc
import cccorelib
import numpy as np

CC = pycc.GetInstance()

xs = np.arange(0.0, 5.0, 0.1, pycc.PointCoordinateType)
ys = np.ones(len(xs), pycc.PointCoordinateType) * 18.5
zs = np.ones(len(xs), pycc.PointCoordinateType) * 17.33

pc = pycc.ccPointCloud(xs, ys, zs)

label = pycc.cc2DLabel()
label.addPickedPoint(pc, 0)

label.setName("Hello, World")
label.setVisible(True)
label.setDisplayedIn2D(True)
label.displayPointLegend(True)
label.setPosition(0.1, 0.1)
label.displayPointLegend(False)

pc.addChild(label)
CC.addToDB(pc)
CC.addToDB(label)

display = CC.getActiveGLWindow()
label.setDisplay(display)

does this image

eglrp commented 2 months ago

good