Commit 7aeaa55e authored by Timothy M. Shead's avatar Timothy M. Shead
Browse files

ENH: Adding new N-Way Array data structures.

parent 5d9ef07d
......@@ -252,6 +252,8 @@ VTK_DEPENDENT_OPTION(VTK_USE_VIEWS "Build the vtkViews kit. Needed for creating
VTK_DEPENDENT_OPTION(VTK_USE_GEOVIS "Build the vtkGeovis kit. Needed for performing geographic visualization." ON "VTK_USE_VIEWS" OFF)
OPTION(VTK_USE_N_WAY_ARRAYS "Add support for arbitrary-dimension sparse and dense arrays." OFF)
# Determine Shading Support
VTK_DEPENDENT_OPTION(VTK_USE_CG_SHADERS "Build pixel and vertex shader support for Cg." OFF
"VTK_USE_RENDERING" OFF)
......
......@@ -331,6 +331,37 @@ SET_SOURCE_FILES_PROPERTIES(
SET_SOURCE_FILES_PROPERTIES(vtkVariant.cxx PROPERTIES
COMPILE_FLAGS -DVTK_VARIANT_IMPL)
IF(VTK_USE_N_WAY_ARRAYS)
SET(Kit_SRCS
${Kit_SRCS}
vtkArray.cxx
vtkArrayExtents.cxx
vtkArrayCoordinates.cxx
vtkArrayCoordinateIterator.cxx
vtkArrayRange.cxx
vtkArraySlice.cxx
vtkArraySlices.cxx
vtkArrayWeights.cxx
)
SET_SOURCE_FILES_PROPERTIES(
vtkArray.cxx
ABSTRACT
)
SET_SOURCE_FILES_PROPERTIES(
vtkArrayExtents.cxx
vtkArrayCoordinates.cxx
vtkArrayRange.cxx
vtkArraySlice.cxx
vtkArraySlices.cxx
vtkArrayWeights.cxx
WRAP_EXCLUDE
)
ENDIF(VTK_USE_N_WAY_ARRAYS)
SET(Kit_EXTRA_SRCS)
SET(Kit_EXTRA_CMDS)
SET(Kit_TCL_EXTRA_SRCS vtkTclUtil.cxx)
......
......@@ -16,6 +16,16 @@ IF(PYTHON_EXECUTABLE)
vtkAbstractIterator.h
vtkAbstractList.h
vtkAbstractMap.h
vtkArray.h
vtkArrayCoordinateIterator.h
vtkArrayCoordinates.h
vtkArrayExtents.h
vtkArrayInterpolate.h
vtkArrayPrint.h
vtkArrayRange.h
vtkArraySlices.h
vtkArraySlice.h
vtkArrayWeights.h
vtkArrayIteratorIncludes.h
vtkArrayIteratorTemplate.h
vtkArrayMap.h
......@@ -31,6 +41,7 @@ IF(PYTHON_EXECUTABLE)
vtkDataArrayTemplate.h
vtkDebugLeaks.h
vtkDebugLeaksManager.h
vtkDenseArray.h
vtkDynamicLoader.h
vtkEventForwarderCommand.h
vtkErrorCode.h
......@@ -69,6 +80,7 @@ IF(PYTHON_EXECUTABLE)
vtkSetGet.h
vtkSmartPointer.h
vtkSmartPointerBase.h
vtkSparseArray.h
vtkStdString.h
vtkStructuredData.h
vtkSystemIncludes.h
......@@ -77,7 +89,9 @@ IF(PYTHON_EXECUTABLE)
vtkTimeStamp.h
vtkTransformCollection.h
vtkType.h
vtkTypeTemplate.h
vtkTypeTraits.h
vtkTypedArray.h
vtkVariantBoostSerialization.h
vtkVariantInlineOperators.h
vtkVector.h
......
/*=========================================================================
Program: Visualization Toolkit
Module: ArrayAPI.cxx
-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <vtkDenseArray.h>
#include <vtkSmartPointer.h>
#include <vtkSparseArray.h>
#include <vtksys/ios/iostream>
#include <vtksys/ios/sstream>
#include <vtksys/stl/stdexcept>
#define test_expression(expression) \
{ \
if(!(expression)) \
{ \
vtkstd::ostringstream buffer; \
buffer << "Expression failed at line " << __LINE__ << ": " << #expression; \
throw vtkstd::runtime_error(buffer.str()); \
} \
}
int ArrayAPI(int argc, char* argv[])
{
try
{
vtkSmartPointer<vtkArray> array;
// Test to see that we can create every supported combination of storage- and value-type.
vtkstd::vector<int> storage_types;
storage_types.push_back(vtkArray::DENSE);
storage_types.push_back(vtkArray::SPARSE);
vtkstd::vector<int> value_types;
value_types.push_back(VTK_CHAR);
value_types.push_back(VTK_UNSIGNED_CHAR);
value_types.push_back(VTK_SHORT);
value_types.push_back(VTK_UNSIGNED_SHORT);
value_types.push_back(VTK_INT);
value_types.push_back(VTK_UNSIGNED_INT);
value_types.push_back(VTK_LONG);
value_types.push_back(VTK_UNSIGNED_LONG);
value_types.push_back(VTK_DOUBLE);
value_types.push_back(VTK_ID_TYPE);
value_types.push_back(VTK_STRING);
value_types.push_back(VTK_VARIANT);
for(vtkstd::vector<int>::const_iterator storage_type = storage_types.begin(); storage_type != storage_types.end(); ++storage_type)
{
for(vtkstd::vector<int>::const_iterator value_type = value_types.begin(); value_type != value_types.end(); ++value_type)
{
cerr << "creating array with storage type " << *storage_type << " and value type " << vtkImageScalarTypeNameMacro(*value_type) << endl;
array.TakeReference(vtkArray::CreateArray(*storage_type, *value_type));
test_expression(array);
}
}
// Do some spot-checking to see that the actual type matches what we expect ...
array.TakeReference(vtkArray::CreateArray(vtkArray::DENSE, VTK_DOUBLE));
test_expression(vtkDenseArray<double>::SafeDownCast(array));
array.TakeReference(vtkArray::CreateArray(vtkArray::SPARSE, VTK_STRING));
test_expression(vtkSparseArray<vtkStdString>::SafeDownCast(array));
return 0;
}
catch(vtkstd::exception& e)
{
cerr << e.what() << endl;
return 1;
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: ArrayAPIConvenience.cxx
-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <vtkDenseArray.h>
#include <vtkSmartPointer.h>
#include <vtksys/ios/iostream>
#include <vtksys/ios/sstream>
#include <vtksys/stl/stdexcept>
#define test_expression(expression) \
{ \
if(!(expression)) \
{ \
vtkstd::ostringstream buffer; \
buffer << "Expression failed at line " << __LINE__ << ": " << #expression; \
throw vtkstd::runtime_error(buffer.str()); \
} \
}
int ArrayAPIConvenience(int argc, char* argv[])
{
try
{
vtkSmartPointer<vtkDenseArray<double> > a = vtkSmartPointer<vtkDenseArray<double> >::New();
vtkSmartPointer<vtkDenseArray<double> > b = vtkSmartPointer<vtkDenseArray<double> >::New();
a->Resize(5);
b->Resize(vtkArrayExtents(5));
test_expression(a->GetExtents() == b->GetExtents());
a->SetValue(2, 3);
b->SetValue(vtkArrayCoordinates(2), 3);
test_expression(a->GetValue(2) == b->GetValue(vtkArrayCoordinates(2)));
a->Resize(5, 6);
b->Resize(vtkArrayExtents(5, 6));
test_expression(a->GetExtents() == b->GetExtents());
a->SetValue(2, 3, 4);
b->SetValue(vtkArrayCoordinates(2, 3), 4);
test_expression(a->GetValue(2, 3) == b->GetValue(vtkArrayCoordinates(2, 3)));
a->Resize(5, 6, 7);
b->Resize(vtkArrayExtents(5, 6, 7));
test_expression(a->GetExtents() == b->GetExtents());
a->SetValue(2, 3, 4, 5);
b->SetValue(vtkArrayCoordinates(2, 3, 4), 5);
test_expression(a->GetValue(2, 3, 4) == b->GetValue(vtkArrayCoordinates(2, 3, 4)));
return 0;
}
catch(vtkstd::exception& e)
{
cerr << e.what() << endl;
return 1;
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: ArrayAPIDense.cxx
-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <vtkDenseArray.h>
#include <vtkSmartPointer.h>
#include <vtksys/ios/iostream>
#include <vtksys/ios/sstream>
#include <vtksys/stl/stdexcept>
#define test_expression(expression) \
{ \
if(!(expression)) \
{ \
vtkstd::ostringstream buffer; \
buffer << "Expression failed at line " << __LINE__ << ": " << #expression; \
throw vtkstd::runtime_error(buffer.str()); \
} \
}
int ArrayAPIDense(int argc, char* argv[])
{
try
{
// Create an array ...
vtkSmartPointer<vtkDenseArray<double> > array = vtkSmartPointer<vtkDenseArray<double> >::New();
array->Resize(vtkArrayExtents::Uniform(3, 0));
test_expression(array);
// Test to ensure that casting works correctly ...
test_expression(vtkTypedArray<double>::SafeDownCast(array));
test_expression(vtkArray::SafeDownCast(array));
test_expression(vtkObject::SafeDownCast(array));
test_expression(!vtkTypedArray<int>::SafeDownCast(array));
// Confirm the initial state of the array ...
test_expression(array->GetDimensions() == 3);
test_expression(array->GetSize() == 0);
test_expression(array->GetNonNullSize() == 0);
test_expression(array->GetExtents() == vtkArrayExtents(0, 0, 0));
// Resize the array and verify that everything adds-up ...
array->Resize(vtkArrayExtents(1, 2, 3));
test_expression(array->GetDimensions() == 3);
test_expression(array->GetSize() == 6);
test_expression(array->GetNonNullSize() == 6);
test_expression(array->GetExtents() == vtkArrayExtents(1, 2, 3));
// Verify that the array contains all zeros ...
{
const vtkArrayExtents extents = array->GetExtents();
for(int i = 0; i != extents[0]; ++i)
{
for(int j = 0; j != extents[1]; ++j)
{
for(int k = 0; k != extents[2]; ++k)
{
test_expression(array->GetValue(vtkArrayCoordinates(i, j, k)) == 0);
}
}
}
}
// Verify that we can write data into the array and read it out again ...
{
double value = 0;
const vtkArrayExtents extents = array->GetExtents();
for(int i = 0; i != extents[0]; ++i)
{
for(int j = 0; j != extents[1]; ++j)
{
for(int k = 0; k != extents[2]; ++k)
{
array->SetValue(vtkArrayCoordinates(i, j, k), value++);
}
}
}
}
{
double value = 0;
vtkIdType index = 0;
const vtkArrayExtents extents = array->GetExtents();
for(int i = 0; i != extents[0]; ++i)
{
for(int j = 0; j != extents[1]; ++j)
{
for(int k = 0; k != extents[2]; ++k)
{
test_expression(array->GetValue(vtkArrayCoordinates(i, j, k)) == value);
vtkArrayCoordinates coordinates;
array->GetCoordinatesN(index, coordinates);
++index;
++value;
}
}
}
}
// Verify that fill works correctly ...
array->Fill(19700827);
// Test unordered access ...
for(int n = 0; n != array->GetNonNullSize(); ++n)
test_expression(array->GetValueN(n) == 19700827);
// Verify that deep-copy works correctly ...
vtkSmartPointer<vtkDenseArray<double> > deep_copy;
deep_copy.TakeReference(vtkDenseArray<double>::SafeDownCast(array->DeepCopy()));
test_expression(deep_copy->GetDimensions() == array->GetDimensions());
test_expression(deep_copy->GetSize() == array->GetSize());
test_expression(deep_copy->GetNonNullSize() == array->GetNonNullSize());
test_expression(deep_copy->GetExtents() == array->GetExtents());
for(int n = 0; n != deep_copy->GetNonNullSize(); ++n)
test_expression(deep_copy->GetValueN(n) == 19700827);
// Verify that data is organized in fortran-order ...
array->SetValue(vtkArrayCoordinates(0, 0, 0), 2);
array->SetValue(vtkArrayCoordinates(1, 0, 0), 4);
array->SetValue(vtkArrayCoordinates(2, 0, 0), 6);
test_expression(array->GetStorage()[0] == 2);
test_expression(array->GetStorage()[1] == 4);
test_expression(array->GetStorage()[2] == 6);
return 0;
}
catch(vtkstd::exception& e)
{
cerr << e.what() << endl;
return 1;
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: ArrayAPISparse.cxx
-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <vtkSparseArray.h>
#include <vtkSmartPointer.h>
#include <vtksys/ios/iostream>
#include <vtksys/stl/stdexcept>
#define test_expression(expression) \
{ \
if(!(expression)) \
throw vtkstd::runtime_error("Expression failed: " #expression); \
}
int ArrayAPISparse(int argc, char* argv[])
{
try
{
// Create an array ...
vtkSmartPointer<vtkSparseArray<double> > array = vtkSmartPointer<vtkSparseArray<double> >::New();
array->Resize(vtkArrayExtents::Uniform(3, 0));
test_expression(array);
// Test to ensure that casting works correctly ...
test_expression(vtkTypedArray<double>::SafeDownCast(array));
test_expression(vtkArray::SafeDownCast(array));
test_expression(vtkObject::SafeDownCast(array));
test_expression(!vtkTypedArray<int>::SafeDownCast(array));
// Confirm the initial state of the array ...
test_expression(array->GetDimensions() == 3);
test_expression(array->GetSize() == 0);
test_expression(array->GetNonNullSize() == 0);
test_expression(array->GetExtents() == vtkArrayExtents(0, 0, 0));
// Resize the array and verify that everything adds-up ...
array->Resize(vtkArrayExtents(1, 2, 3));
test_expression(array->GetDimensions() == 3);
test_expression(array->GetSize() == 6);
test_expression(array->GetNonNullSize() == 0);
test_expression(array->GetExtents() == vtkArrayExtents(1, 2, 3));
// Verify that the array contains all zeros ...
{
const vtkArrayExtents extents = array->GetExtents();
for(int i = 0; i != extents[0]; ++i)
{
for(int j = 0; j != extents[1]; ++j)
{
for(int k = 0; k != extents[2]; ++k)
{
test_expression(array->GetValue(vtkArrayCoordinates(i, j, k)) == 0);
}
}
}
}
// Verify that we can write data into the array with AddValue() and read it out again ...
{
double value = 0;
const vtkArrayExtents extents = array->GetExtents();
for(int i = 0; i != extents[0]; ++i)
{
for(int j = 0; j != extents[1]; ++j)
{
for(int k = 0; k != extents[2]; ++k)
{
array->AddValue(vtkArrayCoordinates(i, j, k), value++);
}
}
}
}
{
double value = 0;
vtkIdType index = 0;
const vtkArrayExtents extents = array->GetExtents();
for(int i = 0; i != extents[0]; ++i)
{
for(int j = 0; j != extents[1]; ++j)
{
for(int k = 0; k != extents[2]; ++k)
{
test_expression(array->GetValue(vtkArrayCoordinates(i, j, k)) == value);
test_expression(array->GetValueN(index) == value);
vtkArrayCoordinates coordinates;
array->GetCoordinatesN(index, coordinates);
test_expression(coordinates[0] == i);
test_expression(coordinates[1] == j);
test_expression(coordinates[2] == k);
++index;
++value;
}
}
}
}
// Verify the number of non-null values
test_expression(array->GetNonNullSize() == 6);
// Verify that deep-copy works correctly ...
vtkSmartPointer<vtkSparseArray<double> > deep_copy;
deep_copy.TakeReference(vtkSparseArray<double>::SafeDownCast(array->DeepCopy()));
test_expression(deep_copy->GetDimensions() == array->GetDimensions());
test_expression(deep_copy->GetSize() == array->GetSize());
test_expression(deep_copy->GetNonNullSize() == array->GetNonNullSize());
test_expression(deep_copy->GetExtents() == array->GetExtents());
for(int n = 0; n != deep_copy->GetNonNullSize(); ++n)
test_expression(deep_copy->GetValueN(n) == array->GetValueN(n));
// Verify that the Clear() method removes all values from the array ...
array->Clear();
test_expression(array->GetDimensions() == 3);
test_expression(array->GetSize() == 6);
test_expression(array->GetNonNullSize() == 0);
test_expression(array->GetExtents() == vtkArrayExtents(1, 2, 3));
// Verify that we can write data into the array with SetValue() and read it out again ...
array->Resize(vtkArrayExtents(2, 3, 4));
array->SetValue(vtkArrayCoordinates(0, 1, 2), 1.1);
array->SetValue(vtkArrayCoordinates(1, 2, 3), 2.2);
array->SetValue(vtkArrayCoordinates(0, 1, 1), 3.3);
test_expression(array->GetSize() == 24);
test_expression(array->GetNonNullSize() == 3);
test_expression(array->GetValue(vtkArrayCoordinates(0, 1, 2)) == 1.1);
test_expression(array->GetValue(vtkArrayCoordinates(1, 2, 3)) == 2.2);
test_expression(array->GetValue(vtkArrayCoordinates(0, 1, 1)) == 3.3);
return 0;
}
catch(vtkstd::exception& e)
{
cerr << e.what() << endl;
return 1;
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: ArrayInterpolationDense.cxx
-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <vtkArrayInterpolate.h>
#include <vtkDenseArray.h>
#include <vtkSmartPointer.h>
#include <vtksys/ios/iostream>
#include <vtksys/stl/stdexcept>