vtk-m/vtkm/cont/RegularConnectivity.h

149 lines
4.0 KiB
C
Raw Normal View History

2015-04-15 14:45:39 +00:00
#ifndef vtk_m_cont_RegularConnectivity_h
#define vtk_m_cont_RegularConnectivity_h
2015-05-14 20:08:28 +00:00
#include <vtkm/cont/TopologyType.h>
#include <vtkm/Extent.h>
2015-04-15 14:45:39 +00:00
#include <vtkm/CellType.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 {
template<vtkm::IdComponent> class RegularStructure;
//1 D specialization.
template<>
class RegularStructure<1>
2015-04-15 14:45:39 +00:00
{
public:
void SetNodeDimension(int node_i, int, int)
2015-04-15 14:45:39 +00:00
{
cellDims.Min[0] = nodeDims.Min[0] = 0;
cellDims.Max[0] = node_i-1;
nodeDims.Max[0] = node_i;
2015-04-15 14:45:39 +00:00
}
vtkm::Id GetNumberOfElements() const {return cellDims.Max[0];}
2015-05-14 20:08:28 +00:00
vtkm::Id GetNumberOfIndices(vtkm::Id) const {return 2;}
vtkm::Id GetElementShapeType(vtkm::Id) const {return VTKM_LINE;}
2015-04-15 14:45:39 +00:00
2015-05-14 20:08:28 +00:00
void GetNodesOfCells(vtkm::Id index, vtkm::Vec<vtkm::Id,2> &ids) const
2015-04-15 14:45:39 +00:00
{
ids[0] = index;
2015-05-14 20:08:28 +00:00
ids[1] = ids[0] + 1;
2015-04-15 14:45:39 +00:00
}
private:
Extent<1> cellDims;
Extent<1> nodeDims;
};
//2 D specialization.
template<>
class RegularStructure<2>
{
public:
void SetNodeDimension(int node_i, int node_j, int)
2015-04-15 14:45:39 +00:00
{
cellDims.Min[0] = cellDims.Min[1] = 0;
nodeDims.Min[0] = nodeDims.Min[1] = 0;
cellDims.Max[0] = node_i-1;
nodeDims.Max[0] = node_i;
cellDims.Max[1] = node_j-1;
nodeDims.Max[1] = node_j;
2015-04-15 14:45:39 +00:00
}
vtkm::Id GetNumberOfElements() const {return cellDims.Max[0]*cellDims.Max[1];}
2015-05-14 20:08:28 +00:00
vtkm::Id GetNumberOfIndices(vtkm::Id) const {return 4;}
vtkm::Id GetElementShapeType(vtkm::Id) const {return VTKM_PIXEL;}
2015-05-14 20:08:28 +00:00
void GetNodesOfCells(vtkm::Id index, vtkm::Vec<vtkm::Id,4> &ids) const
2015-04-15 14:45:39 +00:00
{
2015-05-14 20:08:28 +00:00
int i = index % cellDims.Max[0];
int j = index / cellDims.Max[0];
ids[0] = j*nodeDims.Max[0] + i;
ids[1] = ids[0] + 1;
2015-05-14 20:08:28 +00:00
ids[2] = ids[0] + nodeDims.Max[0];
ids[3] = ids[2] + 1;
2015-04-15 14:45:39 +00:00
}
2015-04-15 14:45:39 +00:00
private:
Extent<2> cellDims;
Extent<2> nodeDims;
};
//3 D specialization.
template<>
class RegularStructure<3>
{
public:
void SetNodeDimension(int node_i, int node_j, int node_k)
2015-04-15 14:45:39 +00:00
{
cellDims.Min[0] = cellDims.Min[1] = cellDims.Min[2] = 0;
nodeDims.Min[0] = nodeDims.Min[1] = nodeDims.Min[2] = 0;
cellDims.Max[0] = node_i-1;
nodeDims.Max[0] = node_i;
cellDims.Max[1] = node_j-1;
nodeDims.Max[1] = node_j;
cellDims.Max[2] = node_k-1;
nodeDims.Max[2] = node_k;
2015-04-15 14:45:39 +00:00
}
vtkm::Id GetNumberOfElements() const {return cellDims.Max[0]*cellDims.Max[1]*cellDims.Max[2];}
vtkm::Id GetNumberOfIndices(vtkm::Id) const {return 8;}
vtkm::Id GetElementShapeType(vtkm::Id) const {return VTKM_VOXEL;}
2015-05-14 20:08:28 +00:00
void GetNodesOfCells(vtkm::Id index, vtkm::Vec<vtkm::Id,2> &ids) const
2015-04-15 14:45:39 +00:00
{
int cellDims01 = cellDims.Max[0] * cellDims.Max[1];
int k = index / cellDims01;
int indexij = index % cellDims01;
int j = indexij / cellDims.Max[0];
int i = indexij % cellDims.Max[0];
ids[0] = (k * nodeDims.Max[1] + j) * nodeDims.Max[0] + i;
ids[1] = ids[0] + 1;
ids[2] = ids[0] + nodeDims.Max[0];
ids[3] = ids[2] + 1;
ids[4] = ids[0] + nodeDims.Max[0]*nodeDims.Max[1];
ids[5] = ids[4] + 1;
ids[6] = ids[4] + nodeDims.Max[0];
ids[7] = ids[6] + 1;
2015-04-15 14:45:39 +00:00
}
private:
Extent<3> cellDims;
Extent<3> nodeDims;
};
template<vtkm::IdComponent Dimension>
class RegularConnectivity
{
public:
void SetNodeDimension(int node_i, int node_j=0, int node_k=0)
2015-04-15 14:45:39 +00:00
{
rs.SetNodeDimension(node_i, node_j, node_k);
2015-04-15 14:45:39 +00:00
}
vtkm::Id GetNumberOfElements() const {return rs.GetNumberOfElements();}
vtkm::Id GetNumberOfIndices(vtkm::Id) const {return rs.GetNumberOfIndices();}
vtkm::Id GetElementShapeType(vtkm::Id) const {return rs.GetElementShapeType();}
2015-05-14 20:08:28 +00:00
template <vtkm::IdComponent ItemTupleLength, vtkm::cont::TopologyType Topology>
void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id,ItemTupleLength> &ids)
2015-04-15 14:45:39 +00:00
{
2015-05-14 20:08:28 +00:00
return rs.GetNodesOfCells(index, ids);
2015-04-15 14:45:39 +00:00
}
private:
RegularStructure<Dimension> rs;
2015-04-15 14:45:39 +00:00
};
//TODO:
//Add specialized 1D and 2D versions.
}
} // namespace vtkm::cont
#endif //vtk_m_cont_RegularConnectivity_h