mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 10:35:42 +00:00
Merge branch 'master' of gitlab.kitware.com:Fasel/vtk-m into tetra_explicit
This commit is contained in:
commit
c87b4f50da
@ -37,6 +37,7 @@ set(headers
|
||||
Assert.h
|
||||
CellSet.h
|
||||
CellSetExplicit.h
|
||||
CellSetSingleType.h
|
||||
CellSetListTag.h
|
||||
CellSetStructured.h
|
||||
CoordinateSystem.h
|
||||
|
@ -21,10 +21,10 @@
|
||||
#define vtk_m_cont_CellSetExplicit_h
|
||||
|
||||
#include <vtkm/CellShape.h>
|
||||
#include <vtkm/TopologyElementTag.h>
|
||||
#include <vtkm/cont/CellSet.h>
|
||||
#include <vtkm/cont/internal/ConnectivityExplicitInternals.h>
|
||||
#include <vtkm/exec/ConnectivityExplicit.h>
|
||||
#include <vtkm/TopologyElementTag.h>
|
||||
|
||||
#include <map>
|
||||
#include <utility>
|
||||
@ -56,21 +56,36 @@ struct CellSetExplicitConnectivityChooser
|
||||
#define VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG VTKM_DEFAULT_STORAGE_TAG
|
||||
#endif
|
||||
|
||||
#ifndef VTKM_DEFAULT_OFFSETS_STORAGE_TAG
|
||||
#define VTKM_DEFAULT_OFFSETS_STORAGE_TAG VTKM_DEFAULT_STORAGE_TAG
|
||||
#endif
|
||||
|
||||
template<typename ShapeStorageTag = VTKM_DEFAULT_SHAPE_STORAGE_TAG,
|
||||
typename NumIndicesStorageTag = VTKM_DEFAULT_NUM_INDICES_STORAGE_TAG,
|
||||
typename ConnectivityStorageTag = VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG >
|
||||
typename ConnectivityStorageTag = VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG,
|
||||
typename OffsetsStorageTag = VTKM_DEFAULT_OFFSETS_STORAGE_TAG >
|
||||
class CellSetExplicit : public CellSet
|
||||
{
|
||||
template<typename FromTopology, typename ToTopology>
|
||||
struct ConnectivityChooser
|
||||
{
|
||||
typedef CellSetExplicit< ShapeStorageTag,
|
||||
NumIndicesStorageTag,
|
||||
ConnectivityStorageTag,
|
||||
OffsetsStorageTag > CellSetExplicitType;
|
||||
typedef typename detail::CellSetExplicitConnectivityChooser<
|
||||
CellSetExplicit<
|
||||
ShapeStorageTag,NumIndicesStorageTag,ConnectivityStorageTag>,
|
||||
CellSetExplicitType,
|
||||
FromTopology,
|
||||
ToTopology>::ConnectivityType ConnectivityType;
|
||||
|
||||
typedef typename ConnectivityType::ShapeArrayType ShapeArrayType;
|
||||
typedef typename ConnectivityType::NumIndicesArrayType NumIndicesArrayType;
|
||||
typedef typename ConnectivityType::ConnectivityArrayType ConnectivityArrayType;
|
||||
typedef typename ConnectivityType::IndexOffsetArrayType IndexOffsetArrayType;
|
||||
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
typedef vtkm::Id SchedulingRangeType;
|
||||
|
||||
@ -185,7 +200,8 @@ public:
|
||||
VTKM_CONT_EXPORT
|
||||
void FillViaCopy(const std::vector<vtkm::UInt8> &cellTypes,
|
||||
const std::vector<vtkm::IdComponent> &numIndices,
|
||||
const std::vector<vtkm::Id> &connectivity)
|
||||
const std::vector<vtkm::Id> &connectivity,
|
||||
const std::vector<vtkm::Id> &offsets = std::vector<vtkm::Id>() )
|
||||
{
|
||||
|
||||
this->PointToCell.Shapes.Allocate( static_cast<vtkm::UInt8>(cellTypes.size()) );
|
||||
@ -204,7 +220,25 @@ public:
|
||||
this->PointToCell.Connectivity.GetPortalControl()));
|
||||
|
||||
this->PointToCell.ElementsValid = true;
|
||||
this->PointToCell.IndexOffsetsValid = false;
|
||||
|
||||
if(offsets.size() == cellTypes.size())
|
||||
{
|
||||
this->PointToCell.IndexOffsets.Allocate( static_cast<vtkm::Id>(offsets.size()) );
|
||||
std::copy(offsets.begin(), offsets.end(),
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(
|
||||
this->PointToCell.IndexOffsets.GetPortalControl()));
|
||||
this->PointToCell.IndexOffsetsValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->PointToCell.IndexOffsetsValid = false;
|
||||
if (offsets.size() != 0)
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"Explicit cell offsets array unexpected size. "
|
||||
"Use an empty array to automatically generate.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Second method to add cells -- all at once.
|
||||
@ -212,14 +246,31 @@ public:
|
||||
/// the way you can fill the memory from another system without copying
|
||||
void Fill(const vtkm::cont::ArrayHandle<vtkm::UInt8, ShapeStorageTag> &cellTypes,
|
||||
const vtkm::cont::ArrayHandle<vtkm::IdComponent, NumIndicesStorageTag> &numIndices,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id, ConnectivityStorageTag> &connectivity)
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id, ConnectivityStorageTag> &connectivity,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id, OffsetsStorageTag> &offsets
|
||||
= vtkm::cont::ArrayHandle<vtkm::Id, OffsetsStorageTag>() )
|
||||
{
|
||||
this->PointToCell.Shapes = cellTypes;
|
||||
this->PointToCell.NumIndices = numIndices;
|
||||
this->PointToCell.Connectivity = connectivity;
|
||||
|
||||
this->PointToCell.ElementsValid = true;
|
||||
this->PointToCell.IndexOffsetsValid = false;
|
||||
|
||||
if(offsets.GetNumberOfValues() == cellTypes.GetNumberOfValues())
|
||||
{
|
||||
this->PointToCell.IndexOffsets = offsets;
|
||||
this->PointToCell.IndexOffsetsValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->PointToCell.IndexOffsetsValid = false;
|
||||
if (offsets.GetNumberOfValues() != 0)
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"Explicit cell offsets array unexpected size. "
|
||||
"Use an empty array to automatically generate.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter, typename FromTopology, typename ToTopology>
|
||||
@ -229,14 +280,12 @@ public:
|
||||
VTKM_IS_TOPOLOGY_ELEMENT_TAG(FromTopology);
|
||||
VTKM_IS_TOPOLOGY_ELEMENT_TAG(ToTopology);
|
||||
|
||||
typedef typename
|
||||
ConnectivityChooser<FromTopology,ToTopology>::ConnectivityType
|
||||
ContObjectType;
|
||||
typedef ConnectivityChooser<FromTopology,ToTopology> ConnectivityTypes;
|
||||
|
||||
typedef typename ContObjectType::ShapeArrayType::template ExecutionTypes<DeviceAdapter>::PortalConst ShapePortalType;
|
||||
typedef typename ContObjectType::NumIndicesArrayType::template ExecutionTypes<DeviceAdapter>::PortalConst IndicePortalType;
|
||||
typedef typename ContObjectType::ConnectivityArrayType::template ExecutionTypes<DeviceAdapter>::PortalConst ConnectivityPortalType;
|
||||
typedef typename ContObjectType::IndexOffsetArrayType::template ExecutionTypes<DeviceAdapter>::PortalConst IndexOffsetPortalType;
|
||||
typedef typename ConnectivityTypes::ShapeArrayType::template ExecutionTypes<DeviceAdapter>::PortalConst ShapePortalType;
|
||||
typedef typename ConnectivityTypes::NumIndicesArrayType::template ExecutionTypes<DeviceAdapter>::PortalConst IndicePortalType;
|
||||
typedef typename ConnectivityTypes::ConnectivityArrayType::template ExecutionTypes<DeviceAdapter>::PortalConst ConnectivityPortalType;
|
||||
typedef typename ConnectivityTypes::IndexOffsetArrayType::template ExecutionTypes<DeviceAdapter>::PortalConst IndexOffsetPortalType;
|
||||
|
||||
typedef vtkm::exec::ConnectivityExplicit<ShapePortalType,
|
||||
IndicePortalType,
|
||||
@ -271,8 +320,9 @@ public:
|
||||
void BuildConnectivity(FromTopology, ToTopology) const
|
||||
{
|
||||
typedef CellSetExplicit<ShapeStorageTag,
|
||||
NumIndicesStorageTag,
|
||||
ConnectivityStorageTag> CSE;
|
||||
NumIndicesStorageTag,
|
||||
ConnectivityStorageTag,
|
||||
OffsetsStorageTag> CSE;
|
||||
CSE *self = const_cast<CSE*>(this);
|
||||
|
||||
self->CreateConnectivity(FromTopology(), ToTopology());
|
||||
@ -297,25 +347,34 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::multimap<vtkm::Id,vtkm::Id> cells_of_nodes;
|
||||
|
||||
vtkm::Id pairCount = 0;
|
||||
vtkm::Id maxNodeID = 0;
|
||||
vtkm::Id numCells = GetNumberOfCells();
|
||||
vtkm::Id numPoints = GetNumberOfPoints();
|
||||
for (vtkm::Id cell = 0, cindex = 0; cell < numCells; ++cell)
|
||||
{
|
||||
vtkm::Id npts = this->PointToCell.NumIndices.GetPortalControl().Get(cell);
|
||||
vtkm::Id npts = this->PointToCell.NumIndices.GetPortalConstControl().Get(cell);
|
||||
for (int pt=0; pt<npts; ++pt)
|
||||
{
|
||||
vtkm::Id index = this->PointToCell.Connectivity.GetPortalControl().Get(cindex++);
|
||||
vtkm::Id index = this->PointToCell.Connectivity.GetPortalConstControl().Get(cindex++);
|
||||
if (index > maxNodeID)
|
||||
{
|
||||
maxNodeID = index;
|
||||
}
|
||||
cells_of_nodes.insert(std::pair<vtkm::Id,vtkm::Id>(index,cell));
|
||||
pairCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if(GetNumberOfPoints() <= 0)
|
||||
{
|
||||
this->NumberOfPoints = maxNodeID + 1;
|
||||
}
|
||||
|
||||
vtkm::Id numPoints = GetNumberOfPoints();
|
||||
|
||||
this->CellToPoint.Shapes.Allocate(numPoints);
|
||||
this->CellToPoint.NumIndices.Allocate(numPoints);
|
||||
this->CellToPoint.Connectivity.Allocate(pairCount);
|
||||
@ -335,11 +394,13 @@ public:
|
||||
this->CellToPoint.NumIndices.GetPortalControl().Set(pointIndex,0);
|
||||
++pointIndex;
|
||||
}
|
||||
|
||||
vtkm::Id cellId = iter->second;
|
||||
this->CellToPoint.Connectivity.GetPortalControl().Set(connIndex,cellId);
|
||||
++connIndex;
|
||||
|
||||
const vtkm::IdComponent oldCellCount =
|
||||
this->CellToPoint.NumIndices.GetPortalControl().Get(pointIndex-1);
|
||||
this->CellToPoint.NumIndices.GetPortalConstControl().Get(pointIndex-1);
|
||||
|
||||
this->CellToPoint.NumIndices.GetPortalControl().Set(pointIndex-1,
|
||||
oldCellCount+1);
|
||||
@ -368,7 +429,7 @@ public:
|
||||
|
||||
template<typename FromTopology, typename ToTopology>
|
||||
VTKM_CONT_EXPORT
|
||||
const vtkm::cont::ArrayHandle<vtkm::UInt8, ShapeStorageTag> &
|
||||
const typename ConnectivityChooser<FromTopology,ToTopology>::ShapeArrayType &
|
||||
GetShapesArray(FromTopology,ToTopology) const
|
||||
{
|
||||
return this->GetConnectivity(FromTopology(), ToTopology()).Shapes;
|
||||
@ -376,7 +437,7 @@ public:
|
||||
|
||||
template<typename FromTopology, typename ToTopology>
|
||||
VTKM_CONT_EXPORT
|
||||
const vtkm::cont::ArrayHandle<vtkm::IdComponent, NumIndicesStorageTag> &
|
||||
const typename ConnectivityChooser<FromTopology,ToTopology>::NumIndicesArrayType &
|
||||
GetNumIndicesArray(FromTopology,ToTopology) const
|
||||
{
|
||||
return this->GetConnectivity(FromTopology(), ToTopology()).NumIndices;
|
||||
@ -384,7 +445,7 @@ public:
|
||||
|
||||
template<typename FromTopology, typename ToTopology>
|
||||
VTKM_CONT_EXPORT
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id, ConnectivityStorageTag> &
|
||||
const typename ConnectivityChooser<FromTopology,ToTopology>::ConnectivityArrayType &
|
||||
GetConnectivityArray(FromTopology,ToTopology) const
|
||||
{
|
||||
return this->GetConnectivity(FromTopology(), ToTopology()).Connectivity;
|
||||
@ -392,13 +453,13 @@ public:
|
||||
|
||||
template<typename FromTopology, typename ToTopology>
|
||||
VTKM_CONT_EXPORT
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id> &
|
||||
const typename ConnectivityChooser<FromTopology,ToTopology>::IndexOffsetArrayType &
|
||||
GetIndexOffsetArray(FromTopology,ToTopology) const
|
||||
{
|
||||
return this->GetConnectivity(FromTopology(), ToTopology()).IndexOffsets;
|
||||
}
|
||||
|
||||
private:
|
||||
protected:
|
||||
typename ConnectivityChooser<
|
||||
vtkm::TopologyElementTagPoint,vtkm::TopologyElementTagCell>::
|
||||
ConnectivityType PointToCell;
|
||||
@ -408,6 +469,7 @@ private:
|
||||
typename ConnectivityChooser<
|
||||
vtkm::TopologyElementTagCell,vtkm::TopologyElementTagPoint>::
|
||||
ConnectivityType CellToPoint;
|
||||
private:
|
||||
|
||||
// A set of overloaded methods to get the connectivity from a pair of
|
||||
// topology element types.
|
||||
@ -445,14 +507,14 @@ private:
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename Storage1, typename Storage2, typename Storage3>
|
||||
template<typename Storage1, typename Storage2, typename Storage3, typename Storage4>
|
||||
struct CellSetExplicitConnectivityChooser<
|
||||
vtkm::cont::CellSetExplicit<Storage1,Storage2,Storage3>,
|
||||
vtkm::cont::CellSetExplicit<Storage1,Storage2,Storage3,Storage4>,
|
||||
vtkm::TopologyElementTagPoint,
|
||||
vtkm::TopologyElementTagCell>
|
||||
{
|
||||
typedef vtkm::cont::internal::ConnectivityExplicitInternals<
|
||||
Storage1,Storage2,Storage3> ConnectivityType;
|
||||
Storage1,Storage2,Storage3,Storage4> ConnectivityType;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <vtkm/ListTag.h>
|
||||
|
||||
#include <vtkm/cont/CellSetExplicit.h>
|
||||
#include <vtkm/cont/CellSetSingleType.h>
|
||||
#include <vtkm/cont/CellSetStructured.h>
|
||||
|
||||
namespace vtkm {
|
||||
@ -58,7 +59,9 @@ struct CellSetListTagCommon
|
||||
: vtkm::ListTagBase<
|
||||
vtkm::cont::CellSetStructured<2>,
|
||||
vtkm::cont::CellSetStructured<3>,
|
||||
vtkm::cont::CellSetExplicit<> > { };
|
||||
vtkm::cont::CellSetExplicit<>,
|
||||
vtkm::cont::CellSetSingleType<>
|
||||
> { };
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
162
vtkm/cont/CellSetSingleType.h
Normal file
162
vtkm/cont/CellSetSingleType.h
Normal file
@ -0,0 +1,162 @@
|
||||
//============================================================================
|
||||
// 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_CellSetSingleType_h
|
||||
#define vtk_m_cont_CellSetSingleType_h
|
||||
|
||||
#include <vtkm/CellShape.h>
|
||||
#include <vtkm/CellTraits.h>
|
||||
#include <vtkm/cont/ArrayHandleConstant.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/CellSet.h>
|
||||
#include <vtkm/cont/CellSetExplicit.h>
|
||||
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
|
||||
//Only works with fixed sized cell sets
|
||||
|
||||
template< typename ConnectivityStorageTag = VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG >
|
||||
class CellSetSingleType :
|
||||
public vtkm::cont::CellSetExplicit<
|
||||
typename vtkm::cont::ArrayHandleConstant<vtkm::UInt8>::StorageTag, //ShapeStorageTag
|
||||
typename vtkm::cont::ArrayHandleConstant<vtkm::IdComponent>::StorageTag, //NumIndicesStorageTag
|
||||
ConnectivityStorageTag,
|
||||
typename vtkm::cont::ArrayHandleCounting<vtkm::Id>::StorageTag //IndexOffsetStorageTag
|
||||
>
|
||||
{
|
||||
typedef vtkm::cont::CellSetExplicit<
|
||||
typename vtkm::cont::ArrayHandleConstant<vtkm::UInt8>::StorageTag,
|
||||
typename vtkm::cont::ArrayHandleConstant<vtkm::IdComponent>::StorageTag,
|
||||
ConnectivityStorageTag,
|
||||
typename vtkm::cont::ArrayHandleCounting<vtkm::Id>::StorageTag > Superclass;
|
||||
|
||||
public:
|
||||
template<typename CellShapeTag>
|
||||
VTKM_CONT_EXPORT
|
||||
CellSetSingleType(CellShapeTag, const std::string &name = std::string())
|
||||
: Superclass(0, name, vtkm::CellTraits<CellShapeTag>::TOPOLOGICAL_DIMENSIONS),
|
||||
CellTypeAsId(CellShapeTag::Id)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
CellSetSingleType(const std::string &name = std::string())
|
||||
: Superclass(0, name, vtkm::CellTraits<CellShapeTagEmpty>::TOPOLOGICAL_DIMENSIONS),
|
||||
CellTypeAsId(CellShapeTagEmpty::Id)
|
||||
{
|
||||
}
|
||||
|
||||
//This is the way you can fill the memory from another system without copying
|
||||
VTKM_CONT_EXPORT
|
||||
void Fill(const vtkm::cont::ArrayHandle<vtkm::Id> &connectivity)
|
||||
{
|
||||
|
||||
vtkm::IdComponent numberOfPointsPerCell = this->DetermineNumberOfPoints();
|
||||
const vtkm::Id length = connectivity.GetNumberOfValues() / numberOfPointsPerCell;
|
||||
const vtkm::UInt8 shapeTypeValue = static_cast<vtkm::UInt8>(this->CellTypeAsId);
|
||||
this->PointToCell.Shapes =
|
||||
vtkm::cont::make_ArrayHandleConstant(shapeTypeValue, length);
|
||||
this->PointToCell.NumIndices =
|
||||
vtkm::cont::make_ArrayHandleConstant(numberOfPointsPerCell,
|
||||
length);
|
||||
this->PointToCell.IndexOffsets =
|
||||
vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0),
|
||||
static_cast<vtkm::Id>(numberOfPointsPerCell),
|
||||
length );
|
||||
this->PointToCell.Connectivity = connectivity;
|
||||
|
||||
this->PointToCell.ElementsValid = true;
|
||||
this->PointToCell.IndexOffsetsValid = true;
|
||||
}
|
||||
|
||||
/// 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<vtkm::Id> &connectivity)
|
||||
{
|
||||
vtkm::IdComponent numberOfPointsPerCell = this->DetermineNumberOfPoints();
|
||||
const vtkm::Id connectSize = static_cast<vtkm::Id>(connectivity.size());
|
||||
|
||||
const vtkm::Id length = connectSize / numberOfPointsPerCell;
|
||||
const vtkm::UInt8 shapeTypeValue = static_cast<vtkm::UInt8>(this->CellTypeAsId);
|
||||
this->PointToCell.Shapes =
|
||||
vtkm::cont::make_ArrayHandleConstant(shapeTypeValue, length);
|
||||
this->PointToCell.NumIndices =
|
||||
vtkm::cont::make_ArrayHandleConstant(numberOfPointsPerCell,
|
||||
length);
|
||||
this->PointToCell.IndexOffsets =
|
||||
vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0),
|
||||
static_cast<vtkm::Id>(numberOfPointsPerCell),
|
||||
length );
|
||||
|
||||
|
||||
this->PointToCell.Connectivity.Allocate( connectSize );
|
||||
std::copy(connectivity.begin(), connectivity.end(),
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(
|
||||
this->PointToCell.Connectivity.GetPortalControl()));
|
||||
|
||||
this->PointToCell.ElementsValid = true;
|
||||
this->PointToCell.IndexOffsetsValid = true;
|
||||
}
|
||||
|
||||
private:
|
||||
template< typename CellShapeTag>
|
||||
void DetermineNumberOfPoints(CellShapeTag,
|
||||
vtkm::CellTraitsTagSizeFixed,
|
||||
vtkm::IdComponent& numberOfPoints) const
|
||||
{
|
||||
numberOfPoints = vtkm::CellTraits<CellShapeTag>::NUM_POINTS;
|
||||
}
|
||||
|
||||
template< typename CellShapeTag>
|
||||
void DetermineNumberOfPoints(CellShapeTag,
|
||||
vtkm::CellTraitsTagSizeVariable,
|
||||
vtkm::IdComponent& numberOfPoints) const
|
||||
{ //variable length cells can't be used with this class
|
||||
numberOfPoints = -1;
|
||||
}
|
||||
|
||||
|
||||
vtkm::IdComponent DetermineNumberOfPoints() const
|
||||
{
|
||||
vtkm::IdComponent numberOfPointsPerCell = -1;
|
||||
switch (this->CellTypeAsId)
|
||||
{
|
||||
vtkmGenericCellShapeMacro( this->DetermineNumberOfPoints(CellShapeTag(),
|
||||
vtkm::CellTraits<CellShapeTag>::IsSizeFixed(),
|
||||
numberOfPointsPerCell) );
|
||||
default:
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"CellSetSingleType unable to determine the cell type");
|
||||
}
|
||||
return numberOfPointsPerCell;
|
||||
}
|
||||
|
||||
vtkm::Id CellTypeAsId;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtk_m_cont_CellSetSingleType_h
|
@ -29,6 +29,41 @@ namespace vtkm {
|
||||
namespace cont {
|
||||
namespace internal {
|
||||
|
||||
template<typename NumIndicesStorageTag,
|
||||
typename IndexOffsetStorageTag,
|
||||
typename DeviceAdapterTag>
|
||||
void buildIndexOffsets(vtkm::cont::ArrayHandle<vtkm::IdComponent, NumIndicesStorageTag> numIndices,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id, IndexOffsetStorageTag> offsets,
|
||||
DeviceAdapterTag)
|
||||
{
|
||||
typedef vtkm::cont::ArrayHandle<vtkm::IdComponent, NumIndicesStorageTag> NumIndicesArrayType;
|
||||
//We first need to make sure that NumIndices and IndexOffsetArrayType
|
||||
//have the same type so we can call scane exclusive
|
||||
typedef vtkm::cont::ArrayHandleCast< vtkm::Id,
|
||||
NumIndicesArrayType > CastedNumIndicesType;
|
||||
|
||||
// Although technically we are making changes to this object, the changes
|
||||
// are logically consistent with the previous state, so we consider it
|
||||
// valid under const.
|
||||
typedef vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapterTag> Algorithm;
|
||||
Algorithm::ScanExclusive( CastedNumIndicesType(numIndices), offsets);
|
||||
}
|
||||
|
||||
template<typename NumIndicesStorageTag,
|
||||
typename ImplicitPortalTag,
|
||||
typename DeviceAdapterTag>
|
||||
void buildIndexOffsets(vtkm::cont::ArrayHandle<vtkm::IdComponent, NumIndicesStorageTag>,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id,
|
||||
vtkm::cont::StorageTagImplicit< ImplicitPortalTag > >,
|
||||
DeviceAdapterTag)
|
||||
{
|
||||
//this is a no-op as the storage for the offsets is an implicit handle
|
||||
//and should already be built. This signature exists so that
|
||||
//the compiler doesn't try to generate un-used code that will
|
||||
//try and run Algorithm::ScanExclusive on an implicit array which will
|
||||
//cause a compile time failure.
|
||||
}
|
||||
|
||||
template<typename ShapeStorageTag = VTKM_DEFAULT_STORAGE_TAG,
|
||||
typename NumIndicesStorageTag = VTKM_DEFAULT_STORAGE_TAG,
|
||||
typename ConnectivityStorageTag = VTKM_DEFAULT_STORAGE_TAG,
|
||||
@ -43,10 +78,10 @@ struct ConnectivityExplicitInternals
|
||||
ShapeArrayType Shapes;
|
||||
NumIndicesArrayType NumIndices;
|
||||
ConnectivityArrayType Connectivity;
|
||||
IndexOffsetArrayType IndexOffsets;
|
||||
mutable IndexOffsetArrayType IndexOffsets;
|
||||
|
||||
bool ElementsValid;
|
||||
bool IndexOffsetsValid;
|
||||
mutable bool IndexOffsetsValid;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
ConnectivityExplicitInternals()
|
||||
@ -70,24 +105,13 @@ struct ConnectivityExplicitInternals
|
||||
void BuildIndexOffsets(Device) const
|
||||
{
|
||||
VTKM_ASSERT_CONT(this->ElementsValid);
|
||||
if (!this->IndexOffsetsValid)
|
||||
{
|
||||
//We first need to make sure that NumIndices and IndexOffsetArrayType
|
||||
//have the same type so we can call scane exclusive
|
||||
typedef vtkm::cont::ArrayHandleCast< vtkm::Id,
|
||||
NumIndicesArrayType > CastedNumIndicesType;
|
||||
|
||||
// Although technically we are making changes to this object, the changes
|
||||
// are logically consistent with the previous state, so we consider it
|
||||
// valid under const.
|
||||
vtkm::cont::DeviceAdapterAlgorithm<Device>::ScanExclusive(
|
||||
CastedNumIndicesType(this->NumIndices),
|
||||
const_cast<IndexOffsetArrayType&>(this->IndexOffsets));
|
||||
const_cast<bool&>(this->IndexOffsetsValid) = true;
|
||||
}
|
||||
else
|
||||
if(!this->IndexOffsetsValid)
|
||||
{
|
||||
// Index offsets already built. Nothing to do.
|
||||
buildIndexOffsets(this->NumIndices,
|
||||
this->IndexOffsets,
|
||||
Device());
|
||||
this->IndexOffsetsValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ set(unit_tests
|
||||
UnitTestComputeBoundsSerial.cxx
|
||||
UnitTestDataSetRegular.cxx
|
||||
UnitTestDataSetExplicit.cxx
|
||||
UnitTestDataSetSingleType.cxx
|
||||
UnitTestDeviceAdapterAlgorithmDependency.cxx
|
||||
UnitTestDeviceAdapterAlgorithmGeneral.cxx
|
||||
UnitTestDeviceAdapterSerial.cxx
|
||||
|
@ -250,19 +250,16 @@ MakeTestDataSet::Make3DExplicitDataSetCowNose(double *pBounds)
|
||||
dataSet.AddCoordinateSystem(
|
||||
vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts));
|
||||
|
||||
vtkm::cont::CellSetExplicit<> cellSet(nVerts, "cells", 2);
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connectivity;
|
||||
connectivity.Allocate(nPointIds);
|
||||
|
||||
cellSet.PrepareToAddCells(nPointIds/3, nPointIds);
|
||||
for (vtkm::Id i=0; i<nPointIds/3; i++)
|
||||
for(vtkm::Id i=0; i < nPointIds; ++i)
|
||||
{
|
||||
cellSet.AddCell(vtkm::CELL_SHAPE_TRIANGLE,
|
||||
3,
|
||||
make_Vec<vtkm::Id>(pointId[i*3],
|
||||
pointId[i*3+1],
|
||||
pointId[i*3+2]));
|
||||
connectivity.GetPortalControl().Set(i, pointId[i]);
|
||||
}
|
||||
cellSet.CompleteAddingCells();
|
||||
|
||||
vtkm::cont::CellSetSingleType< > cellSet(vtkm::CellShapeTagTriangle(),
|
||||
"cells");
|
||||
cellSet.Fill(connectivity);
|
||||
dataSet.AddCellSet(cellSet);
|
||||
|
||||
// copy bounds
|
||||
|
146
vtkm/cont/testing/UnitTestDataSetSingleType.cxx
Normal file
146
vtkm/cont/testing/UnitTestDataSetSingleType.cxx
Normal file
@ -0,0 +1,146 @@
|
||||
//============================================================================
|
||||
// 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 2014 Sandia Corporation.
|
||||
// Copyright 2014 UT-Battelle, LLC.
|
||||
// Copyright 2014 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/CellSetSingleType.h>
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename T, typename Storage>
|
||||
bool TestArrayHandle(const vtkm::cont::ArrayHandle<T, Storage> &ah, const T *expected,
|
||||
vtkm::Id size)
|
||||
{
|
||||
if (size != ah.GetNumberOfValues())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (vtkm::Id i = 0; i < size; ++i)
|
||||
{
|
||||
if (ah.GetPortalConstControl().Get(i) != expected[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline vtkm::cont::DataSet make_SingleTypeDataSet()
|
||||
{
|
||||
using vtkm::cont::Field;
|
||||
|
||||
vtkm::cont::DataSet dataSet;
|
||||
|
||||
const int nVerts = 5;
|
||||
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
|
||||
CoordType coordinates[nVerts] = {
|
||||
CoordType(0, 0, 0),
|
||||
CoordType(1, 0, 0),
|
||||
CoordType(1, 1, 0),
|
||||
CoordType(2, 1, 0),
|
||||
CoordType(2, 2, 0)
|
||||
};
|
||||
|
||||
//Set coordinate system
|
||||
dataSet.AddCoordinateSystem(
|
||||
vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts));
|
||||
|
||||
//Set point scalar
|
||||
vtkm::Float32 vars[nVerts] = {10.1f, 20.1f, 30.2f, 40.2f, 50.3f};
|
||||
dataSet.AddField(Field("pointvar", 1, vtkm::cont::Field::ASSOC_POINTS, vars, nVerts));
|
||||
|
||||
std::vector<vtkm::Id> conn;
|
||||
// First Cell
|
||||
conn.push_back(0);
|
||||
conn.push_back(1);
|
||||
conn.push_back(2);
|
||||
// Second Cell
|
||||
conn.push_back(1);
|
||||
conn.push_back(2);
|
||||
conn.push_back(3);
|
||||
// Third Cell
|
||||
conn.push_back(2);
|
||||
conn.push_back(3);
|
||||
conn.push_back(4);
|
||||
|
||||
vtkm::cont::CellSetSingleType<> cellSet(vtkm::CellShapeTagTriangle(),
|
||||
"cells");
|
||||
cellSet.FillViaCopy(conn);
|
||||
|
||||
dataSet.AddCellSet(cellSet);
|
||||
|
||||
return dataSet;
|
||||
}
|
||||
|
||||
void TestDataSet_Explicit()
|
||||
{
|
||||
|
||||
vtkm::cont::DataSet ds = make_SingleTypeDataSet();
|
||||
|
||||
ds.PrintSummary(std::cout);
|
||||
|
||||
//verify that we can get a CellSetSingleType from a dataset
|
||||
vtkm::cont::CellSetSingleType<> &cellset =
|
||||
ds.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
|
||||
|
||||
|
||||
//verify that we can compute the cell to point connectivity
|
||||
cellset.BuildConnectivity(vtkm::TopologyElementTagCell(),
|
||||
vtkm::TopologyElementTagPoint());
|
||||
|
||||
|
||||
//verify that the point to cell connectivity types are correct
|
||||
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapesPointToCell = cellset.GetShapesArray(
|
||||
vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell());
|
||||
vtkm::cont::ArrayHandleConstant<vtkm::IdComponent> numIndicesPointToCell = cellset.GetNumIndicesArray(
|
||||
vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell());
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connPointToCell = cellset.GetConnectivityArray(
|
||||
vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell());
|
||||
|
||||
VTKM_TEST_ASSERT( shapesPointToCell.GetNumberOfValues() == 3, "Wrong number of shapes");
|
||||
VTKM_TEST_ASSERT( numIndicesPointToCell.GetNumberOfValues() == 3, "Wrong number of indices");
|
||||
VTKM_TEST_ASSERT( connPointToCell.GetNumberOfValues() == 9, "Wrong connectivity length");
|
||||
|
||||
//verify that the cell to point connectivity types are correct
|
||||
//note the handle storage types differ compared to point to cell
|
||||
vtkm::cont::ArrayHandle<vtkm::UInt8> shapesCellToPoint = cellset.GetShapesArray(
|
||||
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
|
||||
vtkm::cont::ArrayHandle<vtkm::IdComponent> numIndicesCellToPoint = cellset.GetNumIndicesArray(
|
||||
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connCellToPoint = cellset.GetConnectivityArray(
|
||||
vtkm::TopologyElementTagCell(),vtkm::TopologyElementTagPoint());
|
||||
|
||||
VTKM_TEST_ASSERT( shapesCellToPoint.GetNumberOfValues() == 5, "Wrong number of shapes");
|
||||
VTKM_TEST_ASSERT( numIndicesCellToPoint.GetNumberOfValues() == 5, "Wrong number of indices");
|
||||
VTKM_TEST_ASSERT( connCellToPoint.GetNumberOfValues() == 9, "Wrong connectivity length");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int UnitTestDataSetSingleType(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestDataSet_Explicit);
|
||||
}
|
@ -69,6 +69,7 @@ struct Fetch<
|
||||
|
||||
typedef typename ConnectivityType::CellShapeTag ValueType;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Load(vtkm::Id index, const Invocation &invocation) const
|
||||
{
|
||||
|
@ -48,6 +48,7 @@ struct Fetch<
|
||||
|
||||
typedef typename ExecObjectType::ValueType ValueType;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Load(vtkm::Id index, const Invocation &invocation) const
|
||||
{
|
||||
|
@ -49,6 +49,7 @@ struct Fetch<
|
||||
|
||||
typedef typename ExecObjectType::ValueType ValueType;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Load(vtkm::Id index, const Invocation &invocation) const
|
||||
{
|
||||
@ -56,6 +57,7 @@ struct Fetch<
|
||||
Get(index);
|
||||
}
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
void Store(vtkm::Id index,
|
||||
const Invocation &invocation,
|
||||
|
@ -48,6 +48,7 @@ struct Fetch<
|
||||
|
||||
typedef typename ExecObjectType::ValueType ValueType;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Load(vtkm::Id, const Invocation &) const
|
||||
{
|
||||
@ -55,6 +56,7 @@ struct Fetch<
|
||||
return ValueType();
|
||||
}
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
void Store(vtkm::Id index,
|
||||
const Invocation &invocation,
|
||||
|
@ -67,6 +67,7 @@ struct FetchArrayTopologyMapInImplementation
|
||||
typedef vtkm::exec::internal::VecFromPortalPermute<
|
||||
IndexVecType,PortalType> ValueType;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
static ValueType Load(vtkm::Id index,
|
||||
const ConnectivityType &connectivity,
|
||||
@ -132,6 +133,7 @@ struct FetchArrayTopologyMapInImplementation<
|
||||
|
||||
typedef vtkm::VecRectilinearPointCoordinates<NumDimensions> ValueType;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
static ValueType Load(
|
||||
vtkm::Id index,
|
||||
@ -178,6 +180,7 @@ struct Fetch<
|
||||
|
||||
typedef typename Implementation::ValueType ValueType;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Load(vtkm::Id index, const Invocation &invocation) const
|
||||
{
|
||||
|
@ -62,6 +62,7 @@ struct Fetch<
|
||||
|
||||
typedef ExecObjectType ValueType;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Load(vtkm::Id vtkmNotUsed(index),
|
||||
const Invocation &invocation) const
|
||||
|
@ -48,6 +48,7 @@ struct Fetch<
|
||||
|
||||
typedef vtkm::Id ValueType;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Load(vtkm::Id index, const Invocation &invocation) const
|
||||
{
|
||||
|
@ -53,6 +53,7 @@ struct Fetch<FetchTag, vtkm::exec::arg::AspectTagFromCount, Invocation, 1>
|
||||
{
|
||||
typedef vtkm::IdComponent ValueType;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Load(vtkm::Id index, const Invocation &invocation) const
|
||||
{
|
||||
|
@ -68,6 +68,7 @@ struct Fetch<
|
||||
|
||||
typedef typename ConnectivityType::IndicesType ValueType;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
ValueType Load(vtkm::Id index, const Invocation &invocation) const
|
||||
{
|
||||
|
@ -49,6 +49,7 @@ public:
|
||||
this->Worklet.SetErrorMessageBuffer(buffer);
|
||||
}
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(vtkm::Id index) const
|
||||
{
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define vtk_m_testing_Testing_h
|
||||
|
||||
#include <vtkm/CellShape.h>
|
||||
#include <vtkm/Math.h>
|
||||
#include <vtkm/Pair.h>
|
||||
#include <vtkm/TypeListTag.h>
|
||||
#include <vtkm/Types.h>
|
||||
@ -346,7 +347,7 @@ bool test_equal(VectorType1 vector1,
|
||||
vtkm::Float64(Traits1::GetComponent(vector1, component));
|
||||
vtkm::Float64 value2 =
|
||||
vtkm::Float64(Traits2::GetComponent(vector2, component));
|
||||
if ((fabs(value1) <= 2*tolerance) && (fabs(value2) <= 2*tolerance))
|
||||
if ((vtkm::Abs(value1) <= 2*tolerance) && (vtkm::Abs(value2) <= 2*tolerance))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -354,13 +355,15 @@ bool test_equal(VectorType1 vector1,
|
||||
// The following condition is redundant since the previous check
|
||||
// guarantees neither value will be zero, but the MSVC compiler
|
||||
// sometimes complains about it.
|
||||
if (value2 != 0)
|
||||
if ((vtkm::Abs(value2) > tolerance) && (value2 != 0))
|
||||
{
|
||||
ratio = value1 / value2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ratio = 1.0;
|
||||
// If we are here, it means that value2 is close to 0 but value1 is not.
|
||||
// These cannot be within tolerance, so just return false.
|
||||
return false;
|
||||
}
|
||||
if ((ratio > vtkm::Float64(1.0) - tolerance)
|
||||
&& (ratio < vtkm::Float64(1.0) + tolerance))
|
||||
|
Loading…
Reference in New Issue
Block a user