ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
lineset.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 <LineSet.h>
10 #include <ecvPointCloud.h>
11 #include <ecvTetraMesh.h>
12 
13 #include "pybind/docstring.h"
16 
17 namespace cloudViewer {
18 namespace geometry {
19 
20 void pybind_lineset(py::module &m) {
21  py::class_<LineSet, PyGeometry<LineSet>, std::shared_ptr<LineSet>,
22  ccHObject>
23  lineset(m, "LineSet",
24  "LineSet define a sets of lines in 3D. A typical "
25  "application is to display the point cloud correspondence "
26  "pairs.");
27  py::detail::bind_default_constructor<LineSet>(lineset);
28  py::detail::bind_copy_functions<LineSet>(lineset);
29  lineset.def(py::init<const std::vector<Eigen::Vector3d> &,
30  const std::vector<Eigen::Vector2i> &>(),
31  "Create a LineSet from given points and line indices",
32  "points"_a, "lines"_a)
33  .def("__repr__",
34  [](const LineSet &lineset) {
35  return std::string("LineSet with ") +
36  std::to_string(lineset.lines_.size()) + " lines.";
37  })
38  .def(py::self + py::self)
39  .def(py::self += py::self)
40  .def("has_points", &LineSet::HasPoints,
41  "Returns ``True`` if the object contains points.")
42  .def("has_lines", &LineSet::HasLines,
43  "Returns ``True`` if the object contains lines.")
44  .def("has_colors", &LineSet::hasColors,
45  "Returns ``True`` if the object's lines contain "
46  "colors.")
47  .def("get_line_coordinate", &LineSet::GetLineCoordinate,
48  "line_index"_a)
49  .def("paint_uniform_color", &LineSet::PaintUniformColor,
50  "Assigns each line in the line set the same color.", "color"_a)
51  .def_static("create_from_point_cloud_correspondences",
53  "Factory function to create a LineSet from two "
54  "pointclouds and a correspondence set.",
55  "cloud0"_a, "cloud1"_a, "correspondences"_a)
56  .def_static("create_from_oriented_bounding_box",
58  "Factory function to create a LineSet from an "
59  "OrientedBoundingBox.",
60  "box"_a)
61  .def_static("create_from_axis_aligned_bounding_box",
63  "Factory function to create a LineSet from an "
64  "AxisAlignedBoundingBox.",
65  "box"_a)
66  .def_static("create_from_triangle_mesh",
68  "Factory function to create a LineSet from edges of a "
69  "triangle mesh.",
70  "mesh"_a)
71  .def_static("create_from_tetra_mesh", &LineSet::CreateFromTetraMesh,
72  "Factory function to create a LineSet from edges of a "
73  "tetra mesh.",
74  "mesh"_a)
75  .def_static("create_camera_visualization",
77  "Factory function to create a LineSet from intrinsic "
78  "and extrinsic camera matrices",
79  "view_width_px"_a, "view_height_px"_a, "intrinsic"_a,
80  "extrinsic"_a, "scale"_a = 1.0)
81  .def_static(
82  "create_camera_visualization",
83  [](const camera::PinholeCameraIntrinsic &intrinsic,
84  const Eigen::Matrix4d &extrinsic, double scale) {
86  intrinsic.width_, intrinsic.height_,
87  intrinsic.intrinsic_matrix_, extrinsic, scale);
88  },
89  "Factory function to create a LineSet from intrinsic "
90  "and extrinsic camera matrices",
91  "intrinsic"_a, "extrinsic"_a, "scale"_a = 1.0)
92  .def_readwrite("points", &LineSet::points_,
93  "``float64`` array of shape ``(num_points, 3)``, "
94  "use ``numpy.asarray()`` to access data: Points "
95  "coordinates.")
96  .def_readwrite("lines", &LineSet::lines_,
97  "``int`` array of shape ``(num_lines, 2)``, use "
98  "``numpy.asarray()`` to access data: Lines denoted "
99  "by the index of points forming the line.")
100  .def_readwrite(
101  "colors", &LineSet::colors_,
102  "``float64`` array of shape ``(num_lines, 3)``, "
103  "range ``[0, 1]`` , use ``numpy.asarray()`` to access "
104  "data: RGB colors of lines.");
105  docstring::ClassMethodDocInject(m, "LineSet", "has_colors");
106  docstring::ClassMethodDocInject(m, "LineSet", "has_lines");
107  docstring::ClassMethodDocInject(m, "LineSet", "has_points");
108  docstring::ClassMethodDocInject(m, "LineSet", "get_line_coordinate",
109  {{"line_index", "Index of the line."}});
110  docstring::ClassMethodDocInject(m, "LineSet", "paint_uniform_color",
111  {{"color", "Color for the LineSet."}});
113  m, "LineSet", "create_from_point_cloud_correspondences",
114  {{"cloud0", "First point cloud."},
115  {"cloud1", "Second point cloud."},
116  {"correspondences", "Set of correspondences."}});
117  docstring::ClassMethodDocInject(m, "LineSet",
118  "create_from_oriented_bounding_box",
119  {{"box", "The input bounding box."}});
120  docstring::ClassMethodDocInject(m, "LineSet",
121  "create_from_axis_aligned_bounding_box",
122  {{"box", "The input bounding box."}});
123  docstring::ClassMethodDocInject(m, "LineSet", "create_from_triangle_mesh",
124  {{"mesh", "The input triangle mesh."}});
125  docstring::ClassMethodDocInject(m, "LineSet", "create_from_tetra_mesh",
126  {{"mesh", "The input tetra mesh."}});
127 }
128 
129 void pybind_lineset_methods(py::module &m) {}
130 
131 } // namespace geometry
132 } // namespace cloudViewer
virtual bool hasColors() const
Returns whether colors are enabled or not.
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
Contains the pinhole camera intrinsic parameters.
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
Definition: LineSet.h:29
std::pair< Eigen::Vector3d, Eigen::Vector3d > GetLineCoordinate(size_t line_index) const
Returns the coordinates of the line at the given index.
Definition: LineSet.h:92
static std::shared_ptr< LineSet > CreateFromTetraMesh(const TetraMesh &mesh)
static std::shared_ptr< LineSet > CreateCameraVisualization(int view_width_px, int view_height_px, const Eigen::Matrix3d &intrinsic, const Eigen::Matrix4d &extrinsic, double scale=1.0)
std::vector< Eigen::Vector3d > points_
Points coordinates.
Definition: LineSet.h:156
std::vector< Eigen::Vector3d > colors_
RGB colors of lines.
Definition: LineSet.h:160
bool HasLines() const
Returns true if the object contains lines.
Definition: LineSet.h:82
std::vector< Eigen::Vector2i > lines_
Lines denoted by the index of points forming the line.
Definition: LineSet.h:158
static std::shared_ptr< LineSet > CreateFromOrientedBoundingBox(const ecvOrientedBBox &box)
Factory function to create a LineSet from an OrientedBoundingBox.
static std::shared_ptr< LineSet > CreateFromPointCloudCorrespondences(const ccPointCloud &cloud0, const ccPointCloud &cloud1, const std::vector< std::pair< int, int >> &correspondences)
Factory function to create a LineSet from two PointClouds (cloud0, cloud1) and a correspondence set.
static std::shared_ptr< LineSet > CreateFromTriangleMesh(const ccMesh &mesh)
static std::shared_ptr< LineSet > CreateFromAxisAlignedBoundingBox(const ccBBox &box)
Factory function to create a LineSet from an ccBBox.
LineSet & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each line in the LineSet the same color.
Definition: LineSet.h:101
bool HasPoints() const
Returns true if the object contains points.
Definition: LineSet.h:79
void ClassMethodDocInject(py::module &pybind_module, const std::string &class_name, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
Definition: docstring.cpp:27
void pybind_lineset(py::module &m)
Definition: lineset.cpp:20
void pybind_lineset_methods(py::module &m)
Definition: lineset.cpp:129
Generic file read and write utility for python interface.
std::string to_string(const T &n)
Definition: Common.h:20