Commit 65f353a8 authored by David Gobbi's avatar David Gobbi
Browse files

Rename "vtk.mutable()" to "vtk.reference()".

The original name vtk.mutable() is still available, but
vtk.reference() is now the preferred name, and documentation
will be updated to reflect this.
parent 19d97caa
......@@ -11,7 +11,7 @@ vtk_add_test_python(
TestExpects.py
TestGhost.py
TestIterateCollection.py
TestMutable.py
TestPassByReference.py
TestNumpySupport.py
TestNumpyInterface.py
TestNumpyWeakReference.py
......
......@@ -34,7 +34,7 @@ class TestOverloads(Testing.vtkTest):
fd.AddArray(ia)
a = fd.GetArray("Real")
self.assertEqual(id(a), id(fa))
i = vtk.mutable(0)
i = vtk.reference(0)
a = fd.GetArray("Integer", i)
self.assertEqual(id(a), id(ia))
self.assertEqual(i, 1)
......
"""Test the vtk.mutable() type and test pass-by-reference.
"""Test the vtk.reference() type and test pass-by-reference.
Created on Sept 19, 2010 by David Gobbi
"""
......@@ -7,36 +7,36 @@ import sys
import vtk
from vtk.test import Testing
class TestMutable(Testing.vtkTest):
def testFloatMutable(self):
m = vtk.mutable(3.0)
n = vtk.mutable(4.0)
class TestPassByReference(Testing.vtkTest):
def testFloatReference(self):
m = vtk.reference(3.0)
n = vtk.reference(4.0)
m *= 2
self.assertEqual(m, 6.0)
self.assertEqual(str(m), str(m.get()))
o = n + m
self.assertEqual(o, 10.0)
def testIntMutable(self):
m = vtk.mutable(3)
n = vtk.mutable(4)
def testIntReference(self):
m = vtk.reference(3)
n = vtk.reference(4)
m |= n
self.assertEqual(m, 7.0)
self.assertEqual(str(m), str(m.get()))
def testStringMutable(self):
m = vtk.mutable("%s %s!")
def testStringReference(self):
m = vtk.reference("%s %s!")
m %= ("hello", "world")
self.assertEqual(m, "hello world!")
def testTupleMutable(self):
m = vtk.mutable((0,))
def testTupleReference(self):
m = vtk.reference((0,))
self.assertEqual(m, (0,))
self.assertEqual(len(m), 1)
self.assertEqual(m[0], 0)
def testPassByReference(self):
t = vtk.mutable(0.0)
def testPassByReferenceerence(self):
t = vtk.reference(0.0)
p0 = (0.5, 0.0, 0.0)
n = (1.0, 0.0, 0.0)
p1 = (0.0, 0.0, 0.0)
......@@ -68,8 +68,8 @@ class TestMutable(Testing.vtkTest):
self.assertEqual(round(x[2],6), 0.5)
def testPassTupleByReference(self):
n = vtk.mutable(0)
t = vtk.mutable((0,))
n = vtk.reference(0)
t = vtk.reference((0,))
ca = vtk.vtkCellArray()
ca.InsertNextCell(3, (1, 3, 0))
ca.GetCell(0, n, t)
......@@ -77,4 +77,4 @@ class TestMutable(Testing.vtkTest):
self.assertEqual(tuple(t), (1, 3, 0))
if __name__ == "__main__":
Testing.main([(TestMutable, 'test')])
Testing.main([(TestPassByReference, 'test')])
......@@ -71,9 +71,9 @@ def CheckWedge(success, x, pcoords):
def CheckCell(cell, checkCellFunction):
closestPoint = [0., 0., 0.]
subId = mutable(0)
subId = reference(0)
pcoords = [0., 0., 0.]
dist2 = mutable(0.)
dist2 = reference(0.)
weights = [0.]*30
x = [.25, .25, .25]
for i in range(21):
......
......@@ -66,7 +66,7 @@ dsClosest.SetNumberOfIds(numProbes)
genCell = vtk.vtkGenericCell()
pc = [0,0,0]
weights = [0,0,0,0,0,0,0,0,0,0,0,0]
subId = 0
subId = vtk.reference(0)
# Print initial statistics
print("Processing NumCells: {0}".format(numCells))
......@@ -231,7 +231,8 @@ print("\n")
#############################################################
# For comparison purposes compare to FindCell()
timer.StartTimer()
output.FindCell(ProbeCells.GetPoint(0),genCell,-1,0.001,vtk.mutable(subId),pc,weights)
output.FindCell(ProbeCells.GetPoint(0),genCell,-1,0.001,subId,pc,weights)
timer.StopTimer()
time = timer.GetElapsedTime()
print("Point Locator: {0}".format(time))
......@@ -239,7 +240,7 @@ print("Point Locator: {0}".format(time))
# Probe the dataset with FindClosestPoint() and time it
timer.StartTimer()
for i in range (0,numProbes):
dsClosest.SetId(i, output.FindCell(ProbeCells.GetPoint(0),genCell,-1,0.001,vtk.mutable(subId),pc,weights))
dsClosest.SetId(i, output.FindCell(ProbeCells.GetPoint(0),genCell,-1,0.001,subId,pc,weights))
timer.StopTimer()
opTime = timer.GetElapsedTime()
print(" Find cell probing: {0}".format(opTime))
......
......@@ -32,11 +32,11 @@ bounds = output.GetBounds()
# Support subsequent method calls
genCell = vtk.vtkGenericCell()
t = vtk.mutable(0.0)
t = vtk.reference(0.0)
x = [0,0,0]
pc = [0,0,0]
subId = vtk.mutable(0)
cellId = vtk.mutable(0)
subId = vtk.reference(0)
cellId = vtk.reference(0)
# Build the locator
locator = vtk.vtkStaticCellLocator()
......
......@@ -15,8 +15,8 @@ class TestGetRangeColorTransferFunction(Testing.vtkTest):
def testGetRangeTwoDoubleStarArg(self):
cmap = vtk.vtkColorTransferFunction()
localMin = vtk.mutable(-1)
localMax = vtk.mutable(-1)
localMin = vtk.reference(-1)
localMax = vtk.reference(-1)
cmap.GetRange(localMin, localMax)
self.assertEqual(localMin, 0.0)
self.assertEqual(localMax, 0.0)
......
......@@ -15,8 +15,8 @@ class TestGetRangeDiscretizableColorTransferFunction(Testing.vtkTest):
def testGetRangeTwoDoubleStarArg(self):
cmap = vtk.vtkDiscretizableColorTransferFunction()
localMin = vtk.mutable(-1)
localMax = vtk.mutable(-1)
localMin = vtk.reference(-1)
localMax = vtk.reference(-1)
cmap.GetRange(localMin, localMax)
self.assertEqual(localMin, 0.0)
self.assertEqual(localMax, 0.0)
......
......@@ -289,10 +289,10 @@ Pass-by-reference
Pass-by-reference of values that are mutable in C++ but not in
Python (such as string, int, and float) is only possible by
using vtk.mutable(), which is in the vtk module:
using vtk.reference(), which is in the vtkCommonCore Python module:
>>> plane = vtkPlane()
>>> t = mutable(0.0)
>>> plane = vtk.vtkPlane()
>>> t = vtk.reference(0.0)
>>> x = [0.0, 0.0, 0.0]
>>> plane.InsersectWithLine([0, 0, -1], [0, 0, 1], t, x)
>>> print t
......
......@@ -9,7 +9,7 @@ set(Module_SRCS
vtkSmartPyObject.cxx
PyVTKExtras.cxx
PyVTKMethodDescriptor.cxx
PyVTKMutableObject.cxx
PyVTKReference.cxx
PyVTKNamespace.cxx
PyVTKObject.cxx
PyVTKSpecialObject.cxx
......
......@@ -15,7 +15,7 @@
#include "PyVTKExtras.h"
#include "vtkPythonCompatibility.h"
#include "PyVTKMutableObject.h"
#include "PyVTKReference.h"
// Silence warning like
// "dereferencing type-punned pointer will break strict-aliasing rules"
......@@ -133,13 +133,14 @@ static PyMethodDef PyVTKExtras_Methods[] = {
void PyVTKAddFile_PyVTKExtras(PyObject *dict)
{
// It is necessary to call PyType_Ready() on all subclasses
PyType_Ready(&PyVTKMutableNumber_Type);
PyType_Ready(&PyVTKMutableString_Type);
PyType_Ready(&PyVTKMutableTuple_Type);
PyType_Ready(&PyVTKNumberReference_Type);
PyType_Ready(&PyVTKStringReference_Type);
PyType_Ready(&PyVTKTupleReference_Type);
// Add the "mutable" object (used for C++ pass-by-reference)
PyObject *o = (PyObject *)&PyVTKMutableObject_Type;
PyDict_SetItemString(dict, "mutable", o);
PyObject *o = (PyObject *)&PyVTKReference_Type;
PyDict_SetItemString(dict, "reference", o); // new name (as of VTK 8.1)
PyDict_SetItemString(dict, "mutable", o); // old name
for (PyMethodDef *meth = PyVTKExtras_Methods;
meth->ml_name != nullptr;
......
/*=========================================================================
Program: Visualization Toolkit
Module: PyVTKMutableObject.h
Module: PyVTKReference.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
......@@ -13,33 +13,33 @@
=========================================================================*/
/*-----------------------------------------------------------------------
The PyVTKMutableObject was created in Sep 2010 by David Gobbi.
The PyVTKReference was created in Sep 2010 by David Gobbi.
This class is a proxy for python int and float, it allows these objects
to be passed to VTK methods that require a ref to a numeric type.
-----------------------------------------------------------------------*/
#ifndef PyVTKMutableObject_h
#define PyVTKMutableObject_h
#ifndef PyVTKReference_h
#define PyVTKReference_h
#include "vtkWrappingPythonCoreModule.h" // For export macro
#include "vtkPython.h"
#include "vtkSystemIncludes.h"
// The PyVTKMutableObject is a wrapper around a PyObject of
// The PyVTKReference is a wrapper around a PyObject of
// type int or float.
struct PyVTKMutableObject {
struct PyVTKReference {
PyObject_HEAD
PyObject *value;
};
extern VTKWRAPPINGPYTHONCORE_EXPORT PyTypeObject PyVTKMutableObject_Type;
extern VTKWRAPPINGPYTHONCORE_EXPORT PyTypeObject PyVTKMutableNumber_Type;
extern VTKWRAPPINGPYTHONCORE_EXPORT PyTypeObject PyVTKMutableString_Type;
extern VTKWRAPPINGPYTHONCORE_EXPORT PyTypeObject PyVTKMutableTuple_Type;
extern VTKWRAPPINGPYTHONCORE_EXPORT PyTypeObject PyVTKReference_Type;
extern VTKWRAPPINGPYTHONCORE_EXPORT PyTypeObject PyVTKNumberReference_Type;
extern VTKWRAPPINGPYTHONCORE_EXPORT PyTypeObject PyVTKStringReference_Type;
extern VTKWRAPPINGPYTHONCORE_EXPORT PyTypeObject PyVTKTupleReference_Type;
#define PyVTKMutableObject_Check(obj) \
PyObject_TypeCheck(obj, &PyVTKMutableObject_Type)
#define PyVTKReference_Check(obj) \
PyObject_TypeCheck(obj, &PyVTKReference_Type)
extern "C"
{
......@@ -47,12 +47,12 @@ extern "C"
// of the provided value. Only float, long, and int are allowed.
// A return value of -1 indicates than an error occurred.
VTKWRAPPINGPYTHONCORE_EXPORT
int PyVTKMutableObject_SetValue(PyObject *self, PyObject *val);
int PyVTKReference_SetValue(PyObject *self, PyObject *val);
// Get the value held by a mutable object. A borrowed reference
// is returned.
VTKWRAPPINGPYTHONCORE_EXPORT
PyObject *PyVTKMutableObject_GetValue(PyObject *self);
PyObject *PyVTKReference_GetValue(PyObject *self);
}
#endif
......@@ -1010,9 +1010,9 @@ int vtkPythonArgs::GetArgAsSIPEnum(
bool vtkPythonArgs::GetValue(T &a) \
{ \
PyObject *o = PyTuple_GET_ITEM(this->Args, this->I++); \
if (PyVTKMutableObject_Check(o)) \
if (PyVTKReference_Check(o)) \
{ \
o = PyVTKMutableObject_GetValue(o); \
o = PyVTKReference_GetValue(o); \
} \
if (vtkPythonGetValue(o, a)) \
{ \
......@@ -1204,7 +1204,7 @@ bool vtkPythonArgs::SetArgValue(int i, T a) \
{ \
PyObject *m = PyTuple_GET_ITEM(this->Args, this->M + i); \
PyObject *o = vtkPythonArgs::BuildValue(a); \
int r = PyVTKMutableObject_SetValue(m, o); \
int r = PyVTKReference_SetValue(m, o); \
if (r == 0) \
{ \
return true; \
......@@ -1222,7 +1222,7 @@ bool vtkPythonArgs::SetArgValue(int i, const T *a, int n) \
{ \
PyObject *m = PyTuple_GET_ITEM(this->Args, this->M + i); \
PyObject *o = vtkPythonArgs::BuildTuple(a, n); \
int r = PyVTKMutableObject_SetValue(m, o); \
int r = PyVTKReference_SetValue(m, o); \
if (r == 0) \
{ \
return true; \
......
......@@ -280,9 +280,9 @@ int vtkPythonOverload::CheckArg(
const char *classname = classtext;
// If mutable object, check the type of the value inside
if (PyVTKMutableObject_Check(arg))
if (PyVTKReference_Check(arg))
{
arg = PyVTKMutableObject_GetValue(arg);
arg = PyVTKReference_GetValue(arg);
}
switch (*format)
......
......@@ -22,7 +22,7 @@
#include "vtkPython.h"
#include "vtkPythonCompatibility.h"
#include "PyVTKMutableObject.h"
#include "PyVTKReference.h"
#include "PyVTKNamespace.h"
#include "PyVTKObject.h"
#include "PyVTKSpecialObject.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment