improve(CompositeArr): remove dispatch from implementation

dev
Julien Fausty 3 months ago
parent 139d236f13
commit 73b84ead94

@ -42,8 +42,8 @@
* CHECK(compositArr->GetValue(1) == 1);
* ```
*/
#include "vtkSmartPointer.h" // for internal variables
#include "vtkCommonImplicitArraysModule.h"
#include <memory>
VTK_ABI_NAMESPACE_BEGIN
class vtkDataArray;
@ -52,14 +52,13 @@ class vtkCompositeImplicitBackend
{
public:
vtkCompositeImplicitBackend(vtkDataArray* leftArr, vtkDataArray* rightArr);
~vtkCompositeImplicitBackend() = default;
~vtkCompositeImplicitBackend();
ValueType operator()(int idx) const;
protected:
vtkSmartPointer<vtkDataArray> Left = nullptr;
vtkSmartPointer<vtkDataArray> Right = nullptr;
int Offset = 0;
struct Internals;
std::unique_ptr<Internals> Internal;
};
VTK_ABI_NAMESPACE_END

@ -17,66 +17,55 @@
#include "vtkArrayDispatch.h"
#include "vtkArrayDispatchImplicitArrayList.h"
#include "vtkDataArray.h"
#include "vtkDataArrayRange.h"
#include "vtkSmartPointer.h"
VTK_ABI_NAMESPACE_BEGIN
//-----------------------------------------------------------------------
namespace
{
template <typename ValueType>
struct GetValueDispatch
struct vtkCompositeImplicitBackend<ValueType>::Internals
{
template <typename ArrayT>
void operator()(ArrayT* arr, int& idx, ValueType& val) const
Internals(vtkDataArray* leftArr, vtkDataArray* rightArr)
: Left(leftArr)
, Right(rightArr)
{
val = static_cast<ValueType>(arr->GetValue(idx));
if (this->Left == nullptr || this->Right == nullptr)
{
vtkWarningWithObjectMacro(nullptr, "Creating composite array with nullptr");
return;
}
this->LeftRange = vtk::DataArrayValueRange(this->Left);
this->RightRange = vtk::DataArrayValueRange(this->Right);
this->Offset = LeftRange.size();
}
};
}
vtkSmartPointer<vtkDataArray> Left;
vtk::detail::SelectValueRange<vtkDataArray*, vtk::detail::DynamicTupleSize>::type LeftRange;
vtkSmartPointer<vtkDataArray> Right;
vtk::detail::SelectValueRange<vtkDataArray*, vtk::detail::DynamicTupleSize>::type RightRange;
int Offset = -1;
};
VTK_ABI_NAMESPACE_BEGIN
//-----------------------------------------------------------------------
template <typename ValueType>
vtkCompositeImplicitBackend<ValueType>::vtkCompositeImplicitBackend(
vtkDataArray* leftArr, vtkDataArray* rightArr)
: Left(leftArr)
, Right(rightArr)
: Internal(std::unique_ptr<Internals>(new Internals(leftArr, rightArr)))
{
if (this->Left == nullptr || this->Right == nullptr)
{
vtkWarningWithObjectMacro(nullptr, "Creating composite array with nullptr");
return;
}
this->Offset = this->Left->GetDataSize();
}
//-----------------------------------------------------------------------
template <typename ValueType>
ValueType vtkCompositeImplicitBackend<ValueType>::operator()(int idx) const
vtkCompositeImplicitBackend<ValueType>::~vtkCompositeImplicitBackend()
{
int nxtIdx = idx;
vtkDataArray* branch;
if (idx < this->Offset)
{
branch = this->Left;
}
else
{
nxtIdx -= this->Offset;
branch = this->Right;
}
using DisArrays = vtkArrayDispatch::AllArrays;
using Dispatcher = vtkArrayDispatch::DispatchByArray<DisArrays>;
}
ValueType val;
::GetValueDispatch<ValueType> worklet;
if (!Dispatcher::Execute(branch, worklet, nxtIdx, val))
{
int iTup = nxtIdx / branch->GetNumberOfComponents();
int iComp = iTup * branch->GetNumberOfComponents() - nxtIdx;
val = static_cast<ValueType>(branch->GetComponent(iTup, iComp));
}
return val;
//-----------------------------------------------------------------------
template <typename ValueType>
ValueType vtkCompositeImplicitBackend<ValueType>::operator()(int idx) const
{
return static_cast<ValueType>((idx < this->Internal->Offset)
? this->Internal->LeftRange[idx]
: this->Internal->RightRange[idx - this->Internal->Offset]);
}
VTK_ABI_NAMESPACE_END

Loading…
Cancel
Save