9 #include <pybind11/functional.h>
10 #include <pybind11/numpy.h>
11 #include <pybind11/pybind11.h>
12 #include <pybind11/stl.h>
13 #include <pybind11/stl_bind.h>
27 using namespace pybind11::literals;
138 #if ((PYBIND11_VERSION_MAJOR > 2) || (PYBIND11_VERSION_MAJOR == 2 && PYBIND11_VERSION_MINOR > 11))
144 py::module_ numpy = py::module_::import(
"numpy");
145 py::str version_string = numpy.attr(
"__version__");
147 py::module_ numpy_lib = py::module_::import(
"numpy.lib");
148 py::object numpy_version = numpy_lib.attr(
"NumpyVersion")(version_string);
149 int major_version = numpy_version.attr(
"major").cast<
int>();
151 if (major_version < 2)
153 const py::detail::PyArrayDescr1_Proxy *descr =
154 py::detail::array_descriptor1_proxy(py::detail::array_proxy(array.ptr())->descr);
155 names = py::cast<py::list>(descr->names);
159 const py::detail::PyArrayDescr2_Proxy *descr =
160 py::detail::array_descriptor2_proxy(py::detail::array_proxy(array.ptr())->descr);
161 names = py::cast<py::list>(descr->names);
164 const py::detail::PyArrayDescr_Proxy *descr =
165 py::detail::array_descriptor_proxy(py::detail::array_proxy(array.ptr())->descr);
166 names = py::cast<py::list>(descr->names);
168 if (names.size() >= 3)
170 m_xs = array[names[0]].cast<py::array_t<PointCoordinateType>>();
171 m_ys = array[names[1]].cast<py::array_t<PointCoordinateType>>();
172 m_zs = array[names[2]].cast<py::array_t<PointCoordinateType>>();
176 m_xs = array[py::make_tuple(py::ellipsis(), 0)].cast<py::array_t<PointCoordinateType>>();
177 m_ys = array[py::make_tuple(py::ellipsis(), 1)].cast<py::array_t<PointCoordinateType>>();
178 m_zs = array[py::make_tuple(py::ellipsis(), 2)].cast<py::array_t<PointCoordinateType>>();
186 m_pts.
x = m_xs.at(index);
187 m_pts.y = m_ys.at(index);
188 m_pts.z = m_zs.at(index);
193 P.
x = m_xs.at(index);
194 P.
y = m_ys.at(index);
195 P.
z = m_zs.at(index);
197 unsigned int size()
const override
201 return static_cast<unsigned int>(m_xs.size());
206 auto xs = m_xs.mutable_unchecked<1>();
207 auto ys = m_xs.mutable_unchecked<1>();
208 auto zs = m_xs.mutable_unchecked<1>();
211 for (
size_t i{0}; i <
size(); ++i)
217 ScalarType todoScalar = 0;
218 action(p, todoScalar);
223 const auto updateMinMax = [&bbMin, &bbMax](
const CCVector3 &
point, ScalarType _s)
233 forEach(updateMinMax);
256 py::array_t<PointCoordinateType> m_xs;
257 py::array_t<PointCoordinateType> m_ys;
258 py::array_t<PointCoordinateType> m_zs;
269 py::bind_vector<std::vector<CCVector2>>(m,
"CCVector2List");
284 py::bind_vector<cloudViewer::ReferenceCloudContainer>(m,
"ReferenceCloudContainer");
319 py::class_<NumpyCloud, cloudViewer::GenericIndexedCloud, cloudViewer::GenericCloud>(m,
"NumpyCloud")
320 .def(py::init<py::array>());
335 #ifdef USE_EMBEDDED_MODULES
336 #include <pybind11/embed.h>
PYBIND11_EMBEDDED_MODULE(ccinternals, m)
void define_WeibullDistribution(py::module &)
void define_ReferenceCloud(py::module &cccorelib)
void define_CCMiscTools(py::module &)
void define_GenericTriangle(py::module &)
void define_cccorelib(py::module &m)
void define_DgmOctreeReferenceCloud(py::module &)
void define_KdTree(py::module &cccorelib)
void define_GenericCloud(py::module &)
void define_SimpleTriangle(py::module &)
void define_ManualSegmentationTools(py::module &)
void define_DistanceComputationTools(py::module &)
void define_NormalDistribution(py::module &)
void define_GenericIndexedMesh(py::module &)
void define_GenericDistribution(py::module &)
void define_PointProjectionTools(py::module &cccorelib)
void define_GenericIndexedCloud(py::module &)
void define_ChamferDistanceTransform(py::module &)
void define_GeometricalAnalysisTools(py::module &)
void define_Polyline(py::module &cccorelib)
void define_FastMarching(py::module &)
void define_AutoSegmentationTools(py::module &)
PYBIND11_MODULE(cccorelib, m)
void define_CCGeom(py::module &)
void define_StatisticalTestingTools(py::module &)
void define_ScalarFieldTools(py::module &cccorelib)
void define_TrueKdTree(py::module &)
void define_PointCloud(py::module &cccorelib)
void define_SimpleMesh(py::module &cccorelib)
void define_LocalModel(py::module &cccorelib)
void define_RegistrationTools(py::module &cccorelib)
void define_GenericProgressCallback(py::module &)
void define_BoundingBox(py::module &)
void define_CloudSamplingTools(py::module &)
void define_ErrorFunction(py::module &)
void define_DgmOctree(py::module &)
void define_CCMath(py::module &)
void define_GenericMesh(py::module &)
void define_CCShareable(py::module &)
void define_CCConst(py::module &)
void define_GenericOctree(py::module &cccorelib)
void define_ScalarField(py::module &cccorelib)
void define_Delaunay2dMesh(py::module &)
void define_GenericIndexedCloudPersist(py::module &cccorelib)
unsigned int size() const override
Returns the number of points.
void getBoundingBox(CCVector3 &bbMin, CCVector3 &bbMax) override
Returns the cloud bounding box.
void placeIteratorAtBeginning() override
Sets the cloud iterator at the beginning.
const CCVector3 * getPoint(unsigned int index) const override
const CCVector3 * getNextPoint() override
Returns the next point (relatively to the global iterator position)
bool enableScalarField() override
Enables the scalar field associated to the cloud.
void forEach(genericPointAction action) override
Fast iteration mechanism.
void setPointScalarValue(unsigned int pointIndex, ScalarType value) override
NumpyCloud(const py::array &array)
ScalarType getPointScalarValue(unsigned int pointIndex) const override
bool isScalarFieldEnabled() const override
Returns true if the scalar field is enabled, false otherwise.
void getPoint(unsigned int index, CCVector3 &P) const override
std::function< void(const CCVector3 &, ScalarType &)> genericPointAction
Generic function applied to a point (used by foreach)
A generic 3D point cloud with index-based point access.