ggivtk.src

        Copyright (c) Kapteyn Astronomical Institute, Groningen 2012
        All Rights Reserved.

Name:         ggivtk.src
Creator:      terlouw
Host:         azarquiel
Date:         Sep 3, 2012
Contents:     ggivtk.doc ggivtk.so.make incdir.py ggivtk.so.make.devel incdir.py
              vtkdir.py ggivtk.c ggivtk.pyx ggivtkfield.c ggivtkfield.h
              ggitovtk.cxx

#>            ggivtk.doc
Document:     ggivtk

Purpose:      Python module implementing the VtkField Ggi element for pygipsy.

Category:     SYSTEM

File:         ggivtk.src

Author:       J.P. Terlouw

Description:  ggivtk is a pre-compiled module which augments the
              standard Python module gipsy. It implements the _VtkField
              class and a factory method for _Container.

Use:          The module is automatically imported by the gipsy module.

Updates:      Jul 18, 2007: JPT, Document created.
              Feb 28, 2010: JPT, added -fPIC switch to compilations
              Sep  3, 2012: JPT, conditional code for different VTK versions
#<

#>            ggivtk.so.make
SHELL = /bin/sh

DOCUMENTS = ggivtk.doc

HELPERS   = ggivtk.so.make incdir.py ggivtk.so.make.devel incdir.py vtkdir.py

SOURCES   = ggivtk.c ggivtk.pyx ggivtkfield.c ggivtkfield.h ggitovtk.cxx

ifeq ($(findstring linux, $(ARCHITECTURE)), linux)
LFLAGS = -shared
endif

ifeq ($(findstring apple, $(ARCHITECTURE)), apple)
LFLAGS = -dylib -lpython -bundle
endif

default:: ggivtk.so

pack::
	$${gip_sys}/pack.csh ggivtk.src $(DOCUMENTS) $(HELPERS) $(SOURCES)

ggivtk.so : ggivtk.o ggivtkfield.o ggitovtk.o
	-@rm -f ggivtk.so
	-@$(CC_COMP) -shared ggivtk.o ggivtkfield.o ggitovtk.o $(gip_exe)/gipsy.so -lvtkRendering -lvtkCommonPythonD -o ggivtk.so
	-@if [ ! -r ggivtk.so ] ; then \
	touch ggivtk.so ;\
	chmod +x ggivtk.so ;\
	echo "a dummy ggivtk.so has been created." ;\
	fi

ggivtk.o : ggivtk.c
	-@if [ "$(CC_COMP)" = "gfortran" ] ; then \
	$(CC_COMP) -c -fPIC ggivtk.c -iquote . -iquote $(gip_inc) `python incdir.py` ;\
	else \
	$(CC_COMP) -c -fPIC ggivtk.c -I. -I$(gip_inc) `python incdir.py` -I- ;\
	fi
	touch ggivtk.o

ggivtkfield.o : ggivtkfield.c
	-@$(CC_COMP) -c -fPIC $(CC_OPTS) ggivtkfield.c
	touch ggivtkfield.o

ggitovtk.o : ggitovtk.cxx
	-@g++ -Wno-deprecated -c -fPIC `python incdir.py` -I . ggitovtk.cxx
	touch ggitovtk.o
#<

#>            incdir.py
from distutils.sysconfig import get_python_inc
import numpy
pi = get_python_inc()
ni = numpy.get_include()
print "-I%s -I%s -I%s/numpy" % (pi, ni, ni)
#<

#>            ggivtk.so.make.devel
SHELL = /bin/sh

default:: ggivtk.so

ggivtk.so : ggivtk.o ggivtkfield.o ggitovtk.o
	$(CC_COMP) -shared ggivtk.o ggivtkfield.o ggitovtk.o ./gipsy.so -lvtkRendering -lvtkCommonPythonD -o ggivtk.so

ggivtk.o : ggivtk.c
	$(CC_COMP) -c -fPIC ggivtk.c -I. -I$(gip_inc) `python incdir.py` -I-

ggivtkfield.o : ggivtkfield.c
	$(CC_COMP) -c $(CC_OPTS) ggivtkfield.c

ggitovtk.o : ggitovtk.cxx
	g++ -Wno-deprecated -c -I `python vtkdir.py` `python incdir.py` -I . ggitovtk.cxx

ggivtk.c : ggivtk.pyx
	cython ggivtk.pyx
#<

#>            incdir.py
from distutils.sysconfig import get_python_inc
import numpy
pi = get_python_inc()
ni = numpy.get_include()
print "-I%s -I%s -I%s/numpy" % (pi, ni, ni)
#<

#>            vtkdir.py
from os.path import *

def find(name, dirname, names):
   if name in names:
      print dirname
      exit

walk('/usr', find, 'vtkPythonUtil.h')
#<

#>            ggivtk.c
/* Generated by Cython 0.10.2 on Thu Dec 11 15:04:22 2008 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
#endif
#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
#endif
#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)

  typedef struct {
       void *buf;
       PyObject *obj;
       Py_ssize_t len;
       Py_ssize_t itemsize;
       int readonly;
       int ndim;
       char *format;
       Py_ssize_t *shape;
       Py_ssize_t *strides;
       Py_ssize_t *suboffsets;
       void *internal;
  } Py_buffer;

  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_LOCK 0x0002
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)

#endif
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif
#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyString_Type                PyBytes_Type
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define PyBytes_Type                 PyString_Type
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func)
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
#else
  #define _USE_MATH_DEFINES
#endif
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#include <math.h>
#define __PYX_HAVE_API__ggivtk
#include "keyevents.h"
#include "ggi.h"
#include "ggivtkfield.h"


#ifdef __GNUC__
#define INLINE __inline__
#elif _WIN32
#define INLINE __inline
#else
#define INLINE 
#endif

typedef struct {PyObject **p; char *s; long n; char is_unicode; char intern; char is_identifier;} __Pyx_StringTabEntry; /*proto*/



static int __pyx_skip_dispatch = 0;


/* Type Conversion Predeclarations */

#if PY_MAJOR_VERSION < 3
#define __Pyx_PyBytes_FromString PyString_FromString
#define __Pyx_PyBytes_AsString   PyString_AsString
#else
#define __Pyx_PyBytes_FromString PyBytes_FromString
#define __Pyx_PyBytes_AsString   PyBytes_AsString
#endif

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static INLINE int __Pyx_PyObject_IsTrue(PyObject* x);
static INLINE PY_LONG_LONG __pyx_PyInt_AsLongLong(PyObject* x);
static INLINE unsigned PY_LONG_LONG __pyx_PyInt_AsUnsignedLongLong(PyObject* x);
static INLINE Py_ssize_t __pyx_PyIndex_AsSsize_t(PyObject* b);

#define __pyx_PyInt_AsLong(x) (PyInt_CheckExact(x) ? PyInt_AS_LONG(x) : PyInt_AsLong(x))
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))

static INLINE unsigned char __pyx_PyInt_unsigned_char(PyObject* x);
static INLINE unsigned short __pyx_PyInt_unsigned_short(PyObject* x);
static INLINE char __pyx_PyInt_char(PyObject* x);
static INLINE short __pyx_PyInt_short(PyObject* x);
static INLINE int __pyx_PyInt_int(PyObject* x);
static INLINE long __pyx_PyInt_long(PyObject* x);
static INLINE signed char __pyx_PyInt_signed_char(PyObject* x);
static INLINE signed short __pyx_PyInt_signed_short(PyObject* x);
static INLINE signed int __pyx_PyInt_signed_int(PyObject* x);
static INLINE signed long __pyx_PyInt_signed_long(PyObject* x);
static INLINE long double __pyx_PyInt_long_double(PyObject* x);
#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 ||               (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) 
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
    
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;
static const char **__pyx_f;

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name, PyObject* kw_name); /*proto*/

static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],     PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,     const char* function_name); /*proto*/

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/

static void __Pyx_WriteUnraisable(const char *name); /*proto*/

static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static void __Pyx_AddTraceback(const char *funcname); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/

/* Type declarations */
/* Module declarations from ggivtk */

static ident __pyx_f_6ggivtk_toident(PyObject *); /*proto*/


/* Implementation of ggivtk */
static char __pyx_k_self[] = "self";
static PyObject *__pyx_kp_self;
static char __pyx_k_name[] = "name";
static PyObject *__pyx_kp_name;
static char __pyx_k_width[] = "width";
static PyObject *__pyx_kp_width;
static char __pyx_k_height[] = "height";
static PyObject *__pyx_kp_height;
static char __pyx_k_vtk[] = "vtk";
static PyObject *__pyx_kp_vtk;
static char __pyx_k_gipsy[] = "gipsy";
static PyObject *__pyx_kp_gipsy;
static char __pyx_k__VtkField[] = "_VtkField";
static PyObject *__pyx_kp__VtkField;
static char __pyx_k__Element[] = "_Element";
static PyObject *__pyx_kp__Element;
static char __pyx_k_open[] = "open";
static PyObject *__pyx_kp_open;
static char __pyx_k_Interactor[] = "Interactor";
static PyObject *__pyx_kp_Interactor;
static char __pyx_k_RenderWindow[] = "RenderWindow";
static PyObject *__pyx_kp_RenderWindow;
static char __pyx_k_hook[] = "hook";
static PyObject *__pyx_kp_hook;
static char __pyx_k_1[] = "vtkXRenderWindowInteractor";
static PyObject *__pyx_kp_1;
static char __pyx_k_2[] = "vtkXOpenGLRenderWindow";
static PyObject *__pyx_kp_2;
static char __pyx_k_container[] = "container";
static PyObject *__pyx_kp_container;

/* "/tmp/gftsk/ggivtk.pyx":18
 * #  toident: convert an ident stored in an integer object to an ident
 * #  --------------------------------------------------------------------------
 * cdef ident toident(object id):             # <<<<<<<<<<<<<<
 *    cdef long c_id
 *    c_id = id
 */

static  ident __pyx_f_6ggivtk_toident(PyObject *__pyx_v_id) {
  long __pyx_v_c_id;
  ident __pyx_r;
  long __pyx_1;

  /* "/tmp/gftsk/ggivtk.pyx":20
 * cdef ident toident(object id):
 *    cdef long c_id
 *    c_id = id             # <<<<<<<<<<<<<<
 *    return <ident>c_id
 * 
 */
  __pyx_1 = __pyx_PyInt_long(__pyx_v_id); if (unlikely((__pyx_1 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_c_id = __pyx_1;

  /* "/tmp/gftsk/ggivtk.pyx":21
 *    cdef long c_id
 *    c_id = id
 *    return <ident>c_id             # <<<<<<<<<<<<<<
 * 
 * class _VtkField(gipsy._Element):
 */
  __pyx_r = ((void *)__pyx_v_c_id);
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("ggivtk.toident");
  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

/* "/tmp/gftsk/ggivtk.pyx":25
 * class _VtkField(gipsy._Element):
 * 
 *    def open(self):             # <<<<<<<<<<<<<<
 *       GgiVtkInitialize(toident(self.hook))
 * 
 */

static PyObject *__pyx_pf_6ggivtk_9_VtkField_open(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static PyMethodDef __pyx_mdef_6ggivtk_9_VtkField_open = {"open", (PyCFunction)__pyx_pf_6ggivtk_9_VtkField_open, METH_O, 0};
static PyObject *__pyx_pf_6ggivtk_9_VtkField_open(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  __pyx_self = __pyx_self;

  /* "/tmp/gftsk/ggivtk.pyx":26
 * 
 *    def open(self):
 *       GgiVtkInitialize(toident(self.hook))             # <<<<<<<<<<<<<<
 * 
 *    def Interactor(self):
 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_hook); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  GgiVtkInitialize(__pyx_f_6ggivtk_toident(__pyx_1));
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("ggivtk._VtkField.open");
  __pyx_r = NULL;
  __pyx_L0:;
  return __pyx_r;
}

/* "/tmp/gftsk/ggivtk.pyx":28
 *       GgiVtkInitialize(toident(self.hook))
 * 
 *    def Interactor(self):             # <<<<<<<<<<<<<<
 *       objptr = GgiVtkInteractor(toident(self.hook))
 *       return vtk.vtkXRenderWindowInteractor(objptr)
 */

static PyObject *__pyx_pf_6ggivtk_9_VtkField_Interactor(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static PyMethodDef __pyx_mdef_6ggivtk_9_VtkField_Interactor = {"Interactor", (PyCFunction)__pyx_pf_6ggivtk_9_VtkField_Interactor, METH_O, 0};
static PyObject *__pyx_pf_6ggivtk_9_VtkField_Interactor(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_v_objptr;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  __pyx_self = __pyx_self;
  __pyx_v_objptr = Py_None; Py_INCREF(Py_None);

  /* "/tmp/gftsk/ggivtk.pyx":29
 * 
 *    def Interactor(self):
 *       objptr = GgiVtkInteractor(toident(self.hook))             # <<<<<<<<<<<<<<
 *       return vtk.vtkXRenderWindowInteractor(objptr)
 * 
 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_hook); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_2 = __Pyx_PyBytes_FromString(GgiVtkInteractor(__pyx_f_6ggivtk_toident(__pyx_1))); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_v_objptr);
  __pyx_v_objptr = __pyx_2;
  __pyx_2 = 0;

  /* "/tmp/gftsk/ggivtk.pyx":30
 *    def Interactor(self):
 *       objptr = GgiVtkInteractor(toident(self.hook))
 *       return vtk.vtkXRenderWindowInteractor(objptr)             # <<<<<<<<<<<<<<
 * 
 *    def RenderWindow(self):
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_vtk); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_kp_1); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = PyTuple_New(1); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_INCREF(__pyx_v_objptr);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_objptr);
  __pyx_3 = PyObject_Call(__pyx_2, ((PyObject *)__pyx_1), NULL); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(((PyObject *)__pyx_1)); __pyx_1 = 0;
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("ggivtk._VtkField.Interactor");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_objptr);
  return __pyx_r;
}

/* "/tmp/gftsk/ggivtk.pyx":32
 *       return vtk.vtkXRenderWindowInteractor(objptr)
 * 
 *    def RenderWindow(self):             # <<<<<<<<<<<<<<
 *       objptr = GgiVtkRenderWindow(toident(self.hook))
 *       return vtk.vtkXOpenGLRenderWindow(objptr)
 */

static PyObject *__pyx_pf_6ggivtk_9_VtkField_RenderWindow(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static PyMethodDef __pyx_mdef_6ggivtk_9_VtkField_RenderWindow = {"RenderWindow", (PyCFunction)__pyx_pf_6ggivtk_9_VtkField_RenderWindow, METH_O, 0};
static PyObject *__pyx_pf_6ggivtk_9_VtkField_RenderWindow(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_v_objptr;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  __pyx_self = __pyx_self;
  __pyx_v_objptr = Py_None; Py_INCREF(Py_None);

  /* "/tmp/gftsk/ggivtk.pyx":33
 * 
 *    def RenderWindow(self):
 *       objptr = GgiVtkRenderWindow(toident(self.hook))             # <<<<<<<<<<<<<<
 *       return vtk.vtkXOpenGLRenderWindow(objptr)
 * 
 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_hook); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_2 = __Pyx_PyBytes_FromString(GgiVtkRenderWindow(__pyx_f_6ggivtk_toident(__pyx_1))); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_v_objptr);
  __pyx_v_objptr = __pyx_2;
  __pyx_2 = 0;

  /* "/tmp/gftsk/ggivtk.pyx":34
 *    def RenderWindow(self):
 *       objptr = GgiVtkRenderWindow(toident(self.hook))
 *       return vtk.vtkXOpenGLRenderWindow(objptr)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_vtk); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_kp_2); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = PyTuple_New(1); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_INCREF(__pyx_v_objptr);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_objptr);
  __pyx_3 = PyObject_Call(__pyx_2, ((PyObject *)__pyx_1), NULL); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(((PyObject *)__pyx_1)); __pyx_1 = 0;
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("ggivtk._VtkField.RenderWindow");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_objptr);
  return __pyx_r;
}

/* "/tmp/gftsk/ggivtk.pyx":37
 * 
 * 
 * def VtkField(self, name, width, height):             # <<<<<<<<<<<<<<
 *    result = _VtkField()
 *    result.container = self
 */

static PyObject *__pyx_pf_6ggivtk_VtkField(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6ggivtk_VtkField(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_name = 0;
  PyObject *__pyx_v_width = 0;
  PyObject *__pyx_v_height = 0;
  PyObject *__pyx_v_result;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  char *__pyx_3;
  int __pyx_4;
  int __pyx_5;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_self,&__pyx_kp_name,&__pyx_kp_width,&__pyx_kp_height,0};
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    PyObject* values[4] = {0,0,0,0};
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_self);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_name);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("VtkField", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_kp_width);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("VtkField", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_kp_height);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("VtkField", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "VtkField") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_self = values[0];
    __pyx_v_name = values[1];
    __pyx_v_width = values[2];
    __pyx_v_height = values[3];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_self = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_name = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_width = PyTuple_GET_ITEM(__pyx_args, 2);
    __pyx_v_height = PyTuple_GET_ITEM(__pyx_args, 3);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("VtkField", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("ggivtk.VtkField");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_result = Py_None; Py_INCREF(Py_None);

  /* "/tmp/gftsk/ggivtk.pyx":38
 * 
 * def VtkField(self, name, width, height):
 *    result = _VtkField()             # <<<<<<<<<<<<<<
 *    result.container = self
 *    GgiUseShell(toident(self.hook))
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp__VtkField); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_2 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_v_result);
  __pyx_v_result = __pyx_2;
  __pyx_2 = 0;

  /* "/tmp/gftsk/ggivtk.pyx":39
 * def VtkField(self, name, width, height):
 *    result = _VtkField()
 *    result.container = self             # <<<<<<<<<<<<<<
 *    GgiUseShell(toident(self.hook))
 *    result.hook = <long>GgiVtkField(name, width, height)
 */
  if (PyObject_SetAttr(__pyx_v_result, __pyx_kp_container, __pyx_v_self) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/tmp/gftsk/ggivtk.pyx":40
 *    result = _VtkField()
 *    result.container = self
 *    GgiUseShell(toident(self.hook))             # <<<<<<<<<<<<<<
 *    result.hook = <long>GgiVtkField(name, width, height)
 *    result.name = name
 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_hook); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  GgiUseShell(__pyx_f_6ggivtk_toident(__pyx_1));
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/tmp/gftsk/ggivtk.pyx":41
 *    result.container = self
 *    GgiUseShell(toident(self.hook))
 *    result.hook = <long>GgiVtkField(name, width, height)             # <<<<<<<<<<<<<<
 *    result.name = name
 *    return result
 */
  __pyx_3 = __Pyx_PyBytes_AsString(__pyx_v_name); if (unlikely((!__pyx_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_4 = __pyx_PyInt_int(__pyx_v_width); if (unlikely((__pyx_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_5 = __pyx_PyInt_int(__pyx_v_height); if (unlikely((__pyx_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_2 = PyInt_FromLong(((long)GgiVtkField(__pyx_3, __pyx_4, __pyx_5))); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttr(__pyx_v_result, __pyx_kp_hook, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;

  /* "/tmp/gftsk/ggivtk.pyx":42
 *    GgiUseShell(toident(self.hook))
 *    result.hook = <long>GgiVtkField(name, width, height)
 *    result.name = name             # <<<<<<<<<<<<<<
 *    return result
 * 
 */
  if (PyObject_SetAttr(__pyx_v_result, __pyx_kp_name, __pyx_v_name) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/tmp/gftsk/ggivtk.pyx":43
 *    result.hook = <long>GgiVtkField(name, width, height)
 *    result.name = name
 *    return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
  Py_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("ggivtk.VtkField");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_result);
  return __pyx_r;
}

static struct PyMethodDef __pyx_methods[] = {
  {"VtkField", (PyCFunction)__pyx_pf_6ggivtk_VtkField, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

static void __pyx_init_filenames(void); /*proto*/

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    "ggivtk",
    0, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_self, __pyx_k_self, sizeof(__pyx_k_self), 1, 1, 1},
  {&__pyx_kp_name, __pyx_k_name, sizeof(__pyx_k_name), 1, 1, 1},
  {&__pyx_kp_width, __pyx_k_width, sizeof(__pyx_k_width), 1, 1, 1},
  {&__pyx_kp_height, __pyx_k_height, sizeof(__pyx_k_height), 1, 1, 1},
  {&__pyx_kp_vtk, __pyx_k_vtk, sizeof(__pyx_k_vtk), 1, 1, 1},
  {&__pyx_kp_gipsy, __pyx_k_gipsy, sizeof(__pyx_k_gipsy), 1, 1, 1},
  {&__pyx_kp__VtkField, __pyx_k__VtkField, sizeof(__pyx_k__VtkField), 0, 1, 1},
  {&__pyx_kp__Element, __pyx_k__Element, sizeof(__pyx_k__Element), 1, 1, 1},
  {&__pyx_kp_open, __pyx_k_open, sizeof(__pyx_k_open), 1, 1, 1},
  {&__pyx_kp_Interactor, __pyx_k_Interactor, sizeof(__pyx_k_Interactor), 1, 1, 1},
  {&__pyx_kp_RenderWindow, __pyx_k_RenderWindow, sizeof(__pyx_k_RenderWindow), 1, 1, 1},
  {&__pyx_kp_hook, __pyx_k_hook, sizeof(__pyx_k_hook), 1, 1, 1},
  {&__pyx_kp_1, __pyx_k_1, sizeof(__pyx_k_1), 1, 1, 1},
  {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 1, 1, 1},
  {&__pyx_kp_container, __pyx_k_container, sizeof(__pyx_k_container), 1, 1, 1},
  {0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  return 0;
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initggivtk(void); /*proto*/
PyMODINIT_FUNC initggivtk(void)
#else
PyMODINIT_FUNC PyInit_ggivtk(void); /*proto*/
PyMODINIT_FUNC PyInit_ggivtk(void)
#endif
{
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Library function declarations ---*/
  __pyx_init_filenames();
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("ggivtk", __pyx_methods, 0, 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME);
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_skip_dispatch = 0;
  /*--- Global init code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "/tmp/gftsk/ggivtk.pyx":1
 * import vtk, gipsy             # <<<<<<<<<<<<<<
 * 
 * cdef extern from "keyevents.h":
 */
  __pyx_1 = __Pyx_Import(__pyx_kp_vtk, 0); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_vtk, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = __Pyx_Import(__pyx_kp_gipsy, 0); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_gipsy, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/tmp/gftsk/ggivtk.pyx":23
 *    return <ident>c_id
 * 
 * class _VtkField(gipsy._Element):             # <<<<<<<<<<<<<<
 * 
 *    def open(self):
 */
  __pyx_1 = PyDict_New(); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_kp_gipsy); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_3 = PyObject_GetAttr(__pyx_2, __pyx_kp__Element); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_2 = PyTuple_New(1); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_3);
  __pyx_3 = 0;
  __pyx_3 = __Pyx_CreateClass(((PyObject *)__pyx_2), ((PyObject *)__pyx_1), __pyx_kp__VtkField, "ggivtk"); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(((PyObject *)__pyx_2)); __pyx_2 = 0;

  /* "/tmp/gftsk/ggivtk.pyx":25
 * class _VtkField(gipsy._Element):
 * 
 *    def open(self):             # <<<<<<<<<<<<<<
 *       GgiVtkInitialize(toident(self.hook))
 * 
 */
  __pyx_2 = PyCFunction_New(&__pyx_mdef_6ggivtk_9_VtkField_open, 0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_4 = PyMethod_New(__pyx_2, 0, __pyx_3); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  if (PyObject_SetAttr(__pyx_3, __pyx_kp_open, __pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;

  /* "/tmp/gftsk/ggivtk.pyx":28
 *       GgiVtkInitialize(toident(self.hook))
 * 
 *    def Interactor(self):             # <<<<<<<<<<<<<<
 *       objptr = GgiVtkInteractor(toident(self.hook))
 *       return vtk.vtkXRenderWindowInteractor(objptr)
 */
  __pyx_2 = PyCFunction_New(&__pyx_mdef_6ggivtk_9_VtkField_Interactor, 0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_4 = PyMethod_New(__pyx_2, 0, __pyx_3); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  if (PyObject_SetAttr(__pyx_3, __pyx_kp_Interactor, __pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;

  /* "/tmp/gftsk/ggivtk.pyx":32
 *       return vtk.vtkXRenderWindowInteractor(objptr)
 * 
 *    def RenderWindow(self):             # <<<<<<<<<<<<<<
 *       objptr = GgiVtkRenderWindow(toident(self.hook))
 *       return vtk.vtkXOpenGLRenderWindow(objptr)
 */
  __pyx_2 = PyCFunction_New(&__pyx_mdef_6ggivtk_9_VtkField_RenderWindow, 0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_4 = PyMethod_New(__pyx_2, 0, __pyx_3); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  if (PyObject_SetAttr(__pyx_3, __pyx_kp_RenderWindow, __pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_kp__VtkField, __pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(((PyObject *)__pyx_1)); __pyx_1 = 0;

  /* "/tmp/gftsk/ggivtk.pyx":37
 * 
 * 
 * def VtkField(self, name, width, height):             # <<<<<<<<<<<<<<
 *    result = _VtkField()
 *    result.container = self
 */
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
  __pyx_L1_error:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("ggivtk");
  #if PY_MAJOR_VERSION >= 3
  return NULL;
  #endif
}

static const char *__pyx_filenames[] = {
  "ggivtk.pyx",
};

/* Runtime support code */

static void __pyx_init_filenames(void) {
  __pyx_f = __pyx_filenames;
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AS_STRING(kw_name));
        #endif
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *number, *more_or_less;

    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    number = (num_expected == 1) ? "" : "s";
    PyErr_Format(PyExc_TypeError,
        #if PY_VERSION_HEX < 0x02050000
            "%s() takes %s %d positional argument%s (%d given)",
        #else
            "%s() takes %s %zd positional argument%s (%zd given)",
        #endif
        func_name, more_or_less, num_expected, number, num_found);
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;

    while (PyDict_Next(kwds, &pos, &key, &value)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
        #else
        if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
        #endif
            goto invalid_keyword_type;
        } else {
            name = argnames;
            while (*name && (**name != key)) name++;
            if (*name) {
                if (name < first_kw_arg) goto arg_passed_twice;
                values[name-argnames] = value;
            } else {
                for (name = first_kw_arg; *name; name++) {
                    #if PY_MAJOR_VERSION >= 3
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                        PyUnicode_Compare(**name, key) == 0) break;
                    #else
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                        strcmp(PyString_AS_STRING(**name),
                               PyString_AS_STRING(key)) == 0) break;
                    #endif
                }
                if (*name) {
                    values[name-argnames] = value;
                } else {
                    /* unexpected keyword found */
                    for (name=argnames; name != first_kw_arg; name++) {
                        if (**name == key) goto arg_passed_twice;
                        #if PY_MAJOR_VERSION >= 3
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
                        #else
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                            strcmp(PyString_AS_STRING(**name),
                                   PyString_AS_STRING(key)) == 0) goto arg_passed_twice;
                        #endif
                    }
                    if (kwds2) {
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
                    } else {
                        goto invalid_keyword;
                    }
                }
            }
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *__import__ = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    __import__ = PyObject_GetAttrString(__pyx_b, "__import__");
    if (!__import__)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    module = PyObject_CallFunction(__import__, "OOOO",
        name, global_dict, empty_dict, list);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(__import__);
    Py_XDECREF(empty_dict);
    return module;
}

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

static PyObject *__Pyx_CreateClass(
    PyObject *bases, PyObject *dict, PyObject *name, char *modname)
{
    PyObject *py_modname;
    PyObject *result = 0;

    #if PY_MAJOR_VERSION < 3
    py_modname = PyString_FromString(modname);
    #else
    py_modname = PyUnicode_FromString(modname);
    #endif
    if (!py_modname)
        goto bad;
    if (PyDict_SetItemString(dict, "__module__", py_modname) < 0)
        goto bad;
    #if PY_MAJOR_VERSION < 3
    result = PyClass_New(bases, dict, name);
    #else
    result = PyObject_CallFunctionObjArgs((PyObject *)&PyType_Type, name, bases, dict, NULL);
    #endif
bad:
    Py_XDECREF(py_modname);
    return result;
}

static void __Pyx_WriteUnraisable(const char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
}

static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;

    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}


#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(const char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyObject *empty_string = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;

    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(__pyx_filename);
    #else
    py_srcfile = PyUnicode_FromString(__pyx_filename);
    #endif
    if (!py_srcfile) goto bad;
    if (__pyx_clineno) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    #if PY_MAJOR_VERSION < 3
    empty_string = PyString_FromStringAndSize("", 0);
    #else
    empty_string = PyBytes_FromStringAndSize("", 0);
    #endif
    if (!empty_string) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,            /*int kwonlyargcount,*/
        #endif
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        empty_string, /*PyObject *code,*/
        __pyx_empty_tuple,  /*PyObject *consts,*/
        __pyx_empty_tuple,  /*PyObject *names,*/
        __pyx_empty_tuple,  /*PyObject *varnames,*/
        __pyx_empty_tuple,  /*PyObject *freevars,*/
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        empty_string  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(empty_string);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode && (!t->is_identifier)) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_identifier || (t->is_unicode && t->intern)) {
            *t->p = PyUnicode_InternFromString(t->s);
        } else if (t->is_unicode) {
            *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

/* Type Conversion Functions */

static INLINE Py_ssize_t __pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   if (x == Py_True) return 1;
   else if (x == Py_False) return 0;
   else return PyObject_IsTrue(x);
}

static INLINE PY_LONG_LONG __pyx_PyInt_AsLongLong(PyObject* x) {
    if (PyInt_CheckExact(x)) {
        return PyInt_AS_LONG(x);
    }
    else if (PyLong_CheckExact(x)) {
        return PyLong_AsLongLong(x);
    }
    else {
        PY_LONG_LONG val;
        PyObject* tmp = PyNumber_Int(x); if (!tmp) return (PY_LONG_LONG)-1;
        val = __pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE unsigned PY_LONG_LONG __pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    if (PyInt_CheckExact(x)) {
        long val = PyInt_AS_LONG(x);
        if (unlikely(val < 0)) {
            PyErr_SetString(PyExc_TypeError, "Negative assignment to unsigned type.");
            return (unsigned PY_LONG_LONG)-1;
        }
        return val;
    }
    else if (PyLong_CheckExact(x)) {
        return PyLong_AsUnsignedLongLong(x);
    }
    else {
        PY_LONG_LONG val;
        PyObject* tmp = PyNumber_Int(x); if (!tmp) return (PY_LONG_LONG)-1;
        val = __pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}


static INLINE unsigned char __pyx_PyInt_unsigned_char(PyObject* x) {
    if (sizeof(unsigned char) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        unsigned char val = (unsigned char)long_val;
        if (unlikely((val != long_val)  || (long_val < 0))) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to unsigned char");
            return (unsigned char)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE unsigned short __pyx_PyInt_unsigned_short(PyObject* x) {
    if (sizeof(unsigned short) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        unsigned short val = (unsigned short)long_val;
        if (unlikely((val != long_val)  || (long_val < 0))) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to unsigned short");
            return (unsigned short)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE char __pyx_PyInt_char(PyObject* x) {
    if (sizeof(char) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        char val = (char)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to char");
            return (char)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE short __pyx_PyInt_short(PyObject* x) {
    if (sizeof(short) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        short val = (short)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to short");
            return (short)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE int __pyx_PyInt_int(PyObject* x) {
    if (sizeof(int) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        int val = (int)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to int");
            return (int)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE long __pyx_PyInt_long(PyObject* x) {
    if (sizeof(long) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        long val = (long)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to long");
            return (long)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE signed char __pyx_PyInt_signed_char(PyObject* x) {
    if (sizeof(signed char) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        signed char val = (signed char)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to signed char");
            return (signed char)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE signed short __pyx_PyInt_signed_short(PyObject* x) {
    if (sizeof(signed short) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        signed short val = (signed short)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to signed short");
            return (signed short)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE signed int __pyx_PyInt_signed_int(PyObject* x) {
    if (sizeof(signed int) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        signed int val = (signed int)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to signed int");
            return (signed int)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE signed long __pyx_PyInt_signed_long(PyObject* x) {
    if (sizeof(signed long) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        signed long val = (signed long)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to signed long");
            return (signed long)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

static INLINE long double __pyx_PyInt_long_double(PyObject* x) {
    if (sizeof(long double) < sizeof(long)) {
        long long_val = __pyx_PyInt_AsLong(x);
        long double val = (long double)long_val;
        if (unlikely((val != long_val) )) {
            PyErr_SetString(PyExc_OverflowError, "value too large to convert to long double");
            return (long double)-1;
        }
        return val;
    }
    else {
        return __pyx_PyInt_AsLong(x);
    }
}

#<

#>            ggivtk.pyx
import vtk, gipsy

cdef extern from "keyevents.h":
   ctypedef void *ident

cdef extern from "ggi.h":
   ident GgiUseShell(ident id)

cdef extern from "ggivtkfield.h":
   ident GgiVtkField(char *name, int width, int height)
   void GgiVtkInitialize(ident id)
   char *GgiVtkRenderWindow(ident id)
   char *GgiVtkInteractor(ident id)

#  --------------------------------------------------------------------------
#  toident: convert an ident stored in an integer object to an ident
#  --------------------------------------------------------------------------
cdef ident toident(object id):
   cdef long c_id
   c_id = id
   return <ident>c_id

class _VtkField(gipsy._Element):

   def open(self):
      GgiVtkInitialize(toident(self.hook))

   def Interactor(self):
      objptr = GgiVtkInteractor(toident(self.hook))
      return vtk.vtkXRenderWindowInteractor(objptr)

   def RenderWindow(self):
      objptr = GgiVtkRenderWindow(toident(self.hook))
      return vtk.vtkXOpenGLRenderWindow(objptr)


def VtkField(self, name, width, height):
   result = _VtkField()
   result.container = self
   GgiUseShell(toident(self.hook))
   result.hook = <long>GgiVtkField(name, width, height)
   result.name = name
   return result


#<

#>            ggivtkfield.c
/* ggivtk.c -XT
                           COPYRIGHT (c) 2006
                        Kapteyn Astronomical Institute
         University of Groningen  -  9700 AV Groningen, The Netherlands
*/


#define MAXWINDOWS    20

/*
 * includes:
 */
#include "limits.h"
#include "stdlib.h"
#include "string.h"
#include "stdarg.h"
#include "stdio.h"

#include "gipsyc.h"			/* GIPSY definitions */
#include "ggi.h"
#include "ggidisplay.h"
#include "ggiwindow.h"
#include "ggiwidget.h"
#include "ggicontext.h"
#include "ggivtkfield.h"
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/StringDefs.h>     /* Standard Name-String definitions */

extern void ggitovtk(XtAppContext*, Widget ggi, char*, char*);

#define New(type) ((type *)calloc(1,sizeof(type)))
#define NNew(n,type) ((type *)calloc(n,sizeof(type)))
#define Delete(x)  {free(x); x=NULL;}

typedef struct {
   ident         canvas;                       /* Ggi canvas               */
   Window        window;                       /* canvas' window           */
   Widget        widget;                       /* canvas' widget           */
   char          renwin[40];                   /* VTK render window string */
   char          iren[40];                     /* VTK interactor string    */
} _CanvasContext, *CanvasContext;

static Display   *display;          /* one display for all windows */
XtAppContext     *app_context;      /* the application context */

static CanvasContext contexts[MAXWINDOWS];
static int nwindows=0;
static XtTranslations translations;   /* vtkfield core widget translations */

/* -------------------------------------------------------------------------- */
/*                                 enter_plot                                 */
/* -------------------------------------------------------------------------- */
static void enter_plot(Widget curwid, XEvent *event,
                       String *params, Cardinal *num_params)
{
   Widget shell=curwid;
   while (!XtIsShell(shell)) shell = XtParent(shell);
   XtSetKeyboardFocus(shell, curwid);
}

/* -------------------------------------------------------------------------- */
/*                                 initialize                                 */
/* -------------------------------------------------------------------------- */
/*  initialize() initializes a number of common objects and parameters.
 */
static void initialize(void)
{
   static XtActionsRec actions[] = {
      {"enter_plot", enter_plot}
   }; int n_actions=1;

   static String trans =
      "<BtnDown>:   enter_plot()";
   
   static bool initialized=FALSE;
   if (!initialized) {
      ident tmp = GgiCanvas("tmp", 1, 1);       /* force Ggi initialization */
      GgiDelete(&tmp);
      translations = XtParseTranslationTable(trans);
      display = GgiDisplay();
      app_context = GgiContext();
      XtAppAddActions(*app_context, actions, n_actions);   }
   initialized = TRUE;
}
      
/* ========================================================================== */
/*                                 GgiVtkField                                */
/* -------------------------------------------------------------------------- */
extern ident GgiVtkField(char *name, int width, int height)
{
   ident canvas=NULL;
   
   if (nwindows<MAXWINDOWS) {
      contexts[nwindows] = New(_CanvasContext);
      canvas = GgiCanvas("vtk", width, height);
      XtVaSetValues(GgiWidget(canvas), XtNwidth, width, XtNheight, height,
                                       XtNsensitive, True,
                                       NULL);
      contexts[nwindows]->canvas = canvas;
      initialize();
      nwindows++;
   }
   return canvas;
}

/* ========================================================================== */
/*                                 GgiVtkInitialize                           */
/* -------------------------------------------------------------------------- */
void GgiVtkInitialize(ident id)
{
   int current;
   for (current=0; current<nwindows; current++) {
      if (contexts[current]->canvas==id) {
         ggitovtk(app_context, GgiWidget(id),
                 contexts[current]->renwin, contexts[current]->iren);
         XtOverrideTranslations(GgiWidget(id), translations);
         return;
      }
   }
}

/* ========================================================================== */
/*                                 GgiVtkRenderWindow                         */
/* -------------------------------------------------------------------------- */
char *GgiVtkRenderWindow(ident id)
{
   int current;
   for (current=0; current<nwindows; current++) {
      if (contexts[current]->canvas==id) return contexts[current]->renwin;
   }
   return NULL;
}

/* ========================================================================== */
/*                                 GgiVtkInteractor                           */
/* -------------------------------------------------------------------------- */
char *GgiVtkInteractor(ident id)
{
   int current;
   for (current=0; current<nwindows; current++) {
      if (contexts[current]->canvas==id) return contexts[current]->iren;
   }
   return NULL;
}
#<

#>            ggivtkfield.h
ident GgiVtkField(char *name, int width, int height);
void GgiVtkInitialize(ident id);
char *GgiVtkRenderWindow(ident id);
char *GgiVtkInteractor(ident id);
#<

#>            ggitovtk.cxx
#include <vtk/vtkConfigure.h>
#include <vtk/vtkXOpenGLRenderWindow.h>
#include <vtk/vtkXRenderWindowInteractor.h>
#include <vtk/vtkPythonUtil.h>
#include <X11/Xlib.h>
#if VTK_MAJOR_VERSION==5 && VTK_MINOR_VERSION>=8
#define vtkPythonManglePointer vtkPythonUtil::ManglePointer
#endif

extern "C" Display *GgiDisplay(void);

extern "C" void ggitovtk(XtAppContext app, Widget ggi, char *renwinstr, char *irenstr)
{
   vtkXOpenGLRenderWindow     *renwin;
   vtkXRenderWindowInteractor *iren;
   
   renwin = vtkXOpenGLRenderWindow::New();
   renwin->SetDisplayId(GgiDisplay());
   iren = vtkXRenderWindowInteractor::New();
   iren->SetRenderWindow(renwin);
   iren->SetWidget(ggi);
   iren->Initialize(app);
   strcpy(renwinstr,
          vtkPythonManglePointer(renwin, "vtkXOpenGLRenderWindow"));
   strcpy(irenstr,
          vtkPythonManglePointer(iren,   "vtkXRenderWindowInteractor"));
}
#<
