[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] libcvd cvd/python/interface.h cvd/python/types....
|
From: |
Damian Eads |
|
Subject: |
[libcvd-members] libcvd cvd/python/interface.h cvd/python/types.... |
|
Date: |
Sun, 24 Aug 2008 01:18:07 +0000 |
CVSROOT: /sources/libcvd
Module name: libcvd
Changes by: Damian Eads <eads> 08/08/24 01:18:07
Modified files:
cvd/python : interface.h types.h
Added files:
python : setup.py
Log message:
Added python directory where the python interface to libcvd will be
stored.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/python/interface.h?cvsroot=libcvd&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/python/types.h?cvsroot=libcvd&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/libcvd/python/setup.py?cvsroot=libcvd&rev=1.1
Patches:
Index: cvd/python/interface.h
===================================================================
RCS file: /sources/libcvd/libcvd/cvd/python/interface.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- cvd/python/interface.h 22 Aug 2008 19:18:34 -0000 1.1
+++ cvd/python/interface.h 24 Aug 2008 01:18:06 -0000 1.2
@@ -28,14 +28,14 @@
#include <Python.h>
#include <numpy/arrayobject.h>
-#include <vector>
#include <sstream>
+#include <string>
#include <cvd/image.h>
#include <cvd/image_io.h>
-#include <cvd/vector_image_ref.h>
#include <cvd/convolution.h>
#include "types.h"
+#include "selector.h"
////////////////////////////////////////////////////////////////////////////////
//
@@ -48,21 +48,56 @@
template <class T>
PyArrayObject *fromBasicImageToNumpy(const CVD::BasicImage<T> &image) {
npy_intp a[] = {image.size().y, image.size().x};
- PyArrayObject *retval = (PyArrayObject*)PyArray_SimpleNew(2, a,
NumpyType<T>::type);
+ PyArrayObject *retval = (PyArrayObject*)PyArray_SimpleNew(2, a,
NumpyType<T>::num);
T *data = (T*)retval->data;
copy(image.begin(), image.end(), data);
return retval;
}
template <class T>
- void allocateNumpyCVDImageSiblings(int width, int height,
- /**out: */ CVD::BasicImage<T> *image,
+ CVD::BasicImage<T> allocateNumpyCVDImageSiblings(int width, int height,
+ /**out: */
PyArrayObject **numpy) {
npy_intp a[] = {height, width};
- *numpy = (PyArrayObject*)PyArray_SimpleNew(2, a, NumpyType<T>::type);
- *image = CVD::BasicImage<T>((T*)(*numpy)->data, CVD::ImageRef(width,
height));
+ *numpy = (PyArrayObject*)PyArray_SimpleNew(2, a, NumpyType<T>::num);
+ return CVD::BasicImage<T>((T*)(*numpy)->data, CVD::ImageRef(width,
height));
}
+ template<class I>
+ CVD::BasicImage<I> fromNumpyToBasicImage(PyObject *p, const std::string
&n="") {
+
+ if (!PyArray_Check(p)
+ || PyArray_NDIM(p) != 2
+ || !PyArray_ISCONTIGUOUS(p)
+ || PyArray_TYPE(p) != NumpyType<I>::num) {
+ throw std::string(n + " must be a contiguous array of " +
NumpyType<I>::name() + " (type code " + NumpyType<I>::code() + ")!");
+ }
+
+ PyArrayObject* image = (PyArrayObject*)p;
+
+ int sm = image->dimensions[1];
+ int sn = image->dimensions[0];
+ CVD::BasicImage <I> img((I*)image->data, CVD::ImageRef(sm, sn));
+ return img;
+ }
+
+ template<class I>
+ CVD::BasicImage<I> fromNumpyToBasicImage(PyArrayObject *image, const
std::string& n="") {
+
+ if (PyArray_NDIM(image) != 2
+ || !PyArray_ISCONTIGUOUS(image)
+ || PyArray_TYPE(image) != NumpyType<I>::num) {
+ throw std::string(n + " must be a contiguous array of " +
NumpyType<I>::name() + " (type code " + NumpyType<I>::code() + ")!");
+ }
+
+ int sm = image->dimensions[1];
+ int sn = image->dimensions[0];
+ CVD::BasicImage <I> img((I*)image->data, CVD::ImageRef(sm, sn));
+ return img;
+ }
+
+
}
+
#endif
Index: cvd/python/types.h
===================================================================
RCS file: /sources/libcvd/libcvd/cvd/python/types.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- cvd/python/types.h 22 Aug 2008 19:18:34 -0000 1.1
+++ cvd/python/types.h 24 Aug 2008 01:18:06 -0000 1.2
@@ -8,9 +8,9 @@
* Copyright (C) 2005 The Authors
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -32,9 +32,9 @@
#define DEFINE_NUMPY_TYPE(Type, PyType) \
template<> struct NumpyType<Type>\
{\
- static const int type = PyType;\
+ static const int num = PyType; \
static std::string name(){ return #Type;} \
- static char code(){ return PyType##LTR;}\
+ static char code(){ return PyType##LTR;} \
}
template<class C> struct NumpyType
@@ -70,6 +70,10 @@
TypeList<float,
TypeList<double, End> > > > > > > > > CVDTypes;
+
+
+ typedef TypeList<float,
+ TypeList<double, End> > CVDFloatTypes;
}
#endif
Index: python/setup.py
===================================================================
RCS file: python/setup.py
diff -N python/setup.py
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ python/setup.py 24 Aug 2008 01:18:06 -0000 1.1
@@ -0,0 +1,61 @@
+from distutils.core import setup, Extension
+import sys, os, os.path, string
+
+try:
+ import py2exe
+except ImportError:
+ print "No support for py2exe! Must be non-windows."
+
+def contains_arrayobject_h(path):
+ """
+ Returns True iff the python path string contains the arrayobject.h
+ include file where it is supposed to be.
+ """
+ f=False
+ try:
+ s=os.stat(os.path.join(path, 'numpy', 'core', 'include', \
+ 'numpy', 'arrayobject.h'))
+ f=True
+ except OSError:
+ pass
+ return f
+
+if sys.platform != 'darwin':
+ extra_link_args = ['-s']
+
+other_exts = []
+
+valid_paths = filter(contains_arrayobject_h, sys.path)
+
+# The base path is by default the first python path with arrayobject.h in it.
+include_numpy_array=valid_paths[0]
+
+if len(valid_paths) > 1:
+ print "There are several valid include directories containing
numpy/arrayobject.h"
+ l=[('%d: %s' % (i + 1, valid_paths[i])) for i in xrange(0,
len(valid_paths))]
+ s = 1
+ print string.join(l, '\n')
+ # Prompt the user with a list of selections.
+ while not (s >= 1 and s <= len(valid_paths)):
+ s = raw_input('Selection [default=1]: ')
+ if s == '':
+ s = 1
+ else:
+ s = int(s)
+ include_numpy_array=valid_paths[s-1]
+
+# Add the children directory path suffix to the base path.
+include_numpy_array=os.path.join(include_numpy_array, 'numpy', 'core', \
+ 'include')
+
+
+setup(name='cvd',
+ version='0.9',
+ description='Python CVD',
+ author='Damian Eads and Edward Rosten',
+ packages=['CVD'],
+ scripts=[],
+ ext_modules=[Extension('cvd',
+ ['CVD/cvd.cpp'],
+ extra_link_args = extra_link_args,
+ include_dirs=[include_numpy_array])])
| [Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libcvd-members] libcvd cvd/python/interface.h cvd/python/types....,
Damian Eads <=