1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
// qwt3d_numeric.cpp: encapsulates all PyQwt3D's calls to the Numeric C-API.
//
// Copyright (C) 2004-2007 Gerard Vermeulen
//
// This file is part of PyQwt3D.
//
// PyQwt3D is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PyQwt3D is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with PyQwt3D; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#ifdef HAS_NUMERIC
#include <Python.h>
#include <Numeric/arrayobject.h>
#include <qwt3d_python.h>
#include <qwt3d_numeric.h>
void qwt3d_import_numeric() {
import_array();
}
int try_PyObject_to_NumericArrayContiguousFloat2D(
PyObject *in,
PyObject **out, double **data, unsigned int *nx, unsigned int *ny)
{
if (!PyArray_Check(in))
return 0;
*out = PyArray_ContiguousFromObject(in, PyArray_DOUBLE, 2, 2);
if (!*out) {
PyErr_SetString(
PyExc_RuntimeError,
"Failed to make contiguous 2D array of PyArray_DOUBLE");
return -1;
}
*data = reinterpret_cast<double *>(
reinterpret_cast<PyArrayObject *>(*out)->data);
*nx = reinterpret_cast<PyArrayObject *>(*out)->dimensions[0];
*ny = reinterpret_cast<PyArrayObject *>(*out)->dimensions[1];
return 1;
}
int try_PyObject_to_NumericArrayContiguousFloat3D(
PyObject *in,
PyObject **out, double **data, unsigned int *nx, unsigned int *ny, unsigned int *nz)
{
if (!PyArray_Check(in))
return 0;
*out = PyArray_ContiguousFromObject(in, PyArray_DOUBLE, 3, 3);
if (!*out) {
PyErr_SetString(
PyExc_RuntimeError,
"Failed to make contiguous 3D array of PyArray_DOUBLE");
return -1;
}
*data = reinterpret_cast<double *>(
reinterpret_cast<PyArrayObject *>(*out)->data);
*nx = reinterpret_cast<PyArrayObject *>(*out)->dimensions[0];
*ny = reinterpret_cast<PyArrayObject *>(*out)->dimensions[1];
*nz = reinterpret_cast<PyArrayObject *>(*out)->dimensions[2];
return 1;
}
#endif // HAS_NUMERIC
// Local Variables:
// mode: C++
// c-file-style: "stroustrup"
// indent-tabs-mode: nil
// End:
|