//============================================================================ // 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 { template class ExplicitConnectivity { public: VTKM_CONT_EXPORT ExplicitConnectivity() { NumShapes = 0; ConnectivityLength = 0; } VTKM_CONT_EXPORT vtkm::Id GetNumberOfElements() { return Shapes.GetNumberOfValues(); } VTKM_CONT_EXPORT vtkm::Id GetNumberOfIndices(vtkm::Id index) { return NumIndices.GetPortalControl().Get(index); } VTKM_CONT_EXPORT vtkm::Id GetElementShapeType(vtkm::Id index) { return Shapes.GetPortalControl().Get(index); } template VTKM_CONT_EXPORT void GetIndices(vtkm::Id index, vtkm::Vec &ids) { int n = GetNumberOfIndices(index); int start = MapCellToConnectivityIndex.GetPortalControl().Get(index); for (int i=0; i VTKM_CONT_EXPORT 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; } VTKM_CONT_EXPORT void CompleteAddingCells() { Connectivity.Shrink(ConnectivityLength); } /// Second method to add cells -- all at once. /// Copies the data from the vectors, so they can be released. VTKM_CONT_EXPORT void FillViaCopy(const std::vector &cellTypes, const std::vector &numIndices, const std::vector &connectivity) { this->Shapes.Allocate( static_cast(cellTypes.size()) ); std::copy(cellTypes.begin(), cellTypes.end(), vtkm::cont::ArrayPortalToIteratorBegin(this->Shapes.GetPortalControl())); this->NumIndices.Allocate( static_cast(numIndices.size()) ); std::copy(numIndices.begin(), numIndices.end(), vtkm::cont::ArrayPortalToIteratorBegin(this->NumIndices.GetPortalControl())); this->Connectivity.Allocate( static_cast(connectivity.size()) ); std::copy(connectivity.begin(), connectivity.end(), vtkm::cont::ArrayPortalToIteratorBegin(this->Connectivity.GetPortalControl())); this->NumShapes = this->Shapes.GetNumberOfValues(); this->ConnectivityLength = this->Connectivity.GetNumberOfValues(); // allocate and build reverse index MapCellToConnectivityIndex.Allocate(NumShapes); vtkm::Id counter = 0; for (vtkm::Id i=0; i &cellTypes, const vtkm::cont::ArrayHandle &numIndices, const vtkm::cont::ArrayHandle &connectivity) { this->Shapes = cellTypes; this->NumIndices = numIndices; this->Connectivity = connectivity; this->NumShapes = this->Shapes.GetNumberOfValues(); this->ConnectivityLength = this->Connectivity.GetNumberOfValues(); // allocate and build reverse index MapCellToConnectivityIndex.Allocate(this->NumShapes); vtkm::Id counter = 0; for (vtkm::Id i=0; iNumShapes; ++i) { MapCellToConnectivityIndex.GetPortalControl().Set(i, counter); counter += this->NumIndices.GetPortalControl().Get(i); } } template struct ExecutionTypes { 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 { 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 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