Commit 2cd2b99f authored by Allison Vacanti's avatar Allison Vacanti Committed by Kitware Robot

Merge topic 'accessor_to_range'

29c95ce0 Use ranges in vtkDataSetAttributes.
8b9927a7 Remove vtkDataArrayAccessor from vtkOGLVBO.cxx.
4b8f4d83 Remove vtkDataArrayAccessor from vtkOGLIBO.cxx.
86c79ef8 Remove vtkDataArrayAccessor from vtkMotionGXCFGReader.cxx
6dd6c254 Remove vtkDataArrayAccessor from vtkPConnectivityFilter.
82415d6c Remove vtkDataArrayAccessor from vtkPResampleWithDataSet.cxx
f381e85c Remove vtkDataArrayAccessor from vtkPResampleToImage.cxx.
6945709a Remove vtkDataArrayAccessor from TemporalArrayOperatorFilter.cxx.
...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Robert Maynard's avatarRobert Maynard <robert.maynard@kitware.com>
Merge-request: !6224
parents c5553928 29c95ce0
Pipeline #152893 pending with stage
......@@ -18,8 +18,8 @@
#include "vtkArrayDispatch.h"
#include "vtkBitArray.h"
#include "vtkCharArray.h"
#include "vtkDataArrayAccessor.h"
#include "vtkDataArrayPrivate.txx"
#include "vtkDataArrayRange.h"
#include "vtkDoubleArray.h"
#include "vtkFloatArray.h"
#include "vtkGenericDataArray.h"
......@@ -56,7 +56,8 @@ struct DeepCopyWorker
{
// AoS --> AoS same-type specialization:
template <typename ValueType>
void operator()(vtkAOSDataArrayTemplate<ValueType>* src, vtkAOSDataArrayTemplate<ValueType>* dst)
void operator()(
vtkAOSDataArrayTemplate<ValueType>* src, vtkAOSDataArrayTemplate<ValueType>* dst) const
{
std::copy(src->Begin(), src->End(), dst->Begin());
}
......@@ -70,7 +71,8 @@ struct DeepCopyWorker
// SoA --> SoA same-type specialization:
template <typename ValueType>
void operator()(vtkSOADataArrayTemplate<ValueType>* src, vtkSOADataArrayTemplate<ValueType>* dst)
void operator()(
vtkSOADataArrayTemplate<ValueType>* src, vtkSOADataArrayTemplate<ValueType>* dst) const
{
vtkIdType numTuples = src->GetNumberOfTuples();
for (int comp = 0; comp < src->GetNumberOfComponents(); ++comp)
......@@ -108,45 +110,32 @@ struct DeepCopyWorker
#endif
#endif
// Generic implementations:
template <typename Array1DerivedT, typename Array1ValueT, typename Array2DerivedT,
typename Array2ValueT>
void operator()(vtkGenericDataArray<Array1DerivedT, Array1ValueT>* src,
vtkGenericDataArray<Array2DerivedT, Array2ValueT>* dst)
// Generic implementation:
template <typename SrcArrayT, typename DstArrayT>
void DoGenericCopy(SrcArrayT* src, DstArrayT* dst) const
{
using Array1T = vtkGenericDataArray<Array1DerivedT, Array1ValueT>;
using Array2T = vtkGenericDataArray<Array2DerivedT, Array2ValueT>;
const auto srcRange = vtk::DataArrayValueRange(src);
auto dstRange = vtk::DataArrayValueRange(dst);
vtkDataArrayAccessor<Array1T> s(src);
vtkDataArrayAccessor<Array2T> d(dst);
typedef typename vtkDataArrayAccessor<Array2T>::APIType DestType;
vtkIdType tuples = src->GetNumberOfTuples();
int comps = src->GetNumberOfComponents();
using SrcT = typename decltype(srcRange)::ValueType;
using DstT = typename decltype(dstRange)::ValueType;
for (vtkIdType t = 0; t < tuples; ++t)
{
for (int c = 0; c < comps; ++c)
{
d.Set(t, c, static_cast<DestType>(s.Get(t, c)));
}
}
// use transform instead of copy to avoid -Wconversion warnings
std::transform(srcRange.cbegin(), srcRange.cend(), dstRange.begin(),
[](const SrcT v) -> DstT { return static_cast<DstT>(v); });
}
void operator()(vtkDataArray* src, vtkDataArray* dst)
// These overloads are split so that the above specializations will be
// used properly.
template <typename Array1DerivedT, typename Array1ValueT, typename Array2DerivedT,
typename Array2ValueT>
void operator()(vtkGenericDataArray<Array1DerivedT, Array1ValueT>* src,
vtkGenericDataArray<Array2DerivedT, Array2ValueT>* dst) const
{
vtkIdType tuples = src->GetNumberOfTuples();
int comps = src->GetNumberOfComponents();
for (vtkIdType t = 0; t < tuples; ++t)
{
for (int c = 0; c < comps; ++c)
{
dst->SetComponent(t, c, src->GetComponent(t, c));
}
}
this->DoGenericCopy(src, dst);
}
void operator()(vtkDataArray* src, vtkDataArray* dst) const { this->DoGenericCopy(src, dst); }
};
//------------InterpolateTuple workers------------------------------------------
......@@ -167,8 +156,10 @@ struct InterpolateMultiTupleWorker
}
template <typename Array1T, typename Array2T>
void operator()(Array1T* src, Array2T* dst)
void operator()(Array1T* src, Array2T* dst) const
{
// Use vtkDataArrayAccessor here instead of a range, since we need to use
// Insert for legacy compat
vtkDataArrayAccessor<Array1T> s(src);
vtkDataArrayAccessor<Array2T> d(dst);
......@@ -209,8 +200,10 @@ struct InterpolateTupleWorker
}
template <typename Array1T, typename Array2T, typename Array3T>
void operator()(Array1T* src1, Array2T* src2, Array3T* dst)
void operator()(Array1T* src1, Array2T* src2, Array3T* dst) const
{
// Use accessor here instead of ranges since we need to use Insert for
// legacy compat
vtkDataArrayAccessor<Array1T> s1(src1);
vtkDataArrayAccessor<Array2T> s2(src2);
vtkDataArrayAccessor<Array3T> d(dst);
......@@ -242,26 +235,18 @@ struct GetTuplesFromListWorker
}
template <typename Array1T, typename Array2T>
void operator()(Array1T* src, Array2T* dst)
void operator()(Array1T* src, Array2T* dst) const
{
vtkDataArrayAccessor<Array1T> s(src);
vtkDataArrayAccessor<Array2T> d(dst);
typedef typename vtkDataArrayAccessor<Array2T>::APIType DestType;
const auto srcTuples = vtk::DataArrayTupleRange(src);
auto dstTuples = vtk::DataArrayTupleRange(dst);
int numComps = src->GetNumberOfComponents();
vtkIdType* srcTuple = this->Ids->GetPointer(0);
vtkIdType* srcTupleEnd = this->Ids->GetPointer(Ids->GetNumberOfIds());
vtkIdType dstTuple = 0;
vtkIdType* srcTupleId = this->Ids->GetPointer(0);
vtkIdType* srcTupleIdEnd = this->Ids->GetPointer(Ids->GetNumberOfIds());
while (srcTuple != srcTupleEnd)
auto dstTupleIter = dstTuples.begin();
while (srcTupleId != srcTupleIdEnd)
{
for (int c = 0; c < numComps; ++c)
{
d.Set(dstTuple, c, static_cast<DestType>(s.Get(*srcTuple, c)));
}
++srcTuple;
++dstTuple;
*dstTupleIter++ = srcTuples[*srcTupleId++];
}
}
};
......@@ -279,20 +264,14 @@ struct GetTuplesRangeWorker
}
template <typename Array1T, typename Array2T>
void operator()(Array1T* src, Array2T* dst)
void operator()(Array1T* src, Array2T* dst) const
{
vtkDataArrayAccessor<Array1T> s(src);
vtkDataArrayAccessor<Array2T> d(dst);
typedef typename vtkDataArrayAccessor<Array2T>::APIType DestType;
const auto srcTuples = vtk::DataArrayTupleRange(src);
auto dstTuples = vtk::DataArrayTupleRange(dst);
int numComps = src->GetNumberOfComponents();
for (vtkIdType srcT = this->Start, dstT = 0; srcT <= this->End; ++srcT, ++dstT)
{
for (int c = 0; c < numComps; ++c)
{
d.Set(dstT, c, static_cast<DestType>(s.Get(srcT, c)));
}
dstTuples[dstT] = srcTuples[srcT];
}
}
};
......@@ -310,18 +289,12 @@ struct SetTupleArrayWorker
}
template <typename SrcArrayT, typename DstArrayT>
void operator()(SrcArrayT* src, DstArrayT* dst)
void operator()(SrcArrayT* src, DstArrayT* dst) const
{
vtkDataArrayAccessor<SrcArrayT> s(src);
vtkDataArrayAccessor<DstArrayT> d(dst);
const auto srcTuples = vtk::DataArrayTupleRange(src);
auto dstTuples = vtk::DataArrayTupleRange(dst);
typedef typename vtkDataArrayAccessor<DstArrayT>::APIType DestType;
int numComps = src->GetNumberOfComponents();
for (int c = 0; c < numComps; ++c)
{
d.Set(this->DstTuple, c, static_cast<DestType>(s.Get(this->SrcTuple, c)));
}
dstTuples[this->DstTuple] = srcTuples[this->SrcTuple];
}
};
......@@ -338,23 +311,18 @@ struct SetTuplesIdListWorker
}
template <typename SrcArrayT, typename DstArrayT>
void operator()(SrcArrayT* src, DstArrayT* dst)
void operator()(SrcArrayT* src, DstArrayT* dst) const
{
vtkDataArrayAccessor<SrcArrayT> s(src);
vtkDataArrayAccessor<DstArrayT> d(dst);
typedef typename vtkDataArrayAccessor<DstArrayT>::APIType DestType;
const auto srcTuples = vtk::DataArrayTupleRange(src);
auto dstTuples = vtk::DataArrayTupleRange(dst);
vtkIdType numTuples = this->SrcTuples->GetNumberOfIds();
int numComps = src->GetNumberOfComponents();
for (vtkIdType t = 0; t < numTuples; ++t)
{
vtkIdType srcT = this->SrcTuples->GetId(t);
vtkIdType dstT = this->DstTuples->GetId(t);
for (int c = 0; c < numComps; ++c)
{
d.Set(dstT, c, static_cast<DestType>(s.Get(srcT, c)));
}
dstTuples[dstT] = srcTuples[srcT];
}
}
};
......@@ -376,26 +344,18 @@ struct SetTuplesRangeWorker
// Generic implementation. We perform the obvious optimizations for AOS/SOA
// in the derived class implementations.
template <typename SrcArrayT, typename DstArrayT>
void operator()(SrcArrayT* src, DstArrayT* dst)
void operator()(SrcArrayT* src, DstArrayT* dst) const
{
vtkDataArrayAccessor<SrcArrayT> s(src);
vtkDataArrayAccessor<DstArrayT> d(dst);
typedef typename vtkDataArrayAccessor<DstArrayT>::APIType DestType;
const auto srcTuples = vtk::DataArrayTupleRange(src);
auto dstTuples = vtk::DataArrayTupleRange(dst);
int numComps = src->GetNumberOfComponents();
vtkIdType srcT = this->SrcStartTuple;
vtkIdType srcTEnd = srcT + this->NumTuples;
vtkIdType dstT = this->DstStartTuple;
while (srcT < srcTEnd)
{
for (int c = 0; c < numComps; ++c)
{
d.Set(dstT, c, static_cast<DestType>(s.Get(srcT, c)));
}
++srcT;
++dstT;
dstTuples[dstT++] = srcTuples[srcT++];
}
}
};
......
......@@ -18,7 +18,7 @@
#include "vtkAssume.h"
#include "vtkConfigure.h"
#include "vtkDataArrayAccessor.h"
#include "vtkDataArray.h"
#include "vtkMeta.h"
#include "vtkSetGet.h"
#include "vtkType.h"
......@@ -166,12 +166,23 @@ struct GenericTupleSize<DynamicTupleSize>
ComponentIdType value;
};
template <typename ArrayType>
struct GetAPITypeImpl
{
using APIType = typename ArrayType::ValueType;
};
template <>
struct GetAPITypeImpl<vtkDataArray>
{
using APIType = double;
};
} // end namespace detail
//------------------------------------------------------------------------------
// Typedef for double if vtkDataArray, or the array's ValueType for subclasses.
template <typename ArrayType, typename = detail::EnableIfVtkDataArray<ArrayType> >
using GetAPIType = typename vtkDataArrayAccessor<ArrayType>::APIType;
using GetAPIType = typename detail::GetAPITypeImpl<ArrayType>::APIType;
//------------------------------------------------------------------------------
namespace detail
......
......@@ -17,7 +17,7 @@
#include "vtkAssume.h"
#include "vtkDataArray.h"
#include "vtkDataArrayAccessor.h"
#include "vtkDataArrayRange.h"
#include "vtkSMPThreadLocal.h"
#include "vtkSMPTools.h"
#include "vtkTypeTraits.h"
......@@ -140,8 +140,7 @@ public:
}
};
template <int NumComps, typename ArrayT,
typename APIType = typename vtkDataArrayAccessor<ArrayT>::APIType>
template <int NumComps, typename ArrayT, typename APIType = typename vtk::GetAPIType<ArrayT> >
class AllValuesMinAndMax : public MinAndMax<APIType, NumComps>
{
private:
......@@ -159,23 +158,22 @@ public:
void Reduce() { MinAndMaxT::Reduce(); }
void operator()(vtkIdType begin, vtkIdType end)
{
VTK_ASSUME(this->Array->GetNumberOfComponents() == NumComps);
vtkDataArrayAccessor<ArrayT> access(this->Array);
const auto tuples = vtk::DataArrayTupleRange<NumComps>(this->Array, begin, end);
auto& range = MinAndMaxT::TLRange.Local();
for (vtkIdType tupleIdx = begin; tupleIdx < end; ++tupleIdx)
for (const auto tuple : tuples)
{
for (int compIdx = 0, j = 0; compIdx < NumComps; ++compIdx, j += 2)
size_t j = 0;
for (const APIType value : tuple)
{
APIType value = access.Get(tupleIdx, compIdx);
range[j] = detail::min(range[j], value);
range[j + 1] = detail::max(range[j + 1], value);
j += 2;
}
}
}
};
template <int NumComps, typename ArrayT,
typename APIType = typename vtkDataArrayAccessor<ArrayT>::APIType>
template <int NumComps, typename ArrayT, typename APIType = typename vtk::GetAPIType<ArrayT> >
class FiniteMinAndMax : public MinAndMax<APIType, NumComps>
{
private:
......@@ -193,25 +191,25 @@ public:
void Reduce() { MinAndMaxT::Reduce(); }
void operator()(vtkIdType begin, vtkIdType end)
{
VTK_ASSUME(this->Array->GetNumberOfComponents() == NumComps);
vtkDataArrayAccessor<ArrayT> access(this->Array);
const auto tuples = vtk::DataArrayTupleRange<NumComps>(this->Array, begin, end);
auto& range = MinAndMaxT::TLRange.Local();
for (vtkIdType tupleIdx = begin; tupleIdx < end; ++tupleIdx)
for (const auto tuple : tuples)
{
for (int compIdx = 0, j = 0; compIdx < NumComps; ++compIdx, j += 2)
size_t j = 0;
for (const APIType value : tuple)
{
APIType value = access.Get(tupleIdx, compIdx);
if (!detail::isinf(value))
{
range[j] = detail::min(range[j], value);
range[j + 1] = detail::max(range[j + 1], value);
}
j += 2;
}
}
}
};
template <typename ArrayT, typename APIType = typename vtkDataArrayAccessor<ArrayT>::APIType>
template <typename ArrayT, typename APIType = typename vtk::GetAPIType<ArrayT> >
class MagnitudeAllValuesMinAndMax : public MinAndMax<APIType, 1>
{
private:
......@@ -238,16 +236,14 @@ public:
}
void operator()(vtkIdType begin, vtkIdType end)
{
const int NumComps = this->Array->GetNumberOfComponents();
vtkDataArrayAccessor<ArrayT> access(this->Array);
const auto tuples = vtk::DataArrayTupleRange(this->Array, begin, end);
auto& range = MinAndMaxT::TLRange.Local();
for (vtkIdType tupleIdx = begin; tupleIdx < end; ++tupleIdx)
for (const auto tuple : tuples)
{
APIType squaredSum = 0.0;
for (int compIdx = 0; compIdx < NumComps; ++compIdx)
for (const APIType value : tuple)
{
const APIType t = static_cast<APIType>(access.Get(tupleIdx, compIdx));
squaredSum += t * t;
squaredSum += value * value;
}
range[0] = detail::min(range[0], squaredSum);
range[1] = detail::max(range[1], squaredSum);
......@@ -255,7 +251,7 @@ public:
}
};
template <typename ArrayT, typename APIType = typename vtkDataArrayAccessor<ArrayT>::APIType>
template <typename ArrayT, typename APIType = typename vtk::GetAPIType<ArrayT> >
class MagnitudeFiniteMinAndMax : public MinAndMax<APIType, 1>
{
private:
......@@ -282,16 +278,14 @@ public:
}
void operator()(vtkIdType begin, vtkIdType end)
{
const int NumComps = this->Array->GetNumberOfComponents();
vtkDataArrayAccessor<ArrayT> access(this->Array);
const auto tuples = vtk::DataArrayTupleRange(this->Array, begin, end);
auto& range = MinAndMaxT::TLRange.Local();
for (vtkIdType tupleIdx = begin; tupleIdx < end; ++tupleIdx)
for (const auto tuple : tuples)
{
APIType squaredSum = 0.0;
for (int compIdx = 0; compIdx < NumComps; ++compIdx)
for (const APIType value : tuple)
{
const APIType t = static_cast<APIType>(access.Get(tupleIdx, compIdx));
squaredSum += t * t;
squaredSum += value * value;
}
if (!detail::isinf(squaredSum))
{
......@@ -375,7 +369,7 @@ public:
}
};
template <typename ArrayT, typename APIType = typename vtkDataArrayAccessor<ArrayT>::APIType>
template <typename ArrayT, typename APIType = typename vtk::GetAPIType<ArrayT> >
class AllValuesGenericMinAndMax : public GenericMinAndMax<ArrayT, APIType>
{
private:
......@@ -391,21 +385,22 @@ public:
void Reduce() { MinAndMaxT::Reduce(); }
void operator()(vtkIdType begin, vtkIdType end)
{
vtkDataArrayAccessor<ArrayT> access(MinAndMaxT::Array);
const auto tuples = vtk::DataArrayTupleRange(this->Array, begin, end);
auto& range = MinAndMaxT::TLRange.Local();
for (vtkIdType tupleIdx = begin; tupleIdx < end; ++tupleIdx)
for (const auto tuple : tuples)
{
for (int compIdx = 0, j = 0; compIdx < MinAndMaxT::NumComps; ++compIdx, j += 2)
size_t j = 0;
for (const APIType value : tuple)
{
APIType value = access.Get(tupleIdx, compIdx);
range[j] = detail::min(range[j], value);
range[j + 1] = detail::max(range[j + 1], value);
j += 2;
}
}
}
};
template <typename ArrayT, typename APIType = typename vtkDataArrayAccessor<ArrayT>::APIType>
template <typename ArrayT, typename APIType = typename vtk::GetAPIType<ArrayT> >
class FiniteGenericMinAndMax : public GenericMinAndMax<ArrayT, APIType>
{
private:
......@@ -421,18 +416,19 @@ public:
void Reduce() { MinAndMaxT::Reduce(); }
void operator()(vtkIdType begin, vtkIdType end)
{
vtkDataArrayAccessor<ArrayT> access(MinAndMaxT::Array);
const auto tuples = vtk::DataArrayTupleRange(this->Array, begin, end);
auto& range = MinAndMaxT::TLRange.Local();
for (vtkIdType tupleIdx = begin; tupleIdx < end; ++tupleIdx)
for (const auto tuple : tuples)
{
for (int compIdx = 0, j = 0; compIdx < MinAndMaxT::NumComps; ++compIdx, j += 2)
size_t j = 0;
for (const APIType value : tuple)
{
APIType value = access.Get(tupleIdx, compIdx);
if (!detail::isinf(value))
{
range[j] = detail::min(range[j], value);
range[j + 1] = detail::max(range[j + 1], value);
}
j += 2;
}
}
}
......@@ -460,7 +456,6 @@ bool GenericComputeScalarRange(ArrayT* array, RangeValueType* ranges, FiniteValu
template <typename ArrayT, typename RangeValueType, typename ValueType>
bool DoComputeScalarRange(ArrayT* array, RangeValueType* ranges, ValueType tag)
{
vtkDataArrayAccessor<ArrayT> access(array);
const int numComp = array->GetNumberOfComponents();
// setup the initial ranges to be the max,min for double
......
......@@ -15,8 +15,7 @@
/**
* @file vtkDataArrayRange.h
* Provides STL-compatible iterable ranges that provide access vtkDataArray
* elements.
* STL-compatible iterable ranges that provide access to vtkDataArray elements.
*
* @note Since the term 'range' is overloaded, it's worth pointing out that to
* determine the value-range of an array's elements (an unrelated concept to
......@@ -29,7 +28,6 @@
#include "vtkAOSDataArrayTemplate.h"
#include "vtkDataArray.h"
#include "vtkDataArrayAccessor.h"
#include "vtkDataArrayMeta.h"
#include "vtkDataArrayTupleRange_AOS.h"
#include "vtkDataArrayTupleRange_Generic.h"
......
......@@ -60,7 +60,7 @@
* avoided.
*
* @sa
* vtkArrayDispatcher vtkDataArrayAccessor
* vtkArrayDispatcher vtkDataArrayRange
*/
#ifndef vtkGenericDataArray_h
......
......@@ -13,7 +13,6 @@
=========================================================================*/
#include "vtkDataArrayAccessor.h"
#include "vtkFloatArray.h"
#include "vtkMath.h"
#include "vtkMathUtilities.h"
......@@ -129,7 +128,7 @@ int TestPlane(int, char*[])
}
assert(pos == nPoints);
vtkDataArray* input = points->GetData();
vtkFloatArray* input = vtkArrayDownCast<vtkFloatArray>(points->GetData());
vtkNew<vtkFloatArray> arrayOutput;
arrayOutput->SetNumberOfComponents(1);
arrayOutput->SetNumberOfTuples(nPoints);
......@@ -142,16 +141,14 @@ int TestPlane(int, char*[])
vtkNew<vtkFloatArray> loopOutput;
loopOutput->SetNumberOfComponents(1);
loopOutput->SetNumberOfTuples(nPoints);
vtkDataArrayAccessor<vtkFloatArray> output(loopOutput);
vtkDataArrayAccessor<vtkFloatArray> pts(vtkFloatArray::SafeDownCast(input));
for (vtkIdType pt = 0; pt < nPoints; ++pt)
{
double x[3];
x[0] = pts.Get(pt, 0);
x[1] = pts.Get(pt, 1);
x[2] = pts.Get(pt, 2);
output.Set(pt, 0, plane->FunctionValue(x));
x[0] = input->GetTypedComponent(pt, 0);
x[1] = input->GetTypedComponent(pt, 1);
x[2] = input->GetTypedComponent(pt, 2);
loopOutput->SetTypedComponent(pt, 0, plane->FunctionValue(x));
}
for (vtkIdType i = 0; i < nPoints; ++i)
......
......@@ -19,7 +19,7 @@
#include "vtkAssume.h"
#include "vtkCell.h"
#include "vtkCharArray.h"
#include "vtkDataArrayAccessor.h"
#include "vtkDataArrayRange.h"
#include "vtkDoubleArray.h"
#include "vtkFloatArray.h"
#include "vtkIdTypeArray.h"
......@@ -442,8 +442,16 @@ struct CopyStructuredDataWorker
}
template <typename Array1T, typename Array2T>
void operator()(Array1T* dest, Array2T* src)
void operator()(Array1T* dstArray, Array2T* srcArray)
{
// Give the compiler a hand -- allow optimizations that require both arrays
// to have the same stride.
VTK_ASSUME(srcArray->GetNumberOfComponents() == dstArray->GetNumberOfComponents());
// Create some tuple ranges to simplify optimized copying:
const auto srcTuples = vtk::DataArrayTupleRange(srcArray);
auto dstTuples = vtk::DataArrayTupleRange(dstArray);
if (vtkStructuredExtent::Smaller(this->OutExt, this->InExt))
{
// get outExt relative to the inExt to keep the logic simple. This assumes
......@@ -457,20 +465,13 @@ struct CopyStructuredDataWorker
this->OutExt[5] - this->InExt[4],
};
// Give the compiler a hand -- allow optimizations that require both arrays
// to have the same stride.
VTK_ASSUME(src->GetNumberOfComponents() == dest->GetNumberOfComponents());
vtkDataArrayAccessor<Array1T> d(dest);
vtkDataArrayAccessor<Array2T> s(src);
const int dims[3] = {
this->InExt[1] - this->InExt[0] + 1,
this->InExt[3] - this->InExt[2] + 1,
this->InExt[5] - this->InExt[4] + 1,
};
vtkIdType outTupleIdx = 0;
auto dstTupleIter = dstTuples.begin();
for (int outz = relOutExt[4]; outz <= relOutExt[5]; ++outz)
{
const vtkIdType zfactor = static_cast<vtkIdType>(outz) * dims[1];
......@@ -480,61 +481,51 @@ struct CopyStructuredDataWorker
for (int outx = relOutExt[0]; outx <= relOutExt[1]; ++outx)
{
const vtkIdType inTupleIdx = yfactor + outx;
for (int comp = 0, max = dest->GetNumberOfComponents(); comp < max; ++comp)
{
d.Set(outTupleIdx, comp, s.Get(inTupleIdx, comp));
}
outTupleIdx++;
*dstTupleIter++ = srcTuples[inTupleIdx];
}
}
}
}
else
{
vtkDataArrayAccessor<Array1T> d(dest);
vtkDataArrayAccessor<Array2T> s(src);
int writeExt[6];
memcpy(writeExt, this->OutExt, 6 * sizeof(int));
vtkStructuredExtent::Clamp(writeExt, this->InExt);
vtkIdType inDims[3] = { this->InExt[1] - this->InExt[0] + 1,
const vtkIdType inDims[3] = { this->InExt[1] - this->InExt[0] + 1,
this->InExt[3] - this->InExt[2] + 1, this->InExt[5] - this->InExt[4] + 1 };
vtkIdType outDims[3] = { this->OutExt[1] - this->OutExt[0] + 1,
const vtkIdType outDims[3] = { this->OutExt[1] - this->OutExt[0] + 1,
this->OutExt[3] - this->OutExt[2] + 1, this->OutExt[5] - this->OutExt[4] + 1 };
for (int idz = writeExt[4]; idz <= writeExt[5]; ++idz)
{
vtkIdType inTupleId1 = (idz - this->InExt[4]) * inDims[0] * inDims[1];
vtkIdType outTupleId1 = (idz - this->OutExt[4]) * outDims[0] * outDims[1];
const vtkIdType inTupleId1 = (idz - this->InExt[4]) * inDims[0] * inDims[1];
const vtkIdType outTupleId1 = (idz - this->OutExt[4]) * outDims[0] * outDims[1];
for (int idy = writeExt[2]; idy <= writeExt[3]; ++idy)
{
vtkIdType inTupleId2 = inTupleId1 + (idy - this->InExt[2]) * inDims[0];
vtkIdType outTupleId2 = outTupleId1 + (idy - this->OutExt[2]) * outDims[0];
const vtkIdType inTupleId2 = inTupleId1 + (idy - this->InExt[2]) * inDims[0];
const vtkIdType outTupleId2 = outTupleId1 + (idy - this->OutExt[2]) * outDims[0];
for (int idx = writeExt[0]; idx <= writeExt[1]; ++idx)
{
vtkIdType inTupleIdx = inTupleId2 + idx - this->InExt[0];
vtkIdType outTupleIdx = outTupleId2 + idx - this->OutExt[0];
for (int comp = 0, max = dest->GetNumberOfComponents(); comp < max; ++comp)
{
d.Set(outTupleIdx, comp, s.Get(inTupleIdx, comp));
}
const vtkIdType inTupleIdx = inTupleId2 + idx - this->InExt[0];
const vtkIdType outTupleIdx = outTupleId2 + idx - this->OutExt[0];
dstTuples[outTupleIdx] = srcTuples[inTupleIdx];
}
}
}
}
dest->DataChanged();
dstArray->DataChanged();
}
};
} // end anon namespace
//----------------------------------------------------------------------------
// Handle vtkAbstractArrays that aren't vtkDataArrays.
template <class iterT>
void vtkDataSetAttributesCopyValues(iterT* destIter, const int* outExt, vtkIdType outIncs[3],
iterT* srcIter, const int* inExt, vtkIdType inIncs[3])
{
// For vtkDataArray subclasses.
int data_type_size = srcIter->GetArray()->GetDataTypeSize();
vtkIdType rowLength = outIncs[1];
unsigned char* inPtr;
......@@ -569,6 +560,7 @@ void vtkDataSetAttributesCopyValues(iterT* destIter, const int* outExt, vtkIdTyp
}
//----------------------------------------------------------------------------
// Specialize for vtkStringArray.
template <>
void vtkDataSetAttributesCopyValues(vtkArrayIteratorTemplate<vtkStdString>* destIter,
const int* outExt, vtkIdType outIncs[3], vtkArrayIteratorTemplate<vtkStdString>* srcIter,
......@@ -598,6 +590,8 @@ void vtkDataSetAttributesCopyValues(vtkArrayIteratorTemplate<vtkStdString>* dest
}
}
} // end anon namespace
//----------------------------------------------------------------------------
// This is used in the imaging pipeline for copying arrays.
// CopyAllocate needs to be called before this method.
......
......@@ -16,11 +16,12 @@
#include "vtkAbstractTransform.h"
#include "vtkArrayDispatch.h"
#include "vtkAssume.h"
#include "vtkDataArrayAccessor.h"
#include "vtkDataArrayRange.h"
#include "vtkMath.h"
#include "vtkTransform.h"
#include <algorithm>
vtkCxxSetObjectMacro(vtkImplicitFunction, Transform, vtkAbstractTransform);
vtkImplicitFunction::vtkImplicitFunction()
......@@ -49,23 +50,23 @@ struct FunctionWorker
template <typename SourceArray, typename DestinationArray>
void operator()(SourceArray* input, DestinationArray* output)
{
VTK_ASSUME(input->GetNumberOfComponents() == 3);
VTK_ASSUME(output->GetNumberOfComponents() == 1);
vtkIdType numTuples = input->GetNumberOfTuples();