Commit 19c75043 authored by David Gobbi's avatar David Gobbi Committed by Kitware Robot
Browse files

Merge topic 'update-const-correct'

54d93729 Add a test for default args in python wrappers.
f2786d42 Handle default values for array parameters in python.
000e36f1

 Minor tweak to signature to improve const correctness.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Berk Geveci's avatarBerk Geveci <berk.geveci@kitware.com>
Merge-request: !1201
parents 031288af 54d93729
......@@ -4,6 +4,7 @@ vtk_add_test_python(
TestArrays.py
TestArrayArguments.py
TestBuffer.py
TestDefaultArgs.py
TestEmptyInput.py
TestEnums.py
TestExecuteMethodFinalizeCrash.py
......
"""Test methods that use default parameter values.
Created on Feb 9, 2016 by David Gobbi
"""
import sys
import vtk
from vtk.test import Testing
class TestDefaultArgs(Testing.vtkTest):
def testDefaultInt(self):
"""Simple test of an integer arg with default value."""
image = vtk.vtkImageData()
image.SetExtent(0,9,0,9,0,9)
image.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 1)
ipi = vtk.vtkImagePointIterator()
# call this method with the threadId parameter set to 0
ipi.Initialize(image, (0,9,0,9,0,9), None, None, 0)
# call this method without the threadId parameter
ipi.Initialize(image, (0,9,0,9,0,9), None, None)
def testDefaultObjectPointer(self):
"""Test a vtkObject pointer arg with default value of 0."""
image = vtk.vtkImageData()
image.SetExtent(0,9,0,9,0,9)
image.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 1)
ipi = vtk.vtkImagePointIterator()
# call this method with the stencil parameter set to None
ipi.Initialize(image, (0,9,0,9,0,9), None)
# call this method without the stencil parameter
ipi.Initialize(image, (0,9,0,9,0,9))
def testDefaultArray(self):
"""Test an array arg with default value of 0."""
image = vtk.vtkImageData()
image.SetExtent(0,9,0,9,0,9)
image.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 1)
ipi = vtk.vtkImagePointIterator()
# call this method with the parameter set
ipi.Initialize(image, (0,9,0,9,0,9))
# call this method without extent parameter
ipi.Initialize(image)
# do another method for good measure
source = vtk.vtkImageGridSource()
source.SetDataExtent((0,99,0,99,0,0))
# set the parameter
source.UpdateExtent((0,50,0,50,0,0))
# use default parameter value
source.UpdateExtent()
def testDefaultPointer(self):
"""Test a POD pointer arg with default value of 0."""
a = vtk.vtkIntArray()
a.SetNumberOfComponents(3)
# pass an int pointer arg, expect something back
inc = [0]
vtk.vtkImagePointDataIterator.GetVoidPointer(a, 0, inc)
self.assertEqual(inc, [3])
# do not pass the pointer arg, default value 0 is passed
vtk.vtkImagePointDataIterator.GetVoidPointer(a, 0)
if __name__ == "__main__":
Testing.main([(TestDefaultArgs, 'test')])
......@@ -1481,7 +1481,7 @@ int vtkAlgorithm::Update(vtkInformation* requests)
//----------------------------------------------------------------------------
int vtkAlgorithm::UpdatePiece(
int piece, int numPieces, int ghostLevels, int* extents)
int piece, int numPieces, int ghostLevels, const int extents[6])
{
typedef vtkStreamingDemandDrivenPipeline vtkSDDP;
......@@ -1497,7 +1497,7 @@ int vtkAlgorithm::UpdatePiece(
}
//----------------------------------------------------------------------------
int vtkAlgorithm::UpdateExtent(int* extents)
int vtkAlgorithm::UpdateExtent(const int extents[6])
{
typedef vtkStreamingDemandDrivenPipeline vtkSDDP;
......@@ -1508,7 +1508,7 @@ int vtkAlgorithm::UpdateExtent(int* extents)
//----------------------------------------------------------------------------
int vtkAlgorithm::UpdateTimeStep(
double time, int piece, int numPieces, int ghostLevels, int* extents)
double time, int piece, int numPieces, int ghostLevels, const int extents[6])
{
typedef vtkStreamingDemandDrivenPipeline vtkSDDP;
......
......@@ -494,13 +494,13 @@ public:
// Update(int port, vtkInformationVector* requests) for details.
// Supports piece and extent (optional) requests.
virtual int UpdatePiece(
int piece, int numPieces, int ghostLevels, int* extents=0);
int piece, int numPieces, int ghostLevels, const int extents[6]=0);
// Description:
// Convenience method to update an algorithm after passing requests
// to its first output port.
// Supports extent request.
virtual int UpdateExtent(int* extents);
virtual int UpdateExtent(const int extents[6]=0);
// Description:
// Convenience method to update an algorithm after passing requests
......@@ -508,7 +508,7 @@ public:
// Update(int port, vtkInformationVector* requests) for details.
// Supports time, piece (optional) and extent (optional) requests.
virtual int UpdateTimeStep(double time,
int piece=-1, int numPieces=1, int ghostLevels=0, int* extents=0);
int piece=-1, int numPieces=1, int ghostLevels=0, const int extents[6]=0);
// Description:
// Bring the algorithm's information up-to-date.
......
......@@ -422,7 +422,6 @@ int vtkWrap_CountRequiredArguments(FunctionInfo *f)
for (i = 0; i < totalArgs; i++)
{
if (f->Parameters[i]->Value == NULL ||
vtkWrap_IsArray(f->Parameters[i]) ||
vtkWrap_IsNArray(f->Parameters[i]))
{
requiredArgs = i+1;
......@@ -1012,7 +1011,8 @@ void vtkWrap_DeclareVariable(
fprintf(fp, "*");
}
/* arrays of unknown size are handled via pointers */
else if (val->CountHint || vtkWrap_IsPODPointer(val))
else if (val->CountHint || vtkWrap_IsPODPointer(val) ||
(vtkWrap_IsArray(val) && val->Value))
{
fprintf(fp, "*");
}
......@@ -1037,7 +1037,8 @@ void vtkWrap_DeclareVariable(
aType != VTK_PARSE_OBJECT_PTR &&
!vtkWrap_IsQtObject(val) &&
val->CountHint == NULL &&
!vtkWrap_IsPODPointer(val))
!vtkWrap_IsPODPointer(val) &&
!(vtkWrap_IsArray(val) && val->Value))
{
if (val->NumberOfDimensions == 1 && val->Count > 0)
{
......@@ -1114,8 +1115,8 @@ void vtkWrap_DeclareVariableSize(
{
fprintf(fp,
" %sint %s%s = %d;\n",
(val->Count == 0 ? "" : "const "), name, idx,
(val->Count == 0 ? 0 : val->Count));
((val->Count == 0 || val->Value != 0) ? "" : "const "),
name, idx, (val->Count == 0 ? 0 : val->Count));
}
else if (val->NumberOfDimensions == 1)
{
......
......@@ -113,7 +113,7 @@ void vtkWrapPython_DeclareVariables(
if (vtkWrap_IsArray(arg) || vtkWrap_IsNArray(arg) ||
vtkWrap_IsPODPointer(arg))
{
storageSize = 4;
storageSize = (arg->Count ? arg->Count : 4);
if (!vtkWrap_IsConst(arg) &&
!vtkWrap_IsSetVectorMethod(theFunc))
{
......@@ -121,7 +121,8 @@ void vtkWrapPython_DeclareVariables(
vtkWrap_DeclareVariable(fp, data, arg, "save", i, VTK_WRAP_ARG);
storageSize *= 2;
}
if (arg->CountHint || vtkWrap_IsPODPointer(arg))
if (arg->CountHint || vtkWrap_IsPODPointer(arg) ||
(vtkWrap_IsArray(arg) && arg->Value))
{
fprintf(fp,
" %s small%d[%d];\n",
......@@ -167,7 +168,8 @@ static void vtkWrapPython_GetSizesForArrays(
{
arg = theFunc->Parameters[i];
if (arg->CountHint || vtkWrap_IsPODPointer(arg))
if (arg->CountHint || vtkWrap_IsPODPointer(arg) ||
(vtkWrap_IsArray(arg) && arg->Value))
{
if (j == 1)
{
......@@ -200,18 +202,29 @@ static void vtkWrapPython_GetSizesForArrays(
fprintf(fp,
"%s if (size%d > 0)\n"
"%s {\n"
"%s temp%d = small%d;\n"
"%s temp%d = small%d;\n",
indentation, i,
indentation,
indentation, i, i);
if (arg->CountHint || vtkWrap_IsPODPointer(arg))
{
fprintf(fp,
"%s if (size%d > 4)\n"
"%s {\n"
"%s temp%d = new %s[%ssize%d];\n"
"%s }\n",
indentation, i,
indentation,
indentation, i, i,
indentation, i,
indentation,
indentation, i, vtkWrap_GetTypeName(arg), mtwo, i,
indentation);
}
else
{
fprintf(fp,
"%s size%d = %d;\n",
indentation, i, arg->Count);
}
if (*mtwo)
{
......
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