diff --git a/Charts/Core/vtkPlotArea.cxx b/Charts/Core/vtkPlotArea.cxx index 5546a4bc535055ee2d9b790b9082bdefc2a4c6bb..61961534369b668826ee5752297ad4ca3c1bc675 100644 --- a/Charts/Core/vtkPlotArea.cxx +++ b/Charts/Core/vtkPlotArea.cxx @@ -135,8 +135,8 @@ private: assert(array->GetNumberOfComponents() == this->ValidPointMask->GetNumberOfComponents()); using Dispatcher = - vtkArrayDispatch::Dispatch2ByArray<vtkArrayDispatch::Arrays, // First array is input, can be - // anything. + vtkArrayDispatch::Dispatch2ByArray<vtkArrayDispatch::AllArrays, // First array is input, can + // be anything. vtkTypeList::Create<vtkCharArray> // Second is always vtkCharArray. >; ComputeArrayRange worker; diff --git a/Common/Core/CMakeLists.txt b/Common/Core/CMakeLists.txt index 58b137576890062aba7fd8c23f18280d3671f0de..6dcdc418024ab153533fe135eaecd40ef63d6c0a 100644 --- a/Common/Core/CMakeLists.txt +++ b/Common/Core/CMakeLists.txt @@ -111,15 +111,35 @@ configure_file(vtkTypeListMacros.h.in vtkTypeListMacros.h) option(VTK_DISPATCH_AOS_ARRAYS "Include array-of-structs vtkDataArray subclasses in dispatcher." ON) option(VTK_DISPATCH_SOA_ARRAYS "Include struct-of-arrays vtkDataArray subclasses in dispatcher." OFF) option(VTK_DISPATCH_TYPED_ARRAYS "Include vtkTypedDataArray subclasses (e.g. old mapped arrays) in dispatcher." OFF) + +option(VTK_DISPATCH_AFFINE_ARRAYS "Include implicit vtkDataArray subclasses based on an affine function backend in dispatcher" OFF) +option(VTK_DISPATCH_COMPOSITE_ARRAYS "Include implicit vtkDataArray subclasses based on a composite binary tree backend in dispatcher" OFF) +option(VTK_DISPATCH_CONSTANT_ARRAYS "Include implicit vtkDataArray subclasses based on a constant backend in dispatcher" OFF) +option(VTK_DISPATCH_INDEXED_ARRAYS "Include implicit vtkDataArray subclasses based on an index referencing backend in dispatcher" OFF) +option(VTK_DISPATCH_STD_FUNCTION_ARRAYS "Include implicit vtkDataArray subclasses based on std::function in dispatcher" OFF) + option(VTK_WARN_ON_DISPATCH_FAILURE "If enabled, vtkArrayDispatch will print a warning when a dispatch fails." OFF) + mark_as_advanced( VTK_DISPATCH_AOS_ARRAYS VTK_DISPATCH_SOA_ARRAYS VTK_DISPATCH_TYPED_ARRAYS + + VTK_DISPATCH_AFFINE_ARRAYS + VTK_DISPATCH_COMPOSITE_ARRAYS + VTK_DISPATCH_CONSTANT_ARRAYS + VTK_DISPATCH_INDEXED_ARRAYS + VTK_DISPATCH_STD_FUNCTION_ARRAYS + VTK_WARN_ON_DISPATCH_FAILURE) option(VTK_BUILD_SCALED_SOA_ARRAYS "Include struct-of-arrays with scaled vtkDataArray implementation." OFF) +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/vtkVTK_DISPATCH_IMPLICIT_ARRAYS.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/vtkVTK_DISPATCH_IMPLICIT_ARRAYS.h" + @ONLY) + include("${CMAKE_CURRENT_SOURCE_DIR}/vtkCreateArrayDispatchArrayList.cmake") vtkArrayDispatch_default_array_setup() vtkArrayDispatch_generate_array_header(VTK_ARRAYDISPATCH_ARRAY_LIST) @@ -140,7 +160,17 @@ foreach (INSTANTIATION_VALUE_TYPE IN LISTS vtkArrayDispatch_all_types) # create a file suffix from the type string(REPLACE " " "_" _suffix "${INSTANTIATION_VALUE_TYPE}") - set(_list "vtkSOADataArrayTemplateInstantiate") + set(_list + vtkAffineArrayInstantiate + vtkAffineImplicitBackendInstantiate + vtkCompositeArrayInstantiate + vtkCompositeImplicitBackendInstantiate + vtkConstantArrayInstantiate + vtkConstantImplicitBackendInstantiate + vtkIndexedArrayInstantiate + vtkIndexedImplicitBackendInstantiate + vtkSOADataArrayTemplateInstantiate + vtkStdFunctionArrayInstantiate) if (VTK_BUILD_SCALED_SOA_ARRAYS) list(APPEND _list "vtkScaledSOADataArrayTemplateInstantiate") endif () @@ -297,6 +327,9 @@ set(template_classes vtkTypedDataArray) set(nowrap_template_classes + vtkCompositeImplicitBackend + vtkImplicitArray + vtkIndexedImplicitBackend vtkTypeList) set(sources @@ -446,16 +479,25 @@ foreach (smp_backend IN LISTS smp_backends) endforeach () set(nowrap_headers + vtkAffineArray.h + vtkAffineImplicitBackend.h vtkCollectionRange.h + vtkCompositeArray.h + vtkConstantArray.h + vtkConstantImplicitBackend.h vtkDataArrayAccessor.h vtkDataArrayTupleRange_AOS.h vtkDataArrayTupleRange_Generic.h vtkDataArrayValueRange_AOS.h vtkDataArrayValueRange_Generic.h + vtkImplicitArrayTraits.h + vtkIndexedArray.h vtkInherits.h vtkMathPrivate.hxx + vtkStdFunctionArray.h vtkTypeName.h ${vtk_smp_nowrap_headers} + "${CMAKE_CURRENT_BINARY_DIR}/vtkVTK_DISPATCH_IMPLICIT_ARRAYS.h" ) set(generated_headers vtkBuild.h diff --git a/Common/Core/Testing/Cxx/CMakeLists.txt b/Common/Core/Testing/Cxx/CMakeLists.txt index ea4d541f3211433f6b793a07a1027aca3f0fdb68..d137d705771201904945df7b1d9e57c3bddf6541 100644 --- a/Common/Core/Testing/Cxx/CMakeLists.txt +++ b/Common/Core/Testing/Cxx/CMakeLists.txt @@ -172,6 +172,16 @@ vtk_add_test_cxx(vtkCommonCoreCxxTests tests ${data_array_tests} ${scale_soa_test} + + TestAffineArray.cxx + TestCompositeArray.cxx + TestCompositeImplicitBackend.cxx + TestConstantArray.cxx + TestImplicitArraysBase.cxx + TestImplicitArrayTraits.cxx + TestIndexedArray.cxx + TestIndexedImplicitBackend.cxx + TestStdFunctionArray.cxx ) if (VTK_ABI_NAMESPACE_NAME STREQUAL "<DEFAULT>" OR VTK_ABI_NAMESPACE_NAME STREQUAL "") diff --git a/Common/ImplicitArrays/Testing/Cxx/TestAffineArray.cxx b/Common/Core/Testing/Cxx/TestAffineArray.cxx similarity index 98% rename from Common/ImplicitArrays/Testing/Cxx/TestAffineArray.cxx rename to Common/Core/Testing/Cxx/TestAffineArray.cxx index fe6b4a4617295963f2093c768ddd520b808c1783..a1522ecb47f8ae3b0c0e79aaadb411ff51035cb2 100644 --- a/Common/ImplicitArrays/Testing/Cxx/TestAffineArray.cxx +++ b/Common/Core/Testing/Cxx/TestAffineArray.cxx @@ -8,7 +8,6 @@ #ifdef VTK_DISPATCH_AFFINE_ARRAYS #include "vtkArrayDispatch.h" -#include "vtkArrayDispatchImplicitArrayList.h" #endif // VTK_DISPATCH_AFFINE_ARRAYS #include <cstdlib> diff --git a/Common/Core/Testing/Cxx/TestArrayDispatchers.cxx b/Common/Core/Testing/Cxx/TestArrayDispatchers.cxx index 3719f161a98984b9a459d3dc698a3ac0a56049c6..df1ea17844fb86ae8c4a1936715bd3d3577b63f4 100644 --- a/Common/Core/Testing/Cxx/TestArrayDispatchers.cxx +++ b/Common/Core/Testing/Cxx/TestArrayDispatchers.cxx @@ -29,6 +29,7 @@ typedef vtkTypeList::Unique< // vtkSOADataArrayTemplate<unsigned char>, // vtkSOADataArrayTemplate<vtkIdType> // >>::Result Arrays; +typedef Arrays AllArrays; } // end namespace vtkArrayDispatch #include "vtkArrayDispatch.h" diff --git a/Common/ImplicitArrays/Testing/Cxx/TestCompositeArray.cxx b/Common/Core/Testing/Cxx/TestCompositeArray.cxx similarity index 98% rename from Common/ImplicitArrays/Testing/Cxx/TestCompositeArray.cxx rename to Common/Core/Testing/Cxx/TestCompositeArray.cxx index 23abf90c8bcb2928e943023d931c6d0f6b76ff7c..8f201160733c9f62503b80ac3c12b875d69bbd26 100644 --- a/Common/ImplicitArrays/Testing/Cxx/TestCompositeArray.cxx +++ b/Common/Core/Testing/Cxx/TestCompositeArray.cxx @@ -9,7 +9,6 @@ #ifdef VTK_DISPATCH_COMPOSITE_ARRAYS #include "vtkArrayDispatch.h" -#include "vtkArrayDispatchImplicitArrayList.h" #endif // VTK_DISPATCH_AFFINE_ARRAYS #include <cstdlib> diff --git a/Common/ImplicitArrays/Testing/Cxx/TestCompositeImplicitBackend.cxx b/Common/Core/Testing/Cxx/TestCompositeImplicitBackend.cxx similarity index 97% rename from Common/ImplicitArrays/Testing/Cxx/TestCompositeImplicitBackend.cxx rename to Common/Core/Testing/Cxx/TestCompositeImplicitBackend.cxx index bab3f98f59591bccff41dd4ce54ed894bedf4708..88007b519fe77d7e57add9777052ee2535581206 100644 --- a/Common/ImplicitArrays/Testing/Cxx/TestCompositeImplicitBackend.cxx +++ b/Common/Core/Testing/Cxx/TestCompositeImplicitBackend.cxx @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen // SPDX-License-Identifier: BSD-3-Clause #include "vtkCompositeImplicitBackend.h" -#include "vtkCompositeImplicitBackend.txx" #include "vtkDataArrayRange.h" #include "vtkIntArray.h" diff --git a/Common/ImplicitArrays/Testing/Cxx/TestConstantArray.cxx b/Common/Core/Testing/Cxx/TestConstantArray.cxx similarity index 98% rename from Common/ImplicitArrays/Testing/Cxx/TestConstantArray.cxx rename to Common/Core/Testing/Cxx/TestConstantArray.cxx index 707eb6d18fd8ccd446d703b4959dd19136bdfb4d..6b6a556c9471e3e375df6aa4a9b332c43b18059f 100644 --- a/Common/ImplicitArrays/Testing/Cxx/TestConstantArray.cxx +++ b/Common/Core/Testing/Cxx/TestConstantArray.cxx @@ -8,7 +8,6 @@ #ifdef VTK_DISPATCH_CONSTANT_ARRAYS #include "vtkArrayDispatch.h" -#include "vtkArrayDispatchImplicitArrayList.h" #endif // VTK_DISPATCH_CONSTANT_ARRAYS #include <cstdlib> diff --git a/Common/ImplicitArrays/Testing/Cxx/TestImplicitArrayTraits.cxx b/Common/Core/Testing/Cxx/TestImplicitArrayTraits.cxx similarity index 100% rename from Common/ImplicitArrays/Testing/Cxx/TestImplicitArrayTraits.cxx rename to Common/Core/Testing/Cxx/TestImplicitArrayTraits.cxx diff --git a/Common/ImplicitArrays/Testing/Cxx/TestImplicitArraysBase.cxx b/Common/Core/Testing/Cxx/TestImplicitArraysBase.cxx similarity index 100% rename from Common/ImplicitArrays/Testing/Cxx/TestImplicitArraysBase.cxx rename to Common/Core/Testing/Cxx/TestImplicitArraysBase.cxx diff --git a/Common/ImplicitArrays/Testing/Cxx/TestIndexedArray.cxx b/Common/Core/Testing/Cxx/TestIndexedArray.cxx similarity index 98% rename from Common/ImplicitArrays/Testing/Cxx/TestIndexedArray.cxx rename to Common/Core/Testing/Cxx/TestIndexedArray.cxx index fb5089f3d71cf6acca9d2449979f095fb8ad3ed7..64974eda14c0dfee64af2c9e3b1e8a3f4e81fa2d 100644 --- a/Common/ImplicitArrays/Testing/Cxx/TestIndexedArray.cxx +++ b/Common/Core/Testing/Cxx/TestIndexedArray.cxx @@ -9,7 +9,6 @@ #ifdef VTK_DISPATCH_INDEXED_ARRAYS #include "vtkArrayDispatch.h" -#include "vtkArrayDispatchImplicitArrayList.h" #endif // VTK_DISPATCH_INDEXED_ARRAYS #include <cstdlib> diff --git a/Common/ImplicitArrays/Testing/Cxx/TestIndexedImplicitBackend.cxx b/Common/Core/Testing/Cxx/TestIndexedImplicitBackend.cxx similarity index 100% rename from Common/ImplicitArrays/Testing/Cxx/TestIndexedImplicitBackend.cxx rename to Common/Core/Testing/Cxx/TestIndexedImplicitBackend.cxx diff --git a/Common/ImplicitArrays/Testing/Cxx/TestStdFunctionArray.cxx b/Common/Core/Testing/Cxx/TestStdFunctionArray.cxx similarity index 98% rename from Common/ImplicitArrays/Testing/Cxx/TestStdFunctionArray.cxx rename to Common/Core/Testing/Cxx/TestStdFunctionArray.cxx index 09d70bbb2ea20a21dcd6e3e1b9d2edaeb0ad372d..c11fdebd2f8056bfc024e6d52b79d7776ed97116 100644 --- a/Common/ImplicitArrays/Testing/Cxx/TestStdFunctionArray.cxx +++ b/Common/Core/Testing/Cxx/TestStdFunctionArray.cxx @@ -9,7 +9,6 @@ #ifdef VTK_DISPATCH_STD_FUNCTION_ARRAYS #include "vtkArrayDispatch.h" -#include "vtkArrayDispatchImplicitArrayList.h" #endif // VTK_DISPATCH_STD_FUNCTION_ARRAYS #include <cstdlib> diff --git a/Common/Core/vtkAffineArray.h b/Common/Core/vtkAffineArray.h new file mode 100644 index 0000000000000000000000000000000000000000..3e653835270a53abf7f425e387fdf8aa909369b6 --- /dev/null +++ b/Common/Core/vtkAffineArray.h @@ -0,0 +1,99 @@ +// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen +// SPDX-License-Identifier: BSD-3-Clause +// Funded by CEA, DAM, DIF, F-91297 Arpajon, France +#ifndef vtkAffineArray_h +#define vtkAffineArray_h + +#ifdef VTK_AFFINE_ARRAY_INSTANTIATING +#define VTK_IMPLICIT_VALUERANGE_INSTANTIATING +#include "vtkDataArrayPrivate.txx" +#endif + +#include "vtkAffineImplicitBackend.h" // for the array backend +#include "vtkCommonCoreModule.h" // for export macro +#include "vtkImplicitArray.h" + +#ifdef VTK_AFFINE_ARRAY_INSTANTIATING +#undef VTK_IMPLICIT_VALUERANGE_INSTANTIATING +#endif + +/** + * \var vtkAffineArray + * \brief A utility alias for wrapping affine functions in implicit arrays + * + * In order to be usefully included in the dispatchers, these arrays need to be instantiated at the + * vtk library compile time. + * + * @sa + * vtkImplicitArray vtkAffineImplicitBackend + */ + +VTK_ABI_NAMESPACE_BEGIN +template <typename T> +using vtkAffineArray = vtkImplicitArray<vtkAffineImplicitBackend<T>>; +VTK_ABI_NAMESPACE_END + +#endif // vtkAffineArray_h + +#ifdef VTK_AFFINE_ARRAY_INSTANTIATING + +#define VTK_INSTANTIATE_AFFINE_ARRAY(ValueType) \ + VTK_ABI_NAMESPACE_BEGIN \ + template class VTKCOMMONCORE_EXPORT vtkImplicitArray<vtkAffineImplicitBackend<ValueType>>; \ + VTK_ABI_NAMESPACE_END \ + namespace vtkDataArrayPrivate \ + { \ + VTK_ABI_NAMESPACE_BEGIN \ + VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE( \ + vtkImplicitArray<vtkAffineImplicitBackend<ValueType>>, double) \ + VTK_ABI_NAMESPACE_END \ + } +#elif defined(VTK_USE_EXTERN_TEMPLATE) +#ifndef VTK_AFFINE_ARRAY_TEMPLATE_EXTERN +#define VTK_AFFINE_ARRAY_TEMPLATE_EXTERN +#ifdef _MSC_VER +#pragma warning(push) +// The following is needed when the vtkAffineArray is declared +// dllexport and is used from another class in vtkCommonCore +#pragma warning(disable : 4910) // extern and dllexport incompatible +#endif +VTK_ABI_NAMESPACE_BEGIN +vtkExternSecondOrderTemplateMacro( + extern template class VTKCOMMONCORE_EXPORT vtkImplicitArray, vtkAffineImplicitBackend); +#ifdef _MSC_VER +#pragma warning(pop) +#endif +VTK_ABI_NAMESPACE_END +#endif // VTK_AFFINE_ARRAY_TEMPLATE_EXTERN +// The following clause is only for MSVC 2008 and 2010 +#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS) +#pragma warning(push) +// C4091: 'extern ' : ignored on left of 'int' when no variable is declared +#pragma warning(disable : 4091) + +// Compiler-specific extension warning. +#pragma warning(disable : 4231) + +// We need to disable warning 4910 and do an extern dllexport +// anyway. When deriving new arrays from an +// instantiation of this template the compiler does an explicit +// instantiation of the base class. From outside the vtkCommon +// library we block this using an extern dllimport instantiation. +// For classes inside vtkCommon we should be able to just do an +// extern instantiation, but VS 2008 complains about missing +// definitions. We cannot do an extern dllimport inside vtkCommon +// since the symbols are local to the dll. An extern dllexport +// seems to be the only way to convince VS 2008 to do the right +// thing, so we just disable the warning. +#pragma warning(disable : 4910) // extern and dllexport incompatible + +// Use an "extern explicit instantiation" to give the class a DLL +// interface. This is a compiler-specific extension. +VTK_ABI_NAMESPACE_BEGIN +vtkInstantiateSecondOrderTemplateMacro( + extern template class VTKCOMMONCORE_EXPORT vtkImplicitArray, vtkAffineImplicitBackend); + +#pragma warning(pop) + +VTK_ABI_NAMESPACE_END +#endif diff --git a/Common/ImplicitArrays/vtkAffineArrayInstantiate.cxx.in b/Common/Core/vtkAffineArrayInstantiate.cxx.in similarity index 100% rename from Common/ImplicitArrays/vtkAffineArrayInstantiate.cxx.in rename to Common/Core/vtkAffineArrayInstantiate.cxx.in diff --git a/Common/ImplicitArrays/vtkAffineImplicitBackend.h b/Common/Core/vtkAffineImplicitBackend.h similarity index 77% rename from Common/ImplicitArrays/vtkAffineImplicitBackend.h rename to Common/Core/vtkAffineImplicitBackend.h index a88116a81339f9f68f8bd5b76585ae5306087516..2a71f4387a7c98092c851f131a003033500de45b 100644 --- a/Common/ImplicitArrays/vtkAffineImplicitBackend.h +++ b/Common/Core/vtkAffineImplicitBackend.h @@ -4,7 +4,7 @@ #ifndef vtkAffineImplicitBackend_h #define vtkAffineImplicitBackend_h -#include "vtkCommonImplicitArraysModule.h" +#include "vtkCommonCoreModule.h" /** * \struct vtkAffineImplicitBackend @@ -32,7 +32,7 @@ */ VTK_ABI_NAMESPACE_BEGIN template <typename ValueType> -struct vtkAffineImplicitBackend final +struct VTKCOMMONCORE_EXPORT vtkAffineImplicitBackend final { /** * A non-trivially constructible constructor @@ -52,7 +52,10 @@ struct vtkAffineImplicitBackend final * \param index the index at which one wished to evaluate the backend * \return the affinely computed value */ - ValueType operator()(int index) const { return this->Slope * index + this->Intercept; } + ValueType operator()(int index) const + { + return this->Slope * static_cast<ValueType>(index) + this->Intercept; + } /** * The slope of the affine function on the indeces @@ -66,3 +69,10 @@ struct vtkAffineImplicitBackend final VTK_ABI_NAMESPACE_END #endif // vtkAffineImplicitBackend_h + +#ifdef VTK_AFFINE_BACKEND_INSTANTIATING +#define VTK_INSTANTIATE_AFFINE_BACKEND(ValueType) \ + VTK_ABI_NAMESPACE_BEGIN \ + template struct VTKCOMMONCORE_EXPORT vtkAffineImplicitBackend<ValueType>; \ + VTK_ABI_NAMESPACE_END +#endif diff --git a/Common/Core/vtkAffineImplicitBackendInstantiate.cxx.in b/Common/Core/vtkAffineImplicitBackendInstantiate.cxx.in new file mode 100644 index 0000000000000000000000000000000000000000..c3eb3db7d22f1ad53239e7e71365b85e427c8f46 --- /dev/null +++ b/Common/Core/vtkAffineImplicitBackendInstantiate.cxx.in @@ -0,0 +1,18 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: vtkAffineImplicitBackendInstantiate_@INSTANTIATION_VALUE_TYPE@.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. + +=========================================================================*/ +#define VTK_AFFINE_BACKEND_INSTANTIATING +#include "vtkAffineImplicitBackend.h" + +VTK_INSTANTIATE_AFFINE_BACKEND(@INSTANTIATION_VALUE_TYPE@) diff --git a/Common/Core/vtkArrayDispatch.h b/Common/Core/vtkArrayDispatch.h index 418e64c31087d0403b269b28fa78bdd2a987e07b..622d981d3e4fa0867a485e67eeaaa27f289ae803 100644 --- a/Common/Core/vtkArrayDispatch.h +++ b/Common/Core/vtkArrayDispatch.h @@ -235,6 +235,8 @@ struct DispatchByArray; * The entry point is: * bool DispatchByValueType<...>::Execute(vtkDataArray *array, Worker &worker). */ +template <typename ArrayList, typename ValueTypeList> +struct DispatchByValueTypeUsingArrays; template <typename ValueTypeList> struct DispatchByValueType; @@ -257,6 +259,8 @@ struct Dispatch2; * bool Dispatch2SameValueType::Execute( * vtkDataArray *a1, vtkDataArray *a2, Worker &worker). */ +template <typename ArrayList> +struct Dispatch2SameValueTypeUsingArrays; struct Dispatch2SameValueType; //------------------------------------------------------------------------------ @@ -284,6 +288,8 @@ struct Dispatch2ByArray; * bool Dispatch2ByValueType<...>::Execute(vtkDataArray *a1, vtkDataArray *a2, * Worker &worker). */ +template <typename ArrayList, typename ValueTypeList1, typename ValueTypeList2> +struct Dispatch2ByValueTypeUsingArrays; template <typename ValueTypeList1, typename ValueTypeList2> struct Dispatch2ByValueType; @@ -313,6 +319,8 @@ struct Dispatch2ByArrayWithSameValueType; * bool Dispatch2BySameValueType<...>::Execute( * vtkDataArray *a1, vtkDataArray *a2, Worker &worker). */ +template <typename ArrayList, typename ValueTypeList> +struct Dispatch2BySameValueTypeUsingArrays; template <typename ValueTypeList> struct Dispatch2BySameValueType; @@ -335,6 +343,8 @@ struct Dispatch3; * bool Dispatch3SameValueType::Execute( * vtkDataArray *a1, vtkDataArray *a2, vtkDataArray *a3, Worker &worker). */ +template <typename ArrayList> +struct Dispatch3SameValueTypeUsingArrays; struct Dispatch3SameValueType; //------------------------------------------------------------------------------ @@ -364,6 +374,10 @@ struct Dispatch3ByArray; * bool Dispatch3ByValueType<...>::Execute(vtkDataArray *a1, vtkDataArray *a2, * vtkDataArray *a3, Worker &worker). */ + +template <typename ArrayList, typename ValueTypeList1, typename ValueTypeList2, + typename ValueTypeList3> +struct Dispatch3ByValueTypeUsingArrays; template <typename ValueTypeList1, typename ValueTypeList2, typename ValueTypeList3> struct Dispatch3ByValueType; @@ -393,6 +407,8 @@ struct Dispatch3ByArrayWithSameValueType; * bool Dispatch3BySameValueType<...>::Execute( * vtkDataArray *a1, vtkDataArray *a2, vtkDataArray *a3, Worker &worker). */ +template <typename ArrayList, typename ValueTypeList> +struct Dispatch3BySameValueTypeUsingArrays; template <typename ValueTypeList> struct Dispatch3BySameValueType; diff --git a/Common/Core/vtkArrayDispatch.txx b/Common/Core/vtkArrayDispatch.txx index f6f36919b580c39d9652251b311fd78cd413238d..7484ac82f04793675c124f929cbe9d8276143e67 100644 --- a/Common/Core/vtkArrayDispatch.txx +++ b/Common/Core/vtkArrayDispatch.txx @@ -457,13 +457,14 @@ public: // DispatchByValueType implementation: //------------------------------------------------------------------------------ // Preprocess and pass off to impl::Dispatch -template <typename ValueTypeHead, typename ValueTypeTail> -struct DispatchByValueType<vtkTypeList::TypeList<ValueTypeHead, ValueTypeTail>> +template <typename ArrayList, typename ValueTypeHead, typename ValueTypeTail> +struct DispatchByValueTypeUsingArrays<ArrayList, + vtkTypeList::TypeList<ValueTypeHead, ValueTypeTail>> { private: typedef vtkTypeList::TypeList<ValueTypeHead, ValueTypeTail> ValueTypeList; - typedef typename FilterArraysByValueType<Arrays, ValueTypeList>::Result ArrayList; - typedef typename vtkTypeList::Unique<ArrayList>::Result UniqueArrays; + typedef typename FilterArraysByValueType<ArrayList, ValueTypeList>::Result FilteredArrayList; + typedef typename vtkTypeList::Unique<FilteredArrayList>::Result UniqueArrays; typedef typename vtkTypeList::DerivedToFront<UniqueArrays>::Result SortedUniqueArrays; typedef impl::Dispatch<SortedUniqueArrays> ArrayDispatcher; @@ -475,6 +476,10 @@ public: inArray, std::forward<Worker>(worker), std::forward<Params>(params)...); } }; +template <typename ValueTypeList> +struct DispatchByValueType : public DispatchByValueTypeUsingArrays<Arrays, ValueTypeList> +{ +}; //------------------------------------------------------------------------------ // Dispatch2ByArray implementation: @@ -506,7 +511,7 @@ public: struct Dispatch2 { private: - typedef Dispatch2ByArray<vtkArrayDispatch::Arrays, vtkArrayDispatch::Arrays> Dispatcher; + typedef Dispatch2ByArray<Arrays, Arrays> Dispatcher; public: template <typename Worker, typename... Params> @@ -522,14 +527,14 @@ public: // Dispatch2ByValueType implementation: //------------------------------------------------------------------------------ // Preprocess and pass off to impl::Dispatch2 -template <typename ValueTypeList1, typename ValueTypeList2> -struct Dispatch2ByValueType +template <typename ArrayList, typename ValueTypeList1, typename ValueTypeList2> +struct Dispatch2ByValueTypeUsingArrays { private: - typedef typename FilterArraysByValueType<Arrays, ValueTypeList1>::Result ArrayList1; - typedef typename FilterArraysByValueType<Arrays, ValueTypeList2>::Result ArrayList2; - typedef typename vtkTypeList::Unique<ArrayList1>::Result UniqueArray1; - typedef typename vtkTypeList::Unique<ArrayList2>::Result UniqueArray2; + typedef typename FilterArraysByValueType<ArrayList, ValueTypeList1>::Result FilteredArrayList1; + typedef typename FilterArraysByValueType<ArrayList, ValueTypeList2>::Result FilteredArrayList2; + typedef typename vtkTypeList::Unique<FilteredArrayList1>::Result UniqueArray1; + typedef typename vtkTypeList::Unique<FilteredArrayList2>::Result UniqueArray2; typedef typename vtkTypeList::DerivedToFront<UniqueArray1>::Result SortedUniqueArray1; typedef typename vtkTypeList::DerivedToFront<UniqueArray2>::Result SortedUniqueArray2; typedef impl::Dispatch2<SortedUniqueArray1, SortedUniqueArray2> ArrayDispatcher; @@ -543,17 +548,22 @@ public: array1, array2, std::forward<Worker>(worker), std::forward<Params>(params)...); } }; +template <typename ValueTypeList1, typename ValueTypeList2> +struct Dispatch2ByValueType + : Dispatch2ByValueTypeUsingArrays<Arrays, ValueTypeList1, ValueTypeList2> +{ +}; //------------------------------------------------------------------------------ // Dispatch2BySameValueType implementation: //------------------------------------------------------------------------------ // Preprocess and pass off to impl::Dispatch2Same -template <typename ValueTypeList> -struct Dispatch2BySameValueType +template <typename ArrayList, typename ValueTypeList> +struct Dispatch2BySameValueTypeUsingArrays { private: - typedef typename FilterArraysByValueType<Arrays, ValueTypeList>::Result ArrayList; - typedef typename vtkTypeList::Unique<ArrayList>::Result UniqueArray; + typedef typename FilterArraysByValueType<ArrayList, ValueTypeList>::Result FilteredArrayList; + typedef typename vtkTypeList::Unique<FilteredArrayList>::Result UniqueArray; typedef typename vtkTypeList::DerivedToFront<UniqueArray>::Result SortedUniqueArray; typedef impl::Dispatch2Same<SortedUniqueArray, SortedUniqueArray> Dispatcher; @@ -566,6 +576,10 @@ public: array1, array2, std::forward<Worker>(worker), std::forward<Params>(params)...); } }; +template <typename ValueTypeList> +struct Dispatch2BySameValueType : Dispatch2BySameValueTypeUsingArrays<Arrays, ValueTypeList> +{ +}; //------------------------------------------------------------------------------ // Dispatch2ByArrayWithSameValueType implementation: @@ -594,11 +608,11 @@ public: //------------------------------------------------------------------------------ // Dispatch2SameValueType implementation: //------------------------------------------------------------------------------ -struct Dispatch2SameValueType +template <typename ArrayList> +struct Dispatch2SameValueTypeUsingArrays { private: - typedef Dispatch2ByArrayWithSameValueType<vtkArrayDispatch::Arrays, vtkArrayDispatch::Arrays> - Dispatcher; + typedef Dispatch2ByArrayWithSameValueType<ArrayList, ArrayList> Dispatcher; public: template <typename Worker, typename... Params> @@ -609,6 +623,9 @@ public: array1, array2, std::forward<Worker>(worker), std::forward<Params>(params)...); } }; +struct Dispatch2SameValueType : public Dispatch2SameValueTypeUsingArrays<Arrays> +{ +}; //------------------------------------------------------------------------------ // Dispatch3ByArray implementation: @@ -643,9 +660,7 @@ public: struct Dispatch3 { private: - typedef Dispatch3ByArray<vtkArrayDispatch::Arrays, vtkArrayDispatch::Arrays, - vtkArrayDispatch::Arrays> - Dispatcher; + typedef Dispatch3ByArray<Arrays, Arrays, Arrays> Dispatcher; public: template <typename Worker, typename... Params> @@ -661,16 +676,17 @@ public: // Dispatch3ByValueType implementation: //------------------------------------------------------------------------------ // Preprocess and pass off to impl::Dispatch3 -template <typename ValueTypeList1, typename ValueTypeList2, typename ValueTypeList3> -struct Dispatch3ByValueType +template <typename ArrayList, typename ValueTypeList1, typename ValueTypeList2, + typename ValueTypeList3> +struct Dispatch3ByValueTypeUsingArrays { private: - typedef typename FilterArraysByValueType<Arrays, ValueTypeList1>::Result ArrayList1; - typedef typename FilterArraysByValueType<Arrays, ValueTypeList2>::Result ArrayList2; - typedef typename FilterArraysByValueType<Arrays, ValueTypeList3>::Result ArrayList3; - typedef typename vtkTypeList::Unique<ArrayList1>::Result UniqueArray1; - typedef typename vtkTypeList::Unique<ArrayList2>::Result UniqueArray2; - typedef typename vtkTypeList::Unique<ArrayList3>::Result UniqueArray3; + typedef typename FilterArraysByValueType<ArrayList, ValueTypeList1>::Result FilteredArrayList1; + typedef typename FilterArraysByValueType<ArrayList, ValueTypeList2>::Result FilteredArrayList2; + typedef typename FilterArraysByValueType<ArrayList, ValueTypeList3>::Result FilteredArrayList3; + typedef typename vtkTypeList::Unique<FilteredArrayList1>::Result UniqueArray1; + typedef typename vtkTypeList::Unique<FilteredArrayList2>::Result UniqueArray2; + typedef typename vtkTypeList::Unique<FilteredArrayList3>::Result UniqueArray3; typedef typename vtkTypeList::DerivedToFront<UniqueArray1>::Result SortedUniqueArray1; typedef typename vtkTypeList::DerivedToFront<UniqueArray2>::Result SortedUniqueArray2; typedef typename vtkTypeList::DerivedToFront<UniqueArray3>::Result SortedUniqueArray3; @@ -686,17 +702,22 @@ public: array1, array2, array3, std::forward<Worker>(worker), std::forward<Params>(params)...); } }; +template <typename ValueTypeList1, typename ValueTypeList2, typename ValueTypeList3> +struct Dispatch3ByValueType + : public Dispatch3ByValueTypeUsingArrays<Arrays, ValueTypeList1, ValueTypeList2, ValueTypeList3> +{ +}; //------------------------------------------------------------------------------ // Dispatch3BySameValueType implementation: //------------------------------------------------------------------------------ // Preprocess and pass off to impl::Dispatch3Same -template <typename ValueTypeList> -struct Dispatch3BySameValueType +template <typename ArrayList, typename ValueTypeList> +struct Dispatch3BySameValueTypeUsingArrays { private: - typedef typename FilterArraysByValueType<Arrays, ValueTypeList>::Result ArrayList; - typedef typename vtkTypeList::Unique<ArrayList>::Result UniqueArray; + typedef typename FilterArraysByValueType<ArrayList, ValueTypeList>::Result FilteredArrayList; + typedef typename vtkTypeList::Unique<FilteredArrayList>::Result UniqueArray; typedef typename vtkTypeList::DerivedToFront<UniqueArray>::Result SortedUniqueArray; typedef impl::Dispatch3Same<SortedUniqueArray, SortedUniqueArray, SortedUniqueArray> Dispatcher; @@ -709,6 +730,10 @@ public: array1, array2, array3, std::forward<Worker>(worker), std::forward<Params>(params)...); } }; +template <typename ValueTypeList> +struct Dispatch3BySameValueType : public Dispatch3BySameValueTypeUsingArrays<Arrays, ValueTypeList> +{ +}; //------------------------------------------------------------------------------ // Dispatch3BySameValueType implementation: @@ -740,12 +765,11 @@ public: //------------------------------------------------------------------------------ // Dispatch3SameValueType implementation: //------------------------------------------------------------------------------ -struct Dispatch3SameValueType +template <typename ArrayList> +struct Dispatch3SameValueTypeUsingArrays { private: - typedef Dispatch3ByArrayWithSameValueType<vtkArrayDispatch::Arrays, vtkArrayDispatch::Arrays, - vtkArrayDispatch::Arrays> - Dispatcher; + typedef Dispatch3ByArrayWithSameValueType<ArrayList, ArrayList, ArrayList> Dispatcher; public: template <typename Worker, typename... Params> @@ -756,6 +780,9 @@ public: array1, array2, array3, std::forward<Worker>(worker), std::forward<Params>(params)...); } }; +struct Dispatch3SameValueType : Dispatch3SameValueTypeUsingArrays<Arrays> +{ +}; VTK_ABI_NAMESPACE_END } // end namespace vtkArrayDispatch diff --git a/Common/ImplicitArrays/vtkCompositeArray.h b/Common/Core/vtkCompositeArray.h similarity index 60% rename from Common/ImplicitArrays/vtkCompositeArray.h rename to Common/Core/vtkCompositeArray.h index 03ffe402232f3df19ad6579bde1f00f76054dc90..7b674c8e97b05a86ddc908d8bf894c696faf55ff 100644 --- a/Common/ImplicitArrays/vtkCompositeArray.h +++ b/Common/Core/vtkCompositeArray.h @@ -9,8 +9,8 @@ #include "vtkDataArrayPrivate.txx" #endif -#include "vtkCommonImplicitArraysModule.h" // for export macro -#include "vtkCompositeImplicitBackend.h" // for the array backend +#include "vtkCommonCoreModule.h" // for export macro +#include "vtkCompositeImplicitBackend.h" // for the array backend #include "vtkImplicitArray.h" #ifdef VTK_COMPOSITE_ARRAY_INSTANTIATING @@ -73,20 +73,12 @@ VTK_ABI_NAMESPACE_END #endif // vtkCompositeArray_h #ifdef VTK_COMPOSITE_ARRAY_INSTANTIATING - +// The instantiation is separated in two functions because the .txx includes vtkArrayDispatch.h +// which when Dispatching is enabled, it instantiates a class with a value type, before exporting it #define VTK_INSTANTIATE_COMPOSITE_ARRAY(ValueType) \ VTK_ABI_NAMESPACE_BEGIN \ - template class VTKCOMMONIMPLICITARRAYS_EXPORT \ - vtkImplicitArray<vtkCompositeImplicitBackend<ValueType>>; \ - VTK_ABI_NAMESPACE_END \ - namespace vtk \ - { \ - VTK_ABI_NAMESPACE_BEGIN \ - template VTKCOMMONIMPLICITARRAYS_EXPORT \ - vtkSmartPointer<vtkImplicitArray<vtkCompositeImplicitBackend<ValueType>>> \ - ConcatenateDataArrays(const std::vector<vtkDataArray*>& arrays); \ + template class VTKCOMMONCORE_EXPORT vtkImplicitArray<vtkCompositeImplicitBackend<ValueType>>; \ VTK_ABI_NAMESPACE_END \ - } \ namespace vtkDataArrayPrivate \ { \ VTK_ABI_NAMESPACE_BEGIN \ @@ -94,5 +86,62 @@ VTK_ABI_NAMESPACE_END vtkImplicitArray<vtkCompositeImplicitBackend<ValueType>>, double) \ VTK_ABI_NAMESPACE_END \ } +#define VTK_INSTANTIATE_COMPOSITE_ARRAY_FUNCTIONS(ValueType) \ + namespace vtk \ + { \ + VTK_ABI_NAMESPACE_BEGIN \ + template VTKCOMMONCORE_EXPORT \ + vtkSmartPointer<vtkImplicitArray<vtkCompositeImplicitBackend<ValueType>>> \ + ConcatenateDataArrays(const std::vector<vtkDataArray*>& arrays); \ + VTK_ABI_NAMESPACE_END \ + } + +#elif defined(VTK_USE_EXTERN_TEMPLATE) +#ifndef VTK_COMPOSITE_ARRAY_TEMPLATE_EXTERN +#define VTK_COMPOSITE_ARRAY_TEMPLATE_EXTERN +#ifdef _MSC_VER +#pragma warning(push) +// The following is needed when the vtkCompositeArray is declared +// dllexport and is used from another class in vtkCommonCore +#pragma warning(disable : 4910) // extern and dllexport incompatible +#endif +VTK_ABI_NAMESPACE_BEGIN +vtkExternSecondOrderTemplateMacro( + extern template class VTKCOMMONCORE_EXPORT vtkImplicitArray, vtkCompositeImplicitBackend); +#ifdef _MSC_VER +#pragma warning(pop) +#endif +VTK_ABI_NAMESPACE_END +#endif // VTK_COMPOSITE_ARRAY_TEMPLATE_EXTERN +// The following clause is only for MSVC 2008 and 2010 +#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS) +#pragma warning(push) +// C4091: 'extern ' : ignored on left of 'int' when no variable is declared +#pragma warning(disable : 4091) +// Compiler-specific extension warning. +#pragma warning(disable : 4231) + +// We need to disable warning 4910 and do an extern dllexport +// anyway. When deriving new arrays from an +// instantiation of this template the compiler does an explicit +// instantiation of the base class. From outside the vtkCommon +// library we block this using an extern dllimport instantiation. +// For classes inside vtkCommon we should be able to just do an +// extern instantiation, but VS 2008 complains about missing +// definitions. We cannot do an extern dllimport inside vtkCommon +// since the symbols are local to the dll. An extern dllexport +// seems to be the only way to convince VS 2008 to do the right +// thing, so we just disable the warning. +#pragma warning(disable : 4910) // extern and dllexport incompatible + +// Use an "extern explicit instantiation" to give the class a DLL +// interface. This is a compiler-specific extension. +VTK_ABI_NAMESPACE_BEGIN +vtkInstantiateSecondOrderTemplateMacro( + extern template class VTKCOMMONCORE_EXPORT vtkImplicitArray, vtkCompositeImplicitBackend); + +#pragma warning(pop) + +VTK_ABI_NAMESPACE_END #endif diff --git a/Common/ImplicitArrays/vtkCompositeArray.txx b/Common/Core/vtkCompositeArray.txx similarity index 100% rename from Common/ImplicitArrays/vtkCompositeArray.txx rename to Common/Core/vtkCompositeArray.txx diff --git a/Common/ImplicitArrays/vtkCompositeArrayInstantiate.cxx.in b/Common/Core/vtkCompositeArrayInstantiate.cxx.in similarity index 80% rename from Common/ImplicitArrays/vtkCompositeArrayInstantiate.cxx.in rename to Common/Core/vtkCompositeArrayInstantiate.cxx.in index 63b7f507c1779c917e3330d4b373058a05ca602c..dd9409fbafedf23aa31a8bf33d2ca7cee8222b3a 100644 --- a/Common/ImplicitArrays/vtkCompositeArrayInstantiate.cxx.in +++ b/Common/Core/vtkCompositeArrayInstantiate.cxx.in @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause #define VTK_COMPOSITE_ARRAY_INSTANTIATING #include "vtkCompositeArray.h" -#include "vtkCompositeArray.txx" - VTK_INSTANTIATE_COMPOSITE_ARRAY(@INSTANTIATION_VALUE_TYPE@) + +#include "vtkCompositeArray.txx" +VTK_INSTANTIATE_COMPOSITE_ARRAY_FUNCTIONS(@INSTANTIATION_VALUE_TYPE@) diff --git a/Common/ImplicitArrays/vtkCompositeImplicitBackend.h b/Common/Core/vtkCompositeImplicitBackend.h similarity index 93% rename from Common/ImplicitArrays/vtkCompositeImplicitBackend.h rename to Common/Core/vtkCompositeImplicitBackend.h index 95ed5f64bc29ff7ccefae029ce0408971bdda34d..8d00081e1c867fd9580850f60c15aed057a81f8f 100644 --- a/Common/ImplicitArrays/vtkCompositeImplicitBackend.h +++ b/Common/Core/vtkCompositeImplicitBackend.h @@ -38,7 +38,7 @@ * > Arrays input to the backend are flattened upon use and are no longer sensitive to component * > information. */ -#include "vtkCommonImplicitArraysModule.h" +#include "vtkCommonCoreModule.h" #include <memory> #include <vector> @@ -46,7 +46,7 @@ VTK_ABI_NAMESPACE_BEGIN class vtkDataArray; template <typename ValueType> -class vtkCompositeImplicitBackend final +class VTKCOMMONCORE_EXPORT vtkCompositeImplicitBackend final { public: /** @@ -77,6 +77,6 @@ VTK_ABI_NAMESPACE_END #ifdef VTK_COMPOSITE_BACKEND_INSTANTIATING #define VTK_INSTANTIATE_COMPOSITE_BACKEND(ValueType) \ VTK_ABI_NAMESPACE_BEGIN \ - template class VTKCOMMONIMPLICITARRAYS_EXPORT vtkCompositeImplicitBackend<ValueType>; \ + template class VTKCOMMONCORE_EXPORT vtkCompositeImplicitBackend<ValueType>; \ VTK_ABI_NAMESPACE_END #endif diff --git a/Common/ImplicitArrays/vtkCompositeImplicitBackend.txx b/Common/Core/vtkCompositeImplicitBackend.txx similarity index 95% rename from Common/ImplicitArrays/vtkCompositeImplicitBackend.txx rename to Common/Core/vtkCompositeImplicitBackend.txx index 52ee0385581b5d6c60ccd596b28b754b5a309cb3..abd20a1c9d531d63009f660a0608332b098f9bbb 100644 --- a/Common/ImplicitArrays/vtkCompositeImplicitBackend.txx +++ b/Common/Core/vtkCompositeImplicitBackend.txx @@ -4,14 +4,13 @@ #include "vtkAOSDataArrayTemplate.h" #include "vtkArrayDispatch.h" -#include "vtkArrayDispatchImplicitArrayList.h" #include "vtkDataArray.h" -#include "vtkDataArrayRange.h" #include "vtkImplicitArray.h" #include "vtkSmartPointer.h" -namespace +namespace vtkCompositeImplicitBackendDetail { +VTK_ABI_NAMESPACE_BEGIN //----------------------------------------------------------------------- /* * A generic interface towards a typed get value. Specialized structures should inherit from this @@ -109,7 +108,8 @@ private: using Dispatcher = vtkArrayDispatch::DispatchByArray<ArrayList>; std::shared_ptr<TypedArrayCache<ValueType>> Cache = nullptr; }; -} +VTK_ABI_NAMESPACE_END +} // namespace vtkCompositeImplicitBackendDetail VTK_ABI_NAMESPACE_BEGIN //----------------------------------------------------------------------- @@ -117,7 +117,8 @@ template <typename ValueType> struct vtkCompositeImplicitBackend<ValueType>::Internals { using InternalArrayList = vtkArrayDispatch::AllArrays; - using CachedBackend = ::TypedCacheWrapper<InternalArrayList, ValueType>; + using CachedBackend = + vtkCompositeImplicitBackendDetail::TypedCacheWrapper<InternalArrayList, ValueType>; using CachedArray = vtkImplicitArray<CachedBackend>; /* diff --git a/Common/ImplicitArrays/vtkCompositeImplicitBackendInstantiate.cxx.in b/Common/Core/vtkCompositeImplicitBackendInstantiate.cxx.in similarity index 100% rename from Common/ImplicitArrays/vtkCompositeImplicitBackendInstantiate.cxx.in rename to Common/Core/vtkCompositeImplicitBackendInstantiate.cxx.in diff --git a/Common/Core/vtkConstantArray.h b/Common/Core/vtkConstantArray.h new file mode 100644 index 0000000000000000000000000000000000000000..25773b7a06fbdf9abb2c99f537b2752047dad81c --- /dev/null +++ b/Common/Core/vtkConstantArray.h @@ -0,0 +1,99 @@ +// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen +// SPDX-License-Identifier: BSD-3-Clause +// Funded by CEA, DAM, DIF, F-91297 Arpajon, France +#ifndef vtkConstantArray_h +#define vtkConstantArray_h + +#ifdef VTK_CONSTANT_ARRAY_INSTANTIATING +#define VTK_IMPLICIT_VALUERANGE_INSTANTIATING +#include "vtkDataArrayPrivate.txx" +#endif + +#include "vtkCommonCoreModule.h" // for export macro +#include "vtkConstantImplicitBackend.h" // for the array backend +#include "vtkImplicitArray.h" + +#ifdef VTK_CONSTANT_ARRAY_INSTANTIATING +#undef VTK_IMPLICIT_VALUERANGE_INSTANTIATING +#endif + +/** + * \var vtkConstantArray + * \brief A utility alias for wrapping constant functions in implicit arrays + * + * In order to be usefully included in the dispatchers, these arrays need to be instantiated at the + * vtk library compile time. + * + * @sa + * vtkImplicitArray vtkConstantImplicitBackend + */ + +VTK_ABI_NAMESPACE_BEGIN +template <typename T> +using vtkConstantArray = vtkImplicitArray<vtkConstantImplicitBackend<T>>; +VTK_ABI_NAMESPACE_END + +#endif // vtkConstantArray_h + +#ifdef VTK_CONSTANT_ARRAY_INSTANTIATING + +#define VTK_INSTANTIATE_CONSTANT_ARRAY(ValueType) \ + VTK_ABI_NAMESPACE_BEGIN \ + template class VTKCOMMONCORE_EXPORT vtkImplicitArray<vtkConstantImplicitBackend<ValueType>>; \ + VTK_ABI_NAMESPACE_END \ + namespace vtkDataArrayPrivate \ + { \ + VTK_ABI_NAMESPACE_BEGIN \ + VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE( \ + vtkImplicitArray<vtkConstantImplicitBackend<ValueType>>, double) \ + VTK_ABI_NAMESPACE_END \ + } +#elif defined(VTK_USE_EXTERN_TEMPLATE) +#ifndef VTK_CONSTANT_ARRAY_TEMPLATE_EXTERN +#define VTK_CONSTANT_ARRAY_TEMPLATE_EXTERN +#ifdef _MSC_VER +#pragma warning(push) +// The following is needed when the vtkConstantArray is declared +// dllexport and is used from another class in vtkCommonCore +#pragma warning(disable : 4910) // extern and dllexport incompatible +#endif +VTK_ABI_NAMESPACE_BEGIN +vtkExternSecondOrderTemplateMacro( + extern template class VTKCOMMONCORE_EXPORT vtkImplicitArray, vtkConstantImplicitBackend); +#ifdef _MSC_VER +#pragma warning(pop) +#endif +VTK_ABI_NAMESPACE_END +#endif // VTK_CONSTANT_ARRAY_TEMPLATE_EXTERN +// The following clause is only for MSVC 2008 and 2010 +#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS) +#pragma warning(push) +// C4091: 'extern ' : ignored on left of 'int' when no variable is declared +#pragma warning(disable : 4091) + +// Compiler-specific extension warning. +#pragma warning(disable : 4231) + +// We need to disable warning 4910 and do an extern dllexport +// anyway. When deriving new arrays from an +// instantiation of this template the compiler does an explicit +// instantiation of the base class. From outside the vtkCommon +// library we block this using an extern dllimport instantiation. +// For classes inside vtkCommon we should be able to just do an +// extern instantiation, but VS 2008 complains about missing +// definitions. We cannot do an extern dllimport inside vtkCommon +// since the symbols are local to the dll. An extern dllexport +// seems to be the only way to convince VS 2008 to do the right +// thing, so we just disable the warning. +#pragma warning(disable : 4910) // extern and dllexport incompatible + +// Use an "extern explicit instantiation" to give the class a DLL +// interface. This is a compiler-specific extension. +VTK_ABI_NAMESPACE_BEGIN +vtkInstantiateSecondOrderTemplateMacro( + extern template class VTKCOMMONCORE_EXPORT vtkImplicitArray, vtkConstantImplicitBackend); + +#pragma warning(pop) + +VTK_ABI_NAMESPACE_END +#endif diff --git a/Common/ImplicitArrays/vtkConstantArrayInstantiate.cxx.in b/Common/Core/vtkConstantArrayInstantiate.cxx.in similarity index 100% rename from Common/ImplicitArrays/vtkConstantArrayInstantiate.cxx.in rename to Common/Core/vtkConstantArrayInstantiate.cxx.in diff --git a/Common/ImplicitArrays/vtkConstantImplicitBackend.h b/Common/Core/vtkConstantImplicitBackend.h similarity index 78% rename from Common/ImplicitArrays/vtkConstantImplicitBackend.h rename to Common/Core/vtkConstantImplicitBackend.h index aa00f2731ba5e2ef5e1c42cd80f1822ef0eaa611..3d2440d05f8446337e1201dc72f97cee4e6f947b 100644 --- a/Common/ImplicitArrays/vtkConstantImplicitBackend.h +++ b/Common/Core/vtkConstantImplicitBackend.h @@ -4,7 +4,7 @@ #ifndef vtkConstantImplicitBackend_h #define vtkConstantImplicitBackend_h -#include "vtkCommonImplicitArraysModule.h" +#include "vtkCommonCoreModule.h" #include "vtkSetGet.h" // for vtkNotUsed /** @@ -30,7 +30,7 @@ */ VTK_ABI_NAMESPACE_BEGIN template <typename ValueType> -struct vtkConstantImplicitBackend final +struct VTKCOMMONCORE_EXPORT vtkConstantImplicitBackend final { /** * A non-trivially contructible constructor @@ -57,3 +57,10 @@ struct vtkConstantImplicitBackend final VTK_ABI_NAMESPACE_END #endif // vtkConstantImplicitBackend_h + +#ifdef VTK_CONSTANT_BACKEND_INSTANTIATING +#define VTK_INSTANTIATE_CONSTANT_BACKEND(ValueType) \ + VTK_ABI_NAMESPACE_BEGIN \ + template struct VTKCOMMONCORE_EXPORT vtkConstantImplicitBackend<ValueType>; \ + VTK_ABI_NAMESPACE_END +#endif diff --git a/Common/Core/vtkConstantImplicitBackendInstantiate.cxx.in b/Common/Core/vtkConstantImplicitBackendInstantiate.cxx.in new file mode 100644 index 0000000000000000000000000000000000000000..f31a1c234bc69e6ec944620d0ae10144e0c9f10e --- /dev/null +++ b/Common/Core/vtkConstantImplicitBackendInstantiate.cxx.in @@ -0,0 +1,7 @@ +// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen +// SPDX-License-Identifier: BSD-3-Clause + +#define VTK_CONSTANT_BACKEND_INSTANTIATING +#include "vtkConstantImplicitBackend.h" + +VTK_INSTANTIATE_CONSTANT_BACKEND(@INSTANTIATION_VALUE_TYPE@) diff --git a/Common/Core/vtkCreateArrayDispatchArrayList.cmake b/Common/Core/vtkCreateArrayDispatchArrayList.cmake index 63b384186955a11548d588f95c93a68bb49a3029..464488cb4fb36408a0fee17151ac3995a0b4f4ee 100644 --- a/Common/Core/vtkCreateArrayDispatchArrayList.cmake +++ b/Common/Core/vtkCreateArrayDispatchArrayList.cmake @@ -1,5 +1,5 @@ # This file contains macros that are used by VTK to generate the list of -# default arrays used by the vtkArrayDispatch system. +# default and implicit arrays used by the vtkArrayDispatch system. # # There are a number of CMake variables that control the final array list. At # the high level, the following options enable/disable predefined categories of @@ -16,22 +16,43 @@ # by VTK. This enables the old-style in-situ vtkMappedDataArray subclasses # to be used. # +# - VTK_DISPATCH_AFFINE_ARRAYS (default: OFF) +# Include vtkAffineArray<ValueType> for the basic types supported +# by VTK. +# - VTK_DISPATCH_COMPOSITE_ARRAYS (default: OFF) +# Include vtkCompositeDataArrayTemplate<ValueType> for the basic types +# supported by VTK. +# - VTK_DISPATCH_CONSTANT_ARRAYS (default: OFF) +# Include vtkConstantArray<ValueType> for the basic types supported +# by VTK. +# - VTK_DISPATCH_INDEXED_ARRAYS (default: OFF) +# Include vtkIndexedDataArrayTemplate<ValueType> for the basic types +# supported by VTK. +# - VTK_DISPATCH_STD_FUNCTION_ARRAYS (default: OFF) +# Include vtkStdFunctionArray<ValueType> for the basic types supported +# by VTK. +# # At a lower level, specific arrays can be added to the list individually in # two ways: # # For templated classes, set the following variables: # - vtkArrayDispatch_containers: +# - vtkArrayDispatchImplicit_containers: # List of template class names. # - vtkArrayDispatch_[template class name]_types: +# - vtkArrayDispatchImplicit_[template class name]_types: # For the specified template class, add an entry to the array list that # instantiates the container for each type listed here. # - vtkArrayDispatch_[template class name]_header +# - vtkArrayDispatchImplicit_[template class name]_header # Specifies the header file to include for the specified template class. # # Both templated and non-templated arrays can be added using these variables: # - vtkArrayDispatch_extra_arrays: +# - vtkArrayDispatchImplicit_extra_arrays: # List of arrays to add to the list. # - vtkArrayDispatch_extra_headers: +# - vtkArrayDispatchImplicit_extra_headers: # List of headers to include. # ################################ Example ####################################### @@ -46,6 +67,13 @@ # -DvtkArrayDispatch_MyCustomArray2_types="int;unsigned char" # -DvtkArrayDispatch_extra_headers="ExtraHeader1.h;ExtraHeader2.h" # -DvtkArrayDispatch_extra_arrays="ExtraArray1;ExtraArray2<float>;ExtraArray2<char>" +# -DvtkArrayDispatchImplicit_containers="MyCustomArray1;MyCustomArray2" +# -DvtkArrayDispatchImplicit_MyCustomArray1_header="MyCustomArray1.h" +# -DvtkArrayDispatchImplicit_MyCustomArray1_types="float;double" +# -DvtkArrayDispatchImplicit_MyCustomArray2_header="MyCustomArray2.h" +# -DvtkArrayDispatchImplicit_MyCustomArray2_types="int;unsigned char" +# -DvtkArrayDispatchImplicit_extra_headers="ExtraHeader1.h;ExtraHeader2.h" +# -DvtkArrayDispatchImplicit_extra_arrays="ExtraArray1;ExtraArray2<float>;ExtraArray2<char>" # # Generated header: # @@ -87,6 +115,22 @@ # > # >::Result Arrays; # +# typedef vtkTypeList::Unique< +# vtkTypeListvtkTypeList::Create< +# MyCustomArray1<float>, +# MyCustomArray1<double>, +# MyCustomArray2<int>, +# MyCustomArray2<unsigned char>, +# ExtraArray1, +# ExtraArray2<float>, +# ExtraArray2<char> +# > +# >::Result ReadOnlyArrays; +# +# typedef vtkTypeList::Unique< vtkTypeList::TypeList<Arrays, ReadOnlyArrays> >::Result AllArrays; +# +# VTK_ABI_NAMESPACE_END +# # } // end namespace vtkArrayDispatch # # #endif // vtkArrayDispatchArrayList_h @@ -114,37 +158,53 @@ set(vtkArrayDispatch_all_types "vtkIdType" ) -# For each container, define a header and a list of types: -if (VTK_DISPATCH_AOS_ARRAYS) - list(APPEND vtkArrayDispatch_containers vtkAOSDataArrayTemplate) - set(vtkArrayDispatch_vtkAOSDataArrayTemplate_header vtkAOSDataArrayTemplate.h) - set(vtkArrayDispatch_vtkAOSDataArrayTemplate_types - ${vtkArrayDispatch_all_types} - ) -endif() +macro(_vtkCreateArrayDispatch var class types) + if (${var}) + list(APPEND vtkArrayDispatch_containers "${class}") + set("vtkArrayDispatch_${class}_header" "${class}.h") + set("vtkArrayDispatch_${class}_types" "${types}") + endif () +endmacro() -if (VTK_DISPATCH_SOA_ARRAYS) - list(APPEND vtkArrayDispatch_containers vtkSOADataArrayTemplate) - set(vtkArrayDispatch_vtkSOADataArrayTemplate_header vtkSOADataArrayTemplate.h) - 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) - list(APPEND vtkArrayDispatch_containers vtkTypedDataArray) - set(vtkArrayDispatch_vtkTypedDataArray_header vtkTypedDataArray.h) - set(vtkArrayDispatch_vtkTypedDataArray_types - ${vtkArrayDispatch_all_types} - ) -endif() +_vtkCreateArrayDispatch(VTK_DISPATCH_AOS_ARRAYS "vtkAOSDataArrayTemplate" + "${vtkArrayDispatch_all_types}") + +_vtkCreateArrayDispatch(VTK_DISPATCH_SOA_ARRAYS "vtkSOADataArrayTemplate" + "${vtkArrayDispatch_all_types}") + +if (VTK_DISPATCH_SOA_ARRAYS AND VTK_BUILD_SCALED_SOA_ARRAYS) + set(_dispatch_scaled_soa_arrays "ON") +else () + set(_dispatch_scaled_soa_arrays "OFF") +endif () +_vtkCreateArrayDispatch(_dispatch_scaled_soa_arrays "vtkScaledSOADataArrayTemplate" + "${vtkArrayDispatch_all_types}") + +_vtkCreateArrayDispatch(VTK_DISPATCH_TYPED_ARRAYS "vtkTypedDataArray" + "${vtkArrayDispatch_all_types}") + +macro(_vtkCreateArrayDispatchImplicit var class types) + if (${var}) + list(APPEND vtkArrayDispatchImplicit_containers "${class}") + set("vtkArrayDispatchImplicit_${class}_header" "${class}.h") + set("vtkArrayDispatchImplicit_${class}_types" "${types}") + endif () +endmacro() + +_vtkCreateArrayDispatchImplicit(VTK_DISPATCH_AFFINE_ARRAYS "vtkAffineArray" + "${vtkArrayDispatch_all_types}") + +_vtkCreateArrayDispatchImplicit(VTK_DISPATCH_COMPOSITE_ARRAYS "vtkCompositeArray" + "${vtkArrayDispatch_all_types}") + +_vtkCreateArrayDispatchImplicit(VTK_DISPATCH_CONSTANT_ARRAYS "vtkConstantArray" + "${vtkArrayDispatch_all_types}") + +_vtkCreateArrayDispatchImplicit(VTK_DISPATCH_INDEXED_ARRAYS "vtkIndexedArray" + "${vtkArrayDispatch_all_types}") + +_vtkCreateArrayDispatchImplicit(VTK_DISPATCH_STD_FUNCTION_ARRAYS "vtkStdFunctionArray" + "${vtkArrayDispatch_all_types}") endmacro() @@ -153,11 +213,18 @@ macro(vtkArrayDispatch_generate_array_header result) set(vtkAD_headers vtkTypeList.h) set(vtkAD_arrays) +set(vtkAD_readonly_arrays) foreach(container ${vtkArrayDispatch_containers}) list(APPEND vtkAD_headers ${vtkArrayDispatch_${container}_header}) foreach(value_type ${vtkArrayDispatch_${container}_types}) list(APPEND vtkAD_arrays "${container}<${value_type}>") endforeach() +endforeach () +foreach(container ${vtkArrayDispatchImplicit_containers}) + list(APPEND vtkAD_headers ${vtkArrayDispatchImplicit_${container}_header}) + foreach(value_type ${vtkArrayDispatchImplicit_${container}_types}) + list(APPEND vtkAD_readonly_arrays "${container}<${value_type}>") + endforeach() endforeach() # Include externally specified headers/arrays: @@ -165,7 +232,9 @@ list(APPEND vtkAD_headers ${vtkArrayDispatch_extra_headers}) list(APPEND vtkAD_arrays ${vtkArrayDispatch_extra_arrays}) set(temp - "// This file is autogenerated by vtkCreateArrayDispatchArrayList.cmake.\n" + "// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen\n" + "// SPDX-License-Identifier: BSD-3-Clause\n" + "// This file is autogenerated by vtkCreateArrayDispatchImplicitList.cmake.\n" "// Do not edit this file. Your changes will not be saved.\n" "\n" "#ifndef vtkArrayDispatchArrayList_h\n" @@ -186,18 +255,45 @@ list(APPEND temp " vtkTypeList::Create<\n" ) -foreach(array ${vtkAD_arrays}) - list(APPEND temp " ${array},\n") -endforeach() - -# Remove the final comma from the array list: -string(CONCAT temp ${temp}) -string(REGEX REPLACE ",\n$" "\n" temp "${temp}") +list(LENGTH vtkAD_arrays array_size) +math(EXPR last_index "${array_size} - 1") +list(GET vtkAD_arrays ${last_index} vtkAD_arrays_last) +foreach (array ${vtkAD_arrays}) + if (NOT ${array} STREQUAL ${vtkAD_arrays_last}) + list(APPEND temp " ${array},\n") + else () + list(APPEND temp " ${array}\n") + endif () +endforeach () list(APPEND temp " >\n" ">::Result Arrays\;\n" "\n" + "typedef vtkTypeList::Unique<\n" + " vtkTypeList::Create<\n" + ) + +list(LENGTH vtkAD_readonly_arrays read_only_array_size) +math(EXPR read_only_last_index "${read_only_array_size} - 1") +list(GET vtkAD_readonly_arrays ${read_only_last_index} vtkAD_readonly_arrays_last) +foreach (array ${vtkAD_readonly_arrays}) + if (NOT ${array} STREQUAL ${vtkAD_readonly_arrays_last}) + list(APPEND temp " ${array},\n") + else () + list(APPEND temp " ${array}\n") + endif () +endforeach () + +list(APPEND temp + " >\n" + ">::Result ReadOnlyArrays\;\n" + "\n" + "typedef vtkTypeList::Unique<\n" + "vtkTypeList::Append<Arrays,\n" + "ReadOnlyArrays>::Result\n" + ">::Result AllArrays\;\n" + "\n" "VTK_ABI_NAMESPACE_END\n" "\n" "} // end namespace vtkArrayDispatch\n" diff --git a/Common/Core/vtkGenericDataArray.h b/Common/Core/vtkGenericDataArray.h index f0166b6146c6e154a8b5265f2b753010bafcb795..dd954cf81879628bc5ade636c551f0cab11aaf07 100644 --- a/Common/Core/vtkGenericDataArray.h +++ b/Common/Core/vtkGenericDataArray.h @@ -636,7 +636,7 @@ VTK_ABI_NAMESPACE_END #ifdef _MSC_VER #pragma warning(pop) #endif -#endif // VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN +#endif // VTK_GDA_TEMPLATE_EXTERN #endif // VTK_GDA_VALUERANGE_INSTANTIATING diff --git a/Common/ImplicitArrays/vtkImplicitArray.h b/Common/Core/vtkImplicitArray.h similarity index 90% rename from Common/ImplicitArrays/vtkImplicitArray.h rename to Common/Core/vtkImplicitArray.h index 94b8f862338f2a041a201b807f05d72f06c5cac9..56b8ecbe4648ca4c5235588e1cf7f595ed355cf1 100644 --- a/Common/ImplicitArrays/vtkImplicitArray.h +++ b/Common/Core/vtkImplicitArray.h @@ -4,7 +4,7 @@ #ifndef vtkImplicitArray_h #define vtkImplicitArray_h -#include "vtkCommonImplicitArraysModule.h" // for export macro +#include "vtkCommonCoreModule.h" // for export macro #include "vtkGenericDataArray.h" #include "vtkImplicitArrayTraits.h" // for traits @@ -448,21 +448,6 @@ VTK_ABI_NAMESPACE_END #include "vtkImplicitArray.txx" -#define vtkInstantiateSecondOrderTemplateMacro(decl0, decl1) \ - decl0<decl1<float>>; \ - decl0<decl1<double>>; \ - decl0<decl1<char>>; \ - decl0<decl1<signed char>>; \ - decl0<decl1<unsigned char>>; \ - decl0<decl1<short>>; \ - decl0<decl1<unsigned short>>; \ - decl0<decl1<int>>; \ - decl0<decl1<unsigned int>>; \ - decl0<decl1<long>>; \ - decl0<decl1<unsigned long>>; \ - decl0<decl1<long long>>; \ - decl0<decl1<unsigned long long>> - #endif // vtkImplicitArray_h // See vtkGenericDataArray for similar section @@ -481,13 +466,13 @@ VTK_ABI_NAMESPACE_END // Needed to export for this module and not CmmonCore #define VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(ArrayType, ValueType) \ - template VTKCOMMONIMPLICITARRAYS_EXPORT bool DoComputeScalarRange( \ + template VTKCOMMONCORE_EXPORT bool DoComputeScalarRange( \ ArrayType*, ValueType*, vtkDataArrayPrivate::AllValues, const unsigned char*, unsigned char); \ - template VTKCOMMONIMPLICITARRAYS_EXPORT bool DoComputeScalarRange(ArrayType*, ValueType*, \ + template VTKCOMMONCORE_EXPORT bool DoComputeScalarRange(ArrayType*, ValueType*, \ vtkDataArrayPrivate::FiniteValues, const unsigned char*, unsigned char); \ - template VTKCOMMONIMPLICITARRAYS_EXPORT bool DoComputeVectorRange(ArrayType*, ValueType[2], \ + template VTKCOMMONCORE_EXPORT bool DoComputeVectorRange(ArrayType*, ValueType[2], \ vtkDataArrayPrivate::AllValues, const unsigned char*, unsigned char); \ - template VTKCOMMONIMPLICITARRAYS_EXPORT bool DoComputeVectorRange(ArrayType*, ValueType[2], \ + template VTKCOMMONCORE_EXPORT bool DoComputeVectorRange(ArrayType*, ValueType[2], \ vtkDataArrayPrivate::FiniteValues, const unsigned char*, unsigned char); #define VTK_INSTANTIATE_VALUERANGE_VALUETYPE(ValueType) \ @@ -539,14 +524,14 @@ VTK_ABI_NAMESPACE_END } // namespace vtkDataArrayPrivate #define VTK_DECLARE_VALUERANGE_ARRAYTYPE(ArrayType, ValueType) \ - extern template VTKCOMMONIMPLICITARRAYS_EXPORT bool DoComputeScalarRange( \ + extern template VTKCOMMONCORE_EXPORT bool DoComputeScalarRange( \ ArrayType*, ValueType*, vtkDataArrayPrivate::AllValues, const unsigned char*, unsigned char); \ - extern template VTKCOMMONIMPLICITARRAYS_EXPORT bool DoComputeScalarRange(ArrayType*, ValueType*, \ + extern template VTKCOMMONCORE_EXPORT bool DoComputeScalarRange(ArrayType*, ValueType*, \ vtkDataArrayPrivate::FiniteValues, const unsigned char*, unsigned char); \ - extern template VTKCOMMONIMPLICITARRAYS_EXPORT bool DoComputeVectorRange(ArrayType*, \ - ValueType[2], vtkDataArrayPrivate::AllValues, const unsigned char*, unsigned char); \ - extern template VTKCOMMONIMPLICITARRAYS_EXPORT bool DoComputeVectorRange(ArrayType*, \ - ValueType[2], vtkDataArrayPrivate::FiniteValues, const unsigned char*, unsigned char); + extern template VTKCOMMONCORE_EXPORT bool DoComputeVectorRange(ArrayType*, ValueType[2], \ + vtkDataArrayPrivate::AllValues, const unsigned char*, unsigned char); \ + extern template VTKCOMMONCORE_EXPORT bool DoComputeVectorRange(ArrayType*, ValueType[2], \ + vtkDataArrayPrivate::FiniteValues, const unsigned char*, unsigned char); #define VTK_DECLARE_VALUERANGE_VALUETYPE(ValueType) \ VTK_DECLARE_VALUERANGE_ARRAYTYPE( \ diff --git a/Common/ImplicitArrays/vtkImplicitArray.txx b/Common/Core/vtkImplicitArray.txx similarity index 100% rename from Common/ImplicitArrays/vtkImplicitArray.txx rename to Common/Core/vtkImplicitArray.txx diff --git a/Common/ImplicitArrays/vtkImplicitArrayTraits.h b/Common/Core/vtkImplicitArrayTraits.h similarity index 100% rename from Common/ImplicitArrays/vtkImplicitArrayTraits.h rename to Common/Core/vtkImplicitArrayTraits.h diff --git a/Common/ImplicitArrays/vtkIndexedArray.h b/Common/Core/vtkIndexedArray.h similarity index 55% rename from Common/ImplicitArrays/vtkIndexedArray.h rename to Common/Core/vtkIndexedArray.h index f631ff93f159220d7d6d89d4d7be816d5350293a..8aea92b09f4047ebe44afbd1a3be57271a1bcec9 100644 --- a/Common/ImplicitArrays/vtkIndexedArray.h +++ b/Common/Core/vtkIndexedArray.h @@ -9,7 +9,7 @@ #include "vtkDataArrayPrivate.txx" #endif -#include "vtkCommonImplicitArraysModule.h" // for export macro +#include "vtkCommonCoreModule.h" // for export macro #include "vtkImplicitArray.h" #include "vtkIndexedImplicitBackend.h" // for the array backend @@ -64,8 +64,7 @@ VTK_ABI_NAMESPACE_END #define VTK_INSTANTIATE_INDEXED_ARRAY(ValueType) \ VTK_ABI_NAMESPACE_BEGIN \ - template class VTKCOMMONIMPLICITARRAYS_EXPORT \ - vtkImplicitArray<vtkIndexedImplicitBackend<ValueType>>; \ + template class VTKCOMMONCORE_EXPORT vtkImplicitArray<vtkIndexedImplicitBackend<ValueType>>; \ VTK_ABI_NAMESPACE_END \ namespace vtkDataArrayPrivate \ { \ @@ -75,4 +74,52 @@ VTK_ABI_NAMESPACE_END VTK_ABI_NAMESPACE_END \ } +#elif defined(VTK_USE_EXTERN_TEMPLATE) +#ifndef VTK_INDEXED_ARRAY_TEMPLATE_EXTERN +#define VTK_INDEXED_ARRAY_TEMPLATE_EXTERN +#ifdef _MSC_VER +#pragma warning(push) +// The following is needed when the vtkIndexedArray is declared +// dllexport and is used from another class in vtkCommonCore +#pragma warning(disable : 4910) // extern and dllexport incompatible +#endif +VTK_ABI_NAMESPACE_BEGIN +vtkExternSecondOrderTemplateMacro( + extern template class VTKCOMMONCORE_EXPORT vtkImplicitArray, vtkIndexedImplicitBackend); +#ifdef _MSC_VER +#pragma warning(pop) +#endif +VTK_ABI_NAMESPACE_END +#endif // VTK_INDEXED_ARRAY_TEMPLATE_EXTERN +// The following clause is only for MSVC 2008 and 2010 +#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS) +#pragma warning(push) +// C4091: 'extern ' : ignored on left of 'int' when no variable is declared +#pragma warning(disable : 4091) + +// Compiler-specific extension warning. +#pragma warning(disable : 4231) + +// We need to disable warning 4910 and do an extern dllexport +// anyway. When deriving new arrays from an +// instantiation of this template the compiler does an explicit +// instantiation of the base class. From outside the vtkCommon +// library we block this using an extern dllimport instantiation. +// For classes inside vtkCommon we should be able to just do an +// extern instantiation, but VS 2008 complains about missing +// definitions. We cannot do an extern dllimport inside vtkCommon +// since the symbols are local to the dll. An extern dllexport +// seems to be the only way to convince VS 2008 to do the right +// thing, so we just disable the warning. +#pragma warning(disable : 4910) // extern and dllexport incompatible + +// Use an "extern explicit instantiation" to give the class a DLL +// interface. This is a compiler-specific extension. +VTK_ABI_NAMESPACE_BEGIN +vtkInstantiateSecondOrderTemplateMacro( + extern template class VTKCOMMONCORE_EXPORT vtkImplicitArray, vtkIndexedImplicitBackend); + +#pragma warning(pop) + +VTK_ABI_NAMESPACE_END #endif diff --git a/Common/ImplicitArrays/vtkIndexedArrayInstantiate.cxx.in b/Common/Core/vtkIndexedArrayInstantiate.cxx.in similarity index 100% rename from Common/ImplicitArrays/vtkIndexedArrayInstantiate.cxx.in rename to Common/Core/vtkIndexedArrayInstantiate.cxx.in diff --git a/Common/ImplicitArrays/vtkIndexedImplicitBackend.h b/Common/Core/vtkIndexedImplicitBackend.h similarity index 93% rename from Common/ImplicitArrays/vtkIndexedImplicitBackend.h rename to Common/Core/vtkIndexedImplicitBackend.h index a8ea24b07c39a0ecb1e568552df0365de95e4fd7..a57924dd181b660298bb57d632abe3f2cd898a18 100644 --- a/Common/ImplicitArrays/vtkIndexedImplicitBackend.h +++ b/Common/Core/vtkIndexedImplicitBackend.h @@ -42,7 +42,7 @@ * vtkImplicitArray, vtkIndexedArray */ -#include "vtkCommonImplicitArraysModule.h" +#include "vtkCommonCoreModule.h" #include <memory> @@ -50,7 +50,7 @@ VTK_ABI_NAMESPACE_BEGIN class vtkDataArray; class vtkIdList; template <typename ValueType> -class vtkIndexedImplicitBackend final +class VTKCOMMONCORE_EXPORT vtkIndexedImplicitBackend final { public: ///@{ @@ -81,6 +81,6 @@ VTK_ABI_NAMESPACE_END #ifdef VTK_INDEXED_BACKEND_INSTANTIATING #define VTK_INSTANTIATE_INDEXED_BACKEND(ValueType) \ VTK_ABI_NAMESPACE_BEGIN \ - template class VTKCOMMONIMPLICITARRAYS_EXPORT vtkIndexedImplicitBackend<ValueType>; \ + template class VTKCOMMONCORE_EXPORT vtkIndexedImplicitBackend<ValueType>; \ VTK_ABI_NAMESPACE_END #endif diff --git a/Common/ImplicitArrays/vtkIndexedImplicitBackend.txx b/Common/Core/vtkIndexedImplicitBackend.txx similarity index 82% rename from Common/ImplicitArrays/vtkIndexedImplicitBackend.txx rename to Common/Core/vtkIndexedImplicitBackend.txx index 9843f8ff251256bd7a5ad87166e66c68e2bd9a4e..c2800217d211a8292d4d73f06370679c0ec86863 100644 --- a/Common/ImplicitArrays/vtkIndexedImplicitBackend.txx +++ b/Common/Core/vtkIndexedImplicitBackend.txx @@ -3,7 +3,6 @@ #include "vtkIndexedImplicitBackend.h" #include "vtkArrayDispatch.h" -#include "vtkArrayDispatchImplicitArrayList.h" #include "vtkDataArrayRange.h" #include "vtkIdList.h" #include "vtkImplicitArray.h" @@ -11,8 +10,9 @@ #include <memory> -namespace +namespace vtkIndexedImplicitBackendDetail { +VTK_ABI_NAMESPACE_BEGIN //----------------------------------------------------------------------- template <typename ValueType> struct TypedArrayCache @@ -103,8 +103,8 @@ struct IdListWrapper vtkSmartPointer<vtkIdList> Handles; }; - -} +VTK_ABI_NAMESPACE_END +} // namespace vtkIndexedImplicitBackendDetail VTK_ABI_NAMESPACE_BEGIN //----------------------------------------------------------------------- @@ -112,7 +112,7 @@ template <typename ValueType> struct vtkIndexedImplicitBackend<ValueType>::Internals { using InternalArrayList = vtkTypeList::Append<vtkArrayDispatch::AllArrays, - vtkTypeList::Create<vtkImplicitArray<::IdListWrapper>>>::Result; + vtkTypeList::Create<vtkImplicitArray<vtkIndexedImplicitBackendDetail::IdListWrapper>>>::Result; Internals(vtkIdList* indexes, vtkDataArray* array) { @@ -121,8 +121,9 @@ struct vtkIndexedImplicitBackend<ValueType>::Internals vtkErrorWithObjectMacro(nullptr, "Either index array or array itself is nullptr"); return; } - vtkNew<vtkImplicitArray<::IdListWrapper>> newHandles; - newHandles->SetBackend(std::make_shared<IdListWrapper>(indexes)); + vtkNew<vtkImplicitArray<vtkIndexedImplicitBackendDetail::IdListWrapper>> newHandles; + newHandles->SetBackend( + std::make_shared<vtkIndexedImplicitBackendDetail::IdListWrapper>(indexes)); newHandles->SetNumberOfComponents(1); newHandles->SetNumberOfTuples(indexes->GetNumberOfIds()); this->Handles = this->TypeCacheArray<vtkIdType>(newHandles); @@ -147,18 +148,27 @@ struct vtkIndexedImplicitBackend<ValueType>::Internals } template <typename VT> - static vtkSmartPointer<vtkImplicitArray<::TypedCacheWrapper<InternalArrayList, VT>>> + static vtkSmartPointer< + vtkImplicitArray<vtkIndexedImplicitBackendDetail::TypedCacheWrapper<InternalArrayList, VT>>> TypeCacheArray(vtkDataArray* da) { - vtkNew<vtkImplicitArray<::TypedCacheWrapper<InternalArrayList, VT>>> wrapped; - wrapped->SetBackend(std::make_shared<::TypedCacheWrapper<InternalArrayList, VT>>(da)); + vtkNew< + vtkImplicitArray<vtkIndexedImplicitBackendDetail::TypedCacheWrapper<InternalArrayList, VT>>> + wrapped; + wrapped->SetBackend( + std::make_shared<vtkIndexedImplicitBackendDetail::TypedCacheWrapper<InternalArrayList, VT>>( + da)); wrapped->SetNumberOfComponents(1); wrapped->SetNumberOfTuples(da->GetNumberOfTuples() * da->GetNumberOfComponents()); return wrapped; } - vtkSmartPointer<vtkImplicitArray<::TypedCacheWrapper<InternalArrayList, ValueType>>> Array; - vtkSmartPointer<vtkImplicitArray<::TypedCacheWrapper<InternalArrayList, vtkIdType>>> Handles; + vtkSmartPointer<vtkImplicitArray< + vtkIndexedImplicitBackendDetail::TypedCacheWrapper<InternalArrayList, ValueType>>> + Array; + vtkSmartPointer<vtkImplicitArray< + vtkIndexedImplicitBackendDetail::TypedCacheWrapper<InternalArrayList, vtkIdType>>> + Handles; }; //----------------------------------------------------------------------- diff --git a/Common/ImplicitArrays/vtkIndexedImplicitBackendInstantiate.cxx.in b/Common/Core/vtkIndexedImplicitBackendInstantiate.cxx.in similarity index 100% rename from Common/ImplicitArrays/vtkIndexedImplicitBackendInstantiate.cxx.in rename to Common/Core/vtkIndexedImplicitBackendInstantiate.cxx.in diff --git a/Common/ImplicitArrays/vtkStdFunctionArray.h b/Common/Core/vtkStdFunctionArray.h similarity index 50% rename from Common/ImplicitArrays/vtkStdFunctionArray.h rename to Common/Core/vtkStdFunctionArray.h index ff5a7972ce2578b0bb8891857ed7073baa7042ce..3bf1a4cb820eecfafdc96dc734879102aedb2280 100644 --- a/Common/ImplicitArrays/vtkStdFunctionArray.h +++ b/Common/Core/vtkStdFunctionArray.h @@ -9,7 +9,7 @@ #include "vtkDataArrayPrivate.txx" #endif -#include "vtkCommonImplicitArraysModule.h" // for export macro +#include "vtkCommonCoreModule.h" // for export macro #include "vtkImplicitArray.h" #ifdef VTK_STD_FUNCTION_ARRAY_INSTANTIATING @@ -45,7 +45,7 @@ VTK_ABI_NAMESPACE_END #define VTK_INSTANTIATE_STD_FUNCTION_ARRAY(ValueType) \ VTK_ABI_NAMESPACE_BEGIN \ - template class VTKCOMMONIMPLICITARRAYS_EXPORT vtkImplicitArray<std::function<ValueType(int)>>; \ + template class VTKCOMMONCORE_EXPORT vtkImplicitArray<std::function<ValueType(int)>>; \ VTK_ABI_NAMESPACE_END \ namespace vtkDataArrayPrivate \ { \ @@ -53,4 +53,52 @@ VTK_ABI_NAMESPACE_END VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkImplicitArray<std::function<ValueType(int)>>, double) \ VTK_ABI_NAMESPACE_END \ } +#elif defined(VTK_USE_EXTERN_TEMPLATE) +#ifndef VTK_STD_FUNCTION_ARRAY_TEMPLATE_EXTERN +#define VTK_STD_FUNCTION_ARRAY_TEMPLATE_EXTERN +#ifdef _MSC_VER +#pragma warning(push) +// The following is needed when the vtkAffineArray is declared +// dllexport and is used from another class in vtkCommonCore +#pragma warning(disable : 4910) // extern and dllexport incompatible +#endif +VTK_ABI_NAMESPACE_BEGIN +vtkExternStdFunctionTemplateMacro( + extern template class VTKCOMMONCORE_EXPORT vtkImplicitArray, std::function, int); +#ifdef _MSC_VER +#pragma warning(pop) +#endif +VTK_ABI_NAMESPACE_END +#endif // VTK_STD_FUNCTION_ARRAY_TEMPLATE_EXTERN +// The following clause is only for MSVC 2008 and 2010 +#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS) +#pragma warning(push) +// C4091: 'extern ' : ignored on left of 'int' when no variable is declared +#pragma warning(disable : 4091) + +// Compiler-specific extension warning. +#pragma warning(disable : 4231) + +// We need to disable warning 4910 and do an extern dllexport +// anyway. When deriving new arrays from an +// instantiation of this template the compiler does an explicit +// instantiation of the base class. From outside the vtkCommon +// library we block this using an extern dllimport instantiation. +// For classes inside vtkCommon we should be able to just do an +// extern instantiation, but VS 2008 complains about missing +// definitions. We cannot do an extern dllimport inside vtkCommon +// since the symbols are local to the dll. An extern dllexport +// seems to be the only way to convince VS 2008 to do the right +// thing, so we just disable the warning. +#pragma warning(disable : 4910) // extern and dllexport incompatible + +// Use an "extern explicit instantiation" to give the class a DLL +// interface. This is a compiler-specific extension. +VTK_ABI_NAMESPACE_BEGIN +vtkInstantiateStdFunctionTemplateMacro( + extern template class VTKCOMMONCORE_EXPORT vtkImplicitArray, std::function, int); + +#pragma warning(pop) + +VTK_ABI_NAMESPACE_END #endif diff --git a/Common/ImplicitArrays/vtkStdFunctionArrayInstantiate.cxx.in b/Common/Core/vtkStdFunctionArrayInstantiate.cxx.in similarity index 100% rename from Common/ImplicitArrays/vtkStdFunctionArrayInstantiate.cxx.in rename to Common/Core/vtkStdFunctionArrayInstantiate.cxx.in diff --git a/Common/Core/vtkType.h b/Common/Core/vtkType.h index e76d875c4f5cd6037c5da0f8833c3d75b429caef..b45d33fb8e25b4f113a91fb39d082519b90104e8 100644 --- a/Common/Core/vtkType.h +++ b/Common/Core/vtkType.h @@ -56,7 +56,7 @@ #define VTK_OBJECT 21 // deleted value -//#define VTK_UNICODE_STRING 22 <==== do not use +// #define VTK_UNICODE_STRING 22 <==== do not use /*--------------------------------------------------------------------------*/ /* Define a unique integer identifier for each vtkDataObject type. */ @@ -375,11 +375,47 @@ VTK_ABI_NAMESPACE_END decl<long long>; \ decl<unsigned long long> +#define vtkInstantiateSecondOrderTemplateMacro(decl0, decl1) \ + decl0<decl1<float>>; \ + decl0<decl1<double>>; \ + decl0<decl1<char>>; \ + decl0<decl1<signed char>>; \ + decl0<decl1<unsigned char>>; \ + decl0<decl1<short>>; \ + decl0<decl1<unsigned short>>; \ + decl0<decl1<int>>; \ + decl0<decl1<unsigned int>>; \ + decl0<decl1<long>>; \ + decl0<decl1<unsigned long>>; \ + decl0<decl1<long long>>; \ + decl0<decl1<unsigned long long>> + +#define vtkInstantiateStdFunctionTemplateMacro(decl0, decl1, delc2) \ + decl0<decl1<float(delc2)>>; \ + decl0<decl1<double(delc2)>>; \ + decl0<decl1<char(delc2)>>; \ + decl0<decl1<signed char(delc2)>>; \ + decl0<decl1<unsigned char(delc2)>>; \ + decl0<decl1<short(delc2)>>; \ + decl0<decl1<unsigned short(delc2)>>; \ + decl0<decl1<int(delc2)>>; \ + decl0<decl1<unsigned int(delc2)>>; \ + decl0<decl1<long(delc2)>>; \ + decl0<decl1<unsigned long(delc2)>>; \ + decl0<decl1<long long(delc2)>>; \ + decl0<decl1<unsigned long long(delc2)>> + /** A macro to declare extern templates for all numerical types */ #ifdef VTK_USE_EXTERN_TEMPLATE #define vtkExternTemplateMacro(decl) vtkInstantiateTemplateMacro(decl) +#define vtkExternSecondOrderTemplateMacro(decl0, decl1) \ + vtkInstantiateSecondOrderTemplateMacro(decl0, decl1) +#define vtkExternStdFunctionTemplateMacro(decl0, decl1, decl2) \ + vtkInstantiateStdFunctionTemplateMacro(decl0, decl1, decl2) #else #define vtkExternTemplateMacro(decl) +#define vtkExternSecondOrderTemplateMacro(decl0, decl1) +#define vtkExternStdFunctionTemplateMacro(decl0, decl1, decl2) #endif #endif diff --git a/Common/ImplicitArrays/vtkVTK_DISPATCH_IMPLICIT_ARRAYS.h.in b/Common/Core/vtkVTK_DISPATCH_IMPLICIT_ARRAYS.h.in similarity index 100% rename from Common/ImplicitArrays/vtkVTK_DISPATCH_IMPLICIT_ARRAYS.h.in rename to Common/Core/vtkVTK_DISPATCH_IMPLICIT_ARRAYS.h.in diff --git a/Common/ImplicitArrays/CMakeLists.txt b/Common/ImplicitArrays/CMakeLists.txt deleted file mode 100644 index 38fba25061122aee5964b2f9c52c90a8cbc6c1cf..0000000000000000000000000000000000000000 --- a/Common/ImplicitArrays/CMakeLists.txt +++ /dev/null @@ -1,89 +0,0 @@ -option(VTK_DISPATCH_AFFINE_ARRAYS "Include implicit vtkDataArray subclasses based on an affine function backend in dispatcher" OFF) -option(VTK_DISPATCH_COMPOSITE_ARRAYS "Include implicit vtkDataArray subclasses based on a composite binary tree backend in dispatcher" OFF) -option(VTK_DISPATCH_CONSTANT_ARRAYS "Include implicit vtkDataArray subclasses based on a constant backend in dispatcher" OFF) -option(VTK_DISPATCH_INDEXED_ARRAYS "Include implicit vtkDataArray subclasses based on an index referencing backend in dispatcher" OFF) -option(VTK_DISPATCH_STD_FUNCTION_ARRAYS "Include implicit vtkDataArray subclasses based on std::function in dispatcher" OFF) -mark_as_advanced( - VTK_DISPATCH_AFFINE_ARRAYS - VTK_DISPATCH_COMPOSITE_ARRAYS - VTK_DISPATCH_CONSTANT_ARRAYS - VTK_DISPATCH_INDEXED_ARRAYS - VTK_DISPATCH_STD_FUNCTION_ARRAYS -) - -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/vtkVTK_DISPATCH_IMPLICIT_ARRAYS.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/vtkVTK_DISPATCH_IMPLICIT_ARRAYS.h" - @ONLY) - - -include("${CMAKE_CURRENT_SOURCE_DIR}/vtkCreateArrayDispatchImplicitList.cmake") -vtkArrayDispatchImplicit_default_array_setup() -vtkArrayDispatchImplicit_generate_array_header(VTK_ARRAYDISPATCH_IMPLICIT_ARRAY_LIST) -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/vtkArrayDispatchImplicitArrayList.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/vtkArrayDispatchImplicitArrayList.h" - @ONLY) - -set(instantiation_sources) -foreach (INSTANTIATION_VALUE_TYPE IN LISTS vtkArrayDispatchImplicit_all_types) - # only instantiate fundamental types, not typedefs - if (INSTANTIATION_VALUE_TYPE STREQUAL "vtkIdType") - continue() - endif () - # create a file suffix from the type - string(REPLACE " " "_" _suffix "${INSTANTIATION_VALUE_TYPE}") - - list(APPEND _list "vtkAffineArrayInstantiate") - list(APPEND _list "vtkCompositeArrayInstantiate") - list(APPEND _list "vtkCompositeImplicitBackendInstantiate") - list(APPEND _list "vtkConstantArrayInstantiate") - list(APPEND _list "vtkIndexedArrayInstantiate") - list(APPEND _list "vtkIndexedImplicitBackendInstantiate") - list(APPEND _list "vtkStdFunctionArrayInstantiate") - - # generate cxx file to instantiate template with this type - foreach (_prefix IN LISTS _list) - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/${_prefix}.cxx.in" - "${CMAKE_CURRENT_BINARY_DIR}/${_prefix}_${_suffix}.cxx" - @ONLY) - list(APPEND instantiation_sources - "${CMAKE_CURRENT_BINARY_DIR}/${_prefix}_${_suffix}.cxx") - endforeach () -endforeach () - -set(nowrap_headers - vtkAffineArray.h - vtkAffineImplicitBackend.h - vtkCompositeArray.h - vtkConstantArray.h - vtkConstantImplicitBackend.h - vtkImplicitArrayTraits.h - vtkIndexedArray.h - vtkStdFunctionArray.h - "${CMAKE_CURRENT_BINARY_DIR}/vtkVTK_DISPATCH_IMPLICIT_ARRAYS.h" - "${CMAKE_CURRENT_BINARY_DIR}/vtkArrayDispatchImplicitArrayList.h" -) - -set(nowrap_template_classes - vtkImplicitArray - vtkCompositeImplicitBackend - vtkIndexedImplicitBackend -) - -set(sources - ${instantiation_sources} -) - -vtk_module_add_module(VTK::CommonImplicitArrays - NOWRAP_HEADERS ${nowrap_headers} - NOWRAP_TEMPLATE_CLASSES ${nowrap_template_classes} - SOURCES ${sources} -) - -vtk_add_test_mangling(VTK::CommonImplicitArrays) - -vtk_module_compile_features(VTK::CommonImplicitArrays - PUBLIC - cxx_std_11) diff --git a/Common/ImplicitArrays/Testing/CMakeLists.txt b/Common/ImplicitArrays/Testing/CMakeLists.txt deleted file mode 100644 index 35f9732a938a3b073bdf94e86007916ffcd31b49..0000000000000000000000000000000000000000 --- a/Common/ImplicitArrays/Testing/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(Cxx) diff --git a/Common/ImplicitArrays/Testing/Cxx/CMakeLists.txt b/Common/ImplicitArrays/Testing/Cxx/CMakeLists.txt deleted file mode 100644 index b3010bb0ec25943aa4236cdea98bd1a8f3b18a14..0000000000000000000000000000000000000000 --- a/Common/ImplicitArrays/Testing/Cxx/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -vtk_add_test_cxx(vtkCommonImplicitArrayCxxTests tests - NO_DATA NO_OUTPUT NO_VALID - TestAffineArray.cxx - TestCompositeArray.cxx - TestCompositeImplicitBackend.cxx - TestConstantArray.cxx - TestImplicitArraysBase.cxx - TestImplicitArrayTraits.cxx - TestIndexedArray.cxx - TestIndexedImplicitBackend.cxx - TestStdFunctionArray.cxx -) - -vtk_test_cxx_executable(vtkCommonImplicitArrayCxxTests tests) diff --git a/Common/ImplicitArrays/vtk.module b/Common/ImplicitArrays/vtk.module deleted file mode 100644 index e928808ca7420fd69dc2666a451ce3487909ee74..0000000000000000000000000000000000000000 --- a/Common/ImplicitArrays/vtk.module +++ /dev/null @@ -1,18 +0,0 @@ -NAME - VTK::CommonImplicitArrays -LIBRARY_NAME - vtkCommonImplicitArrays -DESCRIPTION - A VTK module for the vtkImplicitArray framework -KIT - VTK::Common -GROUPS - StandAlone -SPDX_LICENSE_IDENTIFIER - BSD-3-Clause -SPDX_COPYRIGHT_TEXT - Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -DEPENDS - VTK::CommonCore -TEST_DEPENDS - VTK::TestingCore diff --git a/Common/ImplicitArrays/vtkAffineArray.h b/Common/ImplicitArrays/vtkAffineArray.h deleted file mode 100644 index df4d51435540ebe53732ac1a68a488ec68d8abf6..0000000000000000000000000000000000000000 --- a/Common/ImplicitArrays/vtkAffineArray.h +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -// SPDX-License-Identifier: BSD-3-Clause -// Funded by CEA, DAM, DIF, F-91297 Arpajon, France -#ifndef vtkAffineArray_h -#define vtkAffineArray_h - -#ifdef VTK_AFFINE_ARRAY_INSTANTIATING -#define VTK_IMPLICIT_VALUERANGE_INSTANTIATING -#include "vtkDataArrayPrivate.txx" -#endif - -#include "vtkAffineImplicitBackend.h" // for the array backend -#include "vtkCommonImplicitArraysModule.h" // for export macro -#include "vtkImplicitArray.h" - -#ifdef VTK_AFFINE_ARRAY_INSTANTIATING -#undef VTK_IMPLICIT_VALUERANGE_INSTANTIATING -#endif - -/** - * \var vtkAffineArray - * \brief A utility alias for wrapping affine functions in implicit arrays - * - * In order to be usefully included in the dispatchers, these arrays need to be instantiated at the - * vtk library compile time. - * - * @sa - * vtkImplicitArray vtkAffineImplicitBackend - */ - -VTK_ABI_NAMESPACE_BEGIN -template <typename T> -using vtkAffineArray = vtkImplicitArray<vtkAffineImplicitBackend<T>>; -VTK_ABI_NAMESPACE_END - -#endif // vtkAffineArray_h - -#ifdef VTK_AFFINE_ARRAY_INSTANTIATING - -#define VTK_INSTANTIATE_AFFINE_ARRAY(ValueType) \ - VTK_ABI_NAMESPACE_BEGIN \ - template class VTKCOMMONIMPLICITARRAYS_EXPORT \ - vtkImplicitArray<vtkAffineImplicitBackend<ValueType>>; \ - VTK_ABI_NAMESPACE_END \ - namespace vtkDataArrayPrivate \ - { \ - VTK_ABI_NAMESPACE_BEGIN \ - VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE( \ - vtkImplicitArray<vtkAffineImplicitBackend<ValueType>>, double) \ - VTK_ABI_NAMESPACE_END \ - } -#endif diff --git a/Common/ImplicitArrays/vtkArrayDispatchImplicitArrayList.h.in b/Common/ImplicitArrays/vtkArrayDispatchImplicitArrayList.h.in deleted file mode 100644 index 0b5fdca75270df4789d573d790f247f4227be248..0000000000000000000000000000000000000000 --- a/Common/ImplicitArrays/vtkArrayDispatchImplicitArrayList.h.in +++ /dev/null @@ -1 +0,0 @@ -@VTK_ARRAYDISPATCH_IMPLICIT_ARRAY_LIST@ diff --git a/Common/ImplicitArrays/vtkConstantArray.h b/Common/ImplicitArrays/vtkConstantArray.h deleted file mode 100644 index 9e2628cbe582e88ba6aaf86a7e8d66fae335086c..0000000000000000000000000000000000000000 --- a/Common/ImplicitArrays/vtkConstantArray.h +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen -// SPDX-License-Identifier: BSD-3-Clause -// Funded by CEA, DAM, DIF, F-91297 Arpajon, France -#ifndef vtkConstantArray_h -#define vtkConstantArray_h - -#ifdef VTK_CONSTANT_ARRAY_INSTANTIATING -#define VTK_IMPLICIT_VALUERANGE_INSTANTIATING -#include "vtkDataArrayPrivate.txx" -#endif - -#include "vtkCommonImplicitArraysModule.h" // for export macro -#include "vtkConstantImplicitBackend.h" // for the array backend -#include "vtkImplicitArray.h" - -#ifdef VTK_CONSTANT_ARRAY_INSTANTIATING -#undef VTK_IMPLICIT_VALUERANGE_INSTANTIATING -#endif - -/** - * \var vtkConstantArray - * \brief A utility alias for wrapping constant functions in implicit arrays - * - * In order to be usefully included in the dispatchers, these arrays need to be instantiated at the - * vtk library compile time. - * - * @sa - * vtkImplicitArray vtkConstantImplicitBackend - */ - -VTK_ABI_NAMESPACE_BEGIN -template <typename T> -using vtkConstantArray = vtkImplicitArray<vtkConstantImplicitBackend<T>>; -VTK_ABI_NAMESPACE_END - -#endif // vtkConstantArray_h - -#ifdef VTK_CONSTANT_ARRAY_INSTANTIATING - -#define VTK_INSTANTIATE_CONSTANT_ARRAY(ValueType) \ - VTK_ABI_NAMESPACE_BEGIN \ - template class VTKCOMMONIMPLICITARRAYS_EXPORT \ - vtkImplicitArray<vtkConstantImplicitBackend<ValueType>>; \ - VTK_ABI_NAMESPACE_END \ - namespace vtkDataArrayPrivate \ - { \ - VTK_ABI_NAMESPACE_BEGIN \ - VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE( \ - vtkImplicitArray<vtkConstantImplicitBackend<ValueType>>, double) \ - VTK_ABI_NAMESPACE_END \ - } -#endif diff --git a/Common/ImplicitArrays/vtkCreateArrayDispatchImplicitList.cmake b/Common/ImplicitArrays/vtkCreateArrayDispatchImplicitList.cmake deleted file mode 100644 index 3e770f8ff26bb5a23a5aa9cae9048c8f374dcc2d..0000000000000000000000000000000000000000 --- a/Common/ImplicitArrays/vtkCreateArrayDispatchImplicitList.cmake +++ /dev/null @@ -1,217 +0,0 @@ -# This file contains macros that are used by VTK to generate the list of -# implicit arrays used by the vtkArrayDispatch system. -# -# There are a number of CMake variables that control the final array list. At -# the high level, the following options enable/disable predefined categories of -# arrays: -# -# - VTK_DISPATCH_AFFINE_ARRAYS (default: OFF) -# Include vtkAffineArray<ValueType> for the basic types supported -# by VTK. -# - VTK_DISPATCH_CONSTANT_ARRAYS (default: OFF) -# Include vtkConstantArray<ValueType> for the basic types supported -# by VTK. -# - VTK_DISPATCH_STD_FUNCTION_ARRAYS (default: OFF) -# Include vtkStdFunctionArray<ValueType> for the basic types supported -# by VTK. -# -# At a lower level, specific arrays can be added to the list individually in -# two ways: -# -# For templated classes, set the following variables: -# - vtkArrayDispatchImplicit_containers: -# List of template class names. -# - vtkArrayDispatchImplicit_[template class name]_types: -# For the specified template class, add an entry to the array list that -# instantiates the container for each type listed here. -# - vtkArrayDispatchImplicit_[template class name]_header -# Specifies the header file to include for the specified template class. -# -# Both templated and non-templated arrays can be added using these variables: -# - vtkArrayDispatchImplicit_extra_arrays: -# List of arrays to add to the list. -# - vtkArrayDispatchImplicit_extra_headers: -# List of headers to include. -# -################################ Example ####################################### -# -# The cmake call below instantiates the array list that follows: -# -# cmake [path to VTK source] -# -DvtkArrayDispatchImplicit_containers="MyCustomArray1;MyCustomArray2" -# -DvtkArrayDispatchImplicit_MyCustomArray1_header="MyCustomArray1.h" -# -DvtkArrayDispatchImplicit_MyCustomArray1_types="float;double" -# -DvtkArrayDispatchImplicit_MyCustomArray2_header="MyCustomArray2.h" -# -DvtkArrayDispatchImplicit_MyCustomArray2_types="int;unsigned char" -# -DvtkArrayDispatchImplicit_extra_headers="ExtraHeader1.h;ExtraHeader2.h" -# -DvtkArrayDispatchImplicit_extra_arrays="ExtraArray1;ExtraArray2<float>;ExtraArray2<char>" -# -# Generated header: -# -# #ifndef vtkArrayDispatchImplicitArrayList_h -# #define vtkArrayDispatchImplicitArrayList_h -# -# #include "vtkTypeList.h" -# #include "MyCustomArray1.h" -# #include "MyCustomArray2.h" -# #include "ExtraHeader1.h" -# #include "ExtraHeader2.h" -# #include "vtkArrayDispatchArrayList.h" -# -# namespace vtkArrayDispatch { -# -# VTK_ABI_NAMESPACE_BEGIN -# -# typedef vtkTypeList::Unique< -# vtkTypeListvtkTypeList::Create< -# MyCustomArray1<float>, -# MyCustomArray1<double>, -# MyCustomArray2<int>, -# MyCustomArray2<unsigned char>, -# ExtraArray1, -# ExtraArray2<float>, -# ExtraArray2<char> -# > -# >::Result ReadOnlyArrays; -# -# typedef vtkTypeList::Unique< vtkTypeList::TypeList<Arrays, ReadOnlyArrays> >::Result AllArrays; -# -# VTK_ABI_NAMESPACE_END -# -# } // end namespace vtkArrayDispatch -# -# #endif // vtkArrayDispatchImplicitArrayList_h -# - -# Populate the environment so that vtk_array_dispatch_generate_array_header will -# create the array TypeList with all known array types. -macro(vtkArrayDispatchImplicit_default_array_setup) - -# The default set of scalar types: -set(vtkArrayDispatchImplicit_all_types - "char" - "double" - "float" - "int" - "long" - "long long" - "short" - "signed char" - "unsigned char" - "unsigned int" - "unsigned long" - "unsigned long long" - "unsigned short" - "vtkIdType" -) - -if (VTK_DISPATCH_STD_FUNCTION_ARRAYS) - list(APPEND vtkArrayDispatchImplicit_containers vtkStdFunctionArray) - set(vtkArrayDispatchImplicit_vtkStdFunctionArray_header vtkStdFunctionArray.h) - set(vtkArrayDispatchImplicit_vtkStdFunctionArray_types - ${vtkArrayDispatchImplicit_all_types} - ) -endif() - -if (VTK_DISPATCH_CONSTANT_ARRAYS) - list(APPEND vtkArrayDispatchImplicit_containers vtkConstantArray) - set(vtkArrayDispatchImplicit_vtkConstantArray_header vtkConstantArray.h) - set(vtkArrayDispatchImplicit_vtkConstantArray_types - ${vtkArrayDispatchImplicit_all_types} - ) -endif() - -if (VTK_DISPATCH_AFFINE_ARRAYS) - list(APPEND vtkArrayDispatchImplicit_containers vtkAffineArray) - set(vtkArrayDispatchImplicit_vtkAffineArray_header vtkAffineArray.h) - set(vtkArrayDispatchImplicit_vtkAffineArray_types - ${vtkArrayDispatchImplicit_all_types} - ) -endif() - -if (VTK_DISPATCH_COMPOSITE_ARRAYS) - list(APPEND vtkArrayDispatchImplicit_containers vtkCompositeArray) - set(vtkArrayDispatchImplicit_vtkCompositeArray_header vtkCompositeArray.h) - set(vtkArrayDispatchImplicit_vtkCompositeArray_types - ${vtkArrayDispatchImplicit_all_types} - ) -endif() - -if (VTK_DISPATCH_INDEXED_ARRAYS) - list(APPEND vtkArrayDispatchImplicit_containers vtkIndexedArray) - set(vtkArrayDispatchImplicit_vtkIndexedArray_header vtkIndexedArray.h) - set(vtkArrayDispatchImplicit_vtkIndexedArray_types - ${vtkArrayDispatchImplicit_all_types} - ) -endif() - -endmacro() - -# Create a header that declares the vtkArrayDispatch::Arrays TypeList. -macro(vtkArrayDispatchImplicit_generate_array_header result) - -set(vtkAD_headers vtkTypeList.h) -list(APPEND vtkAD_headers vtkArrayDispatchArrayList.h) -set(vtkAD_arrays) -foreach(container ${vtkArrayDispatchImplicit_containers}) - list(APPEND vtkAD_headers ${vtkArrayDispatchImplicit_${container}_header}) - foreach(value_type ${vtkArrayDispatchImplicit_${container}_types}) - list(APPEND vtkAD_arrays "${container}<${value_type}>") - endforeach() -endforeach() - -# Include externally specified headers/arrays: -list(APPEND vtkAD_headers ${vtkArrayDispatchImplicit_extra_headers}) -list(APPEND vtkAD_arrays ${vtkArrayDispatchImplicit_extra_arrays}) - -set(temp - "// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen\n" - "// SPDX-License-Identifier: BSD-3-Clause\n" - "// This file is autogenerated by vtkCreateArrayDispatchImplicitList.cmake.\n" - "// Do not edit this file. Your changes will not be saved.\n" - "// Funded by CEA, DAM, DIF, F-91297 Arpajon, France\n" - "\n" - "#ifndef vtkArrayDispatchImplicitArrayList_h\n" - "#define vtkArrayDispatchImplicitArrayList_h\n" - "\n" -) - -foreach(header ${vtkAD_headers}) - list(APPEND temp "#include \"${header}\"\n") -endforeach() - -list(APPEND temp - "\n" - "namespace vtkArrayDispatch {\n" - "VTK_ABI_NAMESPACE_BEGIN\n" - "\n" - "typedef vtkTypeList::Unique<\n" - " vtkTypeList::Create<\n" -) - -foreach(array ${vtkAD_arrays}) - list(APPEND temp " ${array},\n") -endforeach() - -# Remove the final comma from the array list: -string(CONCAT temp ${temp}) -string(REGEX REPLACE ",\n$" "\n" temp "${temp}") - -list(APPEND temp - " >\n" - ">::Result ReadOnlyArrays\;\n" - "\n" - "typedef vtkTypeList::Unique<\n" - "vtkTypeList::Append<Arrays,\n" - "ReadOnlyArrays>::Result\n" - ">::Result AllArrays\;\n" - "\n" - "VTK_ABI_NAMESPACE_END\n" - "\n" - "} // end namespace vtkArrayDispatch\n" - "#endif // vtkArrayDispatchImplicitArrayList_h\n" -) - -string(CONCAT ${result} ${temp}) - -endmacro() diff --git a/Documentation/docs/build_instructions/build_settings.md b/Documentation/docs/build_instructions/build_settings.md index 0e36e5cb69ddb3ae98fea0d013e20c12ece4d72a..a62153f5a1c09767f5669a1ad411aaa18d9eab51 100644 --- a/Documentation/docs/build_instructions/build_settings.md +++ b/Documentation/docs/build_instructions/build_settings.md @@ -212,9 +212,8 @@ More advanced options: The `VTK_DISPATCH_<array_type>_ARRAYS` options (default `OFF` for all but AOS) enable the specified type of array to be included in a dispatch type list. Explicit arrays (such as -AOS, SOA and Typed) are included in the `vtkArrayDispatchTypeList.h` while -`vtkArrayDispatchImplicitTypeList.h` includes both explicit and implicit arrays. The implicit -array framework is included in the `CommonImplicitArrays` module. The following array types +AOS, SOA, Typed, and implicit arrays) are included in the `vtkArrayDispatchTypeList.h` +The implicit array framework is included in the `CommonCore` module. The following array types currently exist for use with the VTK dispatch mechanism: * `VTK_DISPATCH_AOS_ARRAYS` (default `ON`): includes dispatching for the commonly used diff --git a/Documentation/release/9.3.md b/Documentation/release/9.3.md index 65488d787fdaab9169937039fb17a78f5757ac08..b07b3c7b5d63eb4315302ad513fe207b600a7c93 100644 --- a/Documentation/release/9.3.md +++ b/Documentation/release/9.3.md @@ -329,7 +329,7 @@ Changes made since VTK 9.2.0 include the following. - Improved performance of `vtkUnstructuredGrid`'s `IsCellBoundary`/`GetCellNeighbors` methods. - Improved stability of `vtkCellLocator::FindClosestPointWithinRadius`. -[add-vtkImplicitArrays]: https://gitlab.kitware.com/vtk/vtk/-/blob/722365c58bbe829014a6272cf2f55364d68fb0b6/Documentation/release/dev/add-vtkImplicitArrays.md +[add-vtkImplicitArrays]: https://gitlab.kitware.com/vtk/vtk/-/blob/v9.2.0.rc2/Documentation/release/dev/add-vtkImplicitArrays.md [](#new-features-documentation) ### Documentation diff --git a/Documentation/release/dev/add-vtkImplicitArrays.md b/Documentation/release/dev/add-vtkImplicitArrays.md new file mode 100644 index 0000000000000000000000000000000000000000..ac589c38012b05025eac893ea559a8d3b51a4a46 --- /dev/null +++ b/Documentation/release/dev/add-vtkImplicitArrays.md @@ -0,0 +1,221 @@ +## New vtkImplicitArrays! + +### Description + +VTK now offers new flexible `vtkImplicitArray` template class that implements a **read-only** `vtkGenericDataArray` interface. It essentially transforms an implicit function mapping integers to values into a practically zero cost `vtkDataArray`. This is helpful in cases where one needs to attach data to data sets and memory efficiency is paramount. + +### Philosophy + +In order to reduce the overhead of these containers as much as possible, `vtkImplicitArray`s are templated on a "Backend" type. This backend is "duck typed" so that it can be any const functor/closure object or anything that has a `map(int) const` method to provide a certain degree of flexibility and compute performance that is easily obtained through the static dispatching native to templates. If a `void mapTuple(vtkIdType, TupleType*) const` method is also present, the array will use this method to populate the tuple instead of the map method. If a `ValueType mapComponent(vtkIdType, int) const` method is also present, the array will use this method to populate the GetTypedComponent function instead of the map method. As such, developers can use tried and tested backends in the VTK framework when it fits their needs and also develop their own backends on the fly for specific use cases. `vtkImplicitArray`s can then be packed into data sets to be transmitted through the data treatment pipeline with the idea that calls to the "read-only" API of `vtkGenericDataArray` should be inlined through the implicit array and generate close to zero overhead with respect to calling the backend itself. + +### Usage + +Here is a small example using a constant functor in an implicit array: + +``` +struct ConstBackend +{ + int operator()(int vtkNotUsed(idx)) const { return 42; }; +}; + +vtkNew<vtkImplicitArray<ConstBackend>> arr42; +arr42->SetNumberOfComponents(1); +arr42->SetNumberOfTuples(100); +CHECK(arr42->GetValue(77) == 42); // always true +``` + +Here is a small example using map and mapTuple methods in an implicit array: + +``` +struct ConstTupleStruct +{ + int Tuple[3] = { 0, 0, 0 }; + + ConstTupleStruct(int tuple[3]) + { + this->Tuple[0] = tuple[0]; + this->Tuple[1] = tuple[1]; + this->Tuple[2] = tuple[2]; + } + + // used for GetValue + int map(int idx) const + { + int tuple[3]; + this->mapTuple(idx / 3, tuple); + return tuple[idx % 3]; + } + // used for GetTypedTuple + void mapTuple(int vtkNotUsed(idx), int* tuple) const + { + tuple[0] = this->Tuple[0]; + tuple[1] = this->Tuple[1]; + tuple[2] = this->Tuple[2]; + } +}; + +vtkNew<vtkImplicitArray<ConstTupleStruct>> mapTupleArr; +int tuple[3] = { 1, 2, 3 }; +mapTupleArr->ConstructBackend(tuple); +mapTupleArr->SetNumberOfComponents(3); +mapTupleArr->SetNumberOfTuples(100); +int tuple[3] = { 0, 0, 0 }; +mapTupleArr->GetTypedTuple(77, tuple); +CHECK(tuple[0] == 1 && tuple[1] == 2 && tuple[2] == 3); // always true +``` + +Here is a small example using map and mapComponent methods in an implicit array: + +``` +struct ConstComponentStruct +{ + int Tuple[3] = { 0, 0, 0 }; + + ConstComponentStruct(int tuple[3]) + { + this->Tuple[0] = tuple[0]; + this->Tuple[1] = tuple[1]; + this->Tuple[2] = tuple[2]; + } + + // used for GetValue + int map(int idx) const { return this->mapComponent(idx / 3, idx % 3); } + // used for GetTypedComponent + int mapComponent(int vtkNotUsed(idx), int comp) const { return this->Tuple[comp]; } +}; + +vtkNew<vtkImplicitArray<::ConstComponentStruct>> genericComponentConstArr; +int tuple[3] = { 1, 2, 3 }; +genericComponentConstArr->ConstructBackend(tuple); +genericComponentConstArr->SetNumberOfComponents(3); +genericComponentConstArr->SetNumberOfTuples(50); +CHECK(genericComponentConstArr->GetTypeComponent(0, 0) == 1 && genericComponentConstArr->GetTypeComponent(0, 1) == 2 && genericComponentConstArr->GetTypeComponent(0, 2) == 3); // always true +``` + +For convenience, a number of backends have been pre-packed into the `vtkImplicitArray` framework. They are, in alphabetical order: + +- `vtkAffineArray<ValueType>`: using the `vtkAffineImplicitBackend<ValueType>` closure backend that gets constructed with a slope and intercept and then returns values linearly depending on the queried index +- `vtkCompositeArray<ValueType>`: using the `vtkCompositeImplicitBackend<ValueType>` closure backend that takes an `std::vector<vtkDataArray*>` at construction and returns values as if the list has been concatenated into one array +- `vtkConstantArray<ValueType>`: using the `vtkConstantImplicitBackend<ValueType>` closure backend that gets constructed with a given value and then returns that same value regardless of the index queried +- `vtkStdFunctionArray<ValueType>`: using a `std::function<ValueType(int)>` backend capable of covering almost any function one might want to use +- `vtkIndexedArray<ValueType>`: using the `vtkIndexedImplicitBackend<ValueType>` closure backend that takes an indexing array (either `vtkIdList` or `vtkDataArray`) and a base `vtkDataArray` at construction and returns values indirected using the indexing array to give access to a shuffled array without the memory cost + +Here is a small code snippet example to illustrate the usage of the `vtkConstantArray`: + +``` +vtkNew<vtkConstantArray<int>> arr42; +arr42->ConstructBackend(42); +arr42->SetNumberOfComponents(1); +arr42->SetNumberOfTuples(100); +CHECK(arr42->GetValue(77) == 42); // always true +``` + +Multi-component arrays have de-facto AOS ordering with respect to the backend. + +The read-only parts of the `vtkDataArray` API work out of the box for any `vtkImplicitArray` including the following functionalities: + * Get components, typed components, tuples, number of components and number of tuples + * `vtkImplicitArray::GetVoidPointer` (implementing and internal deep copy of the array into an AOS array that can be destroyed with `vtkImplicitArray::Squeeze`) + * Standard library like ranges and iterators using `vtkDataArrayRange` functionalities + * `vtkArrayDispatch`, provided the correct compilation options have been set and the correct type list is used for dispatching (see below) + +### `NewInstance` behavior + +The `NewInstance` method is often used on arrays in cases where one has a `vtkDataArray` and one wants a freshly constructed instance of the same type without actually having to determine its type by hand. The workflow often goes on to populate the newly minted instance with transformed values from the original array. + +``` +vtkSmartPointer<vtkDataArray> originalArr = SomeMethodProvidingAnArray(); +vtkSmartPointer<vtkDataArray> newArr = vtk::TakeSmartPointer(originalArr->NewInstance()); +newArr->SetNumberOfTuples(1); +newArr->SetComponent(0, 0, originalArr->GetComponent(0, 0)); +CHECK(originalArr->getComponent(0, 0) == newArr->GetComponent(0, 0)); +``` + +In the case of `vtkImplicitArray`s, this kind of approach will not work since a `vtkImplicitArray` is by definition read-only. + +In order for `vtkImplicitArray`s to behave nicely in areas where this kind of workflow is implemented, the behavior of `vtkImplicitArray::NewInstance` has been modified to return a new instance of `vtkAOSDataArrayTemplate<vtkImplicitArray<BackendT>::ValueTypeT>` so that explicit population of the new array with values from the previous array will happen seamlessly. + +Of course, in this context, a call to `NewInstance` will not provide the propagation of the implicit nature of the arrays and the new arrays will be explicitly stored in memory. + +### Focus on `vtkCompositeArrays` + +The `vtkCompositeArray` is a family of `vtkImplicitArray`s that can concatenate arrays together to interface a group of arrays as if they were a single array. This concatenation operates in the "tuple" direction and not in the "component" direction. + +This new array relies on the `vtkCompositeImplicitBackend` template class to join an `std::vector` of `vtkDataArray`s. The `vtkCompositeArray`s use internal address referencing and indirection to implement binary search on the indexes of the composite array leading to access with $O(log_2(m))$ time where $m$ is the number of leaves (or base `vtkDataArray`s) composing the composite. + +To facilitate the creation of `vtkCompositeArray`s in practice, a templated utility function `vtkCompositeArrayUtilities::Concatenate` has been made available to users that can take an `std::vector` of `vtkDataArray`s (each with the same number of components) and turn them into a single concatenated `vtkCompositeArray` with the same number of components as the base array and a number of tuples being the sum of all the base arrays tuples. + +A code snippet using this type of array: +``` +std::vector<vtkDataArray*> baseArrays(16); +vtkNew<vtkDoubleArray> baseArray; +baseArray->SetNumberOfComponents(3); +baseArray->SetNumberOfTuples(10); +baseArray->Fill(0.0); + +std::fill(baseArrays.begin(), baseArrays.end(), baseArray); +vtkSmartPointer<vtkCompositeArray<double>> composite = vtkCompositeArrayUtilities::Concatenate<double>(baseArrays); // nTuples = 160 + +CHECK(composite->GetComponent(42, 1) == 0.0); // always true +``` + +> **WARNINGS** +> +> * Any two arrays composited into a `vtkCompositeArray` using the `vtk::ConcatenateDataArrays` method must have the same number of components. +> * Iteration over the composited array incurs a lot of overhead compared to an explicit memory array (~3x slower with only 1 level). The use case is truly when memory efficiency is more important than compute performance +> * This array has no relationship with the `VTKCompositeDataArray` present in the `numpy_interface.dataset_adapter` module of the python wrapping of VTK + +### Focus on `vtkIndexedArray` + +The family of `vtkIndexedArray`s allow you to wrap an existing `vtkDataArray` with a layer of indirection through a list of indexes (`vtkIdList` or another `vtkDataArray`) to create a derived subset data array without any excess memory consumption. As such, by providing a `vtkIndexedImplicitBackend` with an indexation array and a `vtkDataArray`, one can effectively construct a reduced and reordered view of the base array. + +While using this type of feature to create only one indexed array can be counter productive (allocation of the index array more expensive than an explicit copy of the data might be), using this feature you can share the same index list amongst multiple indexed arrays effectively using less memory total. + +Here is an example use case: +``` +vtkNew<vtkIntArray> baseArr; +baseArr->SetNumberOfComponents(3); +baseArr->SetNumberOfComponents(100); +auto range = vtk::DataArrayValueRange<3>(baseArr); +std::iota(range.begin(), range.end(), 0); + +vtkNew<vtkIdList> indexes; +indexes->SetNumberOfIds(30); +for (idx = 0; idx < 30; idx++) +{ + indexes->SetId(ids, 10*idx); +} + +vtkNew<vtkIndexedArray<int>> indexed; +indexed->SetBackend(std::make_shared<vtkIndexedImplicitBackend<int>>(indexes, baseArr)); +indexed->SetNumberOfComponents(1); +indexed->SetNumberOfComponents(indexes->GetNumberOfIds()); +CHECK(indexed->GetValue(13) == 130); // always true +``` + +> **WARNINGS** +> +> * Significant access performance hits can be incurred due to cache missing cause by the inherent indirection in the array. + +### Implementing a `vtkImplicitArray` in VTK + +Implementing a new `vtkImplicitArray` in the VTK library usually passes through the following steps: + * Implementing the backend: this is the step where the underlying functionality of the implicit array needs to be developed. + * Creating an alias and instantiating the concrete types: once the backend is ready, one can create an alias for the array in its own header (`using MySuperArray = vtkImplicitArray<MySuperBackend>`) and use this header and the au tomatic instantiation mechanisms present in `Common/ImplicitArrays/CMakeLists.txt` to make sure that the vtk library gets shipped with pre-compiled objects for your arrays. + * Hooking up the dispatch mechanism: this step ensures that your new arrays can be included in the `vtkArrayDispatch` mechanism when the correct compilation option is set. + * Testing: be sure to set up some tests in order to both verify that your implementation is functioning correctly and to avoid regressions in the future. + +An example merge request that was used for including the `vtkIndexedArray`s can be found here: [!9703](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/9703) + +### Building and Dispatch + +The entire implicit array framework is included in the `CommonCore` module. Support for dispatching implicit arrays can be enforced by including type lists from `vtkArrayDispatchImplicitTypeList.h` and compiling VTK with the correct `VTK_DISPATCH_*_ARRAYS` option. + +## vtkToImplicitArrayFilter: compress explicit memory arrays into a `vtkImplicitArray`s + +You now have access to a new filter `vtkToImplicitArrayFilter` in a new `FiltersReduction` module that can transform explicit memory arrays into `vtkImplicitArray`s. The filter itself delegates the "compression" method to a `vtkToImplicitStrategy` object using a strategy pattern. + +The following strategies (in order of complexity) have been implemented so far: +- `vtkToConstantArrayStrategy`: transform an explicit array that has the same value everywhere into a `vtkConstantArray` +- `vtkToAffineArrayStrategy`: transform an explicit array that follows an affine dependence on its indexes into a `vtkAffineArray` +- `vtkToImplicitTypeErasureStrategy`: transform an explicit integral array (with more range in its value type than necessary for describing it) into a reduced memory explicit integral array wrapped in an implicit array. +- `vtkToImplicitRamerDouglasPeuckerStrategy`: transform an explicit memory array into a `vtkCompositeArray` with constant (`vtkConstantArray`) and affine (`vtkAffineArray`) parts following a Ramer-Douglas-Peucker algorithm. diff --git a/Filters/Core/Testing/Cxx/CMakeLists.txt b/Filters/Core/Testing/Cxx/CMakeLists.txt index 3bfeca46a47490b0713c238ed6fea17056cc564f..689f2368862e7fc2a918d8ee33c418bd38e93dd8 100644 --- a/Filters/Core/Testing/Cxx/CMakeLists.txt +++ b/Filters/Core/Testing/Cxx/CMakeLists.txt @@ -1,10 +1,3 @@ -set(test_implicit_array) -if(TARGET VTK::CommonImplicitArrays) - list(APPEND test_implicit_array - TestContourImplicitArrays.cxx - ) -endif() - vtk_add_test_cxx(vtkFiltersCoreCxxTests tests Test3DLinearGridPlaneCutterCellData.cxx TestAppendArcLength.cxx,NO_VALID @@ -92,7 +85,7 @@ vtk_add_test_cxx(vtkFiltersCoreCxxTests tests TestVaryRadiusTubeFilter.cxx UnitTestMaskPoints.cxx,NO_VALID UnitTestMergeFilter.cxx,NO_VALID - ${test_implicit_array} + TestContourImplicitArrays.cxx ) vtk_test_cxx_executable(vtkFiltersCoreCxxTests tests) diff --git a/Filters/Core/vtk.module b/Filters/Core/vtk.module index d7179bf364e10889efd31cf9dbbece0c7db718d7..410c9d2e0ff1867e78fa359094c78d77aed4b7fd 100644 --- a/Filters/Core/vtk.module +++ b/Filters/Core/vtk.module @@ -26,7 +26,6 @@ DEPENDS VTK::CommonExecutionModel VTK::CommonMisc PRIVATE_DEPENDS - VTK::CommonImplicitArrays VTK::CommonMath VTK::CommonSystem VTK::CommonTransforms @@ -54,4 +53,3 @@ TEST_DEPENDS VTK::TestingDataModel TEST_OPTIONAL_DEPENDS VTK::AcceleratorsVTKmFilters - VTK::CommonImplicitArrays diff --git a/Filters/FlowPaths/Testing/Cxx/CMakeLists.txt b/Filters/FlowPaths/Testing/Cxx/CMakeLists.txt index 4b5b33de4511a3b08e5cc8acb262693a435ae208..040c30d870a18154327b7d162c1f782db3e868c5 100644 --- a/Filters/FlowPaths/Testing/Cxx/CMakeLists.txt +++ b/Filters/FlowPaths/Testing/Cxx/CMakeLists.txt @@ -11,29 +11,13 @@ vtk_add_test_cxx(vtkFiltersFlowPathsCxxTests tests TestLagrangianIntegrationModel.cxx,NO_VALID TestLagrangianParticle.cxx,NO_VALID TestLagrangianParticleTracker.cxx + TestStreamTracerImplicitArray.cxx,NO_VALID TestVortexCore.cxx,NO_VALID TestVectorFieldTopology.cxx TestVectorFieldTopologyNoIterativeSeeding.cxx ) -set(test_implicit_array) -if(TARGET VTK::CommonImplicitArrays) - list(APPEND test_implicit_array - TestStreamTracerImplicitArray.cxx - ) -endif() - -vtk_add_test_cxx(vtkFiltersFlowPathsCxxTests imp_tests - NO_VALID - ${test_implicit_array} -) - -set(all_tests - ${tests} - ${imp_tests} -) - -vtk_test_cxx_executable(vtkFiltersFlowPathsCxxTests all_tests +vtk_test_cxx_executable(vtkFiltersFlowPathsCxxTests tests DISABLE_FLOATING_POINT_EXCEPTIONS RENDERING_FACTORY ) diff --git a/Filters/FlowPaths/vtk.module b/Filters/FlowPaths/vtk.module index a8ce844a59b630c003347b51c595fceed1ff72e2..56ffa5dbea65ee93617cefee14962fdf1f445285 100644 --- a/Filters/FlowPaths/vtk.module +++ b/Filters/FlowPaths/vtk.module @@ -39,5 +39,3 @@ TEST_DEPENDS VTK::RenderingOpenGL2 VTK::TestingCore VTK::TestingRendering -TEST_OPTIONAL_DEPENDS - VTK::CommonImplicitArrays diff --git a/Filters/ParallelDIY2/Testing/Cxx/CMakeLists.txt b/Filters/ParallelDIY2/Testing/Cxx/CMakeLists.txt index de0f3da316a0911eeb7e4bbba736f4c18083705a..2fb5e0d06bbc64c004b95921b38ce5c413b1b2d3 100644 --- a/Filters/ParallelDIY2/Testing/Cxx/CMakeLists.txt +++ b/Filters/ParallelDIY2/Testing/Cxx/CMakeLists.txt @@ -14,22 +14,11 @@ if (TARGET VTK::mpi) TestPUniformGridGhostDataGenerator.cxx,NO_VALID TestPUnstructuredGridGhostCellsGenerator.cxx,NO_VALID TestRedistributeDataSetFilter.cxx + TestRedistributeDataSetFilterImplicitArray.cxx,NO_VALID TestRedistributeDataSetFilterOnIOSS.cxx,NO_VALID TestStructuredGridGhostDataGenerator.cxx,NO_VALID TestUnstructuredGridGeometryFilterGhostCells.cxx,NO_VALID) - set(test_implicit_array) - if(TARGET VTK::CommonImplicitArrays) - list(APPEND test_implicit_array - TestRedistributeDataSetFilterImplicitArray.cxx - ) - endif() - - vtk_add_test_mpi(vtkFiltersParallelDIY2CxxTests-MPI imp_tests - NO_VALID - ${test_implicit_array} - ) - # We want 4 processes to test the vtkAggregateDataSetFilter # properly. set (vtkFiltersParallelDIY2CxxTests-MPI_NUMPROCS 4) @@ -42,7 +31,6 @@ if (TARGET VTK::mpi) set(all_tests ${tests} ${no_data_tests_4_procs} - ${imp_tests} ) vtk_test_cxx_executable(vtkFiltersParallelDIY2CxxTests-MPI all_tests) diff --git a/Filters/ParallelDIY2/vtk.module b/Filters/ParallelDIY2/vtk.module index f383510c99a901a021d2d49fdf5d90ed3bc7f908..2dc673817f865ce108a6b8fe7468110b48a6ac6f 100644 --- a/Filters/ParallelDIY2/vtk.module +++ b/Filters/ParallelDIY2/vtk.module @@ -41,7 +41,6 @@ TEST_DEPENDS VTK::TestingCore VTK::TestingRendering TEST_OPTIONAL_DEPENDS - VTK::CommonImplicitArrays VTK::FiltersParallelMPI VTK::mpi VTK::ParallelMPI diff --git a/Filters/Reduction/vtk.module b/Filters/Reduction/vtk.module index 18afde8f9bf048e5a6ca740ea5b46e317419d1e4..6eb31dc5a4bcf8832ab364123a1b77c141336961 100644 --- a/Filters/Reduction/vtk.module +++ b/Filters/Reduction/vtk.module @@ -13,11 +13,9 @@ SPDX_COPYRIGHT_TEXT DEPENDS VTK::CommonCore VTK::CommonExecutionModel - VTK::CommonImplicitArrays PRIVATE_DEPENDS VTK::CommonDataModel TEST_DEPENDS - VTK::CommonImplicitArrays VTK::CommonSystem VTK::FiltersSources VTK::TestingCore diff --git a/Filters/Reduction/vtkToAffineArrayStrategy.cxx b/Filters/Reduction/vtkToAffineArrayStrategy.cxx index e20c42900c2fb0eb88b64b7477ac2d4f359d6e03..70e593faad21d302c99f8bd8de9bc8d9c31d6d65 100644 --- a/Filters/Reduction/vtkToAffineArrayStrategy.cxx +++ b/Filters/Reduction/vtkToAffineArrayStrategy.cxx @@ -4,7 +4,6 @@ #include "vtkAffineArray.h" #include "vtkArrayDispatch.h" -#include "vtkArrayDispatchImplicitArrayList.h" #include "vtkDataArrayRange.h" #include "vtkObjectFactory.h" #include "vtkSMPTools.h" diff --git a/Filters/Reduction/vtkToConstantArrayStrategy.cxx b/Filters/Reduction/vtkToConstantArrayStrategy.cxx index eddf7d597fd816367bb5732e66739cf4f24f2668..8b56dab6af3b441f569700791125115f19c66cb2 100644 --- a/Filters/Reduction/vtkToConstantArrayStrategy.cxx +++ b/Filters/Reduction/vtkToConstantArrayStrategy.cxx @@ -3,7 +3,6 @@ #include "vtkToConstantArrayStrategy.h" #include "vtkArrayDispatch.h" -#include "vtkArrayDispatchImplicitArrayList.h" #include "vtkConstantArray.h" #include "vtkDataArrayRange.h" #include "vtkObjectFactory.h" diff --git a/Filters/Reduction/vtkToImplicitRamerDouglasPeuckerStrategy.cxx b/Filters/Reduction/vtkToImplicitRamerDouglasPeuckerStrategy.cxx index 730a5a7fbb275dcd0de644c9161fd4a9d2ff651a..346f21b57e5617e0c143612dc0ae5ff83583d1f2 100644 --- a/Filters/Reduction/vtkToImplicitRamerDouglasPeuckerStrategy.cxx +++ b/Filters/Reduction/vtkToImplicitRamerDouglasPeuckerStrategy.cxx @@ -4,7 +4,6 @@ #include "vtkAffineArray.h" #include "vtkArrayDispatch.h" -#include "vtkArrayDispatchImplicitArrayList.h" #include "vtkCompositeArray.h" #include "vtkConstantArray.h" #include "vtkDataArrayRange.h" diff --git a/Filters/Reduction/vtkToImplicitTypeErasureStrategy.cxx b/Filters/Reduction/vtkToImplicitTypeErasureStrategy.cxx index d140c275e0a3a478991c4a7d0a8543969f0544e4..19a783c5ba07fd62bf6c59bc80bc672fee0939f8 100644 --- a/Filters/Reduction/vtkToImplicitTypeErasureStrategy.cxx +++ b/Filters/Reduction/vtkToImplicitTypeErasureStrategy.cxx @@ -3,7 +3,6 @@ #include "vtkToImplicitTypeErasureStrategy.h" #include "vtkArrayDispatch.h" -#include "vtkArrayDispatchImplicitArrayList.h" #include "vtkDataArrayRange.h" #include "vtkImplicitArray.h" #include "vtkMath.h" diff --git a/IO/Geometry/vtk.module b/IO/Geometry/vtk.module index 3b5d5e2f3a6adb575f6625b208c42a5b0a76477c..aa68a6d1ee71f2331294bb5a3cce440a271851bd 100644 --- a/IO/Geometry/vtk.module +++ b/IO/Geometry/vtk.module @@ -18,8 +18,6 @@ DEPENDS VTK::IOCore VTK::IOLegacy VTK::nlohmannjson -OPTIONAL_DEPENDS - VTK::CommonImplicitArrays PRIVATE_DEPENDS VTK::CommonMisc VTK::CommonSystem diff --git a/IO/Geometry/vtkOpenFOAMReader.cxx b/IO/Geometry/vtkOpenFOAMReader.cxx index d106e4149f3c6c550f98f25f4073b111071afb67..421be489b501c9e3791ea22807ff695c08b6cdb6 100644 --- a/IO/Geometry/vtkOpenFOAMReader.cxx +++ b/IO/Geometry/vtkOpenFOAMReader.cxx @@ -163,6 +163,7 @@ #include "vtkCellSizeFilter.h" #include "vtkCharArray.h" #include "vtkCollection.h" +#include "vtkConstantArray.h" #include "vtkDataArrayRange.h" #include "vtkDataArraySelection.h" #include "vtkDataObjectTreeRange.h" @@ -199,10 +200,6 @@ #include "vtkVertex.h" #include "vtkWedge.h" -#if VTK_MODULE_ENABLE_VTK_CommonImplicitArrays -#include "vtkConstantArray.h" -#endif - #if !(defined(_WIN32) && !defined(__CYGWIN__) || defined(__LIBCATAMOUNT__)) #include <pwd.h> // For getpwnam(), getpwuid() #include <sys/types.h> @@ -8543,17 +8540,10 @@ void vtkOpenFOAMReaderPrivate::InterpolateCellToPoint(vtkFloatArray* pData, vtkF */ if (!inCellData->HasArray(::Cell2PointWeightsName.c_str())) { -#if VTK_MODULE_ENABLE_VTK_CommonImplicitArrays vtkNew<vtkConstantArray<double>> ones; ones->ConstructBackend(1.0); ones->SetNumberOfComponents(1); ones->SetNumberOfTuples(mesh->GetNumberOfCells()); -#else - vtkNew<vtkDoubleArray> ones; - ones->SetNumberOfComponents(1); - ones->SetNumberOfTuples(mesh->GetNumberOfCells()); - ones->Fill(1.0); -#endif vtkSmartPointer<vtkDataArray> weights = ones; if (this->Parent->GetSizeAverageCellToPoint()) { diff --git a/IO/XML/vtkXMLWriter.cxx b/IO/XML/vtkXMLWriter.cxx index 2f90772918197b8804de1d18c770172e68f0cda6..ddcf29521af432008049b15f8ca7806115af8653 100644 --- a/IO/XML/vtkXMLWriter.cxx +++ b/IO/XML/vtkXMLWriter.cxx @@ -1139,8 +1139,8 @@ int vtkXMLWriter::WriteBinaryDataInternal(vtkAbstractArray* a) else if (vtkDataArray* da = vtkArrayDownCast<vtkDataArray>(a)) { // Create a dispatcher that also handles vtkBitArray: - using vtkArrayDispatch::Arrays; - using XMLArrays = vtkTypeList::Append<Arrays, vtkBitArray>::Result; + using vtkArrayDispatch::AllArrays; + using XMLArrays = vtkTypeList::Append<AllArrays, vtkBitArray>::Result; using Dispatcher = vtkArrayDispatch::DispatchByArray<XMLArrays>; WriteBinaryDataBlockWorker worker(this, wordType, memWordSize, outWordSize, numValues); diff --git a/Rendering/Volume/Testing/Cxx/CMakeLists.txt b/Rendering/Volume/Testing/Cxx/CMakeLists.txt index 95267ba9874aec52278668a833e8a311bc838318..c47111b4ce0f1068c7eca02170bf851a16465bf1 100644 --- a/Rendering/Volume/Testing/Cxx/CMakeLists.txt +++ b/Rendering/Volume/Testing/Cxx/CMakeLists.txt @@ -1,10 +1,3 @@ -set(test_implicit_array) -if(TARGET VTK::CommonImplicitArrays) - list(APPEND test_implicit_array - TestSmartVolumeMapperImplicitArray.cxx - ) -endif() - set (VolumeCxxTests ProjectedTetrahedraZoomIn.cxx,NO_VALID TestFinalColorWindowLevel.cxx @@ -97,9 +90,9 @@ set (VolumeCxxTests TestProjectedTetrahedraVectorComponent.cxx TestRemoveVolumeNonCurrentContext.cxx TestSmartVolumeMapper.cxx + TestSmartVolumeMapperImplicitArray.cxx TestSmartVolumeMapperVolumeUpdate.cxx TestSmartVolumeMapperWindowLevel.cxx - ${test_implicit_array} ) # everyone gets these tests diff --git a/Rendering/Volume/vtk.module b/Rendering/Volume/vtk.module index b6a9ca6b62e591dd5284ef1b48487a801d5d7f25..acd52011bd1a4cfa4badcf569832283e515b9142 100644 --- a/Rendering/Volume/vtk.module +++ b/Rendering/Volume/vtk.module @@ -48,5 +48,3 @@ TEST_DEPENDS VTK::RenderingVolumeOpenGL2 VTK::TestingCore VTK::TestingRendering -TEST_OPTIONAL_DEPENDS - VTK::CommonImplicitArrays