Commit af18e4b5 authored by Andrew Bauer's avatar Andrew Bauer

Adding an SoA array class that has a scale factor

For zero-copying arrays for in situ work, this allows the situation
where we want to scale the values that are stored in the memory
by a constant value. This is useful for a simulation code that
has multiple physics/simulation codes working together with
different scalings in each physics/simulation so that when we
get to doing zero-copy of their memory we can scale their field
data into a common scale/unit.
parent 15bfffd6
......@@ -61,6 +61,8 @@ mark_as_advanced(
VTK_DISPATCH_TYPED_ARRAYS
VTK_WARN_ON_DISPATCH_FAILURE)
option(VTK_BUILD_SCALED_SOA_ARRAYS "Include struct-of-arrays with scaled vtkDataArray implementation." ON)
include("${CMAKE_CURRENT_SOURCE_DIR}/vtkCreateArrayDispatchArrayList.cmake")
vtkArrayDispatch_default_array_setup()
vtkArrayDispatch_generate_array_header(VTK_ARRAYDISPATCH_ARRAY_LIST)
......@@ -244,6 +246,15 @@ set(sources
"${CMAKE_CURRENT_BINARY_DIR}/vtkVersionMacros.h"
)
if (VTK_BUILD_SCALED_SOA_ARRAYS)
list (APPEND template_classes vtkScaledSOADataArrayTemplate)
list (APPEND sources vtkScaledSOADataArrayTemplateInstantiate.cxx)
set(VTK_USE_SCALED_SOA_ARRAYS 1)
endif ()
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/vtkVTK_USE_SCALED_SOA_ARRAYS.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/vtkVTK_USE_SCALED_SOA_ARRAYS.h")
set(headers
vtkABI.h
vtkArrayIteratorIncludes.h
......@@ -295,7 +306,8 @@ set(headers
"${CMAKE_CURRENT_BINARY_DIR}/vtkMathConfigure.h"
"${CMAKE_CURRENT_BINARY_DIR}/vtkToolkits.h"
"${CMAKE_CURRENT_BINARY_DIR}/vtkTypeListMacros.h"
"${CMAKE_CURRENT_BINARY_DIR}/vtkVersionMacros.h")
"${CMAKE_CURRENT_BINARY_DIR}/vtkVersionMacros.h"
"${CMAKE_CURRENT_BINARY_DIR}/vtkVTK_USE_SCALED_SOA_ARRAYS.h")
set(templates
vtkArrayIteratorTemplateImplicit.txx)
......
......@@ -70,6 +70,19 @@ foreach(value_type ${value_types})
vtkSOADataArrayTemplate.h
"${value_type}"
"vtkSOADataArrayTemplate<${value_type}>")
if(VTK_BUILD_SCALED_SOA_ARRAYS)
add_data_array_test(
"ScaleAoS_${pretty_value_type}"
vtkScaleAOSDataArrayTemplate.h
"${value_type}"
"vtkScaleAOSDataArrayTemplate<${value_type}>")
add_data_array_test(
"ScaleSoA_${pretty_value_type}"
vtkScaledSOADataArrayTemplate.h
"${value_type}"
"vtkScaledSOADataArrayTemplate<${value_type}>")
endif()
endforeach()
# Tell TestSystemInformation where to find the build trees.
......@@ -78,6 +91,11 @@ set(TestSystemInformation_ARGS ${CMAKE_BINARY_DIR})
# Tell TestXMLFileOutputWindow where to write test file
set(TestXMLFileOutputWindow_ARGS ${CMAKE_BINARY_DIR}/Testing/Temporary/XMLFileOutputWindow.txt)
if (VTK_BUILD_SCALED_SOA_ARRAYS)
set(scale_soa_test TestScaledSOADataArrayDispatchers.cxx TestScaledSOADataArrayTemplate.cxx)
endif ()
vtk_add_test_cxx(vtkCommonCoreCxxTests tests
NO_DATA NO_VALID NO_OUTPUT
UnitTestMath.cxx
......@@ -145,6 +163,8 @@ vtk_add_test_cxx(vtkCommonCoreCxxTests tests
otherStringArray.cxx
${data_array_tests}
${scale_soa_test}
)
vtk_test_cxx_executable(vtkCommonCoreCxxTests tests
......
......@@ -20,6 +20,9 @@
#include "vtkFloatArray.h"
#include "vtkNew.h"
#include "vtkSOADataArrayTemplate.h"
#ifdef VTK_USE_SCALED_SOA_ARRAYS
#include "vtkScaledSOADataArrayTemplate.h"
#endif
#include "vtkStringArray.h"
#include <cstdint>
......@@ -110,15 +113,24 @@ int assign_void_array(FreeType, vtkAbstractArray *array, void *ptr,
std::size_t size, bool vtkShouldFree)
{
int errors = 0;
vtkSOADataArrayTemplate<double> *is_soa =
vtkArrayDownCast<vtkSOADataArrayTemplate<double>>(array);
if (is_soa)
if (vtkSOADataArrayTemplate<double> *is_soa =
vtkArrayDownCast<vtkSOADataArrayTemplate<double>>(array))
{
is_soa->SetNumberOfComponents(1);
is_soa->SetArray(0, reinterpret_cast<double *>(ptr),
static_cast<vtkIdType>(size), false, !vtkShouldFree,
FreeType::value);
}
#ifdef VTK_USE_SCALED_SOA_ARRAYS
else if (vtkScaledSOADataArrayTemplate<double> *is_scale_soa =
vtkArrayDownCast<vtkScaledSOADataArrayTemplate<double>>(array))
{
is_scale_soa->SetNumberOfComponents(1);
is_scale_soa->SetArray(0, reinterpret_cast<double *>(ptr),
static_cast<vtkIdType>(size), false, !vtkShouldFree,
FreeType::value);
}
#endif
else
{
const int save = vtkShouldFree ? 0 : 1;
......@@ -141,7 +153,9 @@ template <typename FreeType> int ExerciseDelete(FreeType f)
arrays.push_back(vtkFloatArray::New());
arrays.push_back(vtkAOSDataArrayTemplate<double>::New());
arrays.push_back(vtkSOADataArrayTemplate<double>::New());
#ifdef VTK_USE_SCALED_SOA_ARRAYS
arrays.push_back(vtkScaledSOADataArrayTemplate<double>::New());
#endif
const std::size_t size = 5000;
for (auto it = arrays.begin(); it != arrays.end(); ++it)
{
......
......@@ -27,6 +27,7 @@
#include "vtkNew.h"
#include "vtkSmartPointer.h"
#include "vtkSOADataArrayTemplate.h"
#include "vtkScaledSOADataArrayTemplate.h"
#include "vtkType.h"
#include "vtkTypeTraits.h"
#include "vtkVariant.h"
......@@ -991,6 +992,21 @@ struct CheckShallowCopy
}
return true;
}
// ScaleSOA same-ValueType case:
template <typename ValueType>
bool operator()(vtkScaledSOADataArrayTemplate<ValueType> *a1,
vtkScaledSOADataArrayTemplate<ValueType> *a2)
{
assert(a1->GetNumberOfComponents() == a2->GetNumberOfComponents());
for (int c = 0; c < a1->GetNumberOfComponents(); ++c)
{
if (a1->GetComponentArrayPointer(c) != a2->GetComponentArrayPointer(c))
{
return false;
}
}
return true;
}
};
// Undo warning suppression.
......@@ -1001,7 +1017,7 @@ struct CheckShallowCopy
#endif
// void ShallowCopy(vtkDataArray *other)
// Shallow copies AOS/SOA arrays if and only if arrays are the same type,
// Shallow copies AOS/SOA/ScaleSOA arrays if and only if arrays are the same type,
// otherwise deep copies.
// Test copying into and from the target array type.
// Allocates memory as needed.
......@@ -2146,11 +2162,13 @@ int Test_voidptr_WriteVoidPointer_id_number()
{
DataArrayAPIInit("void* WriteVoidPointer(vtkIdType id, vtkIdType number)");
// Skip SoA arrays, as they do not allow this:
if (typeid(ArrayT) == typeid(vtkSOADataArrayTemplate<ScalarT>))
// Skip SoA and Scale SoA arrays, as they do not allow this:
if (typeid(ArrayT) == typeid(vtkSOADataArrayTemplate<ScalarT>) ||
typeid(ArrayT) == typeid(vtkScaledSOADataArrayTemplate<ScalarT>))
{
std::cerr << "Skipping WriteVoidPointer for "
<< "vtkSOADataArrayTemplate<" << vtkTypeTraits<ScalarT>::Name()
<< "or vtkScaledSOADataArrayTemplate<" << vtkTypeTraits<ScalarT>::Name()
<< ">.\n";
DataArrayAPIFinish();
}
......@@ -3160,6 +3178,20 @@ int ExerciseDataArray()
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<unsigned long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<unsigned long long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkSOADataArrayTemplate<unsigned short> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<char> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<float> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<double> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<vtkIdType> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<int> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<long long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<short> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<signed char> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<unsigned char> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<unsigned int> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<unsigned long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<unsigned long long> >();
errors += Test_void_ShallowCopy_array<ScalarT, ArrayT, vtkScaledSOADataArrayTemplate<unsigned short> >();
errors += Test_doubleptr_GetTupleN_i<ScalarT, ArrayT, 1>();
errors += Test_doubleptr_GetTupleN_i<ScalarT, ArrayT, 2>();
errors += Test_doubleptr_GetTupleN_i<ScalarT, ArrayT, 3>();
......
......@@ -19,6 +19,9 @@
#include "vtkDataArray.h"
#include "vtkFloatArray.h"
#include "vtkSOADataArrayTemplate.h"
#ifdef VTK_USE_SCALED_SOA_ARRAYS
#include "vtkScaledSOADataArrayTemplate.h"
#endif
#include "vtkVector.h"
#include "vtkVectorOperators.h"
......@@ -1836,7 +1839,7 @@ struct UnitTestEdgeCases
DispatchTupleCompat<vtkSOADataArrayTemplate<float>,
vtkAOSDataArrayTemplate<float>>();
std::cerr << "AOS<float> <--> SAO<float>\n";
std::cerr << "AOS<float> <--> SOA<float>\n";
DispatchTupleCompat<vtkAOSDataArrayTemplate<float>,
vtkSOADataArrayTemplate<float>>();
......@@ -1855,6 +1858,32 @@ struct UnitTestEdgeCases
std::cerr << "AOS<float> <--> SOA<int>\n";
DispatchTupleCompat<vtkAOSDataArrayTemplate<float>,
vtkSOADataArrayTemplate<int>>();
#ifdef VTK_USE_SCALED_SOA_ARRAYS
std::cerr << "ScaleSOA<float> <--> AOS<float>\n";
DispatchTupleCompat<vtkScaledSOADataArrayTemplate<float>,
vtkAOSDataArrayTemplate<float>>();
std::cerr << "AOS<float> <--> ScaleSOA<float>\n";
DispatchTupleCompat<vtkAOSDataArrayTemplate<float>,
vtkScaledSOADataArrayTemplate<float>>();
std::cerr << "ScaleSOA<double> <--> AOS<float>\n";
DispatchTupleCompat<vtkScaledSOADataArrayTemplate<double>,
vtkAOSDataArrayTemplate<float>>();
std::cerr << "AOS<float> <--> ScaleSOA<double>\n";
DispatchTupleCompat<vtkAOSDataArrayTemplate<float>,
vtkScaledSOADataArrayTemplate<double>>();
std::cerr << "ScaleSOA<int> <--> AOS<float>\n";
DispatchTupleCompat<vtkScaledSOADataArrayTemplate<int>,
vtkAOSDataArrayTemplate<float>>();
std::cerr << "AOS<float> <--> ScaleSOA<int>\n";
DispatchTupleCompat<vtkAOSDataArrayTemplate<float>,
vtkScaledSOADataArrayTemplate<int>>();
#endif
}
template <typename ArrayType>
......@@ -2330,6 +2359,10 @@ int TestDataArrayTupleRange(int, char*[])
RunTestsForArray<vtkAOSDataArrayTemplate<float>>();
std::cerr << "SOA:\n";
RunTestsForArray<vtkSOADataArrayTemplate<float>>();
#ifdef VTK_USE_SCALED_SOA_ARRAYS
std::cerr << "ScaleSOA:\n";
RunTestsForArray<vtkScaledSOADataArrayTemplate<float>>();
#endif
std::cerr << "vtkFloatArray:\n";
RunTestsForArray<vtkFloatArray>();
......
......@@ -19,6 +19,9 @@
#include "vtkDataArray.h"
#include "vtkFloatArray.h"
#include "vtkSOADataArrayTemplate.h"
#ifdef VTK_USE_SCALED_SOA_ARRAYS
#include "vtkScaledSOADataArrayTemplate.h"
#endif
#include <algorithm>
#include <numeric>
......@@ -760,7 +763,7 @@ struct UnitTestEdgeCases
DispatchValueCompat<vtkSOADataArrayTemplate<float>,
vtkAOSDataArrayTemplate<float>>();
std::cerr << "AOS<float> <--> SAO<float>\n";
std::cerr << "AOS<float> <--> SOA<float>\n";
DispatchValueCompat<vtkAOSDataArrayTemplate<float>,
vtkSOADataArrayTemplate<float>>();
......@@ -779,6 +782,32 @@ struct UnitTestEdgeCases
std::cerr << "AOS<float> <--> SOA<int>\n";
DispatchValueCompat<vtkAOSDataArrayTemplate<float>,
vtkSOADataArrayTemplate<int>>();
#ifdef VTK_USE_SCALED_SOA_ARRAYS
std::cerr << "ScaleSOA<float> <--> AOS<float>\n";
DispatchValueCompat<vtkScaledSOADataArrayTemplate<float>,
vtkAOSDataArrayTemplate<float>>();
std::cerr << "AOS<float> <--> ScaleSOA<float>\n";
DispatchValueCompat<vtkAOSDataArrayTemplate<float>,
vtkScaledSOADataArrayTemplate<float>>();
std::cerr << "ScaleSOA<double> <--> AOS<float>\n";
DispatchValueCompat<vtkScaledSOADataArrayTemplate<double>,
vtkAOSDataArrayTemplate<float>>();
std::cerr << "AOS<float> <--> ScaleSOA<double>\n";
DispatchValueCompat<vtkAOSDataArrayTemplate<float>,
vtkScaledSOADataArrayTemplate<double>>();
std::cerr << "ScaleSOA<int> <--> AOS<float>\n";
DispatchValueCompat<vtkScaledSOADataArrayTemplate<int>,
vtkAOSDataArrayTemplate<float>>();
std::cerr << "AOS<float> <--> ScaleSOA<int>\n";
DispatchValueCompat<vtkAOSDataArrayTemplate<float>,
vtkScaledSOADataArrayTemplate<int>>();
#endif
}
template <typename ArrayType>
......@@ -1144,6 +1173,10 @@ int TestDataArrayValueRange(int, char*[])
RunTestsForArray<vtkAOSDataArrayTemplate<float>>();
std::cerr << "SOA:\n";
RunTestsForArray<vtkSOADataArrayTemplate<float>>();
#ifdef VTK_USE_SCALED_SOA_ARRAYS
std::cerr << "ScaleSOA:\n";
RunTestsForArray<vtkScaledSOADataArrayTemplate<float>>();
#endif
std::cerr << "vtkFloatArray:\n";
RunTestsForArray<vtkFloatArray>();
......
......@@ -41,6 +41,9 @@
#include "vtkShortArray.h"
#include "vtkSignedCharArray.h"
#include "vtkSOADataArrayTemplate.h"
#ifdef VTK_USE_SCALED_SOA_ARRAYS
#include "vtkScaledSOADataArrayTemplate.h"
#endif
#include "vtkUnsignedCharArray.h"
#include "vtkUnsignedIntArray.h"
#include "vtkUnsignedLongArray.h"
......@@ -124,6 +127,24 @@ int TestGenericDataArrayAPI(int, char *[])
errors += ExerciseGenericDataArray<unsigned short, vtkSOADataArrayTemplate<unsigned short> >();
errors += ExerciseGenericDataArray<vtkIdType, vtkSOADataArrayTemplate<vtkIdType> >();
// Explicit scale SoA arrays:
#ifdef VTK_USE_SCALED_SOA_ARRAYS
errors += ExerciseGenericDataArray<char, vtkScaledSOADataArrayTemplate<char> >();
errors += ExerciseGenericDataArray<double, vtkScaledSOADataArrayTemplate<double> >();
errors += ExerciseGenericDataArray<float, vtkScaledSOADataArrayTemplate<float> >();
errors += ExerciseGenericDataArray<int, vtkScaledSOADataArrayTemplate<int> >();
errors += ExerciseGenericDataArray<long, vtkScaledSOADataArrayTemplate<long> >();
errors += ExerciseGenericDataArray<long long, vtkScaledSOADataArrayTemplate<long long> >();
errors += ExerciseGenericDataArray<short, vtkScaledSOADataArrayTemplate<short> >();
errors += ExerciseGenericDataArray<signed char, vtkScaledSOADataArrayTemplate<signed char> >();
errors += ExerciseGenericDataArray<unsigned char, vtkScaledSOADataArrayTemplate<unsigned char> >();
errors += ExerciseGenericDataArray<unsigned int, vtkScaledSOADataArrayTemplate<unsigned int> >();
errors += ExerciseGenericDataArray<unsigned long, vtkScaledSOADataArrayTemplate<unsigned long> >();
errors += ExerciseGenericDataArray<unsigned long long, vtkScaledSOADataArrayTemplate<unsigned long long> >();
errors += ExerciseGenericDataArray<unsigned short, vtkScaledSOADataArrayTemplate<unsigned short> >();
errors += ExerciseGenericDataArray<vtkIdType, vtkScaledSOADataArrayTemplate<vtkIdType> >();
#endif
if (errors > 0)
{
std::cerr << "Test failed! Error count: " << errors << std::endl;
......
This diff is collapsed.
/*==============================================================================
Program: Visualization Toolkit
Module: TestScaledSOADataArrayTemplate.cxx
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 "vtkMathUtilities.h"
#include "vtkScaledSOADataArrayTemplate.h"
// Needed for portable setenv on MSVC...
#include "vtksys/SystemTools.hxx"
int TestScaledSOADataArrayTemplate(int,char *[])
{
const int numValues = 5;
const double trueFirstData[numValues] = {0, 1, 2, 3, 4};
const double trueSecondData[numValues] = {10, 11, 12, 13, 14};
double firstData[numValues];
double secondData[numValues];
for (int i=0;i<5;i++)
{
firstData[i] = trueFirstData[i];
secondData[i] = trueSecondData[i];
}
vtkScaledSOADataArrayTemplate<double>* array = vtkScaledSOADataArrayTemplate<double>::New();
array->SetNumberOfComponents(2);
array->SetNumberOfTuples(numValues);
array->SetArray(0, firstData, numValues, false, true);
array->SetArray(1, secondData, numValues, false, true);
array->SetScale(2.);
// first check that we get twice the values that are stored in firstData and secondData
// returned by GetTypedTuple()
double vals[2];
for (vtkIdType i=0;i<array->GetNumberOfTuples();i++)
{
array->GetTypedTuple(i, vals);
if (!vtkMathUtilities::NearlyEqual(vals[0], trueFirstData[i]*array->GetScale()) ||
!vtkMathUtilities::NearlyEqual(vals[1], trueSecondData[i]*array->GetScale()))
{
vtkGenericWarningMacro("Incorrect values returned from scaled array");
return 1;
}
}
// second check that if we set information based on firstData and secondData
// that we get that back
for (vtkIdType i=0;i<array->GetNumberOfTuples();i++)
{
vals[0] = trueFirstData[i];
vals[1] = trueSecondData[i];
array->SetTypedTuple(i, vals);
array->GetTypedTuple(i, vals);
if (!vtkMathUtilities::NearlyEqual(vals[0], trueFirstData[i]) ||
!vtkMathUtilities::NearlyEqual(vals[1], trueSecondData[i]))
{
vtkGenericWarningMacro(
"Incorrect values returned from scaled array after setting values in the array");
return 1;
}
}
// third check is for FillValue()
array->FillValue(2.);
for (vtkIdType i=0;i<array->GetNumberOfTuples();i++)
{
array->GetTypedTuple(i, vals);
if (!vtkMathUtilities::NearlyEqual(vals[0], 2.) || !vtkMathUtilities::NearlyEqual(vals[1], 2.))
{
vtkGenericWarningMacro(
"Incorrect values returned from scaled array after setting with FillValue(2.)");
return 1;
}
}
// fourth check is for getting raw pointer
// Silence the void pointer warnings for these calls
vtksys::SystemTools::PutEnv("VTK_SILENCE_GET_VOID_POINTER_WARNINGS=1");
double* rawPointer = array->GetPointer(0);
if (!vtkMathUtilities::NearlyEqual(rawPointer[0], 2.))
{
vtkGenericWarningMacro(
"Incorrect values returned from scaled array after GetPointer()");
return 1;
}
array->Delete();
return 0; //success
}
......@@ -2,8 +2,6 @@
import array
import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# types can be specified either with one of the strings listed below,
# or with a numpy dtype. You can get a list of types by calling the
......@@ -12,36 +10,44 @@ types = ['char', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32',
'int64', 'uint64', 'float32', 'float64']
formats = ['c', 'b', 'B', 'h', 'H', 'i', 'I', 'q', 'Q', 'f', 'd']
for T in types:
# instantiate the class for type T
a = vtk.vtkSOADataArrayTemplate[T]()
a.SetNumberOfComponents(3)
# do a simple set/get test
a.SetNumberOfTuples(2)
a.SetTuple(0, (1,2,3))
assert a.GetTuple(0) == (1,2,3)
# test the typed interface
if T != 'char':
a.SetTypedTuple(0, (3,4,6))
t = [0,0,0]
a.GetTypedTuple(0, t)
assert t == [3,4,6]
assert a.GetTypedComponent(0, 0) == 3
assert a.GetTypedComponent(0, 1) == 4
assert a.GetTypedComponent(0, 2) == 6
# test SetArray for types compatible with 'array' module
if T not in ('char', 'int64', 'uint64'):
t = formats[types.index(T)]
b1 = array.array(t, [10, 11, 12, 20])
b2 = array.array(t, [14, 15, 16, 30])
b3 = array.array(t, [17, 18, 19, 40])
a.SetArray(0, b1, 4, True, True)
a.SetArray(1, b2, 4, True, True)
a.SetArray(2, b3, 4, True, True)
assert a.GetNumberOfTuples() == 4
assert a.GetTuple(0) == (10, 14, 17)
assert a.GetTuple(1) == (11, 15, 18)
assert a.GetTuple(2) == (12, 16, 19)
assert a.GetTuple(3) == (20, 30, 40)
numarraytypes = 1
if hasattr(vtk, "vtkScaledSOADataArrayTemplate"):
numarraytypes = 2
for i in range(numarraytypes):
for T in types:
# instantiate the class for type T
if i == 0:
a = vtk.vtkSOADataArrayTemplate[T]()
else:
a = vtk.vtkScaledSOADataArrayTemplate[T]()
a.SetNumberOfComponents(3)
# do a simple set/get test
a.SetNumberOfTuples(2)
a.SetTuple(0, (1,2,3))
assert a.GetTuple(0) == (1,2,3)
# test the typed interface
if T != 'char':
a.SetTypedTuple(0, (3,4,6))
t = [0,0,0]
a.GetTypedTuple(0, t)
assert t == [3,4,6]
assert a.GetTypedComponent(0, 0) == 3
assert a.GetTypedComponent(0, 1) == 4
assert a.GetTypedComponent(0, 2) == 6
# test SetArray for types compatible with 'array' module
if T not in ('char', 'int64', 'uint64'):
t = formats[types.index(T)]
b1 = array.array(t, [10, 11, 12, 20])
b2 = array.array(t, [14, 15, 16, 30])
b3 = array.array(t, [17, 18, 19, 40])
a.SetArray(0, b1, 4, True, True)
a.SetArray(1, b2, 4, True, True)
a.SetArray(2, b3, 4, True, True)
assert a.GetNumberOfTuples() == 4
assert a.GetTuple(0) == (10, 14, 17)
assert a.GetTuple(1) == (11, 15, 18)
assert a.GetTuple(2) == (12, 16, 19)
assert a.GetTuple(3) == (20, 30, 40)
exit()
......@@ -643,6 +643,7 @@ public:
SoADataArrayTemplate,
TypedDataArray,
MappedDataArray,
ScaleSoADataArrayTemplate,
DataArrayTemplate = AoSDataArrayTemplate //! Legacy
};
......
......@@ -129,6 +129,13 @@ if (VTK_DISPATCH_SOA_ARRAYS)
set(vtkArrayDispatch_vtkSOADataArrayTemplate_types
${vtkArrayDispatch_all_types}
)
if (VTK_BUILD_SCALED_SOA_ARRAYS)
list(APPEND vtkArrayDispatch_containers vtkScaledSOADataArrayTemplate)
set(vtkArrayDispatch_vtkScaledSOADataArrayTemplate_header vtkScaledSOADataArrayTemplate.h)
set(vtkArrayDispatch_vtkScaledSOADataArrayTemplate_types
${vtkArrayDispatch_all_types}
)
endif()
endif()
if (VTK_DISPATCH_TYPED_ARRAYS)
......
......@@ -35,6 +35,9 @@
#include "vtkLongArray.h"
#include "vtkMath.h"
#include "vtkSOADataArrayTemplate.h" // For fast paths
#ifdef VTK_USE_SCALED_SOA_ARRAYS
#include "vtkScaledSOADataArrayTemplate.h" // For fast paths
#endif
#include "vtkShortArray.h"
#include "vtkSignedCharArray.h"
#include "vtkTypeTraits.h"
......@@ -81,6 +84,24 @@ struct DeepCopyWorker
}
}
#ifdef VTK_USE_SCALED_SOA_ARRAYS
// ScaleSoA --> ScaleSoA same-type specialization:
template <typename ValueType>
void operator()(vtkScaledSOADataArrayTemplate<ValueType> *src,
vtkScaledSOADataArrayTemplate<ValueType> *dst)
{
vtkIdType numTuples = src->GetNumberOfTuples();
for (int comp = 0; comp < src->GetNumberOfComponents(); ++comp)
{
ValueType *srcBegin = src->GetComponentArrayPointer(comp);
ValueType *srcEnd = srcBegin + numTuples;
ValueType *dstBegin = dst->GetComponentArrayPointer(comp);
std::copy(srcBegin, srcEnd, dstBegin);
}
dst->SetScale(src->GetScale());
}
#endif
// Undo warning suppression.
#if defined(__clang__) && defined(__has_warning)
#if __has_warning("-Wunused-template")
......
......@@ -37,6 +37,7 @@
#include "vtkCommonCoreModule.h" // For export macro
#include "vtkAbstractArray.h"
#include "vtkVTK_USE_SCALED_SOA_ARRAYS.h" // For #define of VTK_USE_SCALED_SOA_ARRAYS
class vtkDoubleArray;
class vtkIdList;
......
This diff is collapsed.
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkScaledSOADataArrayTemplateInstantiate.cxx
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.
=========================================================================*/
// This file generates instantiations of vtkScaledSOADataArrayTemplate for the
// common data types. For AoS arrays, this is done in the more derived classes
// (e.g. vtkFloatArray.cxx.o contains the instantiation of
// vtkAOSDataArrayTemplate<float>), but since these aren't derived from in VTK
// (yet), we instantiate them here.
#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
#include "vtkScaledSOADataArrayTemplate.txx"
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(char);
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(double);
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(float);
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(int);
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(long);
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(long long);
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(short);
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(signed char);
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(unsigned char);
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(unsigned int);
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(unsigned long);
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(unsigned long long);
VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(unsigned short);
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSOADataArrayTemplate.h
Module: vtkTestDataArray.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkVTK_USE_SCALED_SOA_ARRAYS.h
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.
=========================================================================*/
// defined if VTK provides the vtkScaledSOADataArray classes
#cmakedefine VTK_USE_SCALED_SOA_ARRAYS
......@@ -46,6 +46,9 @@
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#ifdef VTK_USE_SCALED_SOA_ARRAYS
#include "vtkScaledSOADataArrayTemplate.h"
#endif
#include "vtkShortArray.h"
#include "vtkSignedCharArray.h"
#include "vtkSOADataArrayTemplate.h"
......@@ -1029,11 +1032,25 @@ T* GetArrayRawPointer(vtkAbstractArray* array, T* ptr, int isAOSArray)
{
return ptr;
}
T* data = new T[array->GetNumberOfComponents()*array->GetNumberOfTuples()];
vtkSOADataArrayTemplate<T>* typedArray =
vtkSOADataArrayTemplate<T>::SafeDownCast(array);
typedArray->ExportToVoidPointer(data);
return data;
if (vtkSOADataArrayTemplate<T>* typedArray =
vtkSOADataArrayTemplate<T>::SafeDownCast(array))
{
T* data = new T[array->GetNumberOfComponents()*array->GetNumberOfTuples()];
typedArray->ExportToVoidPointer(data);
return data;
}