Merge topic 'contour-tree-array-decorator'

ebb265ce0 Add missing VTKM_EXEC_CONT declarations to functor
10ea36bb9 Pick one approach of using array handle decorator for contour tree
585f0ccb1 Two versions for replacing array transform with array decorator

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland <kmorel@sandia.gov>
Merge-request: !2412
This commit is contained in:
Gunther Weber 2021-02-22 02:56:23 +00:00 committed by Kitware Robot
commit e3851ce236
2 changed files with 35 additions and 77 deletions

@ -562,14 +562,14 @@ inline void ContourTreeMesh<FieldType>::MergeWith(ContourTreeMesh<FieldType>& ot
IdArrayType overallSortIndex;
overallSortIndex.Allocate(overallSortOrder.GetNumberOfValues());
{
// Functor return 0,1 for each element depending on whethern the current value is different from the next
mesh_dem_contourtree_mesh_inc::CombinedVectorDifferentFromNext differentFromNextFunctor(
this->GlobalMeshIndex, other.GlobalMeshIndex, overallSortOrder);
// Array based on the functor
// TODO: This should really use ArrayHandleDecorator, not ArrayHandleTransform
auto differentFromNextArr = vtkm::cont::make_ArrayHandleTransform(
vtkm::cont::ArrayHandleIndex(overallSortIndex.GetNumberOfValues() - 1),
differentFromNextFunctor);
// Array decorator with functor returning 0, 1 for each element depending
// on whethern the current value is different from the next
auto differentFromNextArr = vtkm::cont::make_ArrayHandleDecorator(
overallSortIndex.GetNumberOfValues() - 1,
mesh_dem_contourtree_mesh_inc::CombinedVectorDifferentFromNextDecoratorImpl{},
overallSortOrder,
this->GlobalMeshIndex,
other.GlobalMeshIndex);
// Compute the exclusive scan of our transformed combined vector
overallSortIndex.WritePortal().Set(0, 0);

@ -76,84 +76,42 @@ namespace contourtree_augmented
namespace mesh_dem_contourtree_mesh_inc
{
/// transform functor to compute if element i is different from element i+1 in an arrays. The
/// Decorator to compute if element i is different from element i+1 in an arrays. The
/// resulting array should hence be 1 element shorter than the input arrays
class CombinedVectorDifferentFromNextExecObj
class CombinedVectorDifferentFromNextDecoratorImpl
{
public:
using IdPortalType = typename vtkm::cont::ArrayHandle<vtkm::Id>::ReadPortalType;
VTKM_EXEC_CONT
CombinedVectorDifferentFromNextExecObj() {}
VTKM_CONT
CombinedVectorDifferentFromNextExecObj(const IdPortalType& thisGlobalMeshIndex,
const IdPortalType& otherGlobalMeshIndex,
const IdPortalType& sortOrder)
: OverallSortOrderPortal(sortOrder)
, ThisGlobalMeshIndex(thisGlobalMeshIndex)
, OtherGlobalMeshIndex(otherGlobalMeshIndex)
template <typename Portal1Type, typename Portal2Type, typename Portal3Type>
struct Functor
{
}
Portal1Type OverallSortOrderPortal;
Portal2Type ThisGlobalMeshIndex;
Portal3Type OtherGlobalMeshIndex;
VTKM_EXEC_CONT
inline vtkm::Id GetGlobalMeshIndex(vtkm::Id idx) const
VTKM_EXEC_CONT inline vtkm::Id GetGlobalMeshIndex(vtkm::Id idx) const
{
return vtkm::worklet::contourtree_augmented::IsThis(idx)
? this->ThisGlobalMeshIndex.Get(MaskedIndex(idx))
: this->OtherGlobalMeshIndex.Get(MaskedIndex(idx));
}
VTKM_EXEC_CONT vtkm::Id operator()(vtkm::Id i) const
{
vtkm::Id currGlobalIdx = this->GetGlobalMeshIndex(this->OverallSortOrderPortal.Get(i));
vtkm::Id nextGlobalIdx = this->GetGlobalMeshIndex(this->OverallSortOrderPortal.Get(i + 1));
return (currGlobalIdx != nextGlobalIdx) ? 1 : 0;
}
};
template <typename PT1, typename PT2, typename PT3>
Functor<PT1, PT2, PT3> CreateFunctor(PT1 OverallSortOrderPortal,
PT2 ThisGlobalMeshIndex,
PT3 OtherGlobalMeshIndex) const
{
return vtkm::worklet::contourtree_augmented::IsThis(idx)
? this->ThisGlobalMeshIndex.Get(MaskedIndex(idx))
: this->OtherGlobalMeshIndex.Get(MaskedIndex(idx));
}
VTKM_EXEC_CONT
vtkm::Id operator()(vtkm::Id i) const
{
vtkm::Id currGlobalIdx = this->GetGlobalMeshIndex(this->OverallSortOrderPortal.Get(i));
vtkm::Id nextGlobalIdx = this->GetGlobalMeshIndex(this->OverallSortOrderPortal.Get(i + 1));
return (currGlobalIdx != nextGlobalIdx) ? 1 : 0;
}
private:
IdPortalType OverallSortOrderPortal;
IdPortalType ThisGlobalMeshIndex;
IdPortalType OtherGlobalMeshIndex;
};
class CombinedVectorDifferentFromNext : public vtkm::cont::ExecutionAndControlObjectBase
{
IdArrayType OverallSortOrder;
IdArrayType ThisGlobalMeshIndex;
IdArrayType OtherGlobalMeshIndex;
public:
CombinedVectorDifferentFromNext() = default;
CombinedVectorDifferentFromNext(const IdArrayType& thisGlobalMeshIndex,
const IdArrayType& otherGlobalMeshIndex,
const IdArrayType& sortOrder)
: OverallSortOrder(sortOrder)
, ThisGlobalMeshIndex(thisGlobalMeshIndex)
, OtherGlobalMeshIndex(otherGlobalMeshIndex)
{
}
VTKM_CONT CombinedVectorDifferentFromNextExecObj
PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token& token) const
{
return CombinedVectorDifferentFromNextExecObj(
this->ThisGlobalMeshIndex.PrepareForInput(device, token),
this->OtherGlobalMeshIndex.PrepareForInput(device, token),
this->OverallSortOrder.PrepareForInput(device, token));
}
VTKM_CONT CombinedVectorDifferentFromNextExecObj PrepareForControl() const
{
return CombinedVectorDifferentFromNextExecObj(this->ThisGlobalMeshIndex.ReadPortal(),
this->OtherGlobalMeshIndex.ReadPortal(),
this->OverallSortOrder.ReadPortal());
return { OverallSortOrderPortal, ThisGlobalMeshIndex, OtherGlobalMeshIndex };
}
};
} // namespace mesh_dem_contourtree_mesh_inc
} // namespace contourtree_augmented
} // namespace worklet