//============================================================================ // 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. // // Copyright 2015 Sandia Corporation. // Copyright 2015 UT-Battelle, LLC. // Copyright 2015 Los Alamos National Security. // // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, // the U.S. Government retains certain rights in this software. // // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National // Laboratory (LANL), the U.S. Government retains certain rights in // this software. //============================================================================ #ifndef vtk_m_cont_ExplicitConnectivity_h #define vtk_m_cont_ExplicitConnectivity_h #include #include #include #include #include #include namespace vtkm { namespace cont { class ExplicitConnectivity { public: typedef vtkm::exec::ExplicitConnectivity ExecObjectType; public: ExplicitConnectivity() { NumShapes = 0; ConnectivityLength = 0; } vtkm::Id GetNumberOfElements() { return Shapes.GetNumberOfValues(); } vtkm::Id GetNumberOfIndices(vtkm::Id index) { return NumIndices.GetPortalControl().Get(index); } vtkm::Id GetElementShapeType(vtkm::Id index) { return Shapes.GetPortalControl().Get(index); } template void GetIndices(vtkm::Id index, vtkm::Vec &ids) { int n = GetNumberOfIndices(index); int start = MapCellToConnectivityIndex.GetPortalControl().Get(index); for (int i=0; i void AddCell(vtkm::CellType cellType, int numVertices, const vtkm::Vec &ids) { Shapes.GetPortalControl().Set(NumShapes, cellType); NumIndices.GetPortalControl().Set(NumShapes, numVertices); for (int i=0; i < numVertices; ++i) Connectivity.GetPortalControl().Set(ConnectivityLength+i,ids[i]); MapCellToConnectivityIndex.GetPortalControl().Set(NumShapes, ConnectivityLength); NumShapes++; ConnectivityLength += numVertices; } void CompleteAddingCells() { Connectivity.Shrink(ConnectivityLength); } /// Second method to add cells -- all at once. void FillViaCopy(const std::vector &cellTypes, const std::vector &numIndices, const std::vector &connectivity) { vtkm::cont::ArrayHandle t1 = vtkm::cont::make_ArrayHandle(cellTypes); vtkm::cont::DeviceAdapterAlgorithm::Copy(t1, Shapes); vtkm::cont::ArrayHandle t2 = vtkm::cont::make_ArrayHandle(numIndices); vtkm::cont::DeviceAdapterAlgorithm::Copy(t2, NumIndices); vtkm::cont::ArrayHandle t3 = vtkm::cont::make_ArrayHandle(connectivity); vtkm::cont::DeviceAdapterAlgorithm::Copy(t3, Connectivity); NumShapes = cellTypes.size(); ConnectivityLength = connectivity.size(); // allocate and build reverse index MapCellToConnectivityIndex.Allocate(NumShapes); vtkm::Id counter = 0; for (vtkm::Id i=0; i ExecObjectType PrepareForInput(Device d) const { ExecObjectType obj; obj.Shapes = Shapes.PrepareForInput(d); obj.NumIndices = NumIndices.PrepareForInput(d); obj.Connectivity = Connectivity.PrepareForInput(d); obj.MapCellToConnectivityIndex = MapCellToConnectivityIndex.PrepareForInput(d); return obj; } virtual void PrintSummary(std::ostream &out) { out<<" ExplicitConnectivity: #shapes= "< Shapes; vtkm::cont::ArrayHandle NumIndices; vtkm::cont::ArrayHandle Connectivity; vtkm::cont::ArrayHandle MapCellToConnectivityIndex; }; } } // namespace vtkm::cont #endif //vtk_m_cont_ExplicitConnectivity_h