itom  3.0.0
pythonPCL.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, 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  #if (defined linux) | (defined CMAKE)
39  #include "Python.h"
40  #include "numpy/arrayobject.h"
41  #elif (defined __APPLE__) | (defined CMAKE)
42  #include "Python.h"
43  #include "numpy/arrayobject.h"
44  #else
45  #include "Python.h"
46  #include "../Lib/site-packages/numpy/core/include/numpy/arrayobject.h" //for numpy arrays
47  #endif
48  #define _DEBUG
49  #else
50  #ifdef linux
51  #include "Python.h"
52  #include "numpy/arrayobject.h"
53  #elif (defined __APPLE__)
54  #include "Python.h"
55  #include "numpy/arrayobject.h"
56  #else
57  #include "Python.h"
58  #include "../Lib/site-packages/numpy/core/include/numpy/arrayobject.h" //for numpy arrays
59  #endif
60  #endif
61 #endif
62 
63 #include "../global.h"
64 
65 #if ITOM_POINTCLOUDLIBRARY > 0
66 
67 #include "PointCloud/pclStructures.h"
68 
69 
70 namespace ito
71 {
72 
73 class PythonPCL
74 {
75 public:
76  typedef struct
77  {
78  PyObject_HEAD
79  ito::PCLPointCloud *data;
80  PyObject* base;
81  }
82  PyPointCloud;
83 
84  #define PyPointCloud_Check(op) PyObject_TypeCheck(op, &PythonPCL::PyPointCloudType)
85 
86  //-------------------------------------------------------------------------------------------------
87  // constructor, deconstructor, alloc, dellaoc
88  //-------------------------------------------------------------------------------------------------
89  static void PyPointCloud_dealloc(PyPointCloud *self);
90  static PyObject* PyPointCloud_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
91  static int PyPointCloud_init(PyPointCloud *self, PyObject *args, PyObject *kwds);
92 
93 
94  //-------------------------------------------------------------------------------------------------
95  // general members
96  //-------------------------------------------------------------------------------------------------
97  static PyObject *PyPointCloud_name(PyPointCloud *self);
98  static PyObject *PyPointCloud_repr(PyPointCloud *self);
99  static PyObject *PyPointCloud_append(PyPointCloud *self, PyObject *args, PyObject *kwds);
100  static PyObject *PyPointCloud_clear(PyPointCloud *self);
101  static PyObject *PyPointCloud_insert(PyPointCloud *self, PyObject *args);
102  static PyObject *PyPointCloud_erase(PyPointCloud *self, PyObject *args);
103  static PyObject *PyPointCloud_toDataObject(PyPointCloud *self);
104  static PyObject *PyPointCloud_copy(PyPointCloud *self);
105  static PyObject *PyPointCloud_scaleXYZ(PyPointCloud *self, PyObject *args, PyObject *kwds);
106  static PyObject *PyPointCloud_moveXYZ(PyPointCloud *self, PyObject *args, PyObject *kwds);
107 
108  //-------------------------------------------------------------------------------------------------
109  // helper methods
110  //-------------------------------------------------------------------------------------------------
111  static PyObject *PyPointCloud_XYZ_append(PyPointCloud *self, PyObject *xyzObj);
112  static PyObject *PyPointCloud_XYZI_append(PyPointCloud *self, PyObject *xyziObj);
113  static PyObject *PyPointCloud_XYZRGBA_append(PyPointCloud *self, PyObject *xyzObj, PyObject *rgbaObj);
114  static PyObject *PyPointCloud_XYZNormal_append(PyPointCloud *self, PyObject *xyz_nxnynz_curvObj);
115  static PyObject *PyPointCloud_XYZINormal_append(PyPointCloud *self, PyObject *xyz_i_nxnynz_curvObj);
116  static PyObject *PyPointCloud_XYZRGBNormal_append(PyPointCloud *self, PyObject *xyz_i_nxnynz_curvObj, PyObject *rgbaObj);
117 
118  static PyPointCloud* createEmptyPyPointCloud();
119 
120  //-------------------------------------------------------------------------------------------------
121  // getter / setter
122  //-------------------------------------------------------------------------------------------------
123  static PyObject* PyPointCloud_GetType(PyPointCloud *self, void *closure);
124  static PyObject* PyPointCloud_GetSize(PyPointCloud *self, void *closure);
125  static PyObject* PyPointCloud_GetHeight(PyPointCloud *self, void *closure);
126  static PyObject* PyPointCloud_GetWidth(PyPointCloud *self, void *closure);
127  static PyObject* PyPointCloud_GetEmpty(PyPointCloud *self, void *closure);
128  static PyObject* PyPointCloud_GetOrganized(PyPointCloud *self, void *closure);
129  static PyObject* PyPointCloud_GetDense(PyPointCloud *self, void *closure);
130  static int PyPointCloud_SetDense(PyPointCloud *self, PyObject *value, void *closure);
131  static PyObject* PyPointCloud_GetFields(PyPointCloud *self, void *closure);
132 
133  //-------------------------------------------------------------------------------------------------
134  // sequence protocol
135  //-------------------------------------------------------------------------------------------------
136  static Py_ssize_t PyPointCloud_seqLength(PyPointCloud *self);
137  static PyObject *PyPointCloud_seqConcat(PyPointCloud *self, PyObject *rhs);
138  static PyObject *PyPointCloud_seqRepeat(PyPointCloud *self, Py_ssize_t size);
139  static PyObject *PyPointCloud_seqItem(PyPointCloud *self, Py_ssize_t size);
140  static int PyPointCloud_seqAssItem(PyPointCloud *self, Py_ssize_t size, PyObject *point);
141  static PyObject *PyPointCloud_seqInplaceConcat(PyPointCloud *self, PyObject *rhs);
142  static PyObject *PyPointCloud_seqInplaceRepeat(PyPointCloud *self, Py_ssize_t size);
143 
144  //-------------------------------------------------------------------------------------------------
145  // mapping protocol
146  //-------------------------------------------------------------------------------------------------
147  static Py_ssize_t PyPointCloud_mappingLength(PyPointCloud *self);
148  static PyObject *PyPointCloud_mappingGetElem(PyPointCloud *self, PyObject *key);
149  static int PyPointCloud_mappingSetElem(PyPointCloud *self, PyObject *key, PyObject *value);
150 
151  //-------------------------------------------------------------------------------------------------
152  // pickling
153  //-------------------------------------------------------------------------------------------------
154  static PyObject* PyPointCloud_Reduce(PyPointCloud *self, PyObject *args);
155  static PyObject* PyPointCloud_SetState(PyPointCloud *self, PyObject *args);
156 
157  //-------------------------------------------------------------------------------------------------
158  // static methods
159  //-------------------------------------------------------------------------------------------------
160  static PyObject *PyPointCloud_fromXYZ(PyPointCloud *self, PyObject *args);
161  static PyObject *PyPointCloud_fromXYZI(PyPointCloud *self, PyObject *args);
162  static PyObject *PyPointCloud_fromXYZRGBA(PyPointCloud *self, PyObject *args);
163  static PyObject *PyPointCloud_fromTopography(PyPointCloud *self, PyObject *args, PyObject *kwds);
164 
165  //-------------------------------------------------------------------------------------------------
166  // type structures
167  //-------------------------------------------------------------------------------------------------
168  //static PyMemberDef PyNpDataObject_members[];
169  static PyMethodDef PyPointCloud_methods[];
170  static PyTypeObject PyPointCloudType;
171  static PyModuleDef PyPointCloudModule;
172  static PyGetSetDef PyPointCloud_getseters[];
173  static PySequenceMethods PyPointCloud_sequenceProtocol;
174  static PyMappingMethods PyPointCloud_mappingProtocol;
175 
176  static void PyPointCloud_addTpDict(PyObject *tp_dict);
177 
178  //--------------------------------------------------------------------------------------------------
179  // PCL Point
180  //--------------------------------------------------------------------------------------------------
181  typedef struct
182  {
183  PyObject_HEAD
184  ito::PCLPoint *point;
185  PyObject* base;
186  }
187  PyPoint;
188 
189  //-------------------------------------------------------------------------------------------------
190  // constructor, deconstructor, alloc, dellaoc
191  //-------------------------------------------------------------------------------------------------
192  static void PyPoint_dealloc(PyPoint *self);
193  static PyObject* PyPoint_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
194  static int PyPoint_init(PyPoint *self, PyObject *args, PyObject *kwds);
195 
196 
197  //-------------------------------------------------------------------------------------------------
198  // general members
199  //-------------------------------------------------------------------------------------------------
200  static PyObject *PyPoint_name(PyPoint *self);
201  static PyObject *PyPoint_repr(PyPoint *self);
202 
203  //-------------------------------------------------------------------------------------------------
204  // getter / setter
205  //-------------------------------------------------------------------------------------------------
206  static PyObject* PyPoint_GetType(PyPoint *self, void *closure);
207 
208  static PyObject* PyPoint_GetXYZ(PyPoint *self, void *closure);
209  static int PyPoint_SetXYZ(PyPoint *self, PyObject *value, void *closure);
210 
211  static PyObject* PyPoint_GetIntensity(PyPoint *self, void *closure);
212  static int PyPoint_SetIntensity(PyPoint *self, PyObject *value, void *closure);
213 
214  static PyObject* PyPoint_GetRgb(PyPoint *self, void *closure);
215  static int PyPoint_SetRgb(PyPoint *self, PyObject *value, void *closure);
216 
217  static PyObject* PyPoint_GetRgba(PyPoint *self, void *closure);
218  static int PyPoint_SetRgba(PyPoint *self, PyObject *value, void *closure);
219 
220  static PyObject* PyPoint_GetCurvature(PyPoint *self, void *closure);
221  static int PyPoint_SetCurvature(PyPoint *self, PyObject *value, void *closure);
222 
223  static PyObject* PyPoint_GetNormal(PyPoint *self, void *closure);
224  static int PyPoint_SetNormal(PyPoint *self, PyObject *value, void *closure);
225 
226  //-------------------------------------------------------------------------------------------------
227  // mapping members
228  //-------------------------------------------------------------------------------------------------
229  static PyObject* PyPoint_mappingGetElem(PyPoint* self, PyObject* key);
230  static int PyPoint_mappingSetElem(PyPoint* self, PyObject* key, PyObject* value);
231 
232  //-------------------------------------------------------------------------------------------------
233  // type structures
234  //-------------------------------------------------------------------------------------------------
235  //static PyMemberDef PyNpDataObject_members[];
236  static PyMethodDef PyPoint_methods[];
237  static PyTypeObject PyPointType;
238  static PyModuleDef PyPointModule;
239  static PyGetSetDef PyPoint_getseters[];
240  static PyMappingMethods PyPoint_mappingProtocol;
241 
242  static void PyPoint_addTpDict(PyObject *tp_dict);
243 
244 
245 
246 
247 
248 
249  //--------------------------------------------------------------------------------------------------
250  // PCL PolygonMesh
251  //--------------------------------------------------------------------------------------------------
252  typedef struct
253  {
254  PyObject_HEAD
255  ito::PCLPolygonMesh *polygonMesh;
256  PyObject* base;
257  }
258  PyPolygonMesh;
259 
260  #define PyPolygonMesh_Check(op) PyObject_TypeCheck(op, &PythonPCL::PyPolygonMeshType)
261 
262  //-------------------------------------------------------------------------------------------------
263  // constructor, deconstructor, alloc, dellaoc
264  //-------------------------------------------------------------------------------------------------
265  static void PyPolygonMesh_dealloc(PyPolygonMesh *self);
266  static PyObject* PyPolygonMesh_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
267  static int PyPolygonMesh_init(PyPolygonMesh *self, PyObject *args, PyObject *kwds);
268 
269 
270  //-------------------------------------------------------------------------------------------------
271  // general members
272  //-------------------------------------------------------------------------------------------------
273  static PyObject *PyPolygonMesh_name(PyPolygonMesh *self);
274  static PyObject *PyPolygonMesh_repr(PyPolygonMesh *self);
275  static PyObject *PyPolygonMesh_data(PyPolygonMesh *self);
276 
277  static PyObject *PyPolygonMesh_get(PyPolygonMesh *self, PyObject *args, PyObject *kwds);
278  static PyObject* PyPolygonMesh_getCloud(PyPolygonMesh *self, PyObject *args);
279  static PyObject* PyPolygonMesh_getPolygons(PyPolygonMesh *self, PyObject *args);
280 
281  //-------------------------------------------------------------------------------------------------
282  // pickling
283  //-------------------------------------------------------------------------------------------------
284  static PyObject* PyPolygonMesh_Reduce(PyPolygonMesh *self, PyObject *args);
285  static PyObject* PyPolygonMesh_SetState(PyPolygonMesh *self, PyObject *args);
286 
287  //-------------------------------------------------------------------------------------------------
288  // mapping
289  //-------------------------------------------------------------------------------------------------
290  static PyObject* PyPolygonMesh_mappingGetElem(PyPolygonMesh* self, PyObject* key);
291  static int PyPolygonMesh_mappingLength(PyPolygonMesh* self);
292 
293  //-------------------------------------------------------------------------------------------------
294  // static methods
295  //-------------------------------------------------------------------------------------------------
296  static PyObject* PyPolygonMesh_FromCloudAndPolygons(PyObject *self, PyObject *args, PyObject *kwds);
297  static PyObject* PyPolygonMesh_FromOrganizedCloud(PyObject * self, PyObject *args, PyObject *kwds);
298  static PyObject* PyPolygonMesh_FromTopography(PyObject * self, PyObject *args, PyObject *kwds);
299 
300  //-------------------------------------------------------------------------------------------------
301  // getter / setter
302  //-------------------------------------------------------------------------------------------------
303  static PyObject* PyPolygonMesh_getNrOfPolygons(PyPolygonMesh *self, void *closure);
304 
305  //-------------------------------------------------------------------------------------------------
306  // type structures
307  //-------------------------------------------------------------------------------------------------
308  //static PyMemberDef PyNpDataObject_members[];
309  static PyMethodDef PyPolygonMesh_methods[];
310  static PyTypeObject PyPolygonMeshType;
311  static PyModuleDef PyPolygonMeshModule;
312  static PyGetSetDef PyPolygonMesh_getseters[];
313  static PyMappingMethods PyPolygonMesh_mappingProtocol;
314 
315  static void PyPolygonMesh_addTpDict(PyObject *tp_dict);
316 
317  static PyPolygonMesh* createEmptyPyPolygonMesh();
318 
319 private:
320  static PyObject* parseObjAsFloat32Array(PyObject *obj, npy_intp mRequired, npy_intp &n, float32 **elemRows);
321  static PyObject* parseObjAsUInt8Array(PyObject *obj, npy_intp mRequired, npy_intp &n, uint8_t **elemRows);
322 
323  static void PythonPCL_SetString(PyObject *exception, const char *string);
324  static void PythonPCL_SetString(PyObject *exception, const std::string &string);
325 
326 };
327 
328 }; //end namespace ito
329 
330 
331 #endif //#if ITOM_POINTCLOUDLIBRARY > 0
332 
333 #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