itom  4.1.0
pythonPCL.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef PYTHONPCL_H
24 #define PYTHONPCL_H
25 
26 
27 /* includes */
28 #ifndef Q_MOC_RUN
29  #define PY_ARRAY_UNIQUE_SYMBOL itom_ARRAY_API //see numpy help ::array api :: Miscellaneous :: Importing the api (this line must bebefore include global.h)
30  #define NO_IMPORT_ARRAY
31 
32  #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
33 
34  //python
35  // see http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=7f3f750596a105d48ea84ebfe1b1c4ca03e0bab3
36  #if (defined _DEBUG) && (defined WIN32)
37  #undef _DEBUG
38  #include "pythonWrapper.h"
39  #include "numpy/arrayobject.h"
40  #define _DEBUG
41  #else
42  #include "pythonWrapper.h"
43  #include "numpy/arrayobject.h"
44  #endif
45 #endif
46 
47 #include "../global.h"
48 
49 #if ITOM_POINTCLOUDLIBRARY > 0
50 
51 #include "PointCloud/pclStructures.h"
52 
53 
54 namespace ito
55 {
56 
57 class PythonPCL
58 {
59 public:
60  typedef struct
61  {
62  PyObject_HEAD
63  ito::PCLPointCloud *data;
64  PyObject* base;
65  }
66  PyPointCloud;
67 
68  #define PyPointCloud_Check(op) PyObject_TypeCheck(op, &PythonPCL::PyPointCloudType)
69 
70  //-------------------------------------------------------------------------------------------------
71  // constructor, deconstructor, alloc, dellaoc
72  //-------------------------------------------------------------------------------------------------
73  static void PyPointCloud_dealloc(PyPointCloud *self);
74  static PyObject* PyPointCloud_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
75  static int PyPointCloud_init(PyPointCloud *self, PyObject *args, PyObject *kwds);
76 
77 
78  //-------------------------------------------------------------------------------------------------
79  // general members
80  //-------------------------------------------------------------------------------------------------
81  static PyObject *PyPointCloud_name(PyPointCloud *self);
82  static PyObject *PyPointCloud_repr(PyPointCloud *self);
83  static PyObject *PyPointCloud_append(PyPointCloud *self, PyObject *args, PyObject *kwds);
84  static PyObject *PyPointCloud_clear(PyPointCloud *self);
85  static PyObject *PyPointCloud_insert(PyPointCloud *self, PyObject *args);
86  static PyObject *PyPointCloud_erase(PyPointCloud *self, PyObject *args);
87  static PyObject *PyPointCloud_toDataObject(PyPointCloud *self);
88  static PyObject *PyPointCloud_copy(PyPointCloud *self);
89  static PyObject *PyPointCloud_scaleXYZ(PyPointCloud *self, PyObject *args, PyObject *kwds);
90  static PyObject *PyPointCloud_moveXYZ(PyPointCloud *self, PyObject *args, PyObject *kwds);
91 
92  //-------------------------------------------------------------------------------------------------
93  // helper methods
94  //-------------------------------------------------------------------------------------------------
95  static PyObject *PyPointCloud_XYZ_append(PyPointCloud *self, PyObject *xyzObj);
96  static PyObject *PyPointCloud_XYZI_append(PyPointCloud *self, PyObject *xyziObj);
97  static PyObject *PyPointCloud_XYZRGBA_append(PyPointCloud *self, PyObject *xyzObj, PyObject *rgbaObj);
98  static PyObject *PyPointCloud_XYZNormal_append(PyPointCloud *self, PyObject *xyz_nxnynz_curvObj);
99  static PyObject *PyPointCloud_XYZINormal_append(PyPointCloud *self, PyObject *xyz_i_nxnynz_curvObj);
100  static PyObject *PyPointCloud_XYZRGBNormal_append(PyPointCloud *self, PyObject *xyz_i_nxnynz_curvObj, PyObject *rgbaObj);
101 
102  static PyPointCloud* createEmptyPyPointCloud();
103 
104  //-------------------------------------------------------------------------------------------------
105  // getter / setter
106  //-------------------------------------------------------------------------------------------------
107  static PyObject* PyPointCloud_GetType(PyPointCloud *self, void *closure);
108  static PyObject* PyPointCloud_GetSize(PyPointCloud *self, void *closure);
109  static PyObject* PyPointCloud_GetHeight(PyPointCloud *self, void *closure);
110  static PyObject* PyPointCloud_GetWidth(PyPointCloud *self, void *closure);
111  static PyObject* PyPointCloud_GetEmpty(PyPointCloud *self, void *closure);
112  static PyObject* PyPointCloud_GetOrganized(PyPointCloud *self, void *closure);
113  static PyObject* PyPointCloud_GetDense(PyPointCloud *self, void *closure);
114  static int PyPointCloud_SetDense(PyPointCloud *self, PyObject *value, void *closure);
115  static PyObject* PyPointCloud_GetFields(PyPointCloud *self, void *closure);
116 
117  //-------------------------------------------------------------------------------------------------
118  // sequence protocol
119  //-------------------------------------------------------------------------------------------------
120  static Py_ssize_t PyPointCloud_seqLength(PyPointCloud *self);
121  static PyObject *PyPointCloud_seqConcat(PyPointCloud *self, PyObject *rhs);
122  static PyObject *PyPointCloud_seqRepeat(PyPointCloud *self, Py_ssize_t size);
123  static PyObject *PyPointCloud_seqItem(PyPointCloud *self, Py_ssize_t size);
124  static int PyPointCloud_seqAssItem(PyPointCloud *self, Py_ssize_t size, PyObject *point);
125  static PyObject *PyPointCloud_seqInplaceConcat(PyPointCloud *self, PyObject *rhs);
126  static PyObject *PyPointCloud_seqInplaceRepeat(PyPointCloud *self, Py_ssize_t size);
127 
128  //-------------------------------------------------------------------------------------------------
129  // mapping protocol
130  //-------------------------------------------------------------------------------------------------
131  static Py_ssize_t PyPointCloud_mappingLength(PyPointCloud *self);
132  static PyObject *PyPointCloud_mappingGetElem(PyPointCloud *self, PyObject *key);
133  static int PyPointCloud_mappingSetElem(PyPointCloud *self, PyObject *key, PyObject *value);
134 
135  //-------------------------------------------------------------------------------------------------
136  // pickling
137  //-------------------------------------------------------------------------------------------------
138  static PyObject* PyPointCloud_Reduce(PyPointCloud *self, PyObject *args);
139  static PyObject* PyPointCloud_SetState(PyPointCloud *self, PyObject *args);
140 
141  //-------------------------------------------------------------------------------------------------
142  // static methods
143  //-------------------------------------------------------------------------------------------------
144  static PyObject *PyPointCloud_fromXYZ(PyPointCloud *self, PyObject *args, PyObject *kwds);
145  static PyObject *PyPointCloud_fromXYZI(PyPointCloud *self, PyObject *args, PyObject *kwds);
146  static PyObject *PyPointCloud_fromXYZRGBA(PyPointCloud *self, PyObject *args, PyObject *kwds);
147  static PyObject *PyPointCloud_fromTopography(PyPointCloud *self, PyObject *args, PyObject *kwds);
148  static PyObject *PyPointCloud_fromDisparity(PyPointCloud *self, PyObject *args, PyObject *kwds);
149 
150  //-------------------------------------------------------------------------------------------------
151  // type structures
152  //-------------------------------------------------------------------------------------------------
153  //static PyMemberDef PyNpDataObject_members[];
154  static PyMethodDef PyPointCloud_methods[];
155  static PyTypeObject PyPointCloudType;
156  static PyModuleDef PyPointCloudModule;
157  static PyGetSetDef PyPointCloud_getseters[];
158  static PySequenceMethods PyPointCloud_sequenceProtocol;
159  static PyMappingMethods PyPointCloud_mappingProtocol;
160 
161  static void PyPointCloud_addTpDict(PyObject *tp_dict);
162 
163  //--------------------------------------------------------------------------------------------------
164  // PCL Point
165  //--------------------------------------------------------------------------------------------------
166  typedef struct
167  {
168  PyObject_HEAD
169  ito::PCLPoint *point;
170  PyObject* base;
171  }
172  PyPoint;
173 
174  //-------------------------------------------------------------------------------------------------
175  // constructor, deconstructor, alloc, dellaoc
176  //-------------------------------------------------------------------------------------------------
177  static void PyPoint_dealloc(PyPoint *self);
178  static PyObject* PyPoint_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
179  static int PyPoint_init(PyPoint *self, PyObject *args, PyObject *kwds);
180 
181 
182  //-------------------------------------------------------------------------------------------------
183  // general members
184  //-------------------------------------------------------------------------------------------------
185  static PyObject *PyPoint_name(PyPoint *self);
186  static PyObject *PyPoint_repr(PyPoint *self);
187 
188  //-------------------------------------------------------------------------------------------------
189  // getter / setter
190  //-------------------------------------------------------------------------------------------------
191  static PyObject* PyPoint_GetType(PyPoint *self, void *closure);
192 
193  static PyObject* PyPoint_GetXYZ(PyPoint *self, void *closure);
194  static int PyPoint_SetXYZ(PyPoint *self, PyObject *value, void *closure);
195 
196  static PyObject* PyPoint_GetIntensity(PyPoint *self, void *closure);
197  static int PyPoint_SetIntensity(PyPoint *self, PyObject *value, void *closure);
198 
199  static PyObject* PyPoint_GetRgb(PyPoint *self, void *closure);
200  static int PyPoint_SetRgb(PyPoint *self, PyObject *value, void *closure);
201 
202  static PyObject* PyPoint_GetRgba(PyPoint *self, void *closure);
203  static int PyPoint_SetRgba(PyPoint *self, PyObject *value, void *closure);
204 
205  static PyObject* PyPoint_GetCurvature(PyPoint *self, void *closure);
206  static int PyPoint_SetCurvature(PyPoint *self, PyObject *value, void *closure);
207 
208  static PyObject* PyPoint_GetNormal(PyPoint *self, void *closure);
209  static int PyPoint_SetNormal(PyPoint *self, PyObject *value, void *closure);
210 
211  //-------------------------------------------------------------------------------------------------
212  // mapping members
213  //-------------------------------------------------------------------------------------------------
214  static PyObject* PyPoint_mappingGetElem(PyPoint* self, PyObject* key);
215  static int PyPoint_mappingSetElem(PyPoint* self, PyObject* key, PyObject* value);
216 
217  //-------------------------------------------------------------------------------------------------
218  // type structures
219  //-------------------------------------------------------------------------------------------------
220  //static PyMemberDef PyNpDataObject_members[];
221  static PyMethodDef PyPoint_methods[];
222  static PyTypeObject PyPointType;
223  static PyModuleDef PyPointModule;
224  static PyGetSetDef PyPoint_getseters[];
225  static PyMappingMethods PyPoint_mappingProtocol;
226 
227  static void PyPoint_addTpDict(PyObject *tp_dict);
228 
229 
230 
231 
232 
233 
234  //--------------------------------------------------------------------------------------------------
235  // PCL PolygonMesh
236  //--------------------------------------------------------------------------------------------------
237  typedef struct
238  {
239  PyObject_HEAD
240  ito::PCLPolygonMesh *polygonMesh;
241  PyObject* base;
242  }
243  PyPolygonMesh;
244 
245  #define PyPolygonMesh_Check(op) PyObject_TypeCheck(op, &PythonPCL::PyPolygonMeshType)
246 
247  //-------------------------------------------------------------------------------------------------
248  // constructor, deconstructor, alloc, dellaoc
249  //-------------------------------------------------------------------------------------------------
250  static void PyPolygonMesh_dealloc(PyPolygonMesh *self);
251  static PyObject* PyPolygonMesh_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
252  static int PyPolygonMesh_init(PyPolygonMesh *self, PyObject *args, PyObject *kwds);
253 
254 
255  //-------------------------------------------------------------------------------------------------
256  // general members
257  //-------------------------------------------------------------------------------------------------
258  static PyObject *PyPolygonMesh_name(PyPolygonMesh *self);
259  static PyObject *PyPolygonMesh_repr(PyPolygonMesh *self);
260  static PyObject *PyPolygonMesh_data(PyPolygonMesh *self);
261 
262  static PyObject *PyPolygonMesh_get(PyPolygonMesh *self, PyObject *args, PyObject *kwds);
263  static PyObject* PyPolygonMesh_getCloud(PyPolygonMesh *self, PyObject *args);
264  static PyObject* PyPolygonMesh_getPolygons(PyPolygonMesh *self, PyObject *args);
265 
266  //-------------------------------------------------------------------------------------------------
267  // pickling
268  //-------------------------------------------------------------------------------------------------
269  static PyObject* PyPolygonMesh_Reduce(PyPolygonMesh *self, PyObject *args);
270  static PyObject* PyPolygonMesh_SetState(PyPolygonMesh *self, PyObject *args);
271 
272  //-------------------------------------------------------------------------------------------------
273  // mapping
274  //-------------------------------------------------------------------------------------------------
275  static PyObject* PyPolygonMesh_mappingGetElem(PyPolygonMesh* self, PyObject* key);
276  static int PyPolygonMesh_mappingLength(PyPolygonMesh* self);
277 
278  //-------------------------------------------------------------------------------------------------
279  // static methods
280  //-------------------------------------------------------------------------------------------------
281  static PyObject* PyPolygonMesh_FromCloudAndPolygons(PyObject *self, PyObject *args, PyObject *kwds);
282  static PyObject* PyPolygonMesh_FromOrganizedCloud(PyObject * self, PyObject *args, PyObject *kwds);
283  static PyObject* PyPolygonMesh_FromTopography(PyObject * self, PyObject *args, PyObject *kwds);
284 
285  //-------------------------------------------------------------------------------------------------
286  // getter / setter
287  //-------------------------------------------------------------------------------------------------
288  static PyObject* PyPolygonMesh_getNrOfPolygons(PyPolygonMesh *self, void *closure);
289 
290  //-------------------------------------------------------------------------------------------------
291  // type structures
292  //-------------------------------------------------------------------------------------------------
293  //static PyMemberDef PyNpDataObject_members[];
294  static PyMethodDef PyPolygonMesh_methods[];
295  static PyTypeObject PyPolygonMeshType;
296  static PyModuleDef PyPolygonMeshModule;
297  static PyGetSetDef PyPolygonMesh_getseters[];
298  static PyMappingMethods PyPolygonMesh_mappingProtocol;
299 
300  static void PyPolygonMesh_addTpDict(PyObject *tp_dict);
301 
302  static PyPolygonMesh* createEmptyPyPolygonMesh();
303 
304 private:
305  static PyObject* parseObjAsFloat32Array(PyObject *obj, npy_intp mRequired, npy_intp &n, float32 **elemRows);
306  static PyObject* parseObjAsUInt8Array(PyObject *obj, npy_intp mRequired, npy_intp &n, uint8_t **elemRows);
307 
308  static void PythonPCL_SetString(PyObject *exception, const char *string);
309  static void PythonPCL_SetString(PyObject *exception, const std::string &string);
310 
311 };
312 
313 }; //end namespace ito
314 
315 
316 #endif //#if ITOM_POINTCLOUDLIBRARY > 0
317 
318 #endif
generic class that covers one single point of different possible types provided by the Point Cloud Li...
Definition: pclStructures.h:73
generic class that covers one single point cloud of different possible types provided by the Point Cl...
Definition: pclStructures.h:292
generic class that covers a shared pointer to pcl::PolygonMesh that is a class for a polygonal mesh p...
Definition: pclStructures.h:667
Definition: apiFunctionsGraph.cpp:39