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
|
2019-08-30 17:04:17 +00:00
|
|
|
#include <vtkm/cont/CellSetExplicit.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayGetValues.h>
|
|
|
|
#include <vtkm/cont/Logging.h>
|
2017-08-10 20:13:58 +00:00
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
// This file uses a lot of very verbose identifiers and the clang formatted
|
|
|
|
// code quickly becomes unreadable. Stick with manual formatting for now.
|
|
|
|
//
|
|
|
|
// clang-format off
|
|
|
|
|
2017-08-10 20:13:58 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
CellSetExplicit<SST, CST, OST>::CellSetExplicit()
|
2019-08-13 21:28:37 +00:00
|
|
|
: CellSet()
|
2018-08-22 16:09:56 +00:00
|
|
|
, Data(std::make_shared<Internals>())
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
CellSetExplicit<SST, CST, OST>::CellSetExplicit(const Thisclass& src)
|
2017-08-10 20:13:58 +00:00
|
|
|
: CellSet(src)
|
2018-08-22 16:09:56 +00:00
|
|
|
, Data(src.Data)
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
CellSetExplicit<SST, CST, OST>::CellSetExplicit(Thisclass &&src) noexcept
|
|
|
|
: CellSet(std::forward<CellSet>(src))
|
|
|
|
, Data(std::move(src.Data))
|
2018-12-07 20:54:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
auto CellSetExplicit<SST, CST, OST>::operator=(const Thisclass& src)
|
|
|
|
-> Thisclass&
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
auto CellSetExplicit<SST, CST, OST>::operator=(Thisclass&& src) noexcept
|
|
|
|
-> Thisclass&
|
2018-12-07 20:54:20 +00:00
|
|
|
{
|
|
|
|
this->CellSet::operator=(std::forward<CellSet>(src));
|
|
|
|
this->Data = std::move(src.Data);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
CellSetExplicit<SST, CST, OST>::~CellSetExplicit()
|
2017-10-12 17:32:39 +00:00
|
|
|
{
|
2019-08-30 17:04:17 +00:00
|
|
|
// explicitly define instead of '=default' to workaround an intel compiler bug
|
|
|
|
// (see #179)
|
2017-10-12 17:32:39 +00:00
|
|
|
}
|
2017-08-10 20:13:58 +00:00
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
void CellSetExplicit<SST, CST, OST>::PrintSummary(std::ostream& out) const
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-08-30 17:04:17 +00:00
|
|
|
out << " ExplicitCellSet:" << std::endl;
|
|
|
|
out << " CellPointIds:" << std::endl;
|
|
|
|
this->Data->CellPointIds.PrintSummary(out);
|
|
|
|
out << " PointCellIds:" << std::endl;
|
|
|
|
this->Data->PointCellIds.PrintSummary(out);
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
void CellSetExplicit<SST, CST, OST>::ReleaseResourcesExecution()
|
2018-05-30 18:32:06 +00:00
|
|
|
{
|
2019-08-30 17:04:17 +00:00
|
|
|
this->Data->CellPointIds.ReleaseResourcesExecution();
|
|
|
|
this->Data->PointCellIds.ReleaseResourcesExecution();
|
2018-05-30 18:32:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
vtkm::Id CellSetExplicit<SST, CST, OST>::GetNumberOfCells() const
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-08-30 17:04:17 +00:00
|
|
|
return this->Data->CellPointIds.GetNumberOfElements();
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
vtkm::Id CellSetExplicit<SST, CST, OST>::GetNumberOfPoints() const
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2018-08-22 16:09:56 +00:00
|
|
|
return this->Data->NumberOfPoints;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
vtkm::Id CellSetExplicit<SST, CST, OST>::GetNumberOfFaces() const
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
vtkm::Id CellSetExplicit<SST, CST, OST>::GetNumberOfEdges() const
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
void CellSetExplicit<SST, CST, OST>::GetCellPointIds(vtkm::Id cellId,
|
|
|
|
vtkm::Id* ptids) const
|
|
|
|
{
|
2020-01-28 19:14:32 +00:00
|
|
|
const auto offPortal = this->Data->CellPointIds.Offsets.ReadPortal();
|
2019-08-30 17:04:17 +00:00
|
|
|
const vtkm::Id start = offPortal.Get(cellId);
|
|
|
|
const vtkm::Id end = offPortal.Get(cellId + 1);
|
|
|
|
const vtkm::IdComponent numIndices = static_cast<vtkm::IdComponent>(end - start);
|
2020-01-28 19:14:32 +00:00
|
|
|
auto connPortal = this->Data->CellPointIds.Connectivity.ReadPortal();
|
2019-08-30 17:04:17 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < numIndices; i++)
|
|
|
|
{
|
|
|
|
ptids[i] = connPortal.Get(start + i);
|
|
|
|
}
|
2019-03-19 18:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
vtkm::Id CellSetExplicit<SST, CST, OST>
|
|
|
|
::GetSchedulingRange(vtkm::TopologyElementTagCell) const
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
return this->GetNumberOfCells();
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
vtkm::Id CellSetExplicit<SST, CST, OST>
|
|
|
|
::GetSchedulingRange(vtkm::TopologyElementTagPoint) const
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
return this->GetNumberOfPoints();
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
vtkm::IdComponent CellSetExplicit<SST, CST, OST>
|
|
|
|
::GetNumberOfPointsInCell(vtkm::Id cellid) const
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2020-01-28 19:14:32 +00:00
|
|
|
const auto portal = this->Data->CellPointIds.Offsets.ReadPortal();
|
2019-08-30 17:04:17 +00:00
|
|
|
return static_cast<vtkm::IdComponent>(portal.Get(cellid + 1) -
|
|
|
|
portal.Get(cellid));
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
2020-05-14 22:13:03 +00:00
|
|
|
typename vtkm::cont::ArrayHandle<vtkm::UInt8, SST>::ReadPortalType
|
2020-05-14 22:10:32 +00:00
|
|
|
CellSetExplicit<SST, CST, OST>::ShapesReadPortal() const
|
2020-05-12 19:43:40 +00:00
|
|
|
{
|
|
|
|
return this->Data->CellPointIds.Shapes.ReadPortal();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
2020-05-19 00:41:47 +00:00
|
|
|
VTKM_DEPRECATED(1.6, "Calling GetCellShape(cellid) is a performance bug. Call ShapesReadPortal() and loop over the Get.")
|
2019-08-30 17:04:17 +00:00
|
|
|
vtkm::UInt8 CellSetExplicit<SST, CST, OST>
|
|
|
|
::GetCellShape(vtkm::Id cellid) const
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2020-05-12 19:43:40 +00:00
|
|
|
return this->ShapesReadPortal().Get(cellid);
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 19:43:40 +00:00
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
template <vtkm::IdComponent NumVecIndices>
|
|
|
|
VTKM_CONT
|
|
|
|
void CellSetExplicit<SST, CST, OST>
|
|
|
|
::GetIndices(vtkm::Id cellId, vtkm::Vec<vtkm::Id, NumVecIndices>& ids) const
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2020-01-28 19:14:32 +00:00
|
|
|
const auto offPortal = this->Data->CellPointIds.Offsets.ReadPortal();
|
2019-08-30 17:04:17 +00:00
|
|
|
const vtkm::Id start = offPortal.Get(cellId);
|
|
|
|
const vtkm::Id end = offPortal.Get(cellId + 1);
|
|
|
|
const auto numCellIndices = static_cast<vtkm::IdComponent>(end - start);
|
2020-01-28 19:14:32 +00:00
|
|
|
const auto connPortal = this->Data->CellPointIds.Connectivity.ReadPortal();
|
2019-08-30 17:04:17 +00:00
|
|
|
|
|
|
|
VTKM_LOG_IF_S(vtkm::cont::LogLevel::Warn,
|
|
|
|
numCellIndices != NumVecIndices,
|
|
|
|
"GetIndices given a " << NumVecIndices
|
|
|
|
<< "-vec to fetch a cell with " << numCellIndices << "points. "
|
|
|
|
"Truncating result.");
|
|
|
|
|
|
|
|
const vtkm::IdComponent numIndices = vtkm::Min(NumVecIndices, numCellIndices);
|
|
|
|
|
|
|
|
for (vtkm::IdComponent i = 0; i < numIndices; i++)
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-08-30 17:04:17 +00:00
|
|
|
ids[i] = connPortal.Get(start + i);
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
void CellSetExplicit<SST, CST, OST>
|
|
|
|
::GetIndices(vtkm::Id cellId, vtkm::cont::ArrayHandle<vtkm::Id>& ids) const
|
2017-08-28 20:58:44 +00:00
|
|
|
{
|
2020-01-28 19:14:32 +00:00
|
|
|
const auto offPortal = this->Data->CellPointIds.Offsets.ReadPortal();
|
2019-08-30 17:04:17 +00:00
|
|
|
const vtkm::Id start = offPortal.Get(cellId);
|
|
|
|
const vtkm::Id end = offPortal.Get(cellId + 1);
|
|
|
|
const vtkm::IdComponent numIndices = static_cast<vtkm::IdComponent>(end - start);
|
2017-08-28 20:58:44 +00:00
|
|
|
ids.Allocate(numIndices);
|
2020-01-28 19:14:32 +00:00
|
|
|
auto connPortal = this->Data->CellPointIds.Connectivity.ReadPortal();
|
2019-08-30 17:04:17 +00:00
|
|
|
|
2020-01-28 19:14:32 +00:00
|
|
|
auto outIdPortal = ids.WritePortal();
|
2017-08-28 20:58:44 +00:00
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < numIndices; i++)
|
2019-07-30 16:53:51 +00:00
|
|
|
{
|
2019-08-30 17:04:17 +00:00
|
|
|
outIdPortal.Set(i, connPortal.Get(start + i));
|
2019-07-30 16:53:51 +00:00
|
|
|
}
|
2017-08-28 20:58:44 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
|
2017-08-10 20:13:58 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2019-08-30 17:04:17 +00:00
|
|
|
namespace internal
|
|
|
|
{
|
|
|
|
|
|
|
|
// Sets the first value of the array to zero if the handle is writable,
|
|
|
|
// otherwise do nothing:
|
|
|
|
template <typename ArrayType>
|
|
|
|
typename std::enable_if<vtkm::cont::internal::IsWritableArrayHandle<ArrayType>::value>::type
|
|
|
|
SetFirstToZeroIfWritable(ArrayType&& array)
|
|
|
|
{
|
|
|
|
using ValueType = typename std::decay<ArrayType>::type::ValueType;
|
|
|
|
using Traits = vtkm::TypeTraits<ValueType>;
|
2020-01-28 19:14:32 +00:00
|
|
|
array.WritePortal().Set(0, Traits::ZeroInitialization());
|
2019-08-30 17:04:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ArrayType>
|
|
|
|
typename std::enable_if<!vtkm::cont::internal::IsWritableArrayHandle<ArrayType>::value>::type
|
|
|
|
SetFirstToZeroIfWritable(ArrayType&&)
|
|
|
|
{ /* no-op */ }
|
|
|
|
|
|
|
|
} // end namespace internal
|
2017-08-10 20:13:58 +00:00
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
void CellSetExplicit<SST, CST, OST>
|
|
|
|
::PrepareToAddCells(vtkm::Id numCells,
|
|
|
|
vtkm::Id connectivityMaxLen)
|
|
|
|
{
|
|
|
|
this->Data->CellPointIds.Shapes.Allocate(numCells);
|
|
|
|
this->Data->CellPointIds.Connectivity.Allocate(connectivityMaxLen);
|
|
|
|
this->Data->CellPointIds.Offsets.Allocate(numCells + 1);
|
|
|
|
internal::SetFirstToZeroIfWritable(this->Data->CellPointIds.Offsets);
|
2018-08-22 16:09:56 +00:00
|
|
|
this->Data->NumberOfCellsAdded = 0;
|
|
|
|
this->Data->ConnectivityAdded = 0;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
2017-08-10 20:13:58 +00:00
|
|
|
template <typename IdVecType>
|
2019-08-30 17:04:17 +00:00
|
|
|
VTKM_CONT
|
|
|
|
void CellSetExplicit<SST, CST, OST>::AddCell(vtkm::UInt8 cellType,
|
|
|
|
vtkm::IdComponent numVertices,
|
|
|
|
const IdVecType& ids)
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2019-08-30 17:04:17 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue("Not enough indices given to CellSetExplicit::AddCell.");
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
if (this->Data->NumberOfCellsAdded >= this->Data->CellPointIds.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-08-30 17:04:17 +00:00
|
|
|
this->Data->CellPointIds.Connectivity.GetNumberOfValues())
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue(
|
2019-08-30 17:04:17 +00:00
|
|
|
"Connectivity increased past estimated maximum connectivity.");
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:14:32 +00:00
|
|
|
auto shapes = this->Data->CellPointIds.Shapes.WritePortal();
|
|
|
|
auto conn = this->Data->CellPointIds.Connectivity.WritePortal();
|
|
|
|
auto offsets = this->Data->CellPointIds.Offsets.WritePortal();
|
2019-08-30 17:04:17 +00:00
|
|
|
|
|
|
|
shapes.Set(this->Data->NumberOfCellsAdded, cellType);
|
2017-08-10 20:13:58 +00:00
|
|
|
for (vtkm::IdComponent iVec = 0; iVec < numVertices; ++iVec)
|
|
|
|
{
|
2019-08-30 17:04:17 +00:00
|
|
|
conn.Set(this->Data->ConnectivityAdded + iVec,
|
|
|
|
Traits::GetComponent(ids, iVec));
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
2019-08-30 17:04:17 +00:00
|
|
|
|
2018-08-22 16:09:56 +00:00
|
|
|
this->Data->NumberOfCellsAdded++;
|
|
|
|
this->Data->ConnectivityAdded += numVertices;
|
2019-08-30 17:04:17 +00:00
|
|
|
|
|
|
|
// Set the end offset for the added cell:
|
|
|
|
offsets.Set(this->Data->NumberOfCellsAdded, this->Data->ConnectivityAdded);
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
void CellSetExplicit<SST, CST, OST>::CompleteAddingCells(vtkm::Id numPoints)
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2018-08-22 16:09:56 +00:00
|
|
|
this->Data->NumberOfPoints = numPoints;
|
2021-01-28 21:59:40 +00:00
|
|
|
this->Data->CellPointIds.Connectivity.Allocate(this->Data->ConnectivityAdded, vtkm::CopyFlag::On);
|
2019-08-30 17:04:17 +00:00
|
|
|
this->Data->CellPointIds.ElementsValid = 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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
void CellSetExplicit<SST, CST, OST>
|
|
|
|
::Fill(vtkm::Id numPoints,
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::UInt8, SST>& shapes,
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Id, CST>& connectivity,
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Id, OST>& offsets)
|
|
|
|
{
|
|
|
|
// Validate inputs:
|
|
|
|
// Even for an empty cellset, offsets must contain a single 0:
|
|
|
|
VTKM_ASSERT(offsets.GetNumberOfValues() > 0);
|
|
|
|
// Must be [numCells + 1] offsets and [numCells] shapes
|
|
|
|
VTKM_ASSERT(offsets.GetNumberOfValues() == shapes.GetNumberOfValues() + 1);
|
|
|
|
// The last offset must be the size of the connectivity array.
|
|
|
|
VTKM_ASSERT(vtkm::cont::ArrayGetValue(offsets.GetNumberOfValues() - 1,
|
|
|
|
offsets) ==
|
|
|
|
connectivity.GetNumberOfValues());
|
2017-08-10 20:13:58 +00:00
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
this->Data->NumberOfPoints = numPoints;
|
|
|
|
this->Data->CellPointIds.Shapes = shapes;
|
|
|
|
this->Data->CellPointIds.Connectivity = connectivity;
|
|
|
|
this->Data->CellPointIds.Offsets = offsets;
|
2017-08-10 20:13:58 +00:00
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
this->Data->CellPointIds.ElementsValid = true;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
2021-02-01 15:03:11 +00:00
|
|
|
template <typename VisitTopology, typename IncidentTopology>
|
2019-08-30 17:04:17 +00:00
|
|
|
VTKM_CONT
|
|
|
|
auto CellSetExplicit<SST, CST, OST>
|
2021-02-01 15:03:11 +00:00
|
|
|
::PrepareForInput(vtkm::cont::DeviceAdapterId device, VisitTopology, IncidentTopology, vtkm::cont::Token& token) const
|
|
|
|
-> ExecConnectivityType<VisitTopology, IncidentTopology>
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2021-02-01 15:03:11 +00:00
|
|
|
this->BuildConnectivity(device, VisitTopology{}, IncidentTopology{});
|
2017-08-10 20:13:58 +00:00
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
const auto& connectivity = this->GetConnectivity(VisitTopology{},
|
|
|
|
IncidentTopology{});
|
2017-08-10 20:13:58 +00:00
|
|
|
VTKM_ASSERT(connectivity.ElementsValid);
|
|
|
|
|
2021-02-01 15:03:11 +00:00
|
|
|
using ExecObjType = ExecConnectivityType<VisitTopology, IncidentTopology>;
|
2019-08-30 17:04:17 +00:00
|
|
|
|
2021-02-01 15:03:11 +00:00
|
|
|
return ExecObjType(connectivity.Shapes.PrepareForInput(device, token),
|
|
|
|
connectivity.Connectivity.PrepareForInput(device, token),
|
|
|
|
connectivity.Offsets.PrepareForInput(device, token));
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
2019-07-30 16:53:51 +00:00
|
|
|
template <typename VisitTopology, typename IncidentTopology>
|
2019-08-30 17:04:17 +00:00
|
|
|
VTKM_CONT auto CellSetExplicit<SST, CST, OST>
|
|
|
|
::GetShapesArray(VisitTopology, IncidentTopology) const
|
|
|
|
-> const typename ConnectivityChooser<VisitTopology,
|
|
|
|
IncidentTopology>::ShapesArrayType&
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-08-30 17:04:17 +00:00
|
|
|
this->BuildConnectivity(vtkm::cont::DeviceAdapterTagAny{},
|
|
|
|
VisitTopology{},
|
|
|
|
IncidentTopology{});
|
|
|
|
return this->GetConnectivity(VisitTopology{}, IncidentTopology{}).Shapes;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
2019-07-30 16:53:51 +00:00
|
|
|
template <typename VisitTopology, typename IncidentTopology>
|
2019-08-30 17:04:17 +00:00
|
|
|
VTKM_CONT
|
|
|
|
auto CellSetExplicit<SST, CST, OST>
|
|
|
|
::GetConnectivityArray(VisitTopology, IncidentTopology) const
|
|
|
|
-> const typename ConnectivityChooser<VisitTopology,
|
|
|
|
IncidentTopology>::ConnectivityArrayType&
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-08-30 17:04:17 +00:00
|
|
|
this->BuildConnectivity(vtkm::cont::DeviceAdapterTagAny{},
|
|
|
|
VisitTopology{},
|
|
|
|
IncidentTopology{});
|
|
|
|
return this->GetConnectivity(VisitTopology{},
|
|
|
|
IncidentTopology{}).Connectivity;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
2019-07-30 16:53:51 +00:00
|
|
|
template <typename VisitTopology, typename IncidentTopology>
|
2019-08-30 17:04:17 +00:00
|
|
|
VTKM_CONT
|
|
|
|
auto CellSetExplicit<SST, CST, OST>
|
|
|
|
::GetOffsetsArray(VisitTopology, IncidentTopology) const
|
|
|
|
-> const typename ConnectivityChooser<VisitTopology,
|
|
|
|
IncidentTopology>::OffsetsArrayType&
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2019-08-30 17:04:17 +00:00
|
|
|
this->BuildConnectivity(vtkm::cont::DeviceAdapterTagAny{},
|
|
|
|
VisitTopology{},
|
|
|
|
IncidentTopology{});
|
|
|
|
return this->GetConnectivity(VisitTopology{},
|
|
|
|
IncidentTopology{}).Offsets;
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
2019-07-30 16:53:51 +00:00
|
|
|
template <typename VisitTopology, typename IncidentTopology>
|
2019-08-30 17:04:17 +00:00
|
|
|
VTKM_CONT
|
|
|
|
auto CellSetExplicit<SST, CST, OST>
|
|
|
|
::GetNumIndicesArray(VisitTopology visited, IncidentTopology incident) const
|
|
|
|
-> typename ConnectivityChooser<VisitTopology,
|
|
|
|
IncidentTopology>::NumIndicesArrayType
|
2017-08-10 20:13:58 +00:00
|
|
|
{
|
2020-09-24 18:16:11 +00:00
|
|
|
// Converts to NumIndicesArrayType (which is an ArrayHandleOffsetsToNumComponents)
|
|
|
|
return this->GetOffsetsArray(visited, incident);
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
std::shared_ptr<CellSet> CellSetExplicit<SST, CST, OST>::NewInstance() const
|
2019-03-19 18:08:29 +00:00
|
|
|
{
|
|
|
|
return std::make_shared<CellSetExplicit>();
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
template <typename SST, typename CST, typename OST>
|
|
|
|
VTKM_CONT
|
|
|
|
void CellSetExplicit<SST, CST, OST>::DeepCopy(const CellSet* src)
|
2019-03-19 18:08:29 +00:00
|
|
|
{
|
|
|
|
const auto* other = dynamic_cast<const CellSetExplicit*>(src);
|
|
|
|
if (!other)
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadType("CellSetExplicit::DeepCopy types don't match");
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:04:17 +00:00
|
|
|
ShapesArrayType shapes;
|
|
|
|
ConnectivityArrayType conn;
|
|
|
|
OffsetsArrayType offsets;
|
|
|
|
|
|
|
|
const auto ct = vtkm::TopologyElementTagCell{};
|
|
|
|
const auto pt = vtkm::TopologyElementTagPoint{};
|
|
|
|
|
2021-01-14 21:29:47 +00:00
|
|
|
shapes.DeepCopyFrom(other->GetShapesArray(ct, pt));
|
|
|
|
conn.DeepCopyFrom(other->GetConnectivityArray(ct, pt));
|
|
|
|
offsets.DeepCopyFrom(other->GetOffsetsArray(ct, pt));
|
2019-08-30 17:04:17 +00:00
|
|
|
|
|
|
|
this->Fill(other->GetNumberOfPoints(), shapes, conn, offsets);
|
2019-03-19 18:08:29 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 20:13:58 +00:00
|
|
|
}
|
|
|
|
} // vtkm::cont
|
2019-08-30 17:04:17 +00:00
|
|
|
|
|
|
|
// clang-format on
|
|
|
|
|
2019-07-01 18:03:40 +00:00
|
|
|
#endif
|