libcvd-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libcvd-members] libcvd cvd/python/selector.h python/CVD/cvd.cpp


From: Damian Eads
Subject: [libcvd-members] libcvd cvd/python/selector.h python/CVD/cvd.cpp
Date: Sun, 24 Aug 2008 01:18:58 +0000

CVSROOT:        /sources/libcvd
Module name:    libcvd
Changes by:     Damian Eads <eads>      08/08/24 01:18:58

Added files:
        cvd/python     : selector.h 
        python/CVD     : cvd.cpp 

Log message:
        Added some initial files for the libcvd python interface.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/python/selector.h?cvsroot=libcvd&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/libcvd/python/CVD/cvd.cpp?cvsroot=libcvd&rev=1.1

Patches:
Index: cvd/python/selector.h
===================================================================
RCS file: cvd/python/selector.h
diff -N cvd/python/selector.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ cvd/python/selector.h       24 Aug 2008 01:18:58 -0000      1.1
@@ -0,0 +1,18 @@
+#define SELECTOR_START(name) template<class List> struct 
name##_selector_struct { 
+
+
+
+#define SELECTOR_ERROR(name) }; template<> struct 
name##_selector_struct<PyCVD::End> {
+
+#define SELECTOR_END };
+
+
+#define SELECTOR_FUNC_START()  typedef typename List::type type; \
+                               typedef typename List::next next;
+
+
+#define SELECTOR_NEXT(name) name##_selector_struct<next>::fun
+
+#define SELECTOR_INVOKE(name, types) name##_selector_struct<types>::fun
+
+#define SELECTOR_INVOKE_FLOATS(name, types) SELECTOR_INVOKE(name, 
CVDFloatTypes)

Index: python/CVD/cvd.cpp
===================================================================
RCS file: python/CVD/cvd.cpp
diff -N python/CVD/cvd.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ python/CVD/cvd.cpp  24 Aug 2008 01:18:58 -0000      1.1
@@ -0,0 +1,81 @@
+#include <Python.h>
+#include <numpy/arrayobject.h>
+#include <vector>
+#include <sstream>
+#include <cvd/image.h>
+#include <cvd/image_io.h>
+#include <cvd/vector_image_ref.h>
+#include <cvd/convolution.h>
+#include <cvd/python/interface.h>
+
+using namespace std;
+using namespace CVD;
+
+////////////////////////////////////////////////////////////////////////////////////
+///
+///                             convolveGaussian Wrapper
+///
+////////////////////////////////////////////////////////////////////////////////////
+
+SELECTOR_START(convolveGaussianWrap)
+
+  static PyObject* fun(PyArrayObject *py_image, double sigma)
+  {
+
+    SELECTOR_FUNC_START();
+
+    if (PyArray_TYPE(py_image) == PyCVD::NumpyType<type>::num) {
+      BasicImage <type> input(PyCVD::fromNumpyToBasicImage<type>(py_image, 
"image"));
+      PyArrayObject *py_result;
+      BasicImage <type> 
result(PyCVD::allocateNumpyCVDImageSiblings<type>(input.size().x,
+                                                                         
input.size().y, &py_result));
+      
+      //convolveGaussian<type>(input, result, sigma);
+      convolveGaussian(input, result, sigma);
+      return (PyObject*)py_result;
+    }
+    else {
+      return SELECTOR_NEXT(convolveGaussianWrap)(py_image, sigma);
+    }
+  }
+
+SELECTOR_ERROR(convolveGaussianWrap)
+
+  static PyObject* fun(PyArrayObject *image, double sigma)
+  {
+    throw string("Can't convolve image of unsupported type: " + 
PyArray_TYPE(image));
+  }
+
+SELECTOR_END
+
+extern "C" PyObject *convolveGaussian(PyObject *self, PyObject *args) {
+  try{
+    PyArrayObject *_image;
+    double sigma;
+
+    cerr << "foo\n";
+    if (!PyArg_ParseTuple(args, "O!d", &PyArray_Type, &_image, &sigma)) {
+      return 0;
+    }
+    cerr << "bar\n";
+    return SELECTOR_INVOKE(convolveGaussianWrap, PyCVD::CVDFloatTypes)(_image, 
sigma);
+  }
+  catch(string err) {
+    cerr << "bing\n";
+    PyErr_SetString(PyExc_RuntimeError, err.c_str());
+    return 0;  
+  }
+}
+
+//////////////////////////////////////////////// END END END convolveGaussian 
Wrapper
+
+static PyMethodDef _cvd_wrap_methods[] = {
+  {"convolveGaussian",
+   convolveGaussian, METH_VARARGS},
+  {NULL, NULL}     /* Sentinel - marks the end of this structure */
+};
+
+extern "C" void initcvd(void)  {
+  (void) Py_InitModule("cvd", _cvd_wrap_methods);
+  import_array();  // Must be present for NumPy.  Called first after above 
line.
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]