vtk-m2/vtkm/cont/ExplicitConnectivity.h
2015-05-12 12:50:30 -04:00

89 lines
2.9 KiB
C++

//============================================================================
// 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 <vtkm/CellType.h>
#include <vtkm/exec/ExplicitConnectivity.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/Field.h>
#include <vtkm/cont/DynamicArrayHandle.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
namespace vtkm {
namespace cont {
class ExplicitConnectivity
{
public:
typedef vtkm::exec::ExplicitConnectivity<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> ExecObjectType;
public:
ExplicitConnectivity() {}
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 <vtkm::IdComponent ItemTupleLength>
void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id,ItemTupleLength> &ids)
{
int n = GetNumberOfIndices(index);
int start = MapCellToConnectivityIndex.GetPortalControl().Get(index);
for (int i=0; i<n && i<ItemTupleLength; i++)
ids[i] = Connectivity.GetPortalControl().Get(start+i);
}
template <vtkm::IdComponent ItemTupleLength>
void AddShape(vtkm::CellType cellType, int numVertices, vtkm::Vec<vtkm::Id,ItemTupleLength> &ids)
{
///\todo: how do I modify an array handle?
}
template<typename Device>
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;
}
vtkm::cont::ArrayHandle<vtkm::Id, vtkm::cont::StorageTagBasic> Shapes;
vtkm::cont::ArrayHandle<vtkm::Id, vtkm::cont::StorageTagBasic> NumIndices;
vtkm::cont::ArrayHandle<vtkm::Id, vtkm::cont::StorageTagBasic> Connectivity;
vtkm::cont::ArrayHandle<vtkm::Id, vtkm::cont::StorageTagBasic> MapCellToConnectivityIndex;
};
}
} // namespace vtkm::cont
#endif //vtk_m_cont_ExplicitConnectivity_h