vtk-m/vtkm/cont/internal/ConnectivityExplicitInternals.h
Kenneth Moreland e74c0732c5 Compile reverse connectivity builder into vtkm_cont library
Because `CellSetExplicit` is a templated class, the implementation of
most of its features is part of the header files. One of the things that
was included was the code to build the reverse connectivity links. That
is, it figured out which cells were incident on each point using the
standard connections of which points comprise which cells.

Of course, building these links is non-trivial, and it used multiple
DPPs to engage the device. It meant that header had to include the
device adapter algorithms and therefore required a device compiler. We
want to minimize this where possible.

To get around this issue, a non-templated function was added to find the
reverse connections of a `CellSetExplicit`. It does this by passing in
`UnknownArrayHandle`s for the input arrays. (The output visit-points-
with-cells arrays are standard across all template instances.) The
implementation first iterates over all `CellSetExplicit` versions in
`VTKM_DEFAULT_CELL_SETS` and attempts to retrieve arrays of those types.
In the unlikely event that none of these arrays work, it copies the data
to `ArrayHandle<vtkm::Id>` and uses those.
2021-09-17 09:48:21 -06:00

86 lines
2.4 KiB
C++

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// 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.
//============================================================================
#ifndef vtk_m_cont_internal_ConnectivityExplicitInternals_h
#define vtk_m_cont_internal_ConnectivityExplicitInternals_h
#include <vtkm/CellShape.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleCast.h>
#include <vtkm/cont/ArrayHandleConstant.h>
#include <vtkm/cont/ArrayHandleCounting.h>
namespace vtkm
{
namespace cont
{
namespace internal
{
template <typename ShapesStorageTag = VTKM_DEFAULT_STORAGE_TAG,
typename ConnectivityStorageTag = VTKM_DEFAULT_STORAGE_TAG,
typename OffsetsStorageTag = VTKM_DEFAULT_STORAGE_TAG>
struct ConnectivityExplicitInternals
{
using ShapesArrayType = vtkm::cont::ArrayHandle<vtkm::UInt8, ShapesStorageTag>;
using ConnectivityArrayType = vtkm::cont::ArrayHandle<vtkm::Id, ConnectivityStorageTag>;
using OffsetsArrayType = vtkm::cont::ArrayHandle<vtkm::Id, OffsetsStorageTag>;
ShapesArrayType Shapes;
ConnectivityArrayType Connectivity;
OffsetsArrayType Offsets;
bool ElementsValid;
VTKM_CONT
ConnectivityExplicitInternals()
: ElementsValid(false)
{
}
VTKM_CONT
vtkm::Id GetNumberOfElements() const
{
VTKM_ASSERT(this->ElementsValid);
return this->Shapes.GetNumberOfValues();
}
VTKM_CONT
void ReleaseResourcesExecution()
{
this->Shapes.ReleaseResourcesExecution();
this->Connectivity.ReleaseResourcesExecution();
this->Offsets.ReleaseResourcesExecution();
}
VTKM_CONT
void PrintSummary(std::ostream& out) const
{
if (this->ElementsValid)
{
out << " Shapes: ";
vtkm::cont::printSummary_ArrayHandle(this->Shapes, out);
out << " Connectivity: ";
vtkm::cont::printSummary_ArrayHandle(this->Connectivity, out);
out << " Offsets: ";
vtkm::cont::printSummary_ArrayHandle(this->Offsets, out);
}
else
{
out << " Not Allocated" << std::endl;
}
}
};
}
}
} // namespace vtkm::cont::internal
#endif //vtk_m_cont_internal_ConnectivityExplicitInternals_h