itom 2.2.1
|
00001 /* ******************************************************************** 00002 itom software 00003 URL: http://www.uni-stuttgart.de/ito 00004 Copyright (C) 2016, Institut fuer Technische Optik (ITO), 00005 Universitaet Stuttgart, Germany 00006 00007 This file is part of itom. 00008 00009 itom is free software; you can redistribute it and/or modify it 00010 under the terms of the GNU Library General Public Licence as published by 00011 the Free Software Foundation; either version 2 of the Licence, or (at 00012 your option) any later version. 00013 00014 itom is distributed in the hope that it will be useful, but 00015 WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library 00017 General Public Licence for more details. 00018 00019 You should have received a copy of the GNU Library General Public License 00020 along with itom. If not, see <http://www.gnu.org/licenses/>. 00021 *********************************************************************** */ 00022 00023 #ifndef PYTHONPCL_H 00024 #define PYTHONPCL_H 00025 00026 00027 /* includes */ 00028 #ifndef Q_MOC_RUN 00029 #define PY_ARRAY_UNIQUE_SYMBOL itom_ARRAY_API //see numpy help ::array api :: Miscellaneous :: Importing the api (this line must bebefore include global.h) 00030 #define NO_IMPORT_ARRAY 00031 00032 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 00033 00034 //python 00035 // see http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=7f3f750596a105d48ea84ebfe1b1c4ca03e0bab3 00036 #if (defined _DEBUG) && (defined WIN32) 00037 #undef _DEBUG 00038 #if (defined linux) | (defined CMAKE) 00039 #include "Python.h" 00040 #include "numpy/arrayobject.h" 00041 #elif (defined __APPLE__) | (defined CMAKE) 00042 #include "Python.h" 00043 #include "numpy/arrayobject.h" 00044 #else 00045 #include "Python.h" 00046 #include "../Lib/site-packages/numpy/core/include/numpy/arrayobject.h" //for numpy arrays 00047 #endif 00048 #define _DEBUG 00049 #else 00050 #ifdef linux 00051 #include "Python.h" 00052 #include "numpy/arrayobject.h" 00053 #elif (defined __APPLE__) 00054 #include "Python.h" 00055 #include "numpy/arrayobject.h" 00056 #else 00057 #include "Python.h" 00058 #include "../Lib/site-packages/numpy/core/include/numpy/arrayobject.h" //for numpy arrays 00059 #endif 00060 #endif 00061 #endif 00062 00063 #include "../global.h" 00064 00065 #if ITOM_POINTCLOUDLIBRARY > 0 00066 00067 #include "PointCloud/pclStructures.h" 00068 00069 00070 namespace ito 00071 { 00072 00073 class PythonPCL 00074 { 00075 public: 00076 typedef struct 00077 { 00078 PyObject_HEAD 00079 ito::PCLPointCloud *data; 00080 PyObject* base; 00081 } 00082 PyPointCloud; 00083 00084 #define PyPointCloud_Check(op) PyObject_TypeCheck(op, &PythonPCL::PyPointCloudType) 00085 00086 //------------------------------------------------------------------------------------------------- 00087 // constructor, deconstructor, alloc, dellaoc 00088 //------------------------------------------------------------------------------------------------- 00089 static void PyPointCloud_dealloc(PyPointCloud *self); 00090 static PyObject* PyPointCloud_new(PyTypeObject *type, PyObject *args, PyObject *kwds); 00091 static int PyPointCloud_init(PyPointCloud *self, PyObject *args, PyObject *kwds); 00092 00093 00094 //------------------------------------------------------------------------------------------------- 00095 // general members 00096 //------------------------------------------------------------------------------------------------- 00097 static PyObject *PyPointCloud_name(PyPointCloud *self); 00098 static PyObject *PyPointCloud_repr(PyPointCloud *self); 00099 static PyObject *PyPointCloud_append(PyPointCloud *self, PyObject *args, PyObject *kwds); 00100 static PyObject *PyPointCloud_clear(PyPointCloud *self); 00101 static PyObject *PyPointCloud_insert(PyPointCloud *self, PyObject *args); 00102 static PyObject *PyPointCloud_erase(PyPointCloud *self, PyObject *args); 00103 static PyObject *PyPointCloud_toDataObject(PyPointCloud *self); 00104 static PyObject *PyPointCloud_copy(PyPointCloud *self); 00105 static PyObject *PyPointCloud_scaleXYZ(PyPointCloud *self, PyObject *args, PyObject *kwds); 00106 00107 //------------------------------------------------------------------------------------------------- 00108 // helper methods 00109 //------------------------------------------------------------------------------------------------- 00110 static PyObject *PyPointCloud_XYZ_append(PyPointCloud *self, PyObject *xyzObj); 00111 static PyObject *PyPointCloud_XYZI_append(PyPointCloud *self, PyObject *xyziObj); 00112 static PyObject *PyPointCloud_XYZRGBA_append(PyPointCloud *self, PyObject *xyzObj, PyObject *rgbaObj); 00113 static PyObject *PyPointCloud_XYZNormal_append(PyPointCloud *self, PyObject *xyz_nxnynz_curvObj); 00114 static PyObject *PyPointCloud_XYZINormal_append(PyPointCloud *self, PyObject *xyz_i_nxnynz_curvObj); 00115 static PyObject *PyPointCloud_XYZRGBNormal_append(PyPointCloud *self, PyObject *xyz_i_nxnynz_curvObj, PyObject *rgbaObj); 00116 00117 static PyPointCloud* createEmptyPyPointCloud(); 00118 00119 //------------------------------------------------------------------------------------------------- 00120 // getter / setter 00121 //------------------------------------------------------------------------------------------------- 00122 static PyObject* PyPointCloud_GetType(PyPointCloud *self, void *closure); 00123 static PyObject* PyPointCloud_GetSize(PyPointCloud *self, void *closure); 00124 static PyObject* PyPointCloud_GetHeight(PyPointCloud *self, void *closure); 00125 static PyObject* PyPointCloud_GetWidth(PyPointCloud *self, void *closure); 00126 static PyObject* PyPointCloud_GetEmpty(PyPointCloud *self, void *closure); 00127 static PyObject* PyPointCloud_GetOrganized(PyPointCloud *self, void *closure); 00128 static PyObject* PyPointCloud_GetDense(PyPointCloud *self, void *closure); 00129 static int PyPointCloud_SetDense(PyPointCloud *self, PyObject *value, void *closure); 00130 static PyObject* PyPointCloud_GetFields(PyPointCloud *self, void *closure); 00131 00132 //------------------------------------------------------------------------------------------------- 00133 // sequence protocol 00134 //------------------------------------------------------------------------------------------------- 00135 static Py_ssize_t PyPointCloud_seqLength(PyPointCloud *self); 00136 static PyObject *PyPointCloud_seqConcat(PyPointCloud *self, PyObject *rhs); 00137 static PyObject *PyPointCloud_seqRepeat(PyPointCloud *self, Py_ssize_t size); 00138 static PyObject *PyPointCloud_seqItem(PyPointCloud *self, Py_ssize_t size); 00139 static int PyPointCloud_seqAssItem(PyPointCloud *self, Py_ssize_t size, PyObject *point); 00140 static PyObject *PyPointCloud_seqInplaceConcat(PyPointCloud *self, PyObject *rhs); 00141 static PyObject *PyPointCloud_seqInplaceRepeat(PyPointCloud *self, Py_ssize_t size); 00142 00143 //------------------------------------------------------------------------------------------------- 00144 // mapping protocol 00145 //------------------------------------------------------------------------------------------------- 00146 static Py_ssize_t PyPointCloud_mappingLength(PyPointCloud *self); 00147 static PyObject *PyPointCloud_mappingGetElem(PyPointCloud *self, PyObject *key); 00148 static int PyPointCloud_mappingSetElem(PyPointCloud *self, PyObject *key, PyObject *value); 00149 00150 //------------------------------------------------------------------------------------------------- 00151 // pickling 00152 //------------------------------------------------------------------------------------------------- 00153 static PyObject* PyPointCloud_Reduce(PyPointCloud *self, PyObject *args); 00154 static PyObject* PyPointCloud_SetState(PyPointCloud *self, PyObject *args); 00155 00156 //------------------------------------------------------------------------------------------------- 00157 // static methods 00158 //------------------------------------------------------------------------------------------------- 00159 static PyObject *PyPointCloud_fromXYZ(PyPointCloud *self, PyObject *args); 00160 static PyObject *PyPointCloud_fromXYZI(PyPointCloud *self, PyObject *args); 00161 static PyObject *PyPointCloud_fromXYZRGBA(PyPointCloud *self, PyObject *args); 00162 static PyObject *PyPointCloud_fromTopography(PyPointCloud *self, PyObject *args, PyObject *kwds); 00163 00164 //------------------------------------------------------------------------------------------------- 00165 // type structures 00166 //------------------------------------------------------------------------------------------------- 00167 //static PyMemberDef PyNpDataObject_members[]; 00168 static PyMethodDef PyPointCloud_methods[]; 00169 static PyTypeObject PyPointCloudType; 00170 static PyModuleDef PyPointCloudModule; 00171 static PyGetSetDef PyPointCloud_getseters[]; 00172 static PySequenceMethods PyPointCloud_sequenceProtocol; 00173 static PyMappingMethods PyPointCloud_mappingProtocol; 00174 00175 static void PyPointCloud_addTpDict(PyObject *tp_dict); 00176 00177 //-------------------------------------------------------------------------------------------------- 00178 // PCL Point 00179 //-------------------------------------------------------------------------------------------------- 00180 typedef struct 00181 { 00182 PyObject_HEAD 00183 ito::PCLPoint *point; 00184 PyObject* base; 00185 } 00186 PyPoint; 00187 00188 //------------------------------------------------------------------------------------------------- 00189 // constructor, deconstructor, alloc, dellaoc 00190 //------------------------------------------------------------------------------------------------- 00191 static void PyPoint_dealloc(PyPoint *self); 00192 static PyObject* PyPoint_new(PyTypeObject *type, PyObject *args, PyObject *kwds); 00193 static int PyPoint_init(PyPoint *self, PyObject *args, PyObject *kwds); 00194 00195 00196 //------------------------------------------------------------------------------------------------- 00197 // general members 00198 //------------------------------------------------------------------------------------------------- 00199 static PyObject *PyPoint_name(PyPoint *self); 00200 static PyObject *PyPoint_repr(PyPoint *self); 00201 00202 //------------------------------------------------------------------------------------------------- 00203 // getter / setter 00204 //------------------------------------------------------------------------------------------------- 00205 static PyObject* PyPoint_GetType(PyPoint *self, void *closure); 00206 00207 static PyObject* PyPoint_GetXYZ(PyPoint *self, void *closure); 00208 static int PyPoint_SetXYZ(PyPoint *self, PyObject *value, void *closure); 00209 00210 static PyObject* PyPoint_GetIntensity(PyPoint *self, void *closure); 00211 static int PyPoint_SetIntensity(PyPoint *self, PyObject *value, void *closure); 00212 00213 static PyObject* PyPoint_GetRgb(PyPoint *self, void *closure); 00214 static int PyPoint_SetRgb(PyPoint *self, PyObject *value, void *closure); 00215 00216 static PyObject* PyPoint_GetRgba(PyPoint *self, void *closure); 00217 static int PyPoint_SetRgba(PyPoint *self, PyObject *value, void *closure); 00218 00219 static PyObject* PyPoint_GetCurvature(PyPoint *self, void *closure); 00220 static int PyPoint_SetCurvature(PyPoint *self, PyObject *value, void *closure); 00221 00222 static PyObject* PyPoint_GetNormal(PyPoint *self, void *closure); 00223 static int PyPoint_SetNormal(PyPoint *self, PyObject *value, void *closure); 00224 00225 //------------------------------------------------------------------------------------------------- 00226 // mapping members 00227 //------------------------------------------------------------------------------------------------- 00228 static PyObject* PyPoint_mappingGetElem(PyPoint* self, PyObject* key); 00229 static int PyPoint_mappingSetElem(PyPoint* self, PyObject* key, PyObject* value); 00230 00231 //------------------------------------------------------------------------------------------------- 00232 // type structures 00233 //------------------------------------------------------------------------------------------------- 00234 //static PyMemberDef PyNpDataObject_members[]; 00235 static PyMethodDef PyPoint_methods[]; 00236 static PyTypeObject PyPointType; 00237 static PyModuleDef PyPointModule; 00238 static PyGetSetDef PyPoint_getseters[]; 00239 static PyMappingMethods PyPoint_mappingProtocol; 00240 00241 static void PyPoint_addTpDict(PyObject *tp_dict); 00242 00243 00244 00245 00246 00247 00248 //-------------------------------------------------------------------------------------------------- 00249 // PCL PolygonMesh 00250 //-------------------------------------------------------------------------------------------------- 00251 typedef struct 00252 { 00253 PyObject_HEAD 00254 ito::PCLPolygonMesh *polygonMesh; 00255 PyObject* base; 00256 } 00257 PyPolygonMesh; 00258 00259 #define PyPolygonMesh_Check(op) PyObject_TypeCheck(op, &PythonPCL::PyPolygonMeshType) 00260 00261 //------------------------------------------------------------------------------------------------- 00262 // constructor, deconstructor, alloc, dellaoc 00263 //------------------------------------------------------------------------------------------------- 00264 static void PyPolygonMesh_dealloc(PyPolygonMesh *self); 00265 static PyObject* PyPolygonMesh_new(PyTypeObject *type, PyObject *args, PyObject *kwds); 00266 static int PyPolygonMesh_init(PyPolygonMesh *self, PyObject *args, PyObject *kwds); 00267 00268 00269 //------------------------------------------------------------------------------------------------- 00270 // general members 00271 //------------------------------------------------------------------------------------------------- 00272 static PyObject *PyPolygonMesh_name(PyPolygonMesh *self); 00273 static PyObject *PyPolygonMesh_repr(PyPolygonMesh *self); 00274 static PyObject *PyPolygonMesh_data(PyPolygonMesh *self); 00275 00276 static PyObject *PyPolygonMesh_get(PyPolygonMesh *self, PyObject *args, PyObject *kwds); 00277 static PyObject* PyPolygonMesh_getCloud(PyPolygonMesh *self, PyObject *args); 00278 static PyObject* PyPolygonMesh_getPolygons(PyPolygonMesh *self, PyObject *args); 00279 00280 //------------------------------------------------------------------------------------------------- 00281 // pickling 00282 //------------------------------------------------------------------------------------------------- 00283 static PyObject* PyPolygonMesh_Reduce(PyPolygonMesh *self, PyObject *args); 00284 static PyObject* PyPolygonMesh_SetState(PyPolygonMesh *self, PyObject *args); 00285 00286 //------------------------------------------------------------------------------------------------- 00287 // mapping 00288 //------------------------------------------------------------------------------------------------- 00289 static PyObject* PyPolygonMesh_mappingGetElem(PyPolygonMesh* self, PyObject* key); 00290 static int PyPolygonMesh_mappingLength(PyPolygonMesh* self); 00291 00292 //------------------------------------------------------------------------------------------------- 00293 // static methods 00294 //------------------------------------------------------------------------------------------------- 00295 static PyObject* PyPolygonMesh_FromCloudAndPolygons(PyObject *self, PyObject *args, PyObject *kwds); 00296 static PyObject* PyPolygonMesh_FromOrganizedCloud(PyObject * self, PyObject *args, PyObject *kwds); 00297 static PyObject* PyPolygonMesh_FromTopography(PyObject * self, PyObject *args, PyObject *kwds); 00298 00299 //------------------------------------------------------------------------------------------------- 00300 // getter / setter 00301 //------------------------------------------------------------------------------------------------- 00302 static PyObject* PyPolygonMesh_getNrOfPolygons(PyPolygonMesh *self, void *closure); 00303 00304 //------------------------------------------------------------------------------------------------- 00305 // type structures 00306 //------------------------------------------------------------------------------------------------- 00307 //static PyMemberDef PyNpDataObject_members[]; 00308 static PyMethodDef PyPolygonMesh_methods[]; 00309 static PyTypeObject PyPolygonMeshType; 00310 static PyModuleDef PyPolygonMeshModule; 00311 static PyGetSetDef PyPolygonMesh_getseters[]; 00312 static PyMappingMethods PyPolygonMesh_mappingProtocol; 00313 00314 static void PyPolygonMesh_addTpDict(PyObject *tp_dict); 00315 00316 static PyPolygonMesh* createEmptyPyPolygonMesh(); 00317 00318 private: 00319 static PyObject* parseObjAsFloat32Array(PyObject *obj, npy_intp mRequired, npy_intp &n, float32 **elemRows); 00320 static PyObject* parseObjAsUInt8Array(PyObject *obj, npy_intp mRequired, npy_intp &n, uint8_t **elemRows); 00321 00322 static void PythonPCL_SetString(PyObject *exception, const char *string); 00323 static void PythonPCL_SetString(PyObject *exception, const std::string &string); 00324 00325 }; 00326 00327 }; //end namespace ito 00328 00329 00330 #endif //#if ITOM_POINTCLOUDLIBRARY > 0 00331 00332 #endif