Merge topic 'rendering-mesh-conn-no-virtual'

6b144abe4 Remove virtual methods from MeshConnectivity in rendering

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2464
This commit is contained in:
Kenneth Moreland 2021-04-15 14:09:13 +00:00 committed by Kitware Robot
commit 237aff05e6
8 changed files with 211 additions and 413 deletions

@ -23,7 +23,7 @@ set(headers
Logger.h
MeshConnectivityBuilder.h
MeshConnectivityContainers.h
MeshConnectivityBase.h
MeshConnectivity.h
MortonCodes.h
PartialComposite.h
QuadExtractor.h

@ -19,7 +19,6 @@
#include <vtkm/rendering/raytracing/CellIntersector.h>
#include <vtkm/rendering/raytracing/CellSampler.h>
#include <vtkm/rendering/raytracing/CellTables.h>
#include <vtkm/rendering/raytracing/MeshConnectivityBase.h>
#include <vtkm/rendering/raytracing/MeshConnectivityBuilder.h>
#include <vtkm/rendering/raytracing/Ray.h>
#include <vtkm/rendering/raytracing/RayOperations.h>
@ -396,7 +395,7 @@ public:
vtkm::Int32& enterFace,
vtkm::UInt8& rayStatus,
const vtkm::Vec<FloatType, 3>& origin,
const MeshWrapper& meshConn) const
const MeshConnectivity& meshConn) const
{
if (enterFace != -1 && rayStatus == RAY_ACTIVE)
{
@ -505,7 +504,7 @@ public:
vtkm::UInt8& rayStatus,
const vtkm::Vec<FloatType, 3>& origin,
vtkm::Vec<FloatType, 3>& rdir,
const MeshWrapper& meshConn,
const MeshConnectivity& meshConn,
const LocatorType& locator) const
{
// We only process lost rays
@ -1036,7 +1035,7 @@ public:
vtkm::UInt8& rayStatus,
const vtkm::Id& pixelIndex,
const vtkm::Vec<FloatType, 3>& origin,
MeshWrapper& meshConn,
MeshConnectivity& meshConn,
const ColorMapType& colorMap,
FrameBufferType& frameBuffer,
const FloatType& maxDistance) const

@ -108,7 +108,7 @@ public:
void SetSampleDistance(const vtkm::Float32& distance);
void SetColorMap(const vtkm::cont::ArrayHandle<vtkm::Vec4f_32>& colorMap);
MeshConnContainer* GetMeshContainer() { return MeshContainer; }
MeshConnectivityContainer* GetMeshContainer() { return MeshContainer; }
void Init();
@ -193,7 +193,7 @@ protected:
vtkm::Id RaysLost;
IntegrationMode Integrator;
MeshConnContainer* MeshContainer;
MeshConnectivityContainer* MeshContainer;
vtkm::cont::CellLocatorGeneral Locator;
vtkm::Float64 BumpEpsilon;
vtkm::Float64 BumpDistance;

@ -7,14 +7,14 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_rendering_raytracing_MeshConnectivityBase
#define vtk_m_rendering_raytracing_MeshConnectivityBase
#ifndef vtk_m_rendering_raytracing_MeshConnectivity
#define vtk_m_rendering_raytracing_MeshConnectivity
#include <sstream>
#include <vtkm/CellShape.h>
#include <vtkm/VirtualObjectBase.h>
#include <vtkm/cont/ErrorBadValue.h>
#include <vtkm/cont/VirtualObjectHandle.h>
#include <vtkm/exec/internal/Variant.h>
#include <vtkm/rendering/raytracing/BoundingVolumeHierarchy.h>
#include <vtkm/rendering/raytracing/CellTables.h>
#include <vtkm/rendering/raytracing/Logger.h>
@ -27,71 +27,24 @@ namespace rendering
{
namespace raytracing
{
//
// Base class for different types of face-to-connecting-cell
// and other mesh information
//
class VTKM_ALWAYS_EXPORT MeshConnectivityBase : public VirtualObjectBase
{
public:
VTKM_EXEC_CONT
virtual vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const = 0;
VTKM_EXEC_CONT
virtual vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const = 0;
VTKM_EXEC_CONT
virtual vtkm::UInt8 GetCellShape(const vtkm::Id& cellId) const = 0;
};
// A simple concrete type to wrap MeshConnectivityBase so we can
// pass an ExeObject to worklets.
class MeshWrapper
{
private:
MeshConnectivityBase* MeshConn;
public:
MeshWrapper() {}
MeshWrapper(MeshConnectivityBase* meshConn)
: MeshConn(meshConn){};
VTKM_EXEC_CONT
vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const
{
return MeshConn->GetConnectingCell(cellId, face);
}
VTKM_EXEC_CONT
vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const
{
return MeshConn->GetCellIndices(cellIndices, cellId);
}
VTKM_EXEC_CONT
vtkm::UInt8 GetCellShape(const vtkm::Id& cellId) const { return MeshConn->GetCellShape(cellId); }
};
class VTKM_ALWAYS_EXPORT MeshConnStructured : public MeshConnectivityBase
class VTKM_ALWAYS_EXPORT MeshConnectivityStructured
{
protected:
typedef typename vtkm::cont::ArrayHandle<vtkm::Id4> Id4Handle;
vtkm::Id3 CellDims;
vtkm::Id3 PointDims;
VTKM_CONT MeshConnStructured() = default;
public:
VTKM_CONT
MeshConnStructured(const vtkm::Id3& cellDims, const vtkm::Id3& pointDims)
MeshConnectivityStructured(const vtkm::Id3& cellDims, const vtkm::Id3& pointDims)
: CellDims(cellDims)
, PointDims(pointDims)
{
}
VTKM_EXEC_CONT
vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const override
vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const
{
//TODO: there is probably a better way to do this.
vtkm::Id3 logicalCellId;
@ -128,7 +81,7 @@ public:
}
VTKM_EXEC_CONT
vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellIndex) const override
vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellIndex) const
{
vtkm::Id3 cellId;
cellId[0] = cellIndex % CellDims[0];
@ -146,14 +99,13 @@ public:
}
VTKM_EXEC
vtkm::UInt8 GetCellShape(const vtkm::Id& vtkmNotUsed(cellId)) const override
vtkm::UInt8 GetCellShape(const vtkm::Id& vtkmNotUsed(cellId)) const
{
return vtkm::UInt8(CELL_SHAPE_HEXAHEDRON);
}
}; // MeshConnStructured
template <typename Device>
class VTKM_ALWAYS_EXPORT MeshConnUnstructured : public MeshConnectivityBase
class VTKM_ALWAYS_EXPORT MeshConnectivityUnstructured
{
protected:
using IdHandle = typename vtkm::cont::ArrayHandle<vtkm::Id>;
@ -170,26 +122,25 @@ protected:
IdConstPortal CellOffsetsPortal;
UCharConstPortal ShapesPortal;
VTKM_CONT MeshConnUnstructured() = default;
public:
VTKM_CONT
MeshConnUnstructured(const IdHandle& faceConnectivity,
const IdHandle& faceOffsets,
const IdHandle& cellConn,
const IdHandle& cellOffsets,
const UCharHandle& shapes,
vtkm::cont::Token& token)
: FaceConnPortal(faceConnectivity.PrepareForInput(Device(), token))
, FaceOffsetsPortal(faceOffsets.PrepareForInput(Device(), token))
, CellConnPortal(cellConn.PrepareForInput(Device(), token))
, CellOffsetsPortal(cellOffsets.PrepareForInput(Device(), token))
, ShapesPortal(shapes.PrepareForInput(Device(), token))
MeshConnectivityUnstructured(const IdHandle& faceConnectivity,
const IdHandle& faceOffsets,
const IdHandle& cellConn,
const IdHandle& cellOffsets,
const UCharHandle& shapes,
vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token)
: FaceConnPortal(faceConnectivity.PrepareForInput(device, token))
, FaceOffsetsPortal(faceOffsets.PrepareForInput(device, token))
, CellConnPortal(cellConn.PrepareForInput(device, token))
, CellOffsetsPortal(cellOffsets.PrepareForInput(device, token))
, ShapesPortal(shapes.PrepareForInput(device, token))
{
}
VTKM_EXEC_CONT
vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const override
vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const
{
BOUNDS_CHECK(FaceOffsetsPortal, cellId);
vtkm::Id cellStartIndex = FaceOffsetsPortal.Get(cellId);
@ -199,7 +150,7 @@ public:
//----------------------------------------------------------------------------
VTKM_EXEC
vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const override
vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const
{
const vtkm::Int32 shapeId = static_cast<vtkm::Int32>(ShapesPortal.Get(cellId));
CellTables tables;
@ -217,7 +168,7 @@ public:
//----------------------------------------------------------------------------
VTKM_EXEC
vtkm::UInt8 GetCellShape(const vtkm::Id& cellId) const override
vtkm::UInt8 GetCellShape(const vtkm::Id& cellId) const
{
BOUNDS_CHECK(ShapesPortal, cellId);
return ShapesPortal.Get(cellId);
@ -225,8 +176,7 @@ public:
}; // MeshConnUnstructured
template <typename Device>
class MeshConnSingleType : public MeshConnectivityBase
class MeshConnectivitySingleType
{
protected:
using IdHandle = typename vtkm::cont::ArrayHandle<vtkm::Id>;
@ -243,22 +193,19 @@ protected:
vtkm::Int32 NumIndices;
vtkm::Int32 NumFaces;
private:
VTKM_CONT
MeshConnSingleType() {}
public:
VTKM_CONT
MeshConnSingleType(IdHandle& faceConn,
IdHandle& cellConn,
CountingHandle& cellOffsets,
vtkm::Int32 shapeId,
vtkm::Int32 numIndices,
vtkm::Int32 numFaces,
vtkm::cont::Token& token)
: FaceConnPortal(faceConn.PrepareForInput(Device(), token))
, CellConnectivityPortal(cellConn.PrepareForInput(Device(), token))
, CellOffsetsPortal(cellOffsets.PrepareForInput(Device(), token))
MeshConnectivitySingleType(const IdHandle& faceConn,
const IdHandle& cellConn,
const CountingHandle& cellOffsets,
vtkm::Int32 shapeId,
vtkm::Int32 numIndices,
vtkm::Int32 numFaces,
vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token)
: FaceConnPortal(faceConn.PrepareForInput(device, token))
, CellConnectivityPortal(cellConn.PrepareForInput(device, token))
, CellOffsetsPortal(cellOffsets.PrepareForInput(device, token))
, ShapeId(shapeId)
, NumIndices(numIndices)
, NumFaces(numFaces)
@ -269,7 +216,7 @@ public:
// Execution Environment Methods
//----------------------------------------------------------------------------
VTKM_EXEC
vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const override
vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const
{
BOUNDS_CHECK(CellOffsetsPortal, cellId);
vtkm::Id cellStartIndex = cellId * NumFaces;
@ -278,7 +225,7 @@ public:
}
VTKM_EXEC
vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const override
vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const
{
BOUNDS_CHECK(CellOffsetsPortal, cellId);
const vtkm::Id cellOffset = CellOffsetsPortal.Get(cellId);
@ -294,55 +241,89 @@ public:
//----------------------------------------------------------------------------
VTKM_EXEC
vtkm::UInt8 GetCellShape(const vtkm::Id& vtkmNotUsed(cellId)) const override
vtkm::UInt8 GetCellShape(const vtkm::Id& vtkmNotUsed(cellId)) const
{
return vtkm::UInt8(ShapeId);
}
}; //MeshConn Single type specialization
class VTKM_ALWAYS_EXPORT MeshConnHandle
: public vtkm::cont::VirtualObjectHandle<MeshConnectivityBase>
/// \brief General version of mesh connectivity that can be used for all supported mesh types.
class VTKM_ALWAYS_EXPORT MeshConnectivity
{
private:
using Superclass = vtkm::cont::VirtualObjectHandle<MeshConnectivityBase>;
using ConnectivityType = vtkm::exec::internal::
Variant<MeshConnectivityStructured, MeshConnectivityUnstructured, MeshConnectivitySingleType>;
ConnectivityType Connectivity;
public:
MeshConnHandle() = default;
template <typename MeshConnType, typename DeviceAdapterList = VTKM_DEFAULT_DEVICE_ADAPTER_LIST>
explicit MeshConnHandle(MeshConnType* meshConn,
bool aquireOwnership = true,
DeviceAdapterList devices = DeviceAdapterList())
: Superclass(meshConn, aquireOwnership, devices)
// Constructor for structured connectivity
VTKM_CONT MeshConnectivity(const vtkm::Id3& cellDims, const vtkm::Id3& pointDims)
: Connectivity(MeshConnectivityStructured(cellDims, pointDims))
{
}
// Constructor for unstructured connectivity
VTKM_CONT MeshConnectivity(const vtkm::cont::ArrayHandle<vtkm::Id>& faceConnectivity,
const vtkm::cont::ArrayHandle<vtkm::Id>& faceOffsets,
const vtkm::cont::ArrayHandle<vtkm::Id>& cellConn,
const vtkm::cont::ArrayHandle<vtkm::Id>& cellOffsets,
const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token)
: Connectivity(MeshConnectivityUnstructured(faceConnectivity,
faceOffsets,
cellConn,
cellOffsets,
shapes,
device,
token))
{
}
// Constructor for unstructured connectivity with single cell type
VTKM_CONT MeshConnectivity(const vtkm::cont::ArrayHandle<vtkm::Id>& faceConn,
const vtkm::cont::ArrayHandle<vtkm::Id>& cellConn,
const vtkm::cont::ArrayHandleCounting<vtkm::Id>& cellOffsets,
vtkm::Int32 shapeId,
vtkm::Int32 numIndices,
vtkm::Int32 numFaces,
vtkm::cont::DeviceAdapterId device,
vtkm::cont::Token& token)
: Connectivity(MeshConnectivitySingleType(faceConn,
cellConn,
cellOffsets,
shapeId,
numIndices,
numFaces,
device,
token))
{
}
VTKM_EXEC_CONT
vtkm::Id GetConnectingCell(const vtkm::Id& cellId, const vtkm::Id& face) const
{
return this->Connectivity.CastAndCall(
[=](auto conn) { return conn.GetConnectingCell(cellId, face); });
}
VTKM_EXEC_CONT
vtkm::Int32 GetCellIndices(vtkm::Id cellIndices[8], const vtkm::Id& cellId) const
{
return this->Connectivity.CastAndCall(
[=](auto conn) { return conn.GetCellIndices(cellIndices, cellId); });
}
VTKM_EXEC_CONT
vtkm::UInt8 GetCellShape(const vtkm::Id& cellId) const
{
return this->Connectivity.CastAndCall([=](auto conn) { return conn.GetCellShape(cellId); });
}
};
template <typename MeshConnType, typename DeviceAdapterList = VTKM_DEFAULT_DEVICE_ADAPTER_LIST>
VTKM_CONT MeshConnHandle make_MeshConnHandle(MeshConnType&& func,
DeviceAdapterList devices = DeviceAdapterList())
{
using IFType = typename std::remove_reference<MeshConnType>::type;
return MeshConnHandle(new IFType(std::forward<MeshConnType>(func)), true, devices);
}
}
}
} //namespace vtkm::rendering::raytracing
// Cuda seems to have a bug where it expects the template class VirtualObjectTransfer
// to be instantiated in a consistent order among all the translation units of an
// executable. Failing to do so results in random crashes and incorrect results.
// We workaroud this issue by explicitly instantiating VirtualObjectTransfer for
// all the implicit functions here.
#ifdef VTKM_CUDA
#include <vtkm/cont/internal/VirtualObjectTransferInstantiate.h>
VTKM_EXPLICITLY_INSTANTIATE_TRANSFER(vtkm::rendering::raytracing::MeshConnStructured);
VTKM_EXPLICITLY_INSTANTIATE_TRANSFER_CUDA(
vtkm::rendering::raytracing::MeshConnUnstructured<vtkm::cont::DeviceAdapterTagCuda>);
VTKM_EXPLICITLY_INSTANTIATE_TRANSFER_KOKKOS(
vtkm::rendering::raytracing::MeshConnUnstructured<vtkm::cont::DeviceAdapterTagKokkos>);
#endif
#endif // MeshConnectivityBase
#endif // MeshConnectivity

@ -839,7 +839,7 @@ vtkm::cont::ArrayHandle<vtkm::Id4> MeshConnectivityBuilder::GetTriangles()
}
VTKM_CONT
MeshConnContainer* MeshConnectivityBuilder::BuildConnectivity(
MeshConnectivityContainer* MeshConnectivityBuilder::BuildConnectivity(
const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coordinates)
{
@ -891,7 +891,7 @@ MeshConnContainer* MeshConnectivityBuilder::BuildConnectivity(
Logger* logger = Logger::GetInstance();
logger->OpenLogEntry("mesh_conn_construction");
MeshConnContainer* meshConn = nullptr;
MeshConnectivityContainer* meshConn = nullptr;
vtkm::cont::Timer timer;
timer.Start();
@ -899,20 +899,21 @@ MeshConnContainer* MeshConnectivityBuilder::BuildConnectivity(
{
vtkm::cont::CellSetExplicit<> cells = cellset.Cast<vtkm::cont::CellSetExplicit<>>();
this->BuildConnectivity(cells, coordinates.GetDataAsMultiplexer(), coordBounds);
meshConn =
new UnstructuredContainer(cells, coordinates, FaceConnectivity, FaceOffsets, Triangles);
meshConn = new MeshConnectivityContainerUnstructured(
cells, coordinates, FaceConnectivity, FaceOffsets, Triangles);
}
else if (type == UnstructuredSingle)
{
vtkm::cont::CellSetSingleType<> cells = cellset.Cast<vtkm::cont::CellSetSingleType<>>();
this->BuildConnectivity(cells, coordinates.GetDataAsMultiplexer(), coordBounds);
meshConn = new UnstructuredSingleContainer(cells, coordinates, FaceConnectivity, Triangles);
meshConn =
new MeshConnectivityContainerSingleType(cells, coordinates, FaceConnectivity, Triangles);
}
else if (type == Structured)
{
vtkm::cont::CellSetStructured<3> cells = cellset.Cast<vtkm::cont::CellSetStructured<3>>();
Triangles = this->ExternalTrianglesStructured(cells);
meshConn = new StructuredContainer(cells, coordinates, Triangles);
meshConn = new MeshConnectivityContainerStructured(cells, coordinates, Triangles);
}
else
{

@ -27,8 +27,8 @@ public:
~MeshConnectivityBuilder();
VTKM_CONT
MeshConnContainer* BuildConnectivity(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coordinates);
MeshConnectivityContainer* BuildConnectivity(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coordinates);
VTKM_CONT
vtkm::cont::ArrayHandle<vtkm::Id4> ExternalTrianglesStructured(

@ -14,7 +14,7 @@
#include <vtkm/cont/internal/DeviceAdapterListHelpers.h>
#include <vtkm/rendering/raytracing/BoundingVolumeHierarchy.h>
#include <vtkm/rendering/raytracing/Logger.h>
#include <vtkm/rendering/raytracing/MeshConnectivityBase.h>
#include <vtkm/rendering/raytracing/MeshConnectivity.h>
#include <vtkm/rendering/raytracing/MeshConnectivityContainers.h>
#include <vtkm/rendering/raytracing/Ray.h>
#include <vtkm/rendering/raytracing/TriangleIntersector.h>
@ -25,11 +25,11 @@ namespace rendering
namespace raytracing
{
MeshConnContainer::MeshConnContainer(){};
MeshConnContainer::~MeshConnContainer(){};
MeshConnectivityContainer::MeshConnectivityContainer(){};
MeshConnectivityContainer::~MeshConnectivityContainer(){};
template <typename T>
VTKM_CONT void MeshConnContainer::FindEntryImpl(Ray<T>& rays)
VTKM_CONT void MeshConnectivityContainer::FindEntryImpl(Ray<T>& rays)
{
bool getCellIndex = true;
@ -38,28 +38,23 @@ VTKM_CONT void MeshConnContainer::FindEntryImpl(Ray<T>& rays)
Intersector.IntersectRays(rays, getCellIndex);
}
MeshWrapper MeshConnContainer::PrepareForExecution(const vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token)
{
return MeshWrapper(const_cast<MeshConnectivityBase*>(this->Construct(deviceId, token)));
}
void MeshConnContainer::FindEntry(Ray<vtkm::Float32>& rays)
void MeshConnectivityContainer::FindEntry(Ray<vtkm::Float32>& rays)
{
this->FindEntryImpl(rays);
}
void MeshConnContainer::FindEntry(Ray<vtkm::Float64>& rays)
void MeshConnectivityContainer::FindEntry(Ray<vtkm::Float64>& rays)
{
this->FindEntryImpl(rays);
}
VTKM_CONT
UnstructuredContainer::UnstructuredContainer(const vtkm::cont::CellSetExplicit<>& cellset,
const vtkm::cont::CoordinateSystem& coords,
IdHandle& faceConn,
IdHandle& faceOffsets,
Id4Handle& triangles)
MeshConnectivityContainerUnstructured::MeshConnectivityContainerUnstructured(
const vtkm::cont::CellSetExplicit<>& cellset,
const vtkm::cont::CoordinateSystem& coords,
const IdHandle& faceConn,
const IdHandle& faceOffsets,
const Id4Handle& triangles)
: FaceConnectivity(faceConn)
, FaceOffsets(faceOffsets)
, Cellset(cellset)
@ -78,96 +73,27 @@ UnstructuredContainer::UnstructuredContainer(const vtkm::cont::CellSetExplicit<>
Intersector.SetData(Coords, Triangles);
}
UnstructuredContainer::~UnstructuredContainer(){};
MeshConnectivityContainerUnstructured::~MeshConnectivityContainerUnstructured(){};
const MeshConnectivityBase* UnstructuredContainer::Construct(
const vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token)
MeshConnectivity MeshConnectivityContainerUnstructured::PrepareForExecution(
vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) const
{
switch (deviceId.GetValue())
{
#ifdef VTKM_ENABLE_OPENMP
case VTKM_DEVICE_ADAPTER_OPENMP:
using OMP = vtkm::cont::DeviceAdapterTagOpenMP;
{
MeshConnUnstructured<OMP> conn(this->FaceConnectivity,
this->FaceOffsets,
this->CellConn,
this->CellOffsets,
this->Shapes,
token);
Handle = make_MeshConnHandle(conn);
}
return Handle.PrepareForExecution(OMP(), token);
#endif
#ifdef VTKM_ENABLE_TBB
case VTKM_DEVICE_ADAPTER_TBB:
using TBB = vtkm::cont::DeviceAdapterTagTBB;
{
MeshConnUnstructured<TBB> conn(this->FaceConnectivity,
this->FaceOffsets,
this->CellConn,
this->CellOffsets,
this->Shapes,
token);
Handle = make_MeshConnHandle(conn);
}
return Handle.PrepareForExecution(TBB(), token);
#endif
#ifdef VTKM_ENABLE_CUDA
case VTKM_DEVICE_ADAPTER_CUDA:
using CUDA = vtkm::cont::DeviceAdapterTagCuda;
{
MeshConnUnstructured<CUDA> conn(this->FaceConnectivity,
this->FaceOffsets,
this->CellConn,
this->CellOffsets,
this->Shapes,
token);
Handle = make_MeshConnHandle(conn);
}
return Handle.PrepareForExecution(CUDA(), token);
#endif
#ifdef VTKM_ENABLE_KOKKOS
case VTKM_DEVICE_ADAPTER_KOKKOS:
using KOKKOS = vtkm::cont::DeviceAdapterTagKokkos;
{
MeshConnUnstructured<KOKKOS> conn(this->FaceConnectivity,
this->FaceOffsets,
this->CellConn,
this->CellOffsets,
this->Shapes,
token);
Handle = make_MeshConnHandle(conn);
}
return Handle.PrepareForExecution(KOKKOS(), token);
#endif
case VTKM_DEVICE_ADAPTER_SERIAL:
VTKM_FALLTHROUGH;
default:
using SERIAL = vtkm::cont::DeviceAdapterTagSerial;
{
MeshConnUnstructured<SERIAL> conn(this->FaceConnectivity,
this->FaceOffsets,
this->CellConn,
this->CellOffsets,
this->Shapes,
token);
Handle = make_MeshConnHandle(conn);
}
return Handle.PrepareForExecution(SERIAL(), token);
}
return MeshConnectivity(this->FaceConnectivity,
this->FaceOffsets,
this->CellConn,
this->CellOffsets,
this->Shapes,
deviceId,
token);
}
VTKM_CONT
UnstructuredSingleContainer::UnstructuredSingleContainer() {}
VTKM_CONT
UnstructuredSingleContainer::UnstructuredSingleContainer(
MeshConnectivityContainerSingleType::MeshConnectivityContainerSingleType(
const vtkm::cont::CellSetSingleType<>& cellset,
const vtkm::cont::CoordinateSystem& coords,
IdHandle& faceConn,
Id4Handle& triangles)
const IdHandle& faceConn,
const Id4Handle& triangles)
: FaceConnectivity(faceConn)
, Coords(coords)
, Cellset(cellset)
@ -177,16 +103,16 @@ UnstructuredSingleContainer::UnstructuredSingleContainer(
this->Intersector.SetUseWaterTight(true);
CellConnectivity =
this->CellConnectivity =
Cellset.GetConnectivityArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapes =
Cellset.GetShapesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
ShapeId = shapes.ReadPortal().Get(0);
this->ShapeId = shapes.ReadPortal().Get(0);
CellTables tables;
NumIndices = tables.FaceLookUp(tables.CellTypeLookUp(ShapeId), 2);
this->NumIndices = tables.FaceLookUp(tables.CellTypeLookUp(ShapeId), 2);
if (NumIndices == 0)
if (this->NumIndices == 0)
{
std::stringstream message;
message << "Unstructured Mesh Connecitity Single type Error: unsupported cell type: ";
@ -194,147 +120,53 @@ UnstructuredSingleContainer::UnstructuredSingleContainer(
throw vtkm::cont::ErrorBadValue(message.str());
}
vtkm::Id start = 0;
NumFaces = tables.FaceLookUp(tables.CellTypeLookUp(ShapeId), 1);
vtkm::Id numCells = CellConnectivity.ReadPortal().GetNumberOfValues();
CellOffsets = vtkm::cont::make_ArrayHandleCounting<vtkm::Id>(start, NumIndices, numCells);
this->NumFaces = tables.FaceLookUp(tables.CellTypeLookUp(this->ShapeId), 1);
vtkm::Id numCells = this->CellConnectivity.ReadPortal().GetNumberOfValues();
this->CellOffsets =
vtkm::cont::make_ArrayHandleCounting<vtkm::Id>(start, this->NumIndices, numCells);
Logger* logger = Logger::GetInstance();
logger->OpenLogEntry("mesh_conn_construction");
Intersector.SetData(Coords, Triangles);
this->Intersector.SetData(Coords, Triangles);
}
const MeshConnectivityBase* UnstructuredSingleContainer::Construct(
const vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token)
MeshConnectivity MeshConnectivityContainerSingleType::PrepareForExecution(
vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) const
{
switch (deviceId.GetValue())
{
#ifdef VTKM_ENABLE_OPENMP
case VTKM_DEVICE_ADAPTER_OPENMP:
using OMP = vtkm::cont::DeviceAdapterTagOpenMP;
{
MeshConnSingleType<OMP> conn(this->FaceConnectivity,
this->CellConnectivity,
this->CellOffsets,
this->ShapeId,
this->NumIndices,
this->NumFaces,
token);
Handle = make_MeshConnHandle(conn);
}
return Handle.PrepareForExecution(OMP(), token);
#endif
#ifdef VTKM_ENABLE_TBB
case VTKM_DEVICE_ADAPTER_TBB:
using TBB = vtkm::cont::DeviceAdapterTagTBB;
{
MeshConnSingleType<TBB> conn(this->FaceConnectivity,
this->CellConnectivity,
this->CellOffsets,
this->ShapeId,
this->NumIndices,
this->NumFaces,
token);
Handle = make_MeshConnHandle(conn);
}
return Handle.PrepareForExecution(TBB(), token);
#endif
#ifdef VTKM_ENABLE_CUDA
case VTKM_DEVICE_ADAPTER_CUDA:
using CUDA = vtkm::cont::DeviceAdapterTagCuda;
{
MeshConnSingleType<CUDA> conn(this->FaceConnectivity,
this->CellConnectivity,
this->CellOffsets,
this->ShapeId,
this->NumIndices,
this->NumFaces,
token);
Handle = make_MeshConnHandle(conn);
}
return Handle.PrepareForExecution(CUDA(), token);
#endif
#ifdef VTKM_ENABLE_KOKKOS
case VTKM_DEVICE_ADAPTER_KOKKOS:
using KOKKOS = vtkm::cont::DeviceAdapterTagKokkos;
{
MeshConnSingleType<KOKKOS> conn(this->FaceConnectivity,
this->CellConnectivity,
this->CellOffsets,
this->ShapeId,
this->NumIndices,
this->NumFaces,
token);
Handle = make_MeshConnHandle(conn);
}
return Handle.PrepareForExecution(KOKKOS(), token);
#endif
case VTKM_DEVICE_ADAPTER_SERIAL:
VTKM_FALLTHROUGH;
default:
using SERIAL = vtkm::cont::DeviceAdapterTagSerial;
{
MeshConnSingleType<SERIAL> conn(this->FaceConnectivity,
this->CellConnectivity,
this->CellOffsets,
this->ShapeId,
this->NumIndices,
this->NumFaces,
token);
Handle = make_MeshConnHandle(conn);
}
return Handle.PrepareForExecution(SERIAL(), token);
}
return MeshConnectivity(this->FaceConnectivity,
this->CellConnectivity,
this->CellOffsets,
this->ShapeId,
this->NumIndices,
this->NumFaces,
deviceId,
token);
}
StructuredContainer::StructuredContainer(const vtkm::cont::CellSetStructured<3>& cellset,
const vtkm::cont::CoordinateSystem& coords,
Id4Handle& triangles)
MeshConnectivityContainerStructured::MeshConnectivityContainerStructured(
const vtkm::cont::CellSetStructured<3>& cellset,
const vtkm::cont::CoordinateSystem& coords,
const Id4Handle& triangles)
: Coords(coords)
, Cellset(cellset)
{
Triangles = triangles;
Intersector.SetUseWaterTight(true);
this->Triangles = triangles;
this->Intersector.SetUseWaterTight(true);
PointDims = Cellset.GetPointDimensions();
CellDims = Cellset.GetCellDimensions();
this->PointDims = this->Cellset.GetPointDimensions();
this->CellDims = this->Cellset.GetCellDimensions();
this->Intersector.SetData(Coords, Triangles);
}
const MeshConnectivityBase* StructuredContainer::Construct(
const vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token)
MeshConnectivity MeshConnectivityContainerStructured::PrepareForExecution(
vtkm::cont::DeviceAdapterId,
vtkm::cont::Token&) const
{
MeshConnStructured conn(CellDims, PointDims);
Handle = make_MeshConnHandle(conn);
switch (deviceId.GetValue())
{
#ifdef VTKM_ENABLE_OPENMP
case VTKM_DEVICE_ADAPTER_OPENMP:
return Handle.PrepareForExecution(vtkm::cont::DeviceAdapterTagOpenMP(), token);
#endif
#ifdef VTKM_ENABLE_TBB
case VTKM_DEVICE_ADAPTER_TBB:
return Handle.PrepareForExecution(vtkm::cont::DeviceAdapterTagTBB(), token);
#endif
#ifdef VTKM_ENABLE_CUDA
case VTKM_DEVICE_ADAPTER_CUDA:
return Handle.PrepareForExecution(vtkm::cont::DeviceAdapterTagCuda(), token);
#endif
#ifdef VTKM_ENABLE_KOKKOS
case VTKM_DEVICE_ADAPTER_KOKKOS:
return Handle.PrepareForExecution(vtkm::cont::DeviceAdapterTagKokkos(), token);
#endif
case VTKM_DEVICE_ADAPTER_SERIAL:
VTKM_FALLTHROUGH;
default:
return Handle.PrepareForExecution(vtkm::cont::DeviceAdapterTagSerial(), token);
}
return MeshConnectivity(CellDims, PointDims);
}
}
}

@ -11,7 +11,7 @@
#define vtk_m_rendering_raytracing_MeshConnectivityContainer_h
#include <vtkm/cont/DataSet.h>
#include <vtkm/rendering/raytracing/MeshConnectivityBase.h>
#include <vtkm/rendering/raytracing/MeshConnectivity.h>
#include <vtkm/rendering/raytracing/TriangleIntersector.h>
namespace vtkm
@ -21,20 +21,14 @@ namespace rendering
namespace raytracing
{
class MeshConnContainer : vtkm::cont::ExecutionObjectBase
class MeshConnectivityContainer : vtkm::cont::ExecutionObjectBase
{
public:
MeshConnContainer();
virtual ~MeshConnContainer();
MeshConnectivityContainer();
virtual ~MeshConnectivityContainer();
virtual const MeshConnectivityBase* Construct(const vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) = 0;
MeshWrapper PrepareForExecution(const vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token);
template <typename T>
VTKM_CONT void FindEntryImpl(Ray<T>& rays);
virtual MeshConnectivity PrepareForExecution(vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) const = 0;
void FindEntry(Ray<vtkm::Float32>& rays);
@ -45,10 +39,13 @@ protected:
// Mesh Boundary
Id4Handle Triangles;
TriangleIntersector Intersector;
MeshConnHandle Handle;
private:
template <typename T>
VTKM_CONT void FindEntryImpl(Ray<T>& rays);
};
class UnstructuredContainer : public MeshConnContainer
class MeshConnectivityContainerUnstructured : public MeshConnectivityContainer
{
public:
typedef vtkm::cont::ArrayHandle<vtkm::Id> IdHandle;
@ -67,25 +64,21 @@ public:
vtkm::cont::CellSetExplicit<> Cellset;
vtkm::cont::CoordinateSystem Coords;
private:
VTKM_CONT
UnstructuredContainer(){};
public:
VTKM_CONT
UnstructuredContainer(const vtkm::cont::CellSetExplicit<>& cellset,
const vtkm::cont::CoordinateSystem& coords,
IdHandle& faceConn,
IdHandle& faceOffsets,
Id4Handle& triangles);
MeshConnectivityContainerUnstructured(const vtkm::cont::CellSetExplicit<>& cellset,
const vtkm::cont::CoordinateSystem& coords,
const IdHandle& faceConn,
const IdHandle& faceOffsets,
const Id4Handle& triangles);
virtual ~UnstructuredContainer();
virtual ~MeshConnectivityContainerUnstructured();
const MeshConnectivityBase* Construct(const vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) override;
MeshConnectivity PrepareForExecution(vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) const override;
};
class StructuredContainer : public MeshConnContainer
class MeshConnectivityContainerStructured : public MeshConnectivityContainer
{
protected:
typedef vtkm::cont::ArrayHandle<vtkm::Id4> Id4Handle;
@ -95,22 +88,18 @@ protected:
vtkm::cont::CoordinateSystem Coords;
vtkm::cont::CellSetStructured<3> Cellset;
private:
VTKM_CONT
StructuredContainer() {}
public:
VTKM_CONT
StructuredContainer(const vtkm::cont::CellSetStructured<3>& cellset,
const vtkm::cont::CoordinateSystem& coords,
Id4Handle& triangles);
MeshConnectivityContainerStructured(const vtkm::cont::CellSetStructured<3>& cellset,
const vtkm::cont::CoordinateSystem& coords,
const Id4Handle& triangles);
const MeshConnectivityBase* Construct(const vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) override;
MeshConnectivity PrepareForExecution(vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) const override;
}; //structure mesh conn
class UnstructuredSingleContainer : public MeshConnContainer
class MeshConnectivityContainerSingleType : public MeshConnectivityContainer
{
public:
typedef vtkm::cont::ArrayHandle<vtkm::Id> IdHandle;
@ -131,19 +120,15 @@ public:
vtkm::Int32 NumIndices;
vtkm::Int32 NumFaces;
private:
VTKM_CONT
UnstructuredSingleContainer();
public:
VTKM_CONT
UnstructuredSingleContainer(const vtkm::cont::CellSetSingleType<>& cellset,
const vtkm::cont::CoordinateSystem& coords,
IdHandle& faceConn,
Id4Handle& externalFaces);
MeshConnectivityContainerSingleType(const vtkm::cont::CellSetSingleType<>& cellset,
const vtkm::cont::CoordinateSystem& coords,
const IdHandle& faceConn,
const Id4Handle& externalFaces);
const MeshConnectivityBase* Construct(const vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) override;
MeshConnectivity PrepareForExecution(vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) const override;
}; //UnstructuredSingleContainer
}