source: inundation-numpy-branch/pyvolution/vtk_visualiser_ext.cpp @ 3031

Last change on this file since 3031 was 2267, checked in by jack, 19 years ago

Added pause and resume buttons to the vtk visualiser. This
will freeze the evolve thread, allowing interaction with the visualiser.

Disabled use of the vtk_visualiser_ext module, because it doesn't link on windows.
The prebuilt vtk DLLs are built with VC++ and the rest of the project is being built with
MinGW, which don't link together. The speed increase wasn't noticable anyway.

File size: 1.9 KB
Line 
1/*
2 * Additional functions used by the VTK visualiser
3 * currently not used, since it is a pain to link on windows
4 *
5 */
6
7#include "Python.h"
8#include "Numeric/arrayobject.h"
9
10#include "vtkPoints.h"
11#include "vtkPythonUtil.h"
12
13#include <malloc.h>
14
15static PyObject * make_vtkpoints(PyObject *self, PyObject *args);
16
17static PyMethodDef methods[] = {
18  {"make_vtkpoints", make_vtkpoints, METH_VARARGS, "make vtkPoints structure"},
19  {NULL            , NULL          , 0           , NULL                      }
20};
21
22PyMODINIT_FUNC initvtk_visualiser_ext(void){
23  (void) Py_InitModule("vtk_visualiser_ext", methods);
24  import_array();
25}
26
27/* Construct a vtkPoints object, given the number of triangles,
28 * an array of vertex quantity values, an array of vertex x
29 * and y coordinates and an array of triangle data.
30 */
31static PyObject * make_vtkpoints(PyObject *self, PyObject * args){
32  int i, j;
33  int n_tri;
34  int n_vert;
35  double scale;
36  PyArrayObject * qty_values;
37  PyArrayObject * vertex_values;
38  PyArrayObject * triangles;
39  double * qty_index;
40  vtkPoints * grid;
41  int dims[1];
42  if(!PyArg_ParseTuple(args, "iidOOO", &n_tri, &n_vert, &scale, &qty_values, &vertex_values, &triangles))
43    return NULL;
44 
45  dims[0] = n_vert;
46  qty_index = (double*)malloc(n_vert * sizeof(double));
47  if(qty_index == NULL)
48    return NULL;
49 
50  for(i = 0 ; i < n_tri ; i++)
51    for(j = 0 ; j < 3 ; j++)
52      qty_index[*(int*)((triangles->data) + i*(triangles->strides[0]) + j*(triangles->strides[1]))] =
53        *(double*)((qty_values->data) + i*(qty_values->strides[0]) + j*(qty_values->strides[1])) * scale;
54
55  grid = vtkPoints::New();
56  for(i = 0 ; i < n_vert ; i++)
57    grid->InsertNextPoint(*(double*)((vertex_values->data) + i*(vertex_values->strides[0])),
58                        *(double*)((vertex_values->data) + i*(vertex_values->strides[0]) + (vertex_values->strides[1])),
59                        qty_index[i]);
60  free(qty_index);
61  return Py_BuildValue("O", vtkPythonGetObjectFromPointer(grid));
62}
Note: See TracBrowser for help on using the repository browser.