Merge topic 'simplify_cellset_permutation_templates'

6883a5ac Simplify using CellSetPermutation by providing a default permutation type.

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !391
This commit is contained in:
Robert Maynard 2016-04-13 09:17:01 -04:00 committed by Kitware Robot
commit 59f5f24845
8 changed files with 94 additions and 285 deletions

@ -24,242 +24,34 @@
#include <vtkm/CellTraits.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/CellSet.h>
#include <vtkm/cont/CellSetExplicit.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/exec/ConnectivityStructuredPermuted.h>
#include <vtkm/exec/ConnectivityPermuted.h>
namespace vtkm {
namespace cont {
namespace internal{
template<typename ValidCellArrayHandleType, typename OriginalCellSet>
struct CellSetPermutationTraits
template< typename OriginalCellSet, typename ValidCellArrayHandleType> class CellSetPermutation;
namespace internal {
template< typename OriginalCellSet, typename PermutationArrayHandleType >
class CellSetGeneralPermutation : public CellSet
{
typedef typename OriginalCellSet::ShapeArrayType ShapeArrayType;
typedef typename OriginalCellSet::NumIndicesArrayType NumIndicesArrayType;
typedef typename OriginalCellSet::ConnectivityArrayType ConnectivityArrayType;
typedef typename OriginalCellSet::IndexOffsetArrayType IndexOffsetArrayType;
typedef vtkm::cont::ArrayHandlePermutation<ValidCellArrayHandleType,
ShapeArrayType> PermShapeArrayType;
typedef vtkm::cont::ArrayHandlePermutation<ValidCellArrayHandleType,
NumIndicesArrayType> PermNumIndicesArrayType;
typedef vtkm::cont::ArrayHandlePermutation<ValidCellArrayHandleType,
IndexOffsetArrayType> PermIndexOffsetArrayType;
typedef vtkm::cont::CellSetExplicit<
typename PermShapeArrayType::StorageTag,
typename PermNumIndicesArrayType::StorageTag,
typename ConnectivityArrayType::StorageTag,
typename PermIndexOffsetArrayType::StorageTag> PermutedCellSetType;
};
template<typename ValidCellArrayHandleType, vtkm::IdComponent DIMENSION>
struct CellSetPermutationTraits<ValidCellArrayHandleType, CellSetStructured<DIMENSION> >
{
};
}
template< typename ValidCellArrayHandleType,
typename OriginalCellSet >
class CellSetPermutation : public CellSet
{
typedef vtkm::cont::CellSetPermutation<
ValidCellArrayHandleType,OriginalCellSet> Thisclass;
public:
typedef typename vtkm::cont::internal::CellSetPermutationTraits<
ValidCellArrayHandleType,OriginalCellSet>::PermutedCellSetType PermutedCellSetType;
typedef typename PermutedCellSetType::ShapeArrayType ShapeArrayType;
typedef typename PermutedCellSetType::NumIndicesArrayType NumIndicesArrayType;
typedef typename PermutedCellSetType::ConnectivityArrayType ConnectivityArrayType;
typedef typename PermutedCellSetType::IndexOffsetArrayType IndexOffsetArrayType;
VTKM_CONT_EXPORT
CellSetPermutation(const ValidCellArrayHandleType& validCellIds,
const OriginalCellSet& cellset,
const std::string &name = std::string(),
vtkm::IdComponent dimensionality = 3)
: CellSet(name,dimensionality),
PermutedCellSet(0, name, dimensionality)
{
this->Fill(validCellIds, cellset);
}
VTKM_CONT_EXPORT
CellSetPermutation(const std::string &name = std::string(),
vtkm::IdComponent dimensionality = 3)
: CellSet(name,dimensionality),
ValidCellIds(),
PermutedCellSet(0, name, dimensionality)
{
}
VTKM_CONT_EXPORT
CellSetPermutation(const Thisclass &src)
: CellSet(src),
ValidCellIds(src.ValidCellIds),
PermutedCellSet(src.PermutedCellSet)
{ }
VTKM_CONT_EXPORT
Thisclass &operator=(const Thisclass &src)
{
this->CellSet::operator=(src);
this->ValidCellIds = src.ValidCellIds;
this->PermutedCellSet = src.PermutedCellSet;
return *this;
}
virtual ~CellSetPermutation() { }
//This is the way you can fill the memory from another system without copying
VTKM_CONT_EXPORT
void Fill(const ValidCellArrayHandleType &validCellIds,
const OriginalCellSet& cellset)
{
typedef vtkm::cont::internal::CellSetPermutationTraits<
ValidCellArrayHandleType, OriginalCellSet> Traits;
typedef vtkm::TopologyElementTagPoint ElemPointTag;
typedef vtkm::TopologyElementTagCell ElemCellTag;
PermutedCellSetType permutedCellSet(0,this->PermutedCellSet.GetName(),
cellset.GetDimensionality());
typename Traits::PermShapeArrayType shapeArray(validCellIds,
cellset.GetShapesArray(ElemPointTag(),ElemCellTag()));
typename Traits::PermNumIndicesArrayType numArray(validCellIds,
cellset.GetNumIndicesArray(ElemPointTag(),ElemCellTag()));
typename Traits::PermIndexOffsetArrayType offsArray(validCellIds,
cellset.GetIndexOffsetArray(ElemPointTag(),ElemCellTag()));
permutedCellSet.Fill( shapeArray,
numArray,
cellset.GetConnectivityArray(ElemPointTag(),ElemCellTag()),
offsArray);
this->ValidCellIds = validCellIds;
this->PermutedCellSet = permutedCellSet;
}
template<typename FromTopology, typename ToTopology>
VTKM_CONT_EXPORT
const ShapeArrayType&
GetShapesArray(FromTopology,ToTopology) const
{
return this->PermutedCellSet.GetShapesArray(FromTopology(), ToTopology());
}
template<typename FromTopology, typename ToTopology>
VTKM_CONT_EXPORT
const NumIndicesArrayType&
GetNumIndicesArray(FromTopology,ToTopology) const
{
return this->PermutedCellSet.GetNumIndicesArray(FromTopology(),ToTopology());
}
template<typename FromTopology, typename ToTopology>
VTKM_CONT_EXPORT
const ConnectivityArrayType&
GetConnectivityArray(FromTopology,ToTopology) const
{
return this->PermutedCellSet.GetConnectivityArray(FromTopology(),ToTopology());
}
template<typename FromTopology, typename ToTopology>
VTKM_CONT_EXPORT
const IndexOffsetArrayType&
GetIndexOffsetArray(FromTopology,ToTopology) const
{
return this->PermutedCellSet.GetIndexOffsetArray(FromTopology(),ToTopology());
}
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfCells() const
{
return this->PermutedCellSet.GetNumberOfCells();
}
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfPoints() const
{
return this->PermutedCellSet.GetNumberOfPoints();
}
VTKM_CONT_EXPORT
vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const
{
return this->PermutedCellSet.GetNumberOfCells();
}
VTKM_CONT_EXPORT
vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const
{
return this->PermutedCellSet.GetNumberOfPoints();
}
template <typename DeviceAdapter, typename FromTopology, typename ToTopology>
struct ExecutionTypes
{
VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapter);
VTKM_IS_TOPOLOGY_ELEMENT_TAG(FromTopology);
VTKM_IS_TOPOLOGY_ELEMENT_TAG(ToTopology);
typedef typename PermutedCellSetType::template ExecutionTypes<
DeviceAdapter,
FromTopology,
ToTopology>::ExecObjectType ExecObjectType;
};
template<typename Device, typename FromTopology, typename ToTopology>
typename ExecutionTypes<Device,FromTopology,ToTopology>::ExecObjectType
PrepareForInput(Device d, FromTopology f, ToTopology t) const
{
return this->PermutedCellSet.PrepareForInput(d,f,t);
}
virtual void PrintSummary(std::ostream &out) const
{
out << " CellSetPermutation<ExplicitCellType>: " <<std::endl;
PermutedCellSet.PrintSummary(out);
}
private:
ValidCellArrayHandleType ValidCellIds;
PermutedCellSetType PermutedCellSet;
};
template< typename ValidCellArrayHandleType,vtkm::IdComponent Dimension>
class CellSetPermutation<ValidCellArrayHandleType, CellSetStructured<Dimension> > : public CellSet
{
typedef vtkm::internal::ConnectivityStructuredInternals<Dimension>
InternalsType;
public:
VTKM_CONT_EXPORT
CellSetPermutation(const ValidCellArrayHandleType& validCellIds,
const CellSetStructured<Dimension>& cellset,
const std::string &name = std::string(),
vtkm::IdComponent dimensionality = Dimension)
CellSetGeneralPermutation(const PermutationArrayHandleType& validCellIds,
const OriginalCellSet& cellset,
const std::string &name,
vtkm::IdComponent dimensionality)
: CellSet(name,dimensionality),
ValidCellIds(),
FullCellSet()
ValidCellIds(validCellIds),
FullCellSet(cellset)
{
this->Fill(validCellIds, cellset);
}
VTKM_CONT_EXPORT
CellSetPermutation(const std::string &name = std::string(),
vtkm::IdComponent dimensionality = Dimension)
CellSetGeneralPermutation(const std::string &name,
vtkm::IdComponent dimensionality)
: CellSet(name,dimensionality),
ValidCellIds(),
FullCellSet()
@ -280,8 +72,8 @@ public:
//This is the way you can fill the memory from another system without copying
VTKM_CONT_EXPORT
void Fill(const ValidCellArrayHandleType &validCellIds,
const CellSetStructured<Dimension>& cellset)
void Fill(const PermutationArrayHandleType &validCellIds,
const OriginalCellSet& cellset)
{
ValidCellIds = validCellIds;
FullCellSet = cellset;
@ -300,10 +92,14 @@ public:
VTKM_IS_TOPOLOGY_ELEMENT_TAG(FromTopology);
VTKM_IS_TOPOLOGY_ELEMENT_TAG(ToTopology);
typedef typename ValidCellArrayHandleType::template ExecutionTypes<Device>::PortalConst ExecPortalType;
typedef typename PermutationArrayHandleType::template ExecutionTypes<Device>::PortalConst ExecPortalType;
typedef vtkm::exec::ConnectivityStructuredPermuted< ExecPortalType,
FromTopology,ToTopology,Dimension> ExecObjectType;
typedef typename OriginalCellSet::template ExecutionTypes<
Device,
FromTopology,
ToTopology>::ExecObjectType OrigExecObjectType;
typedef vtkm::exec::ConnectivityPermuted< ExecPortalType, OrigExecObjectType> ExecObjectType;
};
template<typename Device, typename FromTopology, typename ToTopology>
@ -319,15 +115,44 @@ public:
virtual void PrintSummary(std::ostream &out) const
{
out << " CellSetPermutation<StructuredCellType<"<<Dimension<<"> >: " <<std::endl;
out << " CellSetGeneralPermutation of: "<< std::endl;
this->FullCellSet.PrintSummary(out);
}
private:
std::string Name;
vtkm::Id Dimensionality;
PermutationArrayHandleType ValidCellIds;
OriginalCellSet FullCellSet;
};
} //namespace internal
#ifndef VTKM_DEFAULT_CELLSET_PERMUTATION_STORAGE_TAG
#define VTKM_DEFAULT_CELLSET_PERMUTATION_STORAGE_TAG VTKM_DEFAULT_STORAGE_TAG
#endif
template< typename OriginalCellSet,
typename PermutationArrayHandleType = vtkm::cont::ArrayHandle< vtkm::Id, VTKM_DEFAULT_CELLSET_PERMUTATION_STORAGE_TAG > >
class CellSetPermutation : public vtkm::cont::internal::CellSetGeneralPermutation<OriginalCellSet, PermutationArrayHandleType>
{
typedef typename vtkm::cont::internal::CellSetGeneralPermutation<
OriginalCellSet, PermutationArrayHandleType> ParentType;
public:
VTKM_CONT_EXPORT
CellSetPermutation(const PermutationArrayHandleType& validCellIds,
const OriginalCellSet& cellset,
const std::string &name = std::string(),
vtkm::IdComponent dimensionality = 3)
: ParentType(validCellIds, cellset, name, dimensionality)
{
}
VTKM_CONT_EXPORT
CellSetPermutation(const std::string &name = std::string(),
vtkm::IdComponent dimensionality = 3)
: ParentType(name, dimensionality)
{
}
ValidCellArrayHandleType ValidCellIds;
CellSetStructured<Dimension> FullCellSet;
};
}

@ -107,8 +107,7 @@ void TestDataSet_Explicit()
dataSet.GetCellSet(0).CopyTo(cellSet);
//verify that we can create a subset of a singlset
typedef vtkm::cont::CellSetPermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::CellSetSingleType<> > SubsetType;
typedef vtkm::cont::CellSetPermutation< vtkm::cont::CellSetSingleType<> > SubsetType;
SubsetType subset;
subset.Fill(validCellIds,cellSet);
@ -158,8 +157,7 @@ void TestDataSet_Structured2D()
dataSet.GetCellSet(0).CopyTo(cellSet);
//verify that we can create a subset of a 2d UniformDataSet
vtkm::cont::CellSetPermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::CellSetStructured<2> > subset;
vtkm::cont::CellSetPermutation< vtkm::cont::CellSetStructured<2> > subset;
subset.Fill(validCellIds,cellSet);
subset.PrintSummary(std::cout);
@ -205,8 +203,7 @@ void TestDataSet_Structured3D()
dataSet.GetCellSet(0).CopyTo(cellSet);
//verify that we can create a subset of a 2d UniformDataSet
vtkm::cont::CellSetPermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::CellSetStructured<3> > subset;
vtkm::cont::CellSetPermutation< vtkm::cont::CellSetStructured<3> > subset;
subset.Fill(validCellIds,cellSet);
subset.PrintSummary(std::cout);

@ -24,14 +24,13 @@ set(headers
CellDerivative.h
CellInterpolate.h
ConnectivityExplicit.h
ConnectivityPermuted.h
ConnectivityStructured.h
ConnectivityStructuredPermuted.h
ExecutionObjectBase.h
ExecutionWholeArray.h
FunctorBase.h
NewtonsMethod.h
ParametricCoordinates.h
)
#-----------------------------------------------------------------------------

@ -19,8 +19,8 @@
//============================================================================
#ifndef vtk_m_exec_ConnectivityStructuredPermuted_h
#define vtk_m_exec_ConnectivityStructuredPermuted_h
#ifndef vtk_m_exec_ConnectivityPermuted_h
#define vtk_m_exec_ConnectivityPermuted_h
#include <vtkm/TopologyElementTag.h>
#include <vtkm/Types.h>
@ -30,70 +30,63 @@ namespace vtkm {
namespace exec {
template<typename PermutationPortal,
typename FromTopology,
typename ToTopology,
vtkm::IdComponent Dimension>
class ConnectivityStructuredPermuted
typename OriginalConnectivity>
class ConnectivityPermuted
{
VTKM_IS_TOPOLOGY_ELEMENT_TAG(FromTopology);
VTKM_IS_TOPOLOGY_ELEMENT_TAG(ToTopology);
typedef vtkm::exec::ConnectivityStructured<FromTopology,
ToTopology,
Dimension> StructuredType;
public:
typedef vtkm::Id SchedulingRangeType;
VTKM_EXEC_CONT_EXPORT
ConnectivityStructuredPermuted():
ConnectivityPermuted():
Portal(),
FullStructuredGrid()
Connectivity()
{
}
VTKM_EXEC_CONT_EXPORT
ConnectivityStructuredPermuted(const PermutationPortal& portal,
const StructuredType &src):
ConnectivityPermuted(const PermutationPortal& portal,
const OriginalConnectivity &src):
Portal(portal),
FullStructuredGrid(src)
Connectivity(src)
{
}
VTKM_EXEC_CONT_EXPORT
ConnectivityStructuredPermuted(const ConnectivityStructuredPermuted &src):
ConnectivityPermuted(const ConnectivityPermuted &src):
Portal(src.Portal),
FullStructuredGrid(src.FullStructuredGrid)
Connectivity(src.Connectivity)
{
}
VTKM_EXEC_EXPORT
vtkm::IdComponent GetNumberOfIndices(vtkm::Id index) const {
return this->FullStructuredGrid.GetNumberOfIndices( this->Portal.Get(index) );
return this->Connectivity.GetNumberOfIndices( this->Portal.Get(index) );
}
// This needs some thought. What does cell shape mean when the to topology
// is not a cell?
typedef typename StructuredType::CellShapeTag CellShapeTag;
typedef typename OriginalConnectivity::CellShapeTag CellShapeTag;
VTKM_EXEC_EXPORT
CellShapeTag GetCellShape(vtkm::Id=0) const {
return CellShapeTag();
CellShapeTag GetCellShape(vtkm::Id index) const {
vtkm::Id pIndex = this->Portal.Get(index);
return this->Connectivity.GetCellShape( pIndex );
}
typedef typename StructuredType::IndicesType IndicesType;
typedef typename OriginalConnectivity::IndicesType IndicesType;
VTKM_EXEC_EXPORT
IndicesType GetIndices(vtkm::Id index) const
{
return this->FullStructuredGrid.GetIndices( this->Portal.Get(index) );
return this->Connectivity.GetIndices( this->Portal.Get(index) );
}
private:
PermutationPortal Portal;
StructuredType FullStructuredGrid;
OriginalConnectivity Connectivity;
};
}
} // namespace vtkm::exec
#endif //vtk_m_exec_ConnectivityStructuredPermuted_h
#endif //vtk_m_exec_ConnectivityPermuted_h

@ -74,7 +74,7 @@ public:
// is not a cell?
typedef typename InternalsType::CellShapeTag CellShapeTag;
VTKM_EXEC_EXPORT
CellShapeTag GetCellShape(vtkm::Id=0) const {
CellShapeTag GetCellShape(vtkm::Id) const {
return CellShapeTag();
}
@ -116,11 +116,11 @@ public:
}
VTKM_EXEC_CONT_EXPORT
vtkm::Vec<vtkm::Id,Dimension> GetPointDimensions() const
vtkm::Vec<vtkm::Id,Dimension> GetPointDimensions() const
{
return this->Internals.GetPointDimensions();
}
private:
InternalsType Internals;
};

@ -64,8 +64,7 @@ public:
template<typename CellSetType>
void operator()(const CellSetType& cellset ) const
{
typedef vtkm::cont::CellSetPermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
CellSetType> PermutationCellSetType;
typedef vtkm::cont::CellSetPermutation<CellSetType> PermutationCellSetType;
PermutationCellSetType permCellSet(*this->ValidIds, cellset,
cellset.GetName(),

@ -102,14 +102,13 @@ public:
};
template <typename CellSetType, typename UnaryPredicate, typename DeviceAdapter>
vtkm::cont::CellSetPermutation<vtkm::cont::ArrayHandle<vtkm::Id>, CellSetType>
vtkm::cont::CellSetPermutation< CellSetType >
Run(const CellSetType &cellSet,
const vtkm::cont::Field &field,
const UnaryPredicate &predicate,
DeviceAdapter)
{
typedef vtkm::cont::CellSetPermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
CellSetType> OutputType;
typedef vtkm::cont::CellSetPermutation< CellSetType > OutputType;
vtkm::cont::ArrayHandle<bool> passFlags;
switch(field.GetAssociation())

@ -60,8 +60,7 @@ public:
std::cout << "Testing threshold on 2D uniform dataset" << std::endl;
typedef vtkm::cont::CellSetStructured<2> CellSetType;
typedef vtkm::cont::CellSetPermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
CellSetType> OutCellSetType;
typedef vtkm::cont::CellSetPermutation<CellSetType> OutCellSetType;
typedef vtkm::cont::ArrayHandlePermutation<
vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::ArrayHandle<vtkm::Float32> > OutCellFieldArrayHandleType;
@ -94,8 +93,7 @@ public:
std::cout << "Testing threshold on 3D uniform dataset" << std::endl;
typedef vtkm::cont::CellSetStructured<3> CellSetType;
typedef vtkm::cont::CellSetPermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
CellSetType> OutCellSetType;
typedef vtkm::cont::CellSetPermutation<CellSetType> OutCellSetType;
typedef vtkm::cont::ArrayHandlePermutation<
vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::ArrayHandle<vtkm::Float32> > OutCellFieldArrayHandleType;
@ -129,8 +127,7 @@ public:
std::cout << "Testing threshold on 3D explicit dataset" << std::endl;
typedef vtkm::cont::CellSetExplicit<> CellSetType;
typedef vtkm::cont::CellSetPermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
CellSetType> OutCellSetType;
typedef vtkm::cont::CellSetPermutation<CellSetType> OutCellSetType;
typedef vtkm::cont::ArrayHandlePermutation<
vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::ArrayHandle<vtkm::Float32> > OutCellFieldArrayHandleType;