2017-08-10 20:13:58 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2017-08-10 20:13:58 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
2019-07-01 18:03:40 +00:00
|
|
|
#ifndef vtk_m_cont_CellSetExplicit_hxx
|
|
|
|
#define vtk_m_cont_CellSetExplicit_hxx
|
|
|
|
|
2017-08-10 20:13:58 +00:00
|
|
|
#include <vtkm/cont/RuntimeDeviceTracker.h>
|
|
|
|
#include <vtkm/cont/TryExecute.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::CellSetExplicit(const std::string& name)
|
|
|
|
: CellSet(name)
|
2018-08-22 16:09:56 +00:00
|
|
|
, Data(std::make_shared<Internals>())
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::CellSetExplicit(const Thisclass& src)
|
|
|
|
: CellSet(src)
|
2018-08-22 16:09:56 +00:00
|
|
|
, Data(src.Data)
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-12-07 20:54:20 +00:00
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::CellSetExplicit(Thisclass &&src) noexcept
|
|
|
|
: CellSet(std::forward<CellSet>(src)),
|
|
|
|
Data(std::move(src.Data))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-10 20:13:58 +00:00
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT auto
|
|
|
|
CellSetExplicit<ShapeStorageTag, NumIndicesStorageTag, ConnectivityStorageTag, OffsetsStorageTag>::
|
|
|
|
operator=(const Thisclass& src) -> Thisclass&
|
|
|
|
{
|
|
|
|
this->CellSet::operator=(src);
|
2018-08-22 16:09:56 +00:00
|
|
|
this->Data = src.Data;
|
2017-08-10 20:13:58 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-12-07 20:54:20 +00:00
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT auto
|
|
|
|
CellSetExplicit<ShapeStorageTag, NumIndicesStorageTag, ConnectivityStorageTag, OffsetsStorageTag>::
|
|
|
|
operator=(Thisclass&& src) noexcept -> Thisclass&
|
|
|
|
{
|
|
|
|
this->CellSet::operator=(std::forward<CellSet>(src));
|
|
|
|
this->Data = std::move(src.Data);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-08-10 20:13:58 +00:00
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
CellSetExplicit<ShapeStorageTag, NumIndicesStorageTag, ConnectivityStorageTag, OffsetsStorageTag>::
|
2017-10-12 17:32:39 +00:00
|
|
|
~CellSetExplicit()
|
|
|
|
// explicitly define instead of '=default' to workaround an intel compiler bug
|
|
|
|
// (see #179)
|
|
|
|
{
|
|
|
|
}
|
2017-08-10 20:13:58 +00:00
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
void CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::PrintSummary(std::ostream& out) const
|
|
|
|
{
|
|
|
|
out << " ExplicitCellSet: " << this->Name << std::endl;
|
2019-07-30 16:53:51 +00:00
|
|
|
out << " VisitCellsWithPoints: " << std::endl;
|
|
|
|
this->Data->VisitCellsWithPoints.PrintSummary(out);
|
|
|
|
out << " VisitPointsWithCells: " << std::endl;
|
|
|
|
this->Data->VisitPointsWithCells.PrintSummary(out);
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 18:32:06 +00:00
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetStorageTag>
|
|
|
|
void CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetStorageTag>::ReleaseResourcesExecution()
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.ReleaseResourcesExecution();
|
|
|
|
this->Data->VisitPointsWithCells.ReleaseResourcesExecution();
|
2018-05-30 18:32:06 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 20:13:58 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
vtkm::Id CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::GetNumberOfCells() const
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
return this->Data->VisitCellsWithPoints.GetNumberOfElements();
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
vtkm::Id CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::GetNumberOfPoints() const
|
|
|
|
{
|
2018-08-22 16:09:56 +00:00
|
|
|
return this->Data->NumberOfPoints;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
vtkm::Id CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::GetNumberOfFaces() const
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
vtkm::Id CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::GetNumberOfEdges() const
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-03-19 18:08:29 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2017-08-10 20:13:58 +00:00
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT vtkm::Id
|
|
|
|
CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::GetSchedulingRange(vtkm::TopologyElementTagCell) const
|
|
|
|
{
|
|
|
|
return this->GetNumberOfCells();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT vtkm::Id
|
|
|
|
CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::GetSchedulingRange(vtkm::TopologyElementTagPoint) const
|
|
|
|
{
|
|
|
|
return this->GetNumberOfPoints();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT vtkm::IdComponent
|
|
|
|
CellSetExplicit<ShapeStorageTag, NumIndicesStorageTag, ConnectivityStorageTag, OffsetsStorageTag>::
|
|
|
|
GetNumberOfPointsInCell(vtkm::Id cellIndex) const
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
return this->Data->VisitCellsWithPoints.NumIndices.GetPortalConstControl().Get(cellIndex);
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT vtkm::UInt8 CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::GetCellShape(vtkm::Id cellIndex) const
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
return this->Data->VisitCellsWithPoints.Shapes.GetPortalConstControl().Get(cellIndex);
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
template <vtkm::IdComponent ItemTupleLength>
|
|
|
|
VTKM_CONT void
|
|
|
|
CellSetExplicit<ShapeStorageTag, NumIndicesStorageTag, ConnectivityStorageTag, OffsetsStorageTag>::
|
|
|
|
GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id, ItemTupleLength>& ids) const
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.BuildIndexOffsets(vtkm::cont::DeviceAdapterTagAny{});
|
2017-08-10 20:13:58 +00:00
|
|
|
vtkm::IdComponent numIndices = this->GetNumberOfPointsInCell(index);
|
2019-07-30 16:53:51 +00:00
|
|
|
vtkm::Id start = this->Data->VisitCellsWithPoints.IndexOffsets.GetPortalConstControl().Get(index);
|
2017-08-10 20:13:58 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < numIndices && i < ItemTupleLength; i++)
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
ids[i] = this->Data->VisitCellsWithPoints.Connectivity.GetPortalConstControl().Get(start + i);
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-28 20:58:44 +00:00
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT void
|
|
|
|
CellSetExplicit<ShapeStorageTag, NumIndicesStorageTag, ConnectivityStorageTag, OffsetsStorageTag>::
|
|
|
|
GetIndices(vtkm::Id index, vtkm::cont::ArrayHandle<vtkm::Id>& ids) const
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.BuildIndexOffsets(vtkm::cont::DeviceAdapterTagAny{});
|
2017-08-28 20:58:44 +00:00
|
|
|
vtkm::IdComponent numIndices = this->GetNumberOfPointsInCell(index);
|
|
|
|
ids.Allocate(numIndices);
|
2019-07-30 16:53:51 +00:00
|
|
|
vtkm::Id start = this->Data->VisitCellsWithPoints.IndexOffsets.GetPortalConstControl().Get(index);
|
2017-08-28 20:58:44 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id>::PortalControl idPortal = ids.GetPortalControl();
|
2019-07-30 16:53:51 +00:00
|
|
|
auto PtCellPortal = this->Data->VisitCellsWithPoints.Connectivity.GetPortalConstControl();
|
2017-08-28 20:58:44 +00:00
|
|
|
|
|
|
|
for (vtkm::IdComponent i = 0; i < numIndices && i < numIndices; i++)
|
2019-07-30 16:53:51 +00:00
|
|
|
{
|
2017-08-28 20:58:44 +00:00
|
|
|
idPortal.Set(i, PtCellPortal.Get(start + i));
|
2019-07-30 16:53:51 +00:00
|
|
|
}
|
2017-08-28 20:58:44 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 20:13:58 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT void CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::PrepareToAddCells(vtkm::Id numCells,
|
|
|
|
vtkm::Id connectivityMaxLen)
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.Shapes.Allocate(numCells);
|
|
|
|
this->Data->VisitCellsWithPoints.NumIndices.Allocate(numCells);
|
|
|
|
this->Data->VisitCellsWithPoints.Connectivity.Allocate(connectivityMaxLen);
|
|
|
|
this->Data->VisitCellsWithPoints.IndexOffsets.Allocate(numCells);
|
2018-08-22 16:09:56 +00:00
|
|
|
this->Data->NumberOfCellsAdded = 0;
|
|
|
|
this->Data->ConnectivityAdded = 0;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
template <typename IdVecType>
|
|
|
|
VTKM_CONT void
|
|
|
|
CellSetExplicit<ShapeStorageTag, NumIndicesStorageTag, ConnectivityStorageTag, OffsetsStorageTag>::
|
|
|
|
AddCell(vtkm::UInt8 cellType, vtkm::IdComponent numVertices, const IdVecType& ids)
|
|
|
|
{
|
|
|
|
using Traits = vtkm::VecTraits<IdVecType>;
|
|
|
|
VTKM_STATIC_ASSERT_MSG((std::is_same<typename Traits::ComponentType, vtkm::Id>::value),
|
|
|
|
"CellSetSingleType::AddCell requires vtkm::Id for indices.");
|
|
|
|
|
|
|
|
if (Traits::GetNumberOfComponents(ids) < numVertices)
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("Not enough indices given to CellSetSingleType::AddCell.");
|
|
|
|
}
|
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
if (this->Data->NumberOfCellsAdded >= this->Data->VisitCellsWithPoints.Shapes.GetNumberOfValues())
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("Added more cells then expected.");
|
|
|
|
}
|
2018-08-22 16:09:56 +00:00
|
|
|
if (this->Data->ConnectivityAdded + numVertices >
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.Connectivity.GetNumberOfValues())
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue(
|
|
|
|
"Connectivity increased passed estimated maximum connectivity.");
|
|
|
|
}
|
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.Shapes.GetPortalControl().Set(this->Data->NumberOfCellsAdded,
|
|
|
|
cellType);
|
|
|
|
this->Data->VisitCellsWithPoints.NumIndices.GetPortalControl().Set(this->Data->NumberOfCellsAdded,
|
|
|
|
numVertices);
|
2017-08-10 20:13:58 +00:00
|
|
|
for (vtkm::IdComponent iVec = 0; iVec < numVertices; ++iVec)
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.Connectivity.GetPortalControl().Set(
|
2018-08-22 16:09:56 +00:00
|
|
|
this->Data->ConnectivityAdded + iVec, Traits::GetComponent(ids, iVec));
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.IndexOffsets.GetPortalControl().Set(
|
|
|
|
this->Data->NumberOfCellsAdded, this->Data->ConnectivityAdded);
|
2018-08-22 16:09:56 +00:00
|
|
|
this->Data->NumberOfCellsAdded++;
|
|
|
|
this->Data->ConnectivityAdded += numVertices;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT void CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
OffsetsStorageTag>::CompleteAddingCells(vtkm::Id numPoints)
|
|
|
|
{
|
2018-08-22 16:09:56 +00:00
|
|
|
this->Data->NumberOfPoints = numPoints;
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.Connectivity.Shrink(this->Data->ConnectivityAdded);
|
|
|
|
this->Data->VisitCellsWithPoints.ElementsValid = true;
|
|
|
|
this->Data->VisitCellsWithPoints.IndexOffsetsValid = true;
|
2017-08-10 20:13:58 +00:00
|
|
|
|
2018-08-22 16:09:56 +00:00
|
|
|
if (this->Data->NumberOfCellsAdded != this->GetNumberOfCells())
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("Did not add as many cells as expected.");
|
|
|
|
}
|
|
|
|
|
2018-08-22 16:09:56 +00:00
|
|
|
this->Data->NumberOfCellsAdded = -1;
|
|
|
|
this->Data->ConnectivityAdded = -1;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT void
|
|
|
|
CellSetExplicit<ShapeStorageTag, NumIndicesStorageTag, ConnectivityStorageTag, OffsetsStorageTag>::
|
|
|
|
Fill(vtkm::Id numPoints,
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::UInt8, ShapeStorageTag>& cellTypes,
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::IdComponent, NumIndicesStorageTag>& numIndices,
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Id, ConnectivityStorageTag>& connectivity,
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Id, OffsetsStorageTag>& offsets)
|
|
|
|
{
|
2018-08-22 16:09:56 +00:00
|
|
|
this->Data->NumberOfPoints = numPoints;
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.Shapes = cellTypes;
|
|
|
|
this->Data->VisitCellsWithPoints.NumIndices = numIndices;
|
|
|
|
this->Data->VisitCellsWithPoints.Connectivity = connectivity;
|
2017-08-10 20:13:58 +00:00
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.ElementsValid = true;
|
2017-08-10 20:13:58 +00:00
|
|
|
|
|
|
|
if (offsets.GetNumberOfValues() == cellTypes.GetNumberOfValues())
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.IndexOffsets = offsets;
|
|
|
|
this->Data->VisitCellsWithPoints.IndexOffsetsValid = true;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->Data->VisitCellsWithPoints.IndexOffsetsValid = false;
|
2017-08-10 20:13:58 +00:00
|
|
|
if (offsets.GetNumberOfValues() != 0)
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("Explicit cell offsets array unexpected size. "
|
|
|
|
"Use an empty array to automatically generate.");
|
|
|
|
}
|
|
|
|
}
|
2018-08-22 16:09:56 +00:00
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
this->ResetConnectivity(TopologyElementTagPoint{}, TopologyElementTagCell{});
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
2019-07-30 16:53:51 +00:00
|
|
|
template <typename Device, typename VisitTopology, typename IncidentTopology>
|
2017-08-10 20:13:58 +00:00
|
|
|
auto CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
2019-07-30 16:53:51 +00:00
|
|
|
OffsetsStorageTag>::PrepareForInput(Device,
|
|
|
|
VisitTopology,
|
|
|
|
IncidentTopology) const ->
|
|
|
|
typename ExecutionTypes<Device, VisitTopology, IncidentTopology>::ExecObjectType
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->BuildConnectivity(Device{}, VisitTopology(), IncidentTopology());
|
2017-08-10 20:13:58 +00:00
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
const auto& connectivity = this->GetConnectivity(VisitTopology(), IncidentTopology());
|
2017-08-10 20:13:58 +00:00
|
|
|
VTKM_ASSERT(connectivity.ElementsValid);
|
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
using ExecObjType =
|
|
|
|
typename ExecutionTypes<Device, VisitTopology, IncidentTopology>::ExecObjectType;
|
2017-08-10 20:13:58 +00:00
|
|
|
return ExecObjType(connectivity.Shapes.PrepareForInput(Device()),
|
|
|
|
connectivity.NumIndices.PrepareForInput(Device()),
|
|
|
|
connectivity.Connectivity.PrepareForInput(Device()),
|
|
|
|
connectivity.IndexOffsets.PrepareForInput(Device()));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
2019-07-30 16:53:51 +00:00
|
|
|
template <typename VisitTopology, typename IncidentTopology>
|
2017-08-10 20:13:58 +00:00
|
|
|
VTKM_CONT auto CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
2019-07-30 16:53:51 +00:00
|
|
|
OffsetsStorageTag>::GetShapesArray(VisitTopology,
|
|
|
|
IncidentTopology) const -> const
|
|
|
|
typename ConnectivityChooser<VisitTopology, IncidentTopology>::ShapeArrayType&
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->BuildConnectivity(vtkm::cont::DeviceAdapterTagAny{}, VisitTopology(), IncidentTopology());
|
|
|
|
return this->GetConnectivity(VisitTopology(), IncidentTopology()).Shapes;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
2019-07-30 16:53:51 +00:00
|
|
|
template <typename VisitTopology, typename IncidentTopology>
|
2017-08-10 20:13:58 +00:00
|
|
|
VTKM_CONT auto CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
2019-07-30 16:53:51 +00:00
|
|
|
OffsetsStorageTag>::GetNumIndicesArray(VisitTopology,
|
|
|
|
IncidentTopology) const
|
|
|
|
-> const typename ConnectivityChooser<VisitTopology, IncidentTopology>::NumIndicesArrayType&
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->BuildConnectivity(vtkm::cont::DeviceAdapterTagAny{}, VisitTopology(), IncidentTopology());
|
|
|
|
return this->GetConnectivity(VisitTopology(), IncidentTopology()).NumIndices;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
2019-07-30 16:53:51 +00:00
|
|
|
template <typename VisitTopology, typename IncidentTopology>
|
2017-08-10 20:13:58 +00:00
|
|
|
VTKM_CONT auto CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
2019-07-30 16:53:51 +00:00
|
|
|
OffsetsStorageTag>::GetConnectivityArray(VisitTopology,
|
|
|
|
IncidentTopology) const
|
|
|
|
-> const typename ConnectivityChooser<VisitTopology, IncidentTopology>::ConnectivityArrayType&
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->BuildConnectivity(vtkm::cont::DeviceAdapterTagAny{}, VisitTopology(), IncidentTopology());
|
|
|
|
return this->GetConnectivity(VisitTopology(), IncidentTopology()).Connectivity;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
2019-07-30 16:53:51 +00:00
|
|
|
template <typename VisitTopology, typename IncidentTopology>
|
2017-08-10 20:13:58 +00:00
|
|
|
VTKM_CONT auto CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
2019-07-30 16:53:51 +00:00
|
|
|
OffsetsStorageTag>::GetIndexOffsetArray(VisitTopology,
|
|
|
|
IncidentTopology) const
|
|
|
|
-> const typename ConnectivityChooser<VisitTopology, IncidentTopology>::IndexOffsetArrayType&
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->BuildConnectivity(vtkm::cont::DeviceAdapterTagAny{}, VisitTopology(), IncidentTopology());
|
|
|
|
return this->GetConnectivity(VisitTopology(), IncidentTopology()).IndexOffsets;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-03-19 18:08:29 +00:00
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
std::shared_ptr<CellSet> CellSetExplicit<ShapeStorageTag,
|
|
|
|
NumIndicesStorageTag,
|
|
|
|
ConnectivityStorageTag,
|
2019-04-02 20:23:51 +00:00
|
|
|
OffsetsStorageTag>::NewInstance() const
|
2019-03-19 18:08:29 +00:00
|
|
|
{
|
|
|
|
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 ct = vtkm::TopologyElementTagCell{};
|
2019-07-30 16:53:51 +00:00
|
|
|
auto pt = vtkm::TopologyElementTagPoint{};
|
2019-03-19 18:08:29 +00:00
|
|
|
this->Fill(other->GetNumberOfPoints(),
|
2019-07-30 16:53:51 +00:00
|
|
|
other->GetShapesArray(ct, pt),
|
|
|
|
other->GetNumIndicesArray(ct, pt),
|
|
|
|
other->GetConnectivityArray(ct, pt),
|
|
|
|
other->GetIndexOffsetArray(ct, pt));
|
2019-03-19 18:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2017-08-10 20:13:58 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
template <typename VisitCellsWithPointsConnectivity>
|
|
|
|
struct BuildVisitCellsWithPointsConnectivityFunctor
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
explicit BuildVisitCellsWithPointsConnectivityFunctor(VisitCellsWithPointsConnectivity& obj)
|
|
|
|
: VisitCellsWithPoints(&obj)
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Device>
|
|
|
|
bool operator()(Device) const
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->VisitCellsWithPoints->BuildIndexOffsets(Device());
|
2017-08-10 20:13:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
VisitCellsWithPointsConnectivity* VisitCellsWithPoints;
|
2017-08-10 20:13:58 +00:00
|
|
|
};
|
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
template <typename VisitCellsWithPointsConnectivity, typename VisitPointsWithCellsConnectivity>
|
|
|
|
struct BuildVisitPointsWithCellsConnectivityFunctor
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
BuildVisitPointsWithCellsConnectivityFunctor(
|
|
|
|
VisitCellsWithPointsConnectivity& visitCellsWithPoints,
|
|
|
|
VisitPointsWithCellsConnectivity& visitPointsWithCells,
|
|
|
|
vtkm::Id numberOfPoints)
|
|
|
|
: VisitCellsWithPoints(&visitCellsWithPoints)
|
|
|
|
, VisitPointsWithCells(&visitPointsWithCells)
|
2017-08-10 20:13:58 +00:00
|
|
|
, NumberOfPoints(numberOfPoints)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Device>
|
|
|
|
bool operator()(Device) const
|
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
this->VisitCellsWithPoints->BuildIndexOffsets(Device());
|
|
|
|
internal::ComputeVisitPointsWithCellsConnectivity(
|
|
|
|
*this->VisitPointsWithCells, *this->VisitCellsWithPoints, this->NumberOfPoints, Device());
|
|
|
|
this->VisitPointsWithCells->BuildIndexOffsets(Device());
|
2017-08-10 20:13:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
VisitCellsWithPointsConnectivity* VisitCellsWithPoints;
|
|
|
|
VisitPointsWithCellsConnectivity* VisitPointsWithCells;
|
2017-08-10 20:13:58 +00:00
|
|
|
vtkm::Id NumberOfPoints;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // detail
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT void
|
|
|
|
CellSetExplicit<ShapeStorageTag, NumIndicesStorageTag, ConnectivityStorageTag, OffsetsStorageTag>::
|
2018-08-22 18:50:38 +00:00
|
|
|
BuildConnectivity(vtkm::cont::DeviceAdapterId device,
|
2019-07-30 16:53:51 +00:00
|
|
|
vtkm::TopologyElementTagCell,
|
|
|
|
vtkm::TopologyElementTagPoint) const
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
using VisitCellsWithPointsConnectivity =
|
|
|
|
typename ConnectivityChooser<vtkm::TopologyElementTagCell,
|
|
|
|
vtkm::TopologyElementTagPoint>::ConnectivityType;
|
2017-08-10 20:13:58 +00:00
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
VTKM_ASSERT(this->Data->VisitCellsWithPoints.ElementsValid);
|
|
|
|
if (!this->Data->VisitCellsWithPoints.IndexOffsetsValid)
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
auto self = const_cast<Thisclass*>(this);
|
|
|
|
auto functor =
|
2019-07-30 16:53:51 +00:00
|
|
|
detail::BuildVisitCellsWithPointsConnectivityFunctor<VisitCellsWithPointsConnectivity>(
|
|
|
|
self->Data->VisitCellsWithPoints);
|
2018-08-22 18:50:38 +00:00
|
|
|
if (!vtkm::cont::TryExecuteOnDevice(device, functor))
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2018-08-22 18:50:38 +00:00
|
|
|
throw vtkm::cont::ErrorExecution("Failed to run BuildConnectivity.");
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ShapeStorageTag,
|
|
|
|
typename NumIndicesStorageTag,
|
|
|
|
typename ConnectivityStorageTag,
|
|
|
|
typename OffsetsStorageTag>
|
|
|
|
VTKM_CONT void
|
|
|
|
CellSetExplicit<ShapeStorageTag, NumIndicesStorageTag, ConnectivityStorageTag, OffsetsStorageTag>::
|
2018-08-22 18:50:38 +00:00
|
|
|
BuildConnectivity(vtkm::cont::DeviceAdapterId device,
|
2019-07-30 16:53:51 +00:00
|
|
|
vtkm::TopologyElementTagPoint,
|
|
|
|
vtkm::TopologyElementTagCell) const
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-07-30 16:53:51 +00:00
|
|
|
using VisitCellsWithPointsConnectivity =
|
2017-08-10 20:13:58 +00:00
|
|
|
typename ConnectivityChooser<vtkm::TopologyElementTagCell,
|
|
|
|
vtkm::TopologyElementTagPoint>::ConnectivityType;
|
2019-07-30 16:53:51 +00:00
|
|
|
using VisitPointsWithCellsConnectivity =
|
|
|
|
typename ConnectivityChooser<vtkm::TopologyElementTagPoint,
|
|
|
|
vtkm::TopologyElementTagCell>::ConnectivityType;
|
2017-08-10 20:13:58 +00:00
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
if (!this->Data->VisitPointsWithCells.ElementsValid ||
|
|
|
|
!this->Data->VisitPointsWithCells.IndexOffsetsValid)
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
auto self = const_cast<Thisclass*>(this);
|
|
|
|
auto functor =
|
2019-07-30 16:53:51 +00:00
|
|
|
detail::BuildVisitPointsWithCellsConnectivityFunctor<VisitCellsWithPointsConnectivity,
|
|
|
|
VisitPointsWithCellsConnectivity>(
|
|
|
|
self->Data->VisitCellsWithPoints,
|
|
|
|
self->Data->VisitPointsWithCells,
|
|
|
|
this->Data->NumberOfPoints);
|
2018-08-22 18:50:38 +00:00
|
|
|
if (!vtkm::cont::TryExecuteOnDevice(device, functor))
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2018-08-22 18:50:38 +00:00
|
|
|
throw vtkm::cont::ErrorExecution("Failed to run BuildConnectivity.");
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // vtkm::cont
|
2019-07-01 18:03:40 +00:00
|
|
|
#endif
|