 |
ACloudViewer
3.9.4
A Modern Library for 3D Data Processing
|
Go to the documentation of this file.
14 #include <pybind11/numpy.h>
15 #include <pybind11/pybind11.h>
18 #include <type_traits>
21 using namespace pybind11::literals;
24 template <
class T>
using observer_ptr = std::unique_ptr<T, py::nodelete>;
33 static_assert(std::is_base_of<CCShareable, T>::value ==
true,
"T must be a subclass of CCShareable");
77 return py::array(shape,
data, capsule);
83 return py::array(len,
data, capsule);
93 template <
class Po
intCloudType>
95 py::array_t<PointCoordinateType> &xs,
96 py::array_t<PointCoordinateType> &ys,
97 py::array_t<PointCoordinateType> &zs)
99 if (xs.size() != ys.size() || xs.size() != zs.size())
101 throw py::value_error(
"xs, ys, zs must have the same size");
104 const py::ssize_t numToReserve =
self.size() + xs.size();
105 if (numToReserve > std::numeric_limits<unsigned int>::max())
107 throw std::out_of_range(
std::to_string(numToReserve) +
" cannot be casted to unsigned int");
109 self.reserve(
static_cast<unsigned int>(numToReserve));
111 auto xs_it = xs.begin();
112 auto ys_it = ys.begin();
113 auto zs_it = zs.begin();
115 for (; xs_it != xs.end();)
128 Adds a scalar field with the given name to the point cloud.
133 name of the scalar field that will be added.
134 values: optional, numpy.array, list of float
135 values to use when initializing the new scalar field
139 RuntimeError if the point cloud already has a scalar field with the given ``name``
140 ValueError if values are provided don't have the same length (size) as the point cloud
145 Returns the size (number of points) in the point cloud.
147 ``len`` also works as an alias to size.
151 pc = pycc.ccPointCloud("name")
152 assert len(pc) == pc.size()
155 #define DEFINE_POINTCLOUDTPL(T, module, name) \
156 py::class_<cloudViewer::PointCloudTpl<T>, T>(module, name) \
157 .def("size", &cloudViewer::PointCloudTpl<T>::size, SIZE_SCALAR_FIELD_DOCSTRING) \
158 .def("forEach", &cloudViewer::PointCloudTpl<T>::forEach, "action"_a) \
159 .def("getBoundingBox", &cloudViewer::PointCloudTpl<T>::getBoundingBox, "bbMin"_a, "bbMax"_a) \
160 .def("getNextPoint", \
161 &cloudViewer::PointCloudTpl<T>::getNextPoint, \
162 py::return_value_policy::reference) \
163 .def("enableScalarField", &cloudViewer::PointCloudTpl<T>::enableScalarField) \
164 .def("isScalarFieldEnabled", &cloudViewer::PointCloudTpl<T>::isScalarFieldEnabled) \
165 .def("setPointScalarValue", \
166 &cloudViewer::PointCloudTpl<T>::setPointScalarValue, \
169 .def("getPointScalarValue", &cloudViewer::PointCloudTpl<T>::getPointScalarValue, "pointIndex"_a) \
170 .def("resize", &cloudViewer::PointCloudTpl<T>::resize, "newCount"_a) \
171 .def("reserve", &cloudViewer::PointCloudTpl<T>::reserve, "newCapacity"_a) \
172 .def("reset", &cloudViewer::PointCloudTpl<T>::reset) \
173 .def("invalidateBoundingBox", &cloudViewer::PointCloudTpl<T>::invalidateBoundingBox) \
174 .def("getNumberOfScalarFields", \
175 &cloudViewer::PointCloudTpl<T>::getNumberOfScalarFields, \
176 "Returns the number of scalar field of the point cloud") \
179 &cloudViewer::PointCloudTpl<T>::getScalarField, \
182 Returns the scalar field identified by its index. \
184 If index is invalid, None is returned \
187 "getScalarFieldName", \
188 &cloudViewer::PointCloudTpl<T>::getScalarFieldName, \
191 Returns the name of the scalar field identified by the index. \
193 If index is invalid, -1 is returned \
196 "getScalarFieldIndexByName", \
197 &cloudViewer::PointCloudTpl<T>::getScalarFieldIndexByName, \
200 Returns the scalar field identified by its name. \
202 If no scalar field has the given name, None is returned \
204 .def("getCurrentInScalarField", &cloudViewer::PointCloudTpl<T>::getCurrentInScalarField) \
205 .def("getCurrentOutScalarField", &cloudViewer::PointCloudTpl<T>::getCurrentOutScalarField) \
206 .def("setCurrentInScalarField", &cloudViewer::PointCloudTpl<T>::setCurrentInScalarField, "index"_a) \
207 .def("getCurrentInScalarFieldIndex", &cloudViewer::PointCloudTpl<T>::getCurrentInScalarFieldIndex) \
209 "setCurrentOutScalarField", &cloudViewer::PointCloudTpl<T>::setCurrentOutScalarField, "index"_a) \
210 .def("getCurrentOutScalarFieldIndex", &cloudViewer::PointCloudTpl<T>::getCurrentOutScalarFieldIndex) \
211 .def("setCurrentScalarField", &cloudViewer::PointCloudTpl<T>::setCurrentScalarField, "index"_a) \
212 .def("renameScalarField", &cloudViewer::PointCloudTpl<T>::renameScalarField, "index"_a, "newName"_a) \
215 [](cloudViewer::PointCloudTpl<T> &self, \
216 const char *sfName, \
217 const py::object &maybe_values = py::none()) \
219 int idx = self.addScalarField(sfName); \
222 throw std::runtime_error("Failed to add scalar field"); \
224 if (!maybe_values.is_none()) \
226 py::array_t<ScalarType> values(maybe_values); \
227 if (values.size() != self.size()) \
229 throw py::value_error("value must have the same len as the poinc cloud size"); \
231 auto values_u = values.unchecked<1>(); \
232 cloudViewer::ScalarField *sf = self.getScalarField(idx); \
233 for (py::ssize_t i{0}; i < values.size(); ++i) \
235 sf->setValue(i, values_u(i)); \
241 "values"_a = py::none(), \
242 ADD_SCALAR_FIELD_DOCSTRING) \
244 "deleteScalarField", \
245 &cloudViewer::PointCloudTpl<T>::deleteScalarField, \
248 Removes the scalar field identified by the index . \
251 This operation may modify the scalar fields order \
252 (especially if the deleted SF is not the last one). \
253 However current IN & OUT scalar fields will stay up-to-date \
254 (while their index may change). \
256 Does nothing if index is invalid \
258 .def("deleteAllScalarFields", \
259 &cloudViewer::PointCloudTpl<T>::deleteAllScalarFields, \
260 "Deletes all scalar fields associated to this cloud") \
263 [](cloudViewer::PointCloudTpl<T> &self, const CCVector3 &P) { self.addPoint(P); }, \
266 Adds a 3D point to the point cloud \
269 For better performances it is better to use :meth:`.addPoints`. \
273 &PyCC::addPointsFromArrays<cloudViewer::PointCloudTpl<T>>, \
278 Takes values from xs, yz, zs array and add them as points of the point cloud. \
282 Value error if xs,ys,zs do not have the same length \
284 .def("__len__", &cloudViewer::PointCloudTpl<T>::size);
A generic 3D point cloud with index-based point access.
Definition: GenericIndexedCloud.h:18
virtual bool removeOuterTriangles(const std::vector< CCVector2 > &vertices2D, const std::vector< CCVector2 > &polygon2D, bool removeOutside=true)
Removes the triangles falling outside of a given (2D) polygon.
Definition: Delaunay2dMesh.cpp:207
void define_GenericMesh(py::module &cccorelib)
Definition: GenericMesh.cpp:16
virtual const CCVector3 * getNextPoint()=0
Returns the next point (relatively to the global iterator position)
void define_KdTree(py::module &cccorelib)
Definition: KdTree.cpp:20
virtual double computePfromZero(ScalarType x) const =0
Computes the cumulative probability between 0 and x.
static Delaunay2dMesh * TesselateContour(const std::vector< CCVector2 > &contourPoints)
Definition: Delaunay2dMesh.cpp:397
Definition: wrappers.h:70
bool oneStep()
Increments total progress value of a single unit.
Definition: NormalizedProgress.cpp:99
void define_CCGeom(py::module &cccorelib)
Definition: CCGeom.cpp:138
void define_GenericOctree(py::module &cccorelib)
Definition: GenericOctree.cpp:16
Definition: CVKdTree.h:20
A generic class to handle a probability distribution.
Definition: GenericDistribution.h:25
virtual unsigned size() const =0
Returns the number of triangles.
unsigned i2
Definition: GenericIndexedMesh.h:19
virtual unsigned size() const =0
Returns the number of points.
virtual void linkMeshWith(GenericIndexedCloud *aCloud, bool passOwnership=false)
Associate this mesh to a point cloud.
Definition: Delaunay2dMesh.cpp:52
Definition: wrappers.h:30
PYBIND11_DECLARE_HOLDER_TYPE(T, CCShareableHolder< T >)
py::array_t< T > SpanAsNumpyArray(T *data, size_t len)
Definition: wrappers.h:80
void define_CCShareable(py::module &cccorelib)
Definition: CCShareable.cpp:17
Triangle described by the indexes of its 3 vertices.
Definition: GenericIndexedMesh.h:16
CCVector3 A
A vertex.
Definition: SimpleTriangle.h:73
static bool Available()
Returns whether 2D Delaunay triangulation is supported or not.
Definition: Delaunay2dMesh.cpp:44
virtual bool buildMesh(const std::vector< CCVector2 > &points2D, std::size_t pointCountToUse, std::string &outputErrorStr)
Build the Delaunay mesh on top a set of 2D points.
Definition: Delaunay2dMesh.cpp:133
GraphType data
Definition: graph_cut.cc:138
static const constexpr char SIZE_SCALAR_FIELD_DOCSTRING[]
Definition: wrappers.h:144
virtual bool isCancelRequested()=0
Checks if the process should be canceled.
void define_GenericCloud(py::module &cccorelib)
Definition: GenericCloud.cpp:16
virtual const CCVector3 * _getA() const =0
Returns the first vertex (A)
float RadiansToDegrees(int radians)
Convert radians to degrees.
Definition: CVMath.h:71
virtual void stop()=0
Notifies the fact that the process has ended.
virtual void setMethodTitle(const char *methodTitle)=0
Notifies the algorithm title.
virtual ScalarType getPointScalarValue(unsigned pointIndex) const =0
Returns the ith point associated scalar value.
virtual double computeP(ScalarType x) const =0
Computes the probability of x.
#define DEFINE_CCVECTOR3(cppname, pyname, type_)
Definition: CCGeom.cpp:123
#define DEFINE_VECTOR2TPL_TYPE(cppname, pyname, type_)
Definition: CCGeom.cpp:17
int * getTriangleVertIndexesArray()
Returns triangles indexes array (pointer to)
Definition: Delaunay2dMesh.h:102
CCVector3 C
C vertex.
Definition: SimpleTriangle.h:77
virtual void setInfo(const char *infoStr)=0
Notifies some information about the ongoing process.
void define_GenericDistribution(py::module &cccorelib)
Definition: GenericDistribution.cpp:20
virtual void getBoundingBox(CCVector3 &bbMin, CCVector3 &bbMax)=0
Returns the cloud bounding box.
int size
Definition: FileIOFactory.cpp:130
virtual void forEach(genericTriangleAction action)=0
Fast iteration mechanism.
~CCShareableHolder()
Definition: wrappers.h:55
T * get()
Definition: wrappers.h:45
virtual const CCVector3 * _getB() const =0
Returns the second vertex (B)
void define_GenericIndexedCloudPersist(py::module &cccorelib)
Definition: GenericIndexedCloudPersist.cpp:16
const CCVector3 * B
B vertex (ref)
Definition: SimpleTriangle.h:43
std::unique_ptr< T, py::nodelete > observer_ptr
A unique_ptr that never free its ptr.
Definition: wrappers.h:24
virtual VerticesIndexes * getNextTriangleVertIndexes()=0
bool GreaterThanEpsilon(float x)
Test a floating point number against our epsilon (a very small number).
Definition: CVMath.h:37
virtual GenericTriangle * _getNextTriangle()=0
Returns the next triangle (relatively to the global iterator position)
virtual void placeIteratorAtBeginning()=0
Places the mesh iterator at the beginning.
virtual void link()
Increase counter.
Definition: CVShareable.cpp:33
unsigned i3
Definition: GenericIndexedMesh.h:19
virtual void release()
Decrease counter and deletes object when 0.
Definition: CVShareable.cpp:35
void define_CCMath(py::module &cccorelib)
Definition: CCMath.cpp:15
void addPointsFromArrays(PointCloudType &self, py::array_t< PointCoordinateType > &xs, py::array_t< PointCoordinateType > &ys, py::array_t< PointCoordinateType > &zs)
Definition: wrappers.h:94
virtual unsigned char testVisibility(const CCVector3 &P) const
Definition: GenericCloud.h:65
GenericIndexedCloud * getAssociatedCloud()
Returns associated cloud.
Definition: Delaunay2dMesh.h:111
const T * get() const
Definition: wrappers.h:50
virtual bool isValid() const
Indicates if the distribution parameters are valid.
Definition: GenericDistribution.h:43
virtual bool computeParameters(const ScalarContainer &values)=0
Computes the distribution parameters from a set of values.
virtual void placeIteratorAtBeginning()=0
Sets the cloud iterator at the beginning.
a[190]
Definition: essential_matrix_poly.h:19
virtual void forEach(genericPointAction action)=0
Fast iteration mechanism.
int points
Definition: FileIOFactory.cpp:144
A generic mesh with index-based vertex access.
Definition: GenericIndexedMesh.h:37
virtual bool textCanBeEdited() const
Returns whether the dialog title and info can be updated or not.
Definition: GenericProgressCallback.h:70
void define_GenericProgressCallback(py::module &cccorelib)
Definition: GenericProgressCallback.cpp:15
const CCVector3 * A
A vertex (ref)
Definition: SimpleTriangle.h:41
const CCVector3 * C
C vertex (ref)
Definition: SimpleTriangle.h:45
CCVector3 B
B vertex.
Definition: SimpleTriangle.h:75
bool steps(unsigned n)
Increments total progress value of more than a single unit.
Definition: NormalizedProgress.cpp:114
A generic 3D point cloud with index-based and presistent access to points.
Definition: GenericIndexedCloudPersist.h:18
A class to compute and handle a Delaunay 2D mesh on a subset of points.
Definition: Delaunay2dMesh.h:24
float DegreesToRadians(int degrees)
Convert degrees to radians.
Definition: CVMath.h:98
void NoOpDelete(void *)
Definition: wrappers.h:72
virtual double computeChi2Dist(const GenericCloud *Yk, unsigned numberOfClasses, int *histo=nullptr)=0
Computes the Chi2 distance (related to the Chi2 Test)
virtual bool enableScalarField()=0
Enables the scalar field associated to the cloud.
virtual void setPointScalarValue(unsigned pointIndex, ScalarType value)=0
Sets the ith point associated scalar value.
virtual void getBoundingBox(CCVector3 &bbMin, CCVector3 &bbMax)=0
Returns the mesh bounding-box.
GenericIndexedCloud * getAssociatedCloud() const
Gets the point cloud from which the tree has been build.
Definition: CVKdTree.h:40
#define DEFINE_TUPLE3TPL(cppname, pyname, type_)
Definition: CCGeom.cpp:72
virtual const CCVector3 * _getC() const =0
Returns the third vertex (C)
CCShareableHolder(T *obj)
Definition: wrappers.h:37
virtual GenericTriangle * _getTriangle(unsigned triangleIndex)=0
Returns the ith triangle.
void define_GenericIndexedCloud(py::module &cccorelib)
Definition: GenericIndexedCloud.cpp:15
void define_GenericIndexedMesh(py::module &cccorelib)
Definition: GenericIndexedMesh.cpp:17
static const constexpr char ADD_SCALAR_FIELD_DOCSTRING[]
Definition: wrappers.h:127
Definition: ccGuiPythonInstance.h:15
virtual const CCVector3 * getPointPersistentPtr(unsigned index)=0
Returns the ith point as a persistent pointer.
void reset()
Resets progress state.
Definition: NormalizedProgress.cpp:91
static double module(T *vector)
Definition: utils.h:105
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
void scale(unsigned totalSteps, unsigned totalPercentage=100, bool updateCurrentProgress=false)
Definition: NormalizedProgress.cpp:61
void define_SimpleTriangle(py::module &cccorelib)
Definition: SimpleTriangle.cpp:17
static constexpr int USE_ALL_POINTS
Definition: Delaunay2dMesh.h:26
py::array_t< T > VectorAsNumpyArray(std::vector< T > &vector)
Definition: wrappers.h:86
bool removeTrianglesWithEdgesLongerThan(PointCoordinateType maxEdgeLength)
Filters out the triangles based on their edge length.
Definition: Delaunay2dMesh.cpp:265
virtual unsigned getLinkCount() const
Returns the current link count.
Definition: CVShareable.h:40
bool buildFromCloud(GenericIndexedCloud *cloud, GenericProgressCallback *progressCb=nullptr)
Builds the KD-tree.
Definition: CVKdTree.cpp:23
virtual const char * getName() const =0
Returns distribution name.
static double distance(T *pot1, T *pot2)
Definition: utils.h:111
std::string to_string(const T &n)
Definition: Common.h:20
bool LessThanEpsilon(float x)
Test a floating point number against our epsilon (a very small number).
Definition: CVMath.h:23
void define_Delaunay2dMesh(py::module &cccorelib)
Definition: Delaynay2dMesh.cpp:19
virtual void update(float percent)=0
Notifies the algorithm progress.
void define_GenericTriangle(py::module &cccorelib)
Definition: GenericTriangle.cpp:17
unsigned i1
Definition: GenericIndexedMesh.h:19