Improve CellSet API

Add useful virtual functions to the vtkm::cont::CellSet base class.
This commit is contained in:
Sujin Philip 2019-03-19 14:08:29 -04:00
parent b44d1b2d6b
commit 8868fb989b
6 changed files with 153 additions and 8 deletions

@ -68,6 +68,13 @@ public:
virtual vtkm::Id GetNumberOfPoints() const = 0; virtual vtkm::Id GetNumberOfPoints() const = 0;
virtual vtkm::UInt8 GetCellShape(vtkm::Id id) const = 0;
virtual vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id id) const = 0;
virtual void GetCellPointIds(vtkm::Id id, vtkm::Id* ptids) const = 0;
virtual std::shared_ptr<CellSet> CreateNewInstance() const = 0;
virtual void DeepCopy(const CellSet* src) = 0;
virtual void PrintSummary(std::ostream&) const = 0; virtual void PrintSummary(std::ostream&) const = 0;
virtual void ReleaseResourcesExecution() = 0; virtual void ReleaseResourcesExecution() = 0;

@ -123,12 +123,16 @@ public:
void PrintSummary(std::ostream& out) const override; void PrintSummary(std::ostream& out) const override;
void ReleaseResourcesExecution() override; void ReleaseResourcesExecution() override;
std::shared_ptr<CellSet> CreateNewInstance() const override;
void DeepCopy(const CellSet* src) override;
VTKM_CONT vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const; VTKM_CONT vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const;
VTKM_CONT vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const; VTKM_CONT vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const;
VTKM_CONT vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id cellIndex) const; VTKM_CONT vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id cellIndex) const override;
void GetCellPointIds(vtkm::Id id, vtkm::Id* ptids) const override;
VTKM_CONT vtkm::UInt8 GetCellShape(vtkm::Id cellIndex) const; VTKM_CONT vtkm::UInt8 GetCellShape(vtkm::Id cellIndex) const override;
template <vtkm::IdComponent ItemTupleLength> template <vtkm::IdComponent ItemTupleLength>
VTKM_CONT void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id, ItemTupleLength>& ids) const; VTKM_CONT void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id, ItemTupleLength>& ids) const;

@ -182,6 +182,21 @@ vtkm::Id CellSetExplicit<ShapeStorageTag,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
template <typename ShapeStorageTag,
typename NumIndicesStorageTag,
typename ConnectivityStorageTag,
typename OffsetsStorageTag>
void CellSetExplicit<ShapeStorageTag,
NumIndicesStorageTag,
ConnectivityStorageTag,
OffsetsStorageTag>::GetCellPointIds(vtkm::Id id, vtkm::Id* ptids) const
{
auto arrayWrapper = vtkm::cont::make_ArrayHandle(ptids, this->GetNumberOfPointsInCell(id));
this->GetIndices(id, arrayWrapper);
}
//----------------------------------------------------------------------------
template <typename ShapeStorageTag, template <typename ShapeStorageTag,
typename NumIndicesStorageTag, typename NumIndicesStorageTag,
typename ConnectivityStorageTag, typename ConnectivityStorageTag,
@ -485,6 +500,45 @@ VTKM_CONT auto CellSetExplicit<ShapeStorageTag,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
template <typename ShapeStorageTag,
typename NumIndicesStorageTag,
typename ConnectivityStorageTag,
typename OffsetsStorageTag>
std::shared_ptr<CellSet> CellSetExplicit<ShapeStorageTag,
NumIndicesStorageTag,
ConnectivityStorageTag,
OffsetsStorageTag>::CreateNewInstance() const
{
return std::make_shared<CellSetExplicit>();
}
template <typename ShapeStorageTag,
typename NumIndicesStorageTag,
typename ConnectivityStorageTag,
typename OffsetsStorageTag>
void CellSetExplicit<ShapeStorageTag,
NumIndicesStorageTag,
ConnectivityStorageTag,
OffsetsStorageTag>::DeepCopy(const CellSet* src)
{
const auto* other = dynamic_cast<const CellSetExplicit*>(src);
if (!other)
{
throw vtkm::cont::ErrorBadType("CellSetExplicit::DeepCopy types don't match");
}
// TODO: implement actual deep-copy of the arrays
auto pt = vtkm::TopologyElementTagPoint{};
auto ct = vtkm::TopologyElementTagCell{};
this->Fill(other->GetNumberOfPoints(),
other->GetShapesArray(pt, ct),
other->GetNumIndicesArray(pt, ct),
other->GetConnectivityArray(pt, ct),
other->GetIndexOffsetArray(pt, ct));
}
//----------------------------------------------------------------------------
namespace detail namespace detail
{ {

@ -213,14 +213,41 @@ public:
this->CellToPoint.ReleaseResourcesExecution(); this->CellToPoint.ReleaseResourcesExecution();
} }
VTKM_CONT VTKM_CONT
vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id cellIndex) const vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id cellIndex) const override
{ {
return this->FullCellSet.GetNumberOfPointsInCell( return this->FullCellSet.GetNumberOfPointsInCell(
this->ValidCellIds.GetPortalConstControl().Get(cellIndex)); this->ValidCellIds.GetPortalConstControl().Get(cellIndex));
} }
vtkm::UInt8 GetCellShape(vtkm::Id id) const override
{
return this->FullCellSet.GetCellShape(this->ValidCellIds.GetPortalConstControl().Get(id));
}
void GetCellPointIds(vtkm::Id id, vtkm::Id* ptids) const override
{
return this->FullCellSet.GetCellPointIds(this->ValidCellIds.GetPortalConstControl().Get(id),
ptids);
}
std::shared_ptr<CellSet> CreateNewInstance() const override
{
return std::make_shared<CellSetPermutation>();
}
void DeepCopy(const CellSet* src) override
{
const auto* other = dynamic_cast<const CellSetPermutation*>(src);
if (!other)
{
throw vtkm::cont::ErrorBadType("CellSetPermutaion::DeepCopy types don't match");
}
this->FullCellSet.DeepCopy(&(other->GetFullCellSet()));
this->ValidCellIds = other->GetValidCellIds();
}
//This is the way you can fill the memory from another system without copying //This is the way you can fill the memory from another system without copying
VTKM_CONT VTKM_CONT
void Fill(const PermutationArrayHandleType& validCellIds, const OriginalCellSetType& cellset) void Fill(const PermutationArrayHandleType& validCellIds, const OriginalCellSetType& cellset)
@ -366,6 +393,11 @@ public:
this->ValidCellIds = make_ArrayHandlePermutation(validCellIds, cellset.GetValidCellIds()); this->ValidCellIds = make_ArrayHandlePermutation(validCellIds, cellset.GetValidCellIds());
this->FullCellSet = cellset.GetFullCellSet(); this->FullCellSet = cellset.GetFullCellSet();
} }
std::shared_ptr<CellSet> CreateNewInstance() const
{
return std::make_shared<CellSetPermutation>();
}
}; };
template <typename OriginalCellSet, typename PermutationArrayHandleType> template <typename OriginalCellSet, typename PermutationArrayHandleType>

@ -206,12 +206,32 @@ public:
vtkm::Id GetCellShapeAsId() const { return this->CellShapeAsId; } vtkm::Id GetCellShapeAsId() const { return this->CellShapeAsId; }
VTKM_CONT VTKM_CONT
vtkm::UInt8 GetCellShape(vtkm::Id vtkmNotUsed(cellIndex)) const vtkm::UInt8 GetCellShape(vtkm::Id vtkmNotUsed(cellIndex)) const override
{ {
return static_cast<vtkm::UInt8>(this->CellShapeAsId); return static_cast<vtkm::UInt8>(this->CellShapeAsId);
} }
virtual void PrintSummary(std::ostream& out) const VTKM_CONT
std::shared_ptr<CellSet> CreateNewInstance() const override
{
return std::make_shared<CellSetSingleType>();
}
VTKM_CONT
void DeepCopy(const CellSet* src) override
{
const auto* other = dynamic_cast<const CellSetSingleType*>(src);
if (!other)
{
throw vtkm::cont::ErrorBadType("CellSetSingleType::DeepCopy types don't match");
}
this->Superclass::DeepCopy(other);
this->CellShapeAsId = other->CellShapeAsId;
this->NumberOfPointsPerCell = other->NumberOfPointsPerCell;
}
virtual void PrintSummary(std::ostream& out) const override
{ {
out << " ExplicitSingleCellSet: " << this->Name << " Type " << this->CellShapeAsId out << " ExplicitSingleCellSet: " << this->Name << " Type " << this->CellShapeAsId
<< std::endl; << std::endl;

@ -87,12 +87,40 @@ public:
return this->Structure.GetGlobalPointIndexStart(); return this->Structure.GetGlobalPointIndexStart();
} }
vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id vtkmNotUsed(cellIndex) = 0) const vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id vtkmNotUsed(cellIndex) = 0) const override
{ {
return this->Structure.GetNumberOfPointsInCell(); return this->Structure.GetNumberOfPointsInCell();
} }
vtkm::IdComponent GetCellShape() const { return this->Structure.GetCellShape(); } vtkm::UInt8 GetCellShape(vtkm::Id vtkmNotUsed(cellIndex) = 0) const override
{
return static_cast<vtkm::UInt8>(this->Structure.GetCellShape());
}
void GetCellPointIds(vtkm::Id id, vtkm::Id* ptids) const override
{
auto asVec = this->Structure.GetPointsOfCell(id);
for (vtkm::IdComponent i = 0; i < InternalsType::NUM_POINTS_IN_CELL; ++i)
{
ptids[i] = asVec[i];
}
}
std::shared_ptr<CellSet> CreateNewInstance() const override
{
return std::make_shared<CellSetStructured>();
}
void DeepCopy(const CellSet* src) override
{
const auto* other = dynamic_cast<const CellSetStructured*>(src);
if (!other)
{
throw vtkm::cont::ErrorBadType("CellSetStructured::DeepCopy types don't match");
}
this->Structure = other->Structure;
}
template <typename TopologyElement> template <typename TopologyElement>
SchedulingRangeType GetSchedulingRange(TopologyElement) const; SchedulingRangeType GetSchedulingRange(TopologyElement) const;