Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Lucas Gandel
VTK
Commits
b57ab421
Commit
b57ab421
authored
Feb 16, 2015
by
Dave DeMarle
Browse files
Merge branch 'python-overloading-and-conversion-REL' into release
Change-Id: I5714e954dcc7bafadc4c8b295107b556abbe1271
parents
d442a751
a051d503
Changes
3
Hide whitespace changes
Inline
Side-by-side
Common/Core/Testing/Python/CMakeLists.txt
View file @
b57ab421
...
...
@@ -10,6 +10,7 @@ vtk_add_test_python(
TestNumpySupport.py
TestNumpyInterface.py
TestOperators.py
TestOverloads.py
TestPointers.py
TestStrings.py
TestSubClass.py
...
...
Common/Core/Testing/Python/TestOverloads.py
0 → 100644
View file @
b57ab421
"""Test overloaded method resolution in VTK-Python
The wrappers should call overloaded C++ methods using similar
overload resolution rules as C++. Python itself does not have
method overloading.
Created on Feb 15, 2015 by David Gobbi
"""
import
sys
import
exceptions
import
vtk
from
vtk.test
import
Testing
class
TestOverloads
(
Testing
.
vtkTest
):
def
testMethods
(
self
):
"""Test overloaded methods"""
# single-argument method vtkTransform::SetMatrix()
t
=
vtk
.
vtkTransform
()
m
=
vtk
.
vtkMatrix4x4
()
m
.
SetElement
(
0
,
0
,
2
)
t
.
SetMatrix
(
m
)
self
.
assertEqual
(
t
.
GetMatrix
().
GetElement
(
0
,
0
),
2
)
t
.
SetMatrix
([
0
,
1
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
0
,
-
1
,
0
,
0
,
0
,
0
,
1
])
self
.
assertEqual
(
t
.
GetMatrix
().
GetElement
(
0
,
0
),
0
)
# mixed number of arguments
w
=
vtk
.
vtkRenderWindow
()
w
.
SetTileScale
(
2
)
self
.
assertEqual
(
w
.
GetTileScale
(),
(
2
,
2
))
w
.
SetTileScale
(
3
,
4
)
self
.
assertEqual
(
w
.
GetTileScale
(),
(
3
,
4
))
def
testConstructors
(
self
):
"""Test overloaded constructors"""
# resolve by number of arguments
v
=
vtk
.
vtkVector3d
(
3
,
4
,
5
)
self
.
assertEqual
((
v
[
0
],
v
[
1
],
v
[
2
]),
(
3
,
4
,
5
))
v
=
vtk
.
vtkVector3d
(
6
)
self
.
assertEqual
((
v
[
0
],
v
[
1
],
v
[
2
]),
(
6
,
6
,
6
))
# resolve by argument type
v
=
vtk
.
vtkVariant
(
3.0
)
self
.
assertEqual
(
v
.
GetType
(),
vtk
.
VTK_DOUBLE
)
v
=
vtk
.
vtkVariant
(
1
)
self
.
assertEqual
(
v
.
GetType
(),
vtk
.
VTK_INT
)
v
=
vtk
.
vtkVariant
(
"hello"
)
self
.
assertEqual
(
v
.
GetType
(),
vtk
.
VTK_STRING
)
v
=
vtk
.
vtkVariant
(
vtk
.
vtkObject
())
self
.
assertEqual
(
v
.
GetType
(),
vtk
.
VTK_OBJECT
)
def
testArgumentConversion
(
self
):
"""Test argument conversion via implicit constructors"""
# automatic conversion to vtkVariant
a
=
vtk
.
vtkVariantArray
()
a
.
InsertNextValue
(
2.5
)
a
.
InsertNextValue
(
vtk
.
vtkObject
())
self
.
assertEqual
(
a
.
GetValue
(
0
),
vtk
.
vtkVariant
(
2.5
))
self
.
assertEqual
(
a
.
GetValue
(
1
).
GetType
(),
vtk
.
VTK_OBJECT
)
# same, but this one is via "const vtkVariant&" argument
a
=
vtk
.
vtkDenseArray
[
float
]()
a
.
Resize
(
1
)
a
.
SetVariantValue
(
0
,
2.5
)
self
.
assertEqual
(
a
.
GetVariantValue
(
0
).
ToDouble
(),
2.5
)
if
__name__
==
"__main__"
:
Testing
.
main
([(
TestOverloads
,
'test'
)])
Wrapping/Tools/vtkWrapPythonOverload.c
View file @
b57ab421
...
...
@@ -307,7 +307,7 @@ static char *vtkWrapPython_ArgCheckString(
result
[
currPos
++
]
=
' '
;
if
((
argtype
==
VTK_PARSE_OBJECT_REF
||
argtype
==
VTK_PARSE_UNKNOWN_REF
)
&&
(
arg
t
ype
&
VTK_PARSE_CONST
)
==
0
)
(
arg
->
T
ype
&
VTK_PARSE_CONST
)
==
0
)
{
result
[
currPos
++
]
=
'&'
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment