ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccQuadric.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 <ecvQuadric.h>
13 
14 #include <utility>
15 
16 #include "../casters.h"
17 
18 namespace py = pybind11;
19 using namespace pybind11::literals;
20 
21 void define_ccQuadric(py::module &m)
22 {
23  py::class_<ccQuadric, ccGenericPrimitive>(m, "ccQuadric", R"doc(
24  ccQuadric
25 
26  Parameters
27  ----------
28  minCorner : cccorelib.CCVector2
29  min corner of the 'representation' base area
30  maxCorner : cccorelib.CCVector2
31  max corner of the 'representation' base area
32  eq: list of PointCoordinateType
33  equation coefficients ( Z = a + b.X + c.Y + d.X^2 + e.X.Y + f.Y^2)
34  6 coefficients
35  dims: list of int, optional
36  optional dimension indexes
37  transMat : , optional
38  optional 3D transformation (can be set afterwards with ccDrawableObject::setGLTransformation)
39  name : str, default: Sphere
40  name of the sphere object
41 
42  Example
43  -------
44 
45  .. code:: Python
46 
47  quadric = pycc.ccQuadric(
48  cccorelib.CCVector2(5.0, 10.0),
49  cccorelib.CCVector2(10.0, 20.0),
50  [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
51  )
52  )doc")
53  .def(
54  py::init(
55  [](CCVector2 minCorner,
56  CCVector2 maxCorner,
57  const py::sequence eq,
58  const Tuple3ub *dims = nullptr,
59  const ccGLMatrix *transMat = nullptr,
60  QString name = QString("Quadric"),
61  unsigned precision = ccQuadric::DEFAULT_DRAWING_PRECISION)
62  {
63  PointCoordinateType eqC[6];
64  if (eq.size() != 6)
65  {
66  throw py::value_error("eq must have 6 elements");
67  }
68 
69  for (size_t i{0}; i < 6; i++)
70  {
71  eqC[i] = eq[i].cast<PointCoordinateType>();
72  }
73  return new ccQuadric(
74  minCorner, maxCorner, eqC, dims, transMat, std::move(name), precision);
75  }),
76  "minCorner"_a,
77  "maxCorner"_a,
78  "eq"_a,
79  "dims"_a = nullptr,
80  "transMat"_a = nullptr,
81 
82  "name"_a = QString("Quadric"),
83  "precision"_a = []() { return ccQuadric::DEFAULT_DRAWING_PRECISION; }())
84  .def_property_readonly_static("DEFAULT_DRAWING_PRECISION",
85  []() { return ccQuadric::DEFAULT_DRAWING_PRECISION; })
86  .def("getMinCorner", &ccQuadric::getMinCorner)
87  .def("getMaxCorner", &ccQuadric::getMaxCorner)
88  .def("getEquationCoefs", &ccQuadric::getEquationCoefs)
89  .def("getEquationDims", &ccQuadric::getEquationDims)
90  .def("projectOnQuadric", &ccQuadric::projectOnQuadric, "P"_a, "Q"_a)
91  .def("getEquationString", &ccQuadric::getEquationString)
92  .def_static("Fit",
94  {
95  double rms;
96  ccQuadric::Fit(cloud, &rms);
97  return rms;
98  });
99 }
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
std::string name
void define_ccQuadric(py::module &m)
Definition: ccQuadric.cpp:21
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
Quadric (primitive)
Definition: ecvQuadric.h:16
const Tuple3ub & getEquationDims() const
Definition: ecvQuadric.h:69
const CCVector2 & getMaxCorner() const
Returns the quadric max corner.
Definition: ecvQuadric.h:62
QString getEquationString() const
Returns the quadric equation coefficients as a string.
const PointCoordinateType * getEquationCoefs() const
Returns the quadric equation coefficients.
Definition: ecvQuadric.h:65
static const unsigned DEFAULT_DRAWING_PRECISION
Default drawing precision.
Definition: ecvQuadric.h:21
const CCVector2 & getMinCorner() const
Returns the quadric min corner.
Definition: ecvQuadric.h:60
PointCoordinateType projectOnQuadric(const CCVector3 &P, CCVector3 &Q) const
Projects a 3D point in the quadric coordinate system.
static ccQuadric * Fit(cloudViewer::GenericIndexedCloudPersist *cloud, double *rms)
Fits a quadric primitive on a cloud.
A generic 3D point cloud with index-based and presistent access to points.