8 #include "../casters.h"
18 #include <pybind11/pytypes.h>
19 #include <type_traits>
23 #include <pybind11/functional.h>
24 #include <pybind11/numpy.h>
25 #include <pybind11/pybind11.h>
26 #include <pybind11/stl.h>
27 #include <pybind11/stl_bind.h>
31 static_assert(std::is_same<PointCoordinateType, float>::value,
32 "PointCoordinateType is neither double or float");
34 "Unexpected layout for CCVector3");
39 py::class_<ccPointCloud, cloudViewer::PointCloudTpl<ccGenericPointCloud>>(m,
42 The main class to represent point clouds in ACloudViewer.
46 Two constructor are available:
51 The name of the point cloud
53 Unique ID, you practically never need to give a value as it is
54 one is already selected by default.
62 pc = pycc.ccPointCloud("Yoshi's Island")
80 x = np.array([1, 2, 3])
81 y = np.array([1, 2, 3])
82 z = np.array([1, 2, 3])
83 pc = pycc.ccPointCloud(x, y, z)
86 .def(py::init<QString>(), "name"_a = QString())
88 [](py::array_t<PointCoordinateType> &xs,
89 py::array_t<PointCoordinateType> &ys,
90 py::array_t<PointCoordinateType> &zs)
97 catch (
const std::exception &)
109 {
return self.partialClone(refCloud); },
120 .def(
"getCurrentDisplayedScalarFieldIndex",
122 .def(
"setCurrentDisplayedScalarField",
129 .def(
"computeNormalsWithGrids",
131 "minTriangleAngle_deg"_a = 1.0,
133 .def(
"orientNormalsTowardViewPoint",
137 .def(
"computeNormalsWithOctree",
140 "preferredOrientation"_a,
143 .def(
"orientNormalsWithMST",
147 .def(
"orientNormalsWithFM",
152 .def(
"addPoints", &PyCC::addPointsFromArrays<ccPointCloud>)
163 const py::array_t<PointCoordinateType> &nx,
164 const py::array_t<PointCoordinateType> &ny,
165 const py::array_t<PointCoordinateType> &nz)
167 if (nx.size() != ny.size() || nx.size() != nz.size())
169 throw py::value_error(
"nx, ny, nz must have the same size");
172 const py::ssize_t numToReserve =
self.size() + nx.size();
176 " cannot be casted to unsigned int");
178 self.reserve(
static_cast<unsigned int>(numToReserve));
180 auto xs_it = nx.begin();
181 auto ys_it = ny.begin();
182 auto zs_it = nz.begin();
184 while (xs_it != nx.end())
200 if (colorsTable ==
nullptr)
211 static_assert(CHAR_BIT == 8,
"A char must have 8 bits");
212 static_assert(
sizeof(
ColorCompType) == 1,
"ColorCompType must have 8 bit");
214 static_assert(
alignof(uint8_t) ==
alignof(
ecvColor::Rgba),
"Not same alignment");
216 auto *ptr =
reinterpret_cast<uint8_t *
>(
colors);
218 auto capsule = py::capsule(ptr, [](
void *) {});
219 py::array a(py::dtype(
"3u1"), colorsTable->size(), ptr, capsule);
230 auto *ptr =
const_cast<CCVector3 *
>(
self.getPoint(0));
231 auto capsule = py::capsule(ptr, [](
void *) {});
232 py::array a(py::dtype(
"3f"),
self.
size(), ptr, capsule);
234 a.attr(
"flags").attr(
"writeable") =
false;
239 return py::array(py::dtype(
"3f"), 0);
245 return std::string(
"<ccPointCloud(") +
"'" +
self.getName().toStdString() +
"', " +
float PointCoordinateType
Type of the coordinates of a (N-D) point.
void define_ccPointCloud(py::module &m)
Array of RGB colors for each point.
A 3D cloud interface with associated features (color, normals, octree, etc.)
void setPointSize(unsigned size=0)
Sets point size.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void setCurrentDisplayedScalarField(int index)
Sets the currently displayed scalar field.
bool sfColorScaleShown() const
Returns whether color scale should be displayed or not.
bool resizeTheNormsTable()
Resizes the compressed normals array.
bool orientNormalsTowardViewPoint(CCVector3 &VP, ecvProgressDialog *pDlg=nullptr)
Normals are forced to point to O.
void addNorm(const CCVector3 &N)
Pushes a normal vector on stack (shortcut)
bool computeNormalsWithGrids(double minTriangleAngle_deg=1.0, ecvProgressDialog *pDlg=nullptr)
Compute the normals with the associated grid structure(s)
void showSFColorsScale(bool state)
Sets whether color scale should be displayed or not.
bool computeNormalsWithOctree(CV_LOCAL_MODEL_TYPES model, ccNormalVectors::Orientation preferredOrientation, PointCoordinateType defaultRadius, ecvProgressDialog *pDlg=nullptr)
Compute the normals by approximating the local surface around each point.
bool orientNormalsWithFM(unsigned char level, ecvProgressDialog *pDlg=nullptr)
Orient normals with Fast Marching.
bool orientNormalsWithMST(unsigned kNN=6, ecvProgressDialog *pDlg=nullptr)
Orient the normals with a Minimum Spanning Tree.
bool colorize(float r, float g, float b)
Multiplies all color components of all points by coefficients.
bool reserveTheNormsTable()
Reserves memory to store the compressed normals.
int getCurrentDisplayedScalarFieldIndex() const
Returns the currently displayed scalar field index (or -1 if none)
void setPointNormal(size_t pointIndex, const CCVector3 &N)
Sets a particular point normal (shortcut)
cloudViewer::ReferenceCloud * crop2D(const ccPolyline *poly, unsigned char orthoDim, bool inside=true)
Crops the cloud inside (or outside) a 2D polyline.
ccScalarField * getCurrentDisplayedScalarField() const
Returns the currently displayed scalar (or 0 if none)
void shrinkToFit()
Removes unused capacity.
bool reserveThePointsTable(unsigned _numberOfPoints)
Reserves memory to store the points coordinates.
A very simple point cloud (no point duplication)
unsigned char ColorCompType
Default color components type (R,G and B)
void addPointsFromArrays(PointCloudType &self, py::array_t< PointCoordinateType > &xs, py::array_t< PointCoordinateType > &ys, py::array_t< PointCoordinateType > &zs)
std::string to_string(const T &n)
#define DEFINE_POINTCLOUDTPL(T, module, name)