From ecec6945bf4a31fcfcc55a4bc6fbdd0a8ea928d5 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 1 Jun 2015 09:42:10 -0400 Subject: [PATCH] ExplicitConnectivity can now use different storage backends. ExplicitConnectivity can now use different storage backends to allow for cheaper representations of the data. For example a pool of triangles can now implicit handles for shape and num indices. --- vtkm/cont/CellSetExplicit.h | 4 +-- vtkm/cont/ExplicitConnectivity.h | 45 +++++++++++++++++++---------- vtkm/cont/testing/MakeTestDataSet.h | 4 +-- vtkm/exec/ExplicitConnectivity.h | 29 +++++++++++++++---- 4 files changed, 57 insertions(+), 25 deletions(-) diff --git a/vtkm/cont/CellSetExplicit.h b/vtkm/cont/CellSetExplicit.h index 3a10f1f2c..091d5f20a 100644 --- a/vtkm/cont/CellSetExplicit.h +++ b/vtkm/cont/CellSetExplicit.h @@ -24,7 +24,7 @@ public: return nodesOfCellsConnectivity.GetNumberOfElements(); } - ExplicitConnectivity &GetNodeToCellConnectivity() + ExplicitConnectivity<> &GetNodeToCellConnectivity() { return nodesOfCellsConnectivity; } @@ -36,7 +36,7 @@ public: } public: - ExplicitConnectivity nodesOfCellsConnectivity; + ExplicitConnectivity<> nodesOfCellsConnectivity; }; } diff --git a/vtkm/cont/ExplicitConnectivity.h b/vtkm/cont/ExplicitConnectivity.h index 1ad692427..3f5c43088 100644 --- a/vtkm/cont/ExplicitConnectivity.h +++ b/vtkm/cont/ExplicitConnectivity.h @@ -30,6 +30,9 @@ namespace vtkm { namespace cont { +template class ExplicitConnectivity { public: @@ -135,9 +138,9 @@ public: /// Second method to add cells -- all at once. /// Assigns the array handles to the explicit connectivity. This is /// the way you can fill the memory from another system without copying - void Fill(const vtkm::cont::ArrayHandle &cellTypes, - const vtkm::cont::ArrayHandle &numIndices, - const vtkm::cont::ArrayHandle &connectivity) + void Fill(const vtkm::cont::ArrayHandle &cellTypes, + const vtkm::cont::ArrayHandle &numIndices, + const vtkm::cont::ArrayHandle &connectivity) { this->Shapes = cellTypes; this->NumIndices = numIndices; @@ -159,20 +162,32 @@ public: template struct ExecutionTypes { - typedef vtkm::exec::ExplicitConnectivity ExecObjectType; + typedef typename vtkm::cont::ArrayHandle ShapeHandle; + typedef typename vtkm::cont::ArrayHandle IndiceHandle; + typedef typename vtkm::cont::ArrayHandle ConnectivityHandle; + typedef vtkm::cont::ArrayHandle MapCellToConnectivityHandle; + + typedef typename ShapeHandle::template ExecutionTypes::PortalConst ShapePortalType; + typedef typename IndiceHandle::template ExecutionTypes::PortalConst IndicePortalType; + typedef typename ConnectivityHandle::template ExecutionTypes::PortalConst ConnectivityPortalType; + typedef typename MapCellToConnectivityHandle::template ExecutionTypes::PortalConst MapConnectivityPortalType; + + typedef vtkm::exec::ExplicitConnectivity ExecObjectType; }; template typename ExecutionTypes::ExecObjectType PrepareForInput(DeviceAdapterTag tag) const { - vtkm::exec::ExplicitConnectivity obj; - obj.Shapes = Shapes.PrepareForInput(tag); - obj.NumIndices = NumIndices.PrepareForInput(tag); - obj.Connectivity = Connectivity.PrepareForInput(tag); - obj.MapCellToConnectivityIndex = MapCellToConnectivityIndex.PrepareForInput(tag); - - return obj; + typedef typename ExecutionTypes::ExecObjectType ExecObjType; + return ExecObjType(this->Shapes.PrepareForInput(tag), + this->NumIndices.PrepareForInput(tag), + this->Connectivity.PrepareForInput(tag), + this->MapCellToConnectivityIndex.PrepareForInput(tag)); } VTKM_CONT_EXPORT @@ -194,10 +209,10 @@ public: private: vtkm::Id ConnectivityLength; vtkm::Id NumShapes; - vtkm::cont::ArrayHandle Shapes; - vtkm::cont::ArrayHandle NumIndices; - vtkm::cont::ArrayHandle Connectivity; - vtkm::cont::ArrayHandle MapCellToConnectivityIndex; + vtkm::cont::ArrayHandle Shapes; + vtkm::cont::ArrayHandle NumIndices; + vtkm::cont::ArrayHandle Connectivity; + vtkm::cont::ArrayHandle MapCellToConnectivityIndex; }; } diff --git a/vtkm/cont/testing/MakeTestDataSet.h b/vtkm/cont/testing/MakeTestDataSet.h index 13868d887..3415af850 100644 --- a/vtkm/cont/testing/MakeTestDataSet.h +++ b/vtkm/cont/testing/MakeTestDataSet.h @@ -155,7 +155,7 @@ MakeTestDataSet::Make3DExplicitDataSet0() boost::shared_ptr< vtkm::cont::CellSetExplicit > cs( new vtkm::cont::CellSetExplicit("cells", 2)); - vtkm::cont::ExplicitConnectivity &ec = cs->nodesOfCellsConnectivity; + vtkm::cont::ExplicitConnectivity<> &ec = cs->nodesOfCellsConnectivity; ec.FillViaCopy(shapes, numindices, conn); //todo this need to be a reference/shared_ptr style class @@ -189,7 +189,7 @@ MakeTestDataSet::Make3DExplicitDataSet1() boost::shared_ptr< vtkm::cont::CellSetExplicit > cs( new vtkm::cont::CellSetExplicit("cells", 2)); - vtkm::cont::ExplicitConnectivity &ec = cs->nodesOfCellsConnectivity; + vtkm::cont::ExplicitConnectivity<> &ec = cs->nodesOfCellsConnectivity; ec.PrepareToAddCells(2, 7); ec.AddCell(vtkm::VTKM_TRIANGLE, 3, make_Vec(0,1,2)); diff --git a/vtkm/exec/ExplicitConnectivity.h b/vtkm/exec/ExplicitConnectivity.h index 801159405..833ed6b4f 100644 --- a/vtkm/exec/ExplicitConnectivity.h +++ b/vtkm/exec/ExplicitConnectivity.h @@ -27,12 +27,29 @@ namespace vtkm { namespace exec { -template +template class ExplicitConnectivity { public: ExplicitConnectivity() {} + ExplicitConnectivity(const ShapePortalType& shapePortal, + const IndicePortalType& indicePortal, + const ConnectivityPortalType& connPortal, + const MapConnectivityPortalType& mapConnPortal + ) + : Shapes(shapePortal), + NumIndices(indicePortal), + Connectivity(connPortal), + MapCellToConnectivityIndex(mapConnPortal) + { + + } + VTKM_EXEC_EXPORT vtkm::Id GetNumberOfElements() { @@ -61,11 +78,11 @@ public: ids[i] = Connectivity.Get(start+i); } - typedef typename vtkm::cont::ArrayHandle::template ExecutionTypes::PortalConst PortalType; - PortalType Shapes; - PortalType NumIndices; - PortalType Connectivity; - PortalType MapCellToConnectivityIndex; +private: + ShapePortalType Shapes; + IndicePortalType NumIndices; + ConnectivityPortalType Connectivity; + MapConnectivityPortalType MapCellToConnectivityIndex; }; } // namespace exec