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 Logger.h
MeshConnectivityBuilder.h MeshConnectivityBuilder.h
MeshConnectivityContainers.h MeshConnectivityContainers.h
MeshConnectivityBase.h MeshConnectivity.h
MortonCodes.h MortonCodes.h
PartialComposite.h PartialComposite.h
QuadExtractor.h QuadExtractor.h

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

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

@ -7,14 +7,14 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information. // PURPOSE. See the above copyright notice for more information.
//============================================================================ //============================================================================
#ifndef vtk_m_rendering_raytracing_MeshConnectivityBase #ifndef vtk_m_rendering_raytracing_MeshConnectivity
#define vtk_m_rendering_raytracing_MeshConnectivityBase #define vtk_m_rendering_raytracing_MeshConnectivity
#include <sstream> #include <sstream>
#include <vtkm/CellShape.h> #include <vtkm/CellShape.h>
#include <vtkm/VirtualObjectBase.h>
#include <vtkm/cont/ErrorBadValue.h> #include <vtkm/cont/ErrorBadValue.h>
#include <vtkm/cont/VirtualObjectHandle.h> #include <vtkm/cont/VirtualObjectHandle.h>
#include <vtkm/exec/internal/Variant.h>
#include <vtkm/rendering/raytracing/BoundingVolumeHierarchy.h> #include <vtkm/rendering/raytracing/BoundingVolumeHierarchy.h>
#include <vtkm/rendering/raytracing/CellTables.h> #include <vtkm/rendering/raytracing/CellTables.h>
#include <vtkm/rendering/raytracing/Logger.h> #include <vtkm/rendering/raytracing/Logger.h>
@ -27,71 +27,24 @@ namespace rendering
{ {
namespace raytracing 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 class VTKM_ALWAYS_EXPORT MeshConnectivityStructured
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
{ {
protected: protected:
typedef typename vtkm::cont::ArrayHandle<vtkm::Id4> Id4Handle; typedef typename vtkm::cont::ArrayHandle<vtkm::Id4> Id4Handle;
vtkm::Id3 CellDims; vtkm::Id3 CellDims;
vtkm::Id3 PointDims; vtkm::Id3 PointDims;
VTKM_CONT MeshConnStructured() = default;
public: public:
VTKM_CONT VTKM_CONT
MeshConnStructured(const vtkm::Id3& cellDims, const vtkm::Id3& pointDims) MeshConnectivityStructured(const vtkm::Id3& cellDims, const vtkm::Id3& pointDims)
: CellDims(cellDims) : CellDims(cellDims)
, PointDims(pointDims) , PointDims(pointDims)
{ {
} }
VTKM_EXEC_CONT 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. //TODO: there is probably a better way to do this.
vtkm::Id3 logicalCellId; vtkm::Id3 logicalCellId;
@ -128,7 +81,7 @@ public:
} }
VTKM_EXEC_CONT 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; vtkm::Id3 cellId;
cellId[0] = cellIndex % CellDims[0]; cellId[0] = cellIndex % CellDims[0];
@ -146,14 +99,13 @@ public:
} }
VTKM_EXEC 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); return vtkm::UInt8(CELL_SHAPE_HEXAHEDRON);
} }
}; // MeshConnStructured }; // MeshConnStructured
template <typename Device> class VTKM_ALWAYS_EXPORT MeshConnectivityUnstructured
class VTKM_ALWAYS_EXPORT MeshConnUnstructured : public MeshConnectivityBase
{ {
protected: protected:
using IdHandle = typename vtkm::cont::ArrayHandle<vtkm::Id>; using IdHandle = typename vtkm::cont::ArrayHandle<vtkm::Id>;
@ -170,26 +122,25 @@ protected:
IdConstPortal CellOffsetsPortal; IdConstPortal CellOffsetsPortal;
UCharConstPortal ShapesPortal; UCharConstPortal ShapesPortal;
VTKM_CONT MeshConnUnstructured() = default;
public: public:
VTKM_CONT VTKM_CONT
MeshConnUnstructured(const IdHandle& faceConnectivity, MeshConnectivityUnstructured(const IdHandle& faceConnectivity,
const IdHandle& faceOffsets, const IdHandle& faceOffsets,
const IdHandle& cellConn, const IdHandle& cellConn,
const IdHandle& cellOffsets, const IdHandle& cellOffsets,
const UCharHandle& shapes, const UCharHandle& shapes,
vtkm::cont::Token& token) vtkm::cont::DeviceAdapterId device,
: FaceConnPortal(faceConnectivity.PrepareForInput(Device(), token)) vtkm::cont::Token& token)
, FaceOffsetsPortal(faceOffsets.PrepareForInput(Device(), token)) : FaceConnPortal(faceConnectivity.PrepareForInput(device, token))
, CellConnPortal(cellConn.PrepareForInput(Device(), token)) , FaceOffsetsPortal(faceOffsets.PrepareForInput(device, token))
, CellOffsetsPortal(cellOffsets.PrepareForInput(Device(), token)) , CellConnPortal(cellConn.PrepareForInput(device, token))
, ShapesPortal(shapes.PrepareForInput(Device(), token)) , CellOffsetsPortal(cellOffsets.PrepareForInput(device, token))
, ShapesPortal(shapes.PrepareForInput(device, token))
{ {
} }
VTKM_EXEC_CONT 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); BOUNDS_CHECK(FaceOffsetsPortal, cellId);
vtkm::Id cellStartIndex = FaceOffsetsPortal.Get(cellId); vtkm::Id cellStartIndex = FaceOffsetsPortal.Get(cellId);
@ -199,7 +150,7 @@ public:
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
VTKM_EXEC 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)); const vtkm::Int32 shapeId = static_cast<vtkm::Int32>(ShapesPortal.Get(cellId));
CellTables tables; CellTables tables;
@ -217,7 +168,7 @@ public:
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
VTKM_EXEC VTKM_EXEC
vtkm::UInt8 GetCellShape(const vtkm::Id& cellId) const override vtkm::UInt8 GetCellShape(const vtkm::Id& cellId) const
{ {
BOUNDS_CHECK(ShapesPortal, cellId); BOUNDS_CHECK(ShapesPortal, cellId);
return ShapesPortal.Get(cellId); return ShapesPortal.Get(cellId);
@ -225,8 +176,7 @@ public:
}; // MeshConnUnstructured }; // MeshConnUnstructured
template <typename Device> class MeshConnectivitySingleType
class MeshConnSingleType : public MeshConnectivityBase
{ {
protected: protected:
using IdHandle = typename vtkm::cont::ArrayHandle<vtkm::Id>; using IdHandle = typename vtkm::cont::ArrayHandle<vtkm::Id>;
@ -243,22 +193,19 @@ protected:
vtkm::Int32 NumIndices; vtkm::Int32 NumIndices;
vtkm::Int32 NumFaces; vtkm::Int32 NumFaces;
private:
VTKM_CONT
MeshConnSingleType() {}
public: public:
VTKM_CONT VTKM_CONT
MeshConnSingleType(IdHandle& faceConn, MeshConnectivitySingleType(const IdHandle& faceConn,
IdHandle& cellConn, const IdHandle& cellConn,
CountingHandle& cellOffsets, const CountingHandle& cellOffsets,
vtkm::Int32 shapeId, vtkm::Int32 shapeId,
vtkm::Int32 numIndices, vtkm::Int32 numIndices,
vtkm::Int32 numFaces, vtkm::Int32 numFaces,
vtkm::cont::Token& token) vtkm::cont::DeviceAdapterId device,
: FaceConnPortal(faceConn.PrepareForInput(Device(), token)) vtkm::cont::Token& token)
, CellConnectivityPortal(cellConn.PrepareForInput(Device(), token)) : FaceConnPortal(faceConn.PrepareForInput(device, token))
, CellOffsetsPortal(cellOffsets.PrepareForInput(Device(), token)) , CellConnectivityPortal(cellConn.PrepareForInput(device, token))
, CellOffsetsPortal(cellOffsets.PrepareForInput(device, token))
, ShapeId(shapeId) , ShapeId(shapeId)
, NumIndices(numIndices) , NumIndices(numIndices)
, NumFaces(numFaces) , NumFaces(numFaces)
@ -269,7 +216,7 @@ public:
// Execution Environment Methods // Execution Environment Methods
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
VTKM_EXEC 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); BOUNDS_CHECK(CellOffsetsPortal, cellId);
vtkm::Id cellStartIndex = cellId * NumFaces; vtkm::Id cellStartIndex = cellId * NumFaces;
@ -278,7 +225,7 @@ public:
} }
VTKM_EXEC 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); BOUNDS_CHECK(CellOffsetsPortal, cellId);
const vtkm::Id cellOffset = CellOffsetsPortal.Get(cellId); const vtkm::Id cellOffset = CellOffsetsPortal.Get(cellId);
@ -294,55 +241,89 @@ public:
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
VTKM_EXEC 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); return vtkm::UInt8(ShapeId);
} }
}; //MeshConn Single type specialization }; //MeshConn Single type specialization
class VTKM_ALWAYS_EXPORT MeshConnHandle /// \brief General version of mesh connectivity that can be used for all supported mesh types.
: public vtkm::cont::VirtualObjectHandle<MeshConnectivityBase> class VTKM_ALWAYS_EXPORT MeshConnectivity
{ {
private: using ConnectivityType = vtkm::exec::internal::
using Superclass = vtkm::cont::VirtualObjectHandle<MeshConnectivityBase>; Variant<MeshConnectivityStructured, MeshConnectivityUnstructured, MeshConnectivitySingleType>;
ConnectivityType Connectivity;
public: public:
MeshConnHandle() = default; // Constructor for structured connectivity
VTKM_CONT MeshConnectivity(const vtkm::Id3& cellDims, const vtkm::Id3& pointDims)
template <typename MeshConnType, typename DeviceAdapterList = VTKM_DEFAULT_DEVICE_ADAPTER_LIST> : Connectivity(MeshConnectivityStructured(cellDims, pointDims))
explicit MeshConnHandle(MeshConnType* meshConn,
bool aquireOwnership = true,
DeviceAdapterList devices = DeviceAdapterList())
: Superclass(meshConn, aquireOwnership, devices)
{ {
} }
// 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 } //namespace vtkm::rendering::raytracing
// Cuda seems to have a bug where it expects the template class VirtualObjectTransfer #endif // MeshConnectivity
// 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

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

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

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

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