ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cc2DLabel.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <pybind11/pybind11.h>
9 #include <pybind11/stl.h>
10 #include <pybind11/stl_bind.h>
11 
12 #include <ecv2DLabel.h>
13 #include <ecvGenericMesh.h>
14 #include <ecvGenericPointCloud.h>
15 
16 #include "../casters.h"
17 
18 namespace py = pybind11;
19 using namespace pybind11::literals;
20 
21 void define_cc2DLabel(py::module &m)
22 {
23  py::class_<cc2DLabel, ccHObject, ccInteractor> Pycc2DLabel(m, "cc2DLabel");
24  Pycc2DLabel.def(py::init<QString>(), "name"_a = QString("Label"));
25  Pycc2DLabel.def("getRawName", &cc2DLabel::getRawName);
26  Pycc2DLabel.def("getLabelContent", &cc2DLabel::getLabelContent, "precision"_a);
27  Pycc2DLabel.def("getTitle", &cc2DLabel::getTitle, "precision"_a);
28  Pycc2DLabel.def("setPosition", &cc2DLabel::setPosition, "x"_a, "y"_a);
29  Pycc2DLabel.def("getPosition",
30  [](const cc2DLabel &self)
31  {
32  py::tuple pos(2);
33  pos[0] = self.getPosition()[0];
34  pos[1] = self.getPosition()[1];
35  return pos;
36  });
37  Pycc2DLabel.def(
38  "clear", &cc2DLabel::clear, "ignoreDependencies"_a = false, "ignoreCaption"_a = true);
39  Pycc2DLabel.def("size", &cc2DLabel::size);
40  Pycc2DLabel.def("addPickedPoint",
41  (bool(cc2DLabel::*)(ccGenericPointCloud *, unsigned, bool)) &
43  "cloud"_a,
44  "pointIndex"_a,
45  "entityCenter"_a = false);
46  Pycc2DLabel.def("addPickedPoint",
47  (bool(cc2DLabel::*)(ccGenericMesh *, unsigned, const CCVector2d &, bool)) &
49  "cloud"_a,
50  "triangleIndex"_a,
51  "uv"_a,
52  "entityCenter"_a = false);
53  Pycc2DLabel.def("setCollapsed", &cc2DLabel::setCollapsed, "state"_a);
54  Pycc2DLabel.def("isCollapsed", &cc2DLabel::isCollapsed);
55  Pycc2DLabel.def("displayPointLegend", &cc2DLabel::displayPointLegend, "state"_a);
56  Pycc2DLabel.def("isPointLegendDisplayed", &cc2DLabel::isPointLegendDisplayed);
57  Pycc2DLabel.def("setDisplayedIn2D", &cc2DLabel::setDisplayedIn2D, "state"_a);
58  Pycc2DLabel.def("isDisplayedIn2D", &cc2DLabel::isDisplayedIn2D);
59  Pycc2DLabel.def("setRelativeMarkerScale", &cc2DLabel::setRelativeMarkerScale, "value"_a);
60 
61  py::class_<cc2DLabel::PickedPoint>(Pycc2DLabel, "PickedPoint")
62  .def_readwrite("_cloud", &cc2DLabel::PickedPoint::cloud, py::return_value_policy::reference)
63  .def_readwrite("_mesh", &cc2DLabel::PickedPoint::mesh, py::return_value_policy::reference)
64  .def_readwrite("index", &cc2DLabel::PickedPoint::index)
65  .def_readwrite("pos2D", &cc2DLabel::PickedPoint::pos2D)
66  .def_readwrite("uv", &cc2DLabel::PickedPoint::uv)
67  .def_readwrite("entityCenterPoint", &cc2DLabel::PickedPoint::entityCenterPoint)
68  .def("getPointPosition", &cc2DLabel::PickedPoint::getPointPosition)
69  .def("cloudOrVertices",
71  py::return_value_policy::reference)
72  .def("getUniqueID", &cc2DLabel::PickedPoint::getUniqueID)
73  .def("entity", &cc2DLabel::PickedPoint::entity, py::return_value_policy::reference)
74  .def("itemTitle", &cc2DLabel::PickedPoint::itemTitle)
75  .def("prefix", &cc2DLabel::PickedPoint::prefix)
76  .def(py::init<>())
77  .def(py::init<ccGenericPointCloud *, unsigned, bool>(),
78  "_cloud"_a,
79  "pointIndex"_a,
80  "centerPoint"_a = false)
81  .def(py::init<ccGenericMesh *, unsigned, const CCVector2d &, bool>(),
82  "_mesh"_a,
83  "triIndex"_a,
84  "uv"_a,
85  "centerPoint"_a = false);
86 
87  Pycc2DLabel.def("addPickedPoint",
88  (bool(cc2DLabel::*)(const cc2DLabel::PickedPoint &)) &
90  "pp"_a);
91  Pycc2DLabel.def("getPickedPoint",
92  (const cc2DLabel::PickedPoint &(cc2DLabel::*)(unsigned) const) &
94  "index"_a);
95  Pycc2DLabel.def("getPickedPoint",
97  "index"_a);
98 }
void define_cc2DLabel(py::module &m)
Definition: cc2DLabel.cpp:21
2D label (typically attached to points)
Definition: ecv2DLabel.h:22
bool addPickedPoint(ccGenericPointCloud *cloud, unsigned pointIndex, bool entityCenter=false)
Adds a point to this label.
const PickedPoint & getPickedPoint(unsigned index) const
Returns a given point.
Definition: ecv2DLabel.h:194
QString getTitle(int precision) const
Returns the (3D) label title.
bool isCollapsed() const
Returns whether the label is collapsed or not.
Definition: ecv2DLabel.h:105
QString getRawName() const
Returns 'raw' name (no replacement of default keywords)
Definition: ecv2DLabel.h:36
void clear(bool ignoreDependencies=false, bool ignoreCaption=true)
Clears label.
void setRelativeMarkerScale(float scale)
Sets marker (relative) scale.
Definition: ecv2DLabel.h:205
void setCollapsed(bool state)
Whether to collapse label or not.
Definition: ecv2DLabel.h:102
bool isPointLegendDisplayed() const
Returns whether the point(s) legend is displayed.
Definition: ecv2DLabel.h:111
void setDisplayedIn2D(bool state)
Whether to display the label in 2D.
Definition: ecv2DLabel.h:114
unsigned size() const
Returns current size.
Definition: ecv2DLabel.h:74
QStringList getLabelContent(int precision) const
Gets label content (as it will be displayed)
void setPosition(float x, float y)
Sets relative position.
bool isDisplayedIn2D() const
Returns whether the label is displayed in 2D.
Definition: ecv2DLabel.h:117
void displayPointLegend(bool state)
Whether to display the point(s) legend (title only)
Definition: ecv2DLabel.h:108
Generic mesh interface.
A 3D cloud interface with associated features (color, normals, octree, etc.)
Picked point descriptor.
Definition: ecv2DLabel.h:122
CCVector2d uv
Barycentric coordinates (for triangles)
Definition: ecv2DLabel.h:136
CCVector3 getPointPosition() const
Returns the point position (3D)
unsigned index
Point/triangle index.
Definition: ecv2DLabel.h:128
QString itemTitle() const
ccGenericPointCloud * cloudOrVertices() const
Returns the cloud or the mesh vertices.
ccGenericMesh * mesh
Mesh.
Definition: ecv2DLabel.h:126
ccHObject * entity() const
Returns the associated entity (cloud or mesh)
bool entityCenterPoint
Entity center mode (index will be invalid)
Definition: ecv2DLabel.h:138
CCVector3d pos2D
Last known '2D' position (i.e. in screen space)
Definition: ecv2DLabel.h:132
ccGenericPointCloud * cloud
Cloud.
Definition: ecv2DLabel.h:124
QString prefix(const char *pointTag) const
Returns the point prefix ('Point' or 'Point@Tri' or 'IDXX Center')
unsigned getUniqueID() const
Returns the cloud or the mesh unique ID.