Merge branch 'dynamic-cast' into 'master'

Improvements to Dynamic casts

Some improvements with how DynamicArrayHandle and
DynamicCellSet perform casting to concrete classes.

See merge request !317
This commit is contained in:
Kenneth Moreland 2016-01-18 18:37:18 -05:00
commit 6d9d7fac83
36 changed files with 369 additions and 260 deletions

@ -241,12 +241,12 @@ int main(int argc, char* argv[])
vtkm::cont::DataSet dataSet = MakeIsosurfaceTestDataSet(dims);
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataSet.GetField("nodevar").GetData().CastToArrayHandle(fieldArray);
dataSet.GetField("nodevar").GetData().CopyTo(fieldArray);
isosurfaceFilter = new vtkm::worklet::MarchingCubes<vtkm::Float32, DeviceAdapter>();
isosurfaceFilter->Run(0.5,
dataSet.GetCellSet().CastTo(CellSet()),
dataSet.GetCellSet().Cast<CellSet>(),
dataSet.GetCoordinateSystem(),
fieldArray,
verticesArray,

@ -145,10 +145,10 @@ void displayCall()
glTranslatef(-0.5f, -0.5f, -0.5f);
// Get the cell set, coordinate system and coordinate data
vtkm::cont::CellSetExplicit<> &cellSet =
outDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetExplicit<> >();
vtkm::cont::CellSetExplicit<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray =
outDataSet.GetCoordinateSystem(0).GetData();
outDataSet.GetCoordinateSystem(0).GetData();
vtkm::Id numberOfCells = cellSet.GetNumberOfCells();
vtkm::Id numberOfPoints = coordArray.GetNumberOfValues();

@ -200,8 +200,8 @@ void displayCall()
glTranslatef(-0.5f, -0.5f, -0.5f);
// Get cell set and the number of cells and vertices
vtkm::cont::CellSetSingleType<> cellSet =
outDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::CellSetSingleType<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::Id numberOfCells = cellSet.GetNumberOfCells();
// Get the coordinate system and coordinate data
@ -303,8 +303,8 @@ int main(int argc, char* argv[])
// Create the input explicit cell set
vtkm::cont::DataSet inDataSet = MakeTetrahedralizeExplicitDataSet();
vtkm::cont::CellSetExplicit<> &inCellSet =
inDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetExplicit<> >();
vtkm::cont::CellSetExplicit<> inCellSet;
inDataSet.GetCellSet(0).CopyTo(inCellSet);
numberOfInPoints = inCellSet.GetNumberOfPoints();

@ -168,7 +168,8 @@ void displayCall()
glTranslatef(-0.5f, -0.5f, -0.5f);
// Get the cell set, coordinate system and coordinate data
vtkm::cont::CellSetSingleType<> &cellSet = tetDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::CellSetSingleType<> cellSet;
tetDataSet.GetCellSet(0).CopyTo(cellSet);
const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray =
tetDataSet.GetCoordinateSystem(0).GetData();

@ -172,8 +172,8 @@ void displayCall()
glLineWidth(3.0f);
// Get cell set and the number of cells and vertices
vtkm::cont::CellSetSingleType<> cellSet =
outDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::CellSetSingleType<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::Id numberOfCells = cellSet.GetNumberOfCells();
// Get the coordinate system and coordinate data
@ -224,8 +224,8 @@ int main(int argc, char* argv[])
// Create the input uniform cell set
vtkm::cont::DataSet inDataSet = MakeTriangulateExplicitDataSet();
vtkm::cont::CellSetExplicit<> &inCellSet =
inDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetExplicit<> >();
vtkm::cont::CellSetExplicit<> inCellSet;
inDataSet.GetCellSet(0).CopyTo(inCellSet);
numberOfInPoints = inCellSet.GetNumberOfPoints();

@ -130,7 +130,8 @@ void displayCall()
glLineWidth(3.0f);
// Get the cellset, coordinate system and coordinate data
vtkm::cont::CellSetSingleType<> &cellSet = tetDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::CellSetSingleType<> cellSet;
tetDataSet.GetCellSet(0).CopyTo(cellSet);
const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray =
tetDataSet.GetCoordinateSystem(0).GetData();

@ -24,7 +24,7 @@
#include <vtkm/VecTraits.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ErrorControlBadValue.h>
#include <vtkm/cont/ErrorControlBadType.h>
#include <vtkm/cont/StorageListTag.h>
#include <vtkm/cont/internal/DynamicTransform.h>
@ -121,6 +121,39 @@ struct DynamicArrayHandleCopyHelper {
}
};
// A simple function to downcast an ArrayHandle encapsulated in a
// PolymorphicArrayHandleContainerBase to the given type of ArrayHandle. If the
// conversion cannot be done, NULL is returned.
template<typename Type, typename Storage>
VTKM_CONT_EXPORT
vtkm::cont::ArrayHandle<Type,Storage> *
DynamicArrayHandleTryCast(
vtkm::cont::detail::PolymorphicArrayHandleContainerBase *arrayContainer)
{
vtkm::cont::detail::PolymorphicArrayHandleContainer<Type,Storage> *
downcastContainer = dynamic_cast<
vtkm::cont::detail::PolymorphicArrayHandleContainer<Type,Storage> *>(
arrayContainer);
if (downcastContainer != NULL)
{
return &downcastContainer->Array;
}
else
{
return NULL;
}
}
template<typename Type, typename Storage>
VTKM_CONT_EXPORT
vtkm::cont::ArrayHandle<Type,Storage> *
DynamicArrayHandleTryCast(
boost::shared_ptr<vtkm::cont::detail::PolymorphicArrayHandleContainerBase>
arrayContainer)
{
return detail::DynamicArrayHandleTryCast<Type,Storage>(arrayContainer.get());
}
} // namespace detail
/// \brief Holds an array handle without having to specify template parameters.
@ -199,51 +232,85 @@ public:
///
template<typename Type, typename Storage>
VTKM_CONT_EXPORT
bool IsTypeAndStorage(Type = Type(), Storage = Storage()) const {
return (this->TryCastContainer<Type,Storage>() != NULL);
bool IsTypeAndStorage() const {
return (
detail::DynamicArrayHandleTryCast<Type,Storage>(this->ArrayContainer)
!= NULL);
}
/// Returns true if this array matches the array handle type passed in.
///
template<typename ArrayHandleType>
VTKM_CONT_EXPORT
bool IsArrayHandleType(const ArrayHandleType &vtkmNotUsed(array))
bool IsArrayHandleType()
{
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
typedef typename ArrayHandleType::ValueType ValueType;
typedef typename ArrayHandleType::StorageTag StorageTag;
return this->IsTypeAndStorage(ValueType(), StorageTag());
return this->IsTypeAndStorage<ValueType,StorageTag>();
}
/// Returns true if the array held in this object is the same (or equivalent)
/// type as the object given.
///
template<typename ArrayHandleType>
VTKM_CONT_EXPORT
bool IsSameType(const ArrayHandleType &)
{
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
return this->IsArrayHandleType<ArrayHandleType>();
}
/// Returns this array cast to an ArrayHandle object of the given type and
/// storage. Throws \c ErrorControlBadValue if the cast does not work. Use
/// storage. Throws \c ErrorControlBadType if the cast does not work. Use
/// \c IsTypeAndStorage to check if the cast can happen.
///
///
template<typename Type, typename Storage>
VTKM_CONT_EXPORT
vtkm::cont::ArrayHandle<Type, Storage>
CastToArrayHandle(Type = Type(), Storage = Storage()) const {
vtkm::cont::detail::PolymorphicArrayHandleContainer<Type,Storage> *container
= this->TryCastContainer<Type,Storage>();
if (container == NULL)
CastToTypeStorage() const {
vtkm::cont::ArrayHandle<Type, Storage> *downcastArray =
detail::DynamicArrayHandleTryCast<Type,Storage>(this->ArrayContainer);
if (downcastArray == NULL)
{
throw vtkm::cont::ErrorControlBadValue("Bad cast of dynamic array.");
throw vtkm::cont::ErrorControlBadType("Bad cast of dynamic array.");
}
return container->Array;
// Technically, this method returns a copy of the \c ArrayHandle. But
// because \c ArrayHandle acts like a shared pointer, it is valid to
// do the copy.
return *downcastArray;
}
/// Returns this array cast to the given \c ArrayHandle type. Throws \c
/// ErrorControlBadType if the cast does not work. Use \c IsArrayHandleType
/// to check if the cast can happen.
///
template<typename ArrayHandleType>
VTKM_CONT_EXPORT
ArrayHandleType Cast() const {
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
typedef typename ArrayHandleType::ValueType ValueType;
typedef typename ArrayHandleType::StorageTag StorageTag;
// Technically, this method returns a copy of the \c ArrayHandle. But
// because \c ArrayHandle acts like a shared pointer, it is valid to
// do the copy.
return this->CastToTypeStorage<ValueType,StorageTag>();
}
/// Given a refernce to an ArrayHandle object, casts this array to the
/// ArrayHandle's type and sets the given ArrayHandle to this array. Throws
/// \c ErrorControlBadValue if the cast does not work. Use \c
/// IsTypeAndStorage to check if the cast can happen.
/// \c ErrorControlBadType if the cast does not work. Use \c
/// ArrayHandleType to check if the cast can happen.
///
/// Note that this is a shallow copy. The data are not copied and a change
/// in the data in one array will be reflected in the other.
///
template<typename ArrayHandleType>
VTKM_CONT_EXPORT
void CastToArrayHandle(ArrayHandleType &array) const {
void CopyTo(ArrayHandleType &array) const {
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
typedef typename ArrayHandleType::ValueType ValueType;
typedef typename ArrayHandleType::StorageTag StorageTag;
array = this->CastToArrayHandle(ValueType(), StorageTag());
array = this->Cast<ArrayHandleType>();
}
/// Changes the types to try casting to when resolving this dynamic array,
@ -348,16 +415,6 @@ private:
ArrayContainer;
friend struct detail::DynamicArrayHandleCopyHelper;
template<typename Type, typename Storage>
VTKM_CONT_EXPORT
vtkm::cont::detail::PolymorphicArrayHandleContainer<Type,Storage> *
TryCastContainer() const {
return
dynamic_cast<
vtkm::cont::detail::PolymorphicArrayHandleContainer<Type,Storage> *>(
this->ArrayContainer.get());
}
};
typedef vtkm::cont::DynamicArrayHandleBase<
@ -389,9 +446,9 @@ private:
void DoCast(Storage, boost::mpl::bool_<true>)
{
if (!this->FoundCast &&
this->Array.IsTypeAndStorage(Type(), Storage()))
this->Array.template IsTypeAndStorage<Type,Storage>())
{
this->Function(this->Array.CastToArrayHandle(Type(), Storage()));
this->Function(this->Array.template CastToTypeStorage<Type,Storage>());
this->FoundCast = true;
}
}

@ -56,6 +56,39 @@ struct DynamicCellSetCopyHelper {
}
};
// A simple function to downcast a CellSet encapsulated in a
// SimplePolymorphicContainerBase to the given subclass of CellSet. If the
// conversion cannot be done, NULL is returned.
template<typename CellSetType>
VTKM_CONT_EXPORT
CellSetType *
DynamicCellSetTryCast(
vtkm::cont::internal::SimplePolymorphicContainerBase *cellSetContainer)
{
vtkm::cont::internal::SimplePolymorphicContainer<CellSetType> *
downcastContainer = dynamic_cast<
vtkm::cont::internal::SimplePolymorphicContainer<CellSetType> *>(
cellSetContainer);
if (downcastContainer != NULL)
{
return &downcastContainer->Item;
}
else
{
return NULL;
}
}
template<typename CellSetType>
VTKM_CONT_EXPORT
CellSetType *
DynamicCellSetTryCast(
boost::shared_ptr<vtkm::cont::internal::SimplePolymorphicContainerBase>
cellSetContainer)
{
return detail::DynamicCellSetTryCast<CellSetType>(cellSetContainer.get());
}
} // namespace detail
/// \brief Holds a cell set without having to specify concrete type.
@ -132,8 +165,18 @@ public:
///
template<typename CellSetType>
VTKM_CONT_EXPORT
bool IsType(CellSetType = CellSetType()) const {
return (this->TryCast<CellSetType>() != NULL);
bool IsType() const {
return (detail::DynamicCellSetTryCast<CellSetType>(this->CellSetContainer)
!= NULL);
}
/// Returns true if this cell set is the same (or equivalent) type as the
/// object provided.
///
template<typename CellSetType>
VTKM_CONT_EXPORT
bool IsSameType(const CellSetType &) const {
return this->IsType<CellSetType>();
}
/// Returns the contained cell set as the abstract \c CellSet type.
@ -144,31 +187,34 @@ public:
this->CellSetContainer->GetVoidPointer());
}
/// Returns this cell set cast to a concrete \c CellSet object of the given
/// type. Throws ErrorControlBadValue if the cast does not work. Use
/// IsTypeAndStorage to check if the cast can happen.
/// Returns this cell set cast to the given \c CellSet type. Throws \c
/// ErrorControlBadType if the cast does not work. Use \c IsType to check if
/// the cast can happen.
///
template<typename CellSetType>
VTKM_CONT_EXPORT
const CellSetType &CastTo(CellSetType = CellSetType()) const {
const vtkm::cont::internal::SimplePolymorphicContainer<CellSetType> *
container = this->TryCast<CellSetType>();
if (container == NULL)
CellSetType &Cast() const {
CellSetType *cellSetPointer =
detail::DynamicCellSetTryCast<CellSetType>(this->CellSetContainer);
if (cellSetPointer == NULL)
{
throw vtkm::cont::ErrorControlBadValue("Bad cast of dynamic cell set.");
throw vtkm::cont::ErrorControlBadType("Bad cast of dynamic cell set.");
}
return container->Item;
return *cellSetPointer;
}
/// Given a reference to a concrete \c CellSet object, attempt to downcast
/// the contain cell set to the provided type and copy into the given \c
/// CellSet object. Throws \c ErrorControlBadType if the cast does not work.
/// Use \c IsType to check if the cast can happen.
///
/// Note that this is a shallow copy. Any data in associated arrays are not
/// copied.
///
template<typename CellSetType>
VTKM_CONT_EXPORT
CellSetType &CastTo(CellSetType = CellSetType()) {
vtkm::cont::internal::SimplePolymorphicContainer<CellSetType> *
container = this->TryCast<CellSetType>();
if (container == NULL)
{
throw vtkm::cont::ErrorControlBadValue("Bad cast of dynamic cell set.");
}
return container->Item;
void CopyTo(CellSetType &cellSet) const {
cellSet = this->Cast<CellSetType>();
}
/// Changes the cell set types to try casting to when resolving this dynamic
@ -217,16 +263,6 @@ private:
CellSetContainer;
friend struct detail::DynamicCellSetCopyHelper;
template<typename CellSetType>
VTKM_CONT_EXPORT
vtkm::cont::internal::SimplePolymorphicContainer<CellSetType> *
TryCast() const {
return
dynamic_cast<
vtkm::cont::internal::SimplePolymorphicContainer<CellSetType> *>(
this->CellSetContainer.get());
}
};
namespace detail {
@ -234,22 +270,23 @@ namespace detail {
template<typename Functor>
struct DynamicCellSetTryCellSet
{
const vtkm::cont::CellSet *AbstractCellSet;
vtkm::cont::internal::SimplePolymorphicContainerBase *CellSetContainer;
const Functor &Function;
bool FoundCast;
VTKM_CONT_EXPORT
DynamicCellSetTryCellSet(const vtkm::cont::CellSet &cellSet,
const Functor &f)
: AbstractCellSet(&cellSet), Function(f), FoundCast(false) { }
DynamicCellSetTryCellSet(
vtkm::cont::internal::SimplePolymorphicContainerBase *cellSetContainer,
const Functor &f)
: CellSetContainer(cellSetContainer), Function(f), FoundCast(false) { }
template<typename CellSetType>
VTKM_CONT_EXPORT
void operator()(CellSetType) {
if (!this->FoundCast)
{
const CellSetType *cellSet =
dynamic_cast<const CellSetType *>(this->AbstractCellSet);
CellSetType *cellSet =
detail::DynamicCellSetTryCast<CellSetType>(this->CellSetContainer);
if (cellSet != NULL)
{
this->Function(*cellSet);
@ -259,22 +296,6 @@ struct DynamicCellSetTryCellSet
}
};
template<typename Functor, typename CellSetTypeList>
VTKM_CONT_EXPORT
void CastAndCallCellSet(
const Functor &f,
const vtkm::cont::DynamicCellSetBase<CellSetTypeList> &cellSet)
{
typedef detail::DynamicCellSetTryCellSet<Functor> TryCellSetType;
TryCellSetType tryCellSet = TryCellSetType(cellSet.GetCellSet(), f);
vtkm::ListForEach(tryCellSet, CellSetTypeList());
if (!tryCellSet.FoundCast)
{
throw vtkm::cont::ErrorControlBadValue(
"Could not find appropriate cast for cell set.");
}
}
} // namespace detail
template<typename CellSetList>
@ -282,7 +303,14 @@ template<typename Functor>
VTKM_CONT_EXPORT
void DynamicCellSetBase<CellSetList>::CastAndCall(const Functor &f) const
{
detail::CastAndCallCellSet(f, *this);
typedef detail::DynamicCellSetTryCellSet<Functor> TryCellSetType;
TryCellSetType tryCellSet = TryCellSetType(this->CellSetContainer.get(), f);
vtkm::ListForEach(tryCellSet, CellSetList());
if (!tryCellSet.FoundCast)
{
throw vtkm::cont::ErrorControlBadValue(
"Could not find appropriate cast for cell set.");
}
}
typedef DynamicCellSetBase< VTKM_DEFAULT_CELL_SET_LIST_TAG > DynamicCellSet;

@ -63,7 +63,7 @@ private:
{
vtkm::cont::testing::MakeTestDataSet tds;
vtkm::cont::DataSet ds = tds.Make3DExplicitDataSet0();
VTKM_TEST_ASSERT(ds.GetNumberOfCellSets() == 1,
"Incorrect number of cell sets");
@ -100,8 +100,9 @@ private:
"Incorrect number of coordinate systems");
// test cell-to-point connectivity
vtkm::cont::CellSetExplicit<> &cellset =
ds.GetCellSet(0).CastTo<vtkm::cont::CellSetExplicit<> >();
vtkm::cont::CellSetExplicit<> cellset;
ds.GetCellSet(0).CopyTo(cellset);
cellset.BuildConnectivity(DeviceAdapterTag(),
vtkm::TopologyElementTagCell(),
vtkm::TopologyElementTagPoint());

@ -106,8 +106,8 @@ private:
vtkm::cont::DataSet dataSet = make_SingleTypeDataSet();
//verify that we can get a CellSetSingleType from a dataset
vtkm::cont::CellSetSingleType<> &cellset =
dataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::CellSetSingleType<> cellset;
dataSet.GetCellSet(0).CopyTo(cellset);
//verify that we can compute the cell to point connectivity

@ -71,15 +71,15 @@ void ValidateDataSet(const vtkm::cont::DataSet &ds,
"Bounds of coordinates do not match");
if (dim == 2)
{
typedef vtkm::cont::CellSetStructured<2> CellSetType;
CellSetType cellSet = ds.GetCellSet(0).CastTo<CellSetType>();
vtkm::cont::CellSetStructured<2> cellSet;
ds.GetCellSet(0).CopyTo(cellSet);
vtkm::IdComponent shape = cellSet.GetCellShape();
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_QUAD, "Wrong element type");
}
else if (dim == 3)
{
typedef vtkm::cont::CellSetStructured<3> CellSetType;
CellSetType cellSet = ds.GetCellSet(0).CastTo<CellSetType>();
vtkm::cont::CellSetStructured<3> cellSet;
ds.GetCellSet(0).CopyTo(cellSet);
vtkm::IdComponent shape = cellSet.GetCellShape();
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_HEXAHEDRON, "Wrong element type");
}
@ -102,6 +102,7 @@ void FillArray(std::vector<T> &arr,
case 2: xi = static_cast<T>(i*2); break;
case 3: xi = static_cast<T>(i*0.1f); break;
case 4: xi = static_cast<T>(i*i); break;
default: VTKM_TEST_FAIL("Bad internal test state: invalid fill method.");
}
arr[i] = xi;
}

@ -73,15 +73,15 @@ void ValidateDataSet(const vtkm::cont::DataSet &ds,
if (dim == 2)
{
typedef vtkm::cont::CellSetStructured<2> CellSetType;
CellSetType cellSet = ds.GetCellSet(0).CastTo<CellSetType>();
vtkm::cont::CellSetStructured<2> cellSet;
ds.GetCellSet(0).CopyTo(cellSet);
vtkm::IdComponent shape = cellSet.GetCellShape();
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_QUAD, "Wrong element type");
}
else if (dim == 3)
{
typedef vtkm::cont::CellSetStructured<3> CellSetType;
CellSetType cellSet = ds.GetCellSet(0).CastTo<CellSetType>();
vtkm::cont::CellSetStructured<3> cellSet;
ds.GetCellSet(0).CopyTo(cellSet);
vtkm::IdComponent shape = cellSet.GetCellShape();
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_HEXAHEDRON, "Wrong element type");
}

@ -104,8 +104,8 @@ void TestDataSet_Explicit()
vtkm::cont::make_ArrayHandle(validIds);
//get the cellset single type from the dataset
typedef vtkm::cont::CellSetSingleType<> CellSetType;
CellSetType cellSet = dataSet.GetCellSet(0).CastTo<CellSetType>();
vtkm::cont::CellSetSingleType<> cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
//verify that we can create a subset of a singlset
typedef vtkm::cont::CellSetPermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
@ -155,8 +155,8 @@ void TestDataSet_Structured2D()
vtkm::cont::make_ArrayHandle(validIds);
typedef vtkm::cont::CellSetStructured<2> CellSetType;
CellSetType cellSet = dataSet.GetCellSet(0).CastTo<CellSetType>();
vtkm::cont::CellSetStructured<2> cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
//verify that we can create a subset of a 2d RegularDataSet
vtkm::cont::CellSetPermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
@ -202,8 +202,8 @@ void TestDataSet_Structured3D()
vtkm::cont::ArrayHandle<vtkm::Id> validCellIds =
vtkm::cont::make_ArrayHandle(validIds);
typedef vtkm::cont::CellSetStructured<3> CellSetType;
CellSetType cellSet = dataSet.GetCellSet(0).CastTo<CellSetType>();
vtkm::cont::CellSetStructured<3> cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
//verify that we can create a subset of a 2d RegularDataSet
vtkm::cont::CellSetPermutation<vtkm::cont::ArrayHandle<vtkm::Id>,

@ -50,8 +50,8 @@ TwoDimRectilinearTest()
vtkm::cont::DataSet dataSet = testDataSet.Make2DRectilinearDataSet0();
typedef vtkm::cont::CellSetStructured<2> CellSetType;
CellSetType cellSet = dataSet.GetCellSet(0).CastTo<CellSetType>();
vtkm::cont::CellSetStructured<2> cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
VTKM_TEST_ASSERT(dataSet.GetNumberOfCellSets() == 1,
"Incorrect number of cell sets");
@ -176,8 +176,8 @@ ThreeDimRectilinearTest()
}
*/
typedef vtkm::cont::CellSetStructured<3> CellSetType;
CellSetType cellSet = dataSet.GetCellSet(0).CastTo<CellSetType>();
vtkm::cont::CellSetStructured<3> cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
VTKM_TEST_ASSERT(dataSet.GetNumberOfCellSets() == 1,
"Incorrect number of cell sets");

@ -49,8 +49,10 @@ TwoDimRegularTest()
vtkm::cont::DataSet dataSet = testDataSet.Make2DRegularDataSet0();
typedef vtkm::cont::CellSetStructured<2> CellSetType;
CellSetType cellSet = dataSet.GetCellSet(0).CastTo<CellSetType>();
dataSet.PrintSummary(std::cout);
vtkm::cont::CellSetStructured<2> cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
VTKM_TEST_ASSERT(dataSet.GetNumberOfCellSets() == 1,
"Incorrect number of cell sets");
@ -157,8 +159,10 @@ ThreeDimRegularTest()
vtkm::cont::DataSet dataSet = testDataSet.Make3DRegularDataSet0();
typedef vtkm::cont::CellSetStructured<3> CellSetType;
CellSetType cellSet = dataSet.GetCellSet(0).CastTo<CellSetType>();
dataSet.PrintSummary(std::cout);
vtkm::cont::CellSetStructured<3> cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
VTKM_TEST_ASSERT(dataSet.GetNumberOfCellSets() == 1,
"Incorrect number of cell sets");

@ -179,18 +179,18 @@ void CheckCastToArrayHandle(const ArrayHandleType &array)
vtkm::cont::DynamicArrayHandle dynamicArray = array;
VTKM_TEST_ASSERT(
!dynamicArray.IsArrayHandleType(vtkm::cont::ArrayHandle<std::string>()),
!dynamicArray.IsArrayHandleType<vtkm::cont::ArrayHandle<std::string> >(),
"Dynamic array reporting is wrong type.");
ArrayHandleType castArray1;
dynamicArray.CastToArrayHandle(castArray1);
VTKM_TEST_ASSERT(dynamicArray.IsArrayHandleType(castArray1),
dynamicArray.CopyTo(castArray1);
VTKM_TEST_ASSERT(dynamicArray.IsSameType(castArray1),
"Did not query handle correctly.");
VTKM_TEST_ASSERT(array == castArray1, "Did not get back same array.");
ArrayHandleType castArray2 =
dynamicArray.CastToArrayHandle(typename ArrayHandleType::ValueType(),
typename ArrayHandleType::StorageTag());
dynamicArray.CastToTypeStorage<typename ArrayHandleType::ValueType,
typename ArrayHandleType::StorageTag>();
VTKM_TEST_ASSERT(array == castArray2, "Did not get back same array.");
}
@ -205,8 +205,8 @@ void TryNewInstance(T, DynamicArrayType originalArray)
std::cout << "Get a static instance of the new array (which checks the type)."
<< std::endl;
vtkm::cont::ArrayHandle<T> staticArray =
newArray.CastToArrayHandle(T(), VTKM_DEFAULT_STORAGE_TAG());
vtkm::cont::ArrayHandle<T> staticArray;
newArray.CopyTo(staticArray);
std::cout << "Fill the new array with invalid values and make sure the original" << std::endl
<< "is uneffected." << std::endl;

@ -54,12 +54,14 @@ void CheckDynamicCellSet(
const CellSetType &cellSet,
vtkm::cont::DynamicCellSetBase<CellSetList> dynamicCellSet)
{
VTKM_TEST_ASSERT(dynamicCellSet.IsType(cellSet),
VTKM_TEST_ASSERT(dynamicCellSet.template IsType<CellSetType>(),
"DynamicCellSet reports wrong type.");
VTKM_TEST_ASSERT(!dynamicCellSet.IsType(vtkm::Id()),
VTKM_TEST_ASSERT(dynamicCellSet.IsSameType(cellSet),
"DynamicCellSet reports wrong type.");
VTKM_TEST_ASSERT(!dynamicCellSet.template IsType<vtkm::Id>(),
"DynamicCellSet reports wrong type.");
dynamicCellSet.CastTo(cellSet);
dynamicCellSet.template Cast<CellSetType>();
CheckCalled = false;
dynamicCellSet.CastAndCall(CheckFunctor<CellSetType>());
@ -75,11 +77,11 @@ void TryNewInstance(
vtkm::cont::DynamicCellSetBase<CellSetList> newCellSet =
originalCellSet.NewInstance();
VTKM_TEST_ASSERT(newCellSet.IsType(CellSetType()),
VTKM_TEST_ASSERT(newCellSet.template IsType<CellSetType>(),
"New cell set wrong type.");
VTKM_TEST_ASSERT(&originalCellSet.CastTo(CellSetType())
!= &newCellSet.CastTo(CellSetType()),
VTKM_TEST_ASSERT(&originalCellSet.GetCellSet()
!= &newCellSet.GetCellSet(),
"NewInstance did not make a copy.");
}

@ -279,7 +279,7 @@ void TestReadingPolyData(Format format)
"Incorrect number of points");
VTKM_TEST_ASSERT(ds.GetCellSet().GetCellSet().GetNumberOfCells() == 6,
"Incorrect number of cells");
VTKM_TEST_ASSERT(ds.GetCellSet().IsType(vtkm::cont::CellSetSingleType<>()),
VTKM_TEST_ASSERT(ds.GetCellSet().IsType<vtkm::cont::CellSetSingleType<> >(),
"Incorrect cellset type");
}
@ -297,7 +297,7 @@ void TestReadingStructuredPoints(Format format)
"Incorrect number of points");
VTKM_TEST_ASSERT(ds.GetCellSet().GetCellSet().GetNumberOfCells() == 30,
"Incorrect number of cells");
VTKM_TEST_ASSERT(ds.GetCellSet().IsType(vtkm::cont::CellSetStructured<3>()),
VTKM_TEST_ASSERT(ds.GetCellSet().IsType<vtkm::cont::CellSetStructured<3> >(),
"Incorrect cellset type");
}
@ -315,7 +315,7 @@ void TestReadingUnstructuredGrid(Format format)
"Incorrect number of points");
VTKM_TEST_ASSERT(ds.GetCellSet().GetCellSet().GetNumberOfCells() == 15,
"Incorrect number of cells");
VTKM_TEST_ASSERT(ds.GetCellSet().IsType(vtkm::cont::CellSetExplicit<>()),
VTKM_TEST_ASSERT(ds.GetCellSet().IsType<vtkm::cont::CellSetExplicit<> >(),
"Incorrect cellset type");
}

@ -369,24 +369,28 @@ public:
vtkm::cont::DynamicCellSet cs = ds.GetCellSet(csindex);
if (cs.IsType<vtkm::cont::CellSetExplicit<> >())
{
WriteDataSetAsUnstructured(out, ds,
cs.CastTo<vtkm::cont::CellSetExplicit<> >());
WriteDataSetAsUnstructured(out,
ds,
cs.Cast<vtkm::cont::CellSetExplicit<> >());
}
else if (cs.IsType<vtkm::cont::CellSetStructured<2> >())
{
WriteDataSetAsStructured(out, ds,
cs.CastTo<vtkm::cont::CellSetStructured<2> >());
WriteDataSetAsStructured(out,
ds,
cs.Cast<vtkm::cont::CellSetStructured<2> >());
}
else if (cs.IsType<vtkm::cont::CellSetStructured<3> >())
{
WriteDataSetAsStructured(out, ds,
cs.CastTo<vtkm::cont::CellSetStructured<3> >());
WriteDataSetAsStructured(out,
ds,
cs.Cast<vtkm::cont::CellSetStructured<3> >());
}
else if (cs.IsType<vtkm::cont::CellSetSingleType<> >())
{
// these function just like explicit cell sets
WriteDataSetAsUnstructured(out, ds,
cs.CastTo<vtkm::cont::CellSetSingleType<> >());
WriteDataSetAsUnstructured(out,
ds,
cs.Cast<vtkm::cont::CellSetSingleType<> >());
}
else
{

@ -345,13 +345,12 @@ public:
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithm;
// Get information from input dataset
vtkm::cont::CellSetStructured<3> &inCellSet =
InDataSet.GetCellSet(0).template CastTo<vtkm::cont::CellSetStructured<3> >();
vtkm::cont::CellSetStructured<3> inCellSet;
InDataSet.GetCellSet(0).CopyTo(inCellSet);
vtkm::Id3 vdims= inCellSet.GetSchedulingRange(vtkm::TopologyElementTagPoint());
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3> > fieldArray =
InDataSet.GetField("vecData").GetData().
CastToArrayHandle<vtkm::Vec<FieldType, 3>, VTKM_DEFAULT_STORAGE_TAG>();
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3> > fieldArray;
InDataSet.GetField("vecData").GetData().CopyTo(fieldArray);
// Generate random seeds for starting streamlines
std::vector<vtkm::Vec<FieldType, 3> > seeds;

@ -212,10 +212,10 @@ public:
void Run()
{
// Cell sets belonging to input and output datasets
vtkm::cont::CellSetExplicit<> &inCellSet =
InDataSet.GetCellSet(0).template CastTo<vtkm::cont::CellSetExplicit<> >();
vtkm::cont::CellSetExplicit<> inCellSet;
InDataSet.GetCellSet(0).CopyTo(inCellSet);
vtkm::cont::CellSetSingleType<> &cellSet =
OutDataSet.GetCellSet(0).template CastTo<vtkm::cont::CellSetSingleType<> >();
this->OutDataSet.GetCellSet(0).template Cast<vtkm::cont::CellSetSingleType<> >();
// Input dataset vertices and cell counts
vtkm::Id dimensionality = inCellSet.GetDimensionality();

@ -173,23 +173,23 @@ public:
void Run()
{
// Get the cell set from the output data set
vtkm::cont::CellSetSingleType<> & cellSet =
OutDataSet.GetCellSet(0).template CastTo<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::CellSetSingleType<> &cellSet =
this->OutDataSet.GetCellSet(0).template Cast<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::ArrayHandle<vtkm::Id> connectivity;
if (cellSet.GetDimensionality() == 2)
{
vtkm::cont::CellSetStructured<2> &inCellSet =
InDataSet.GetCellSet(0).template CastTo<vtkm::cont::CellSetStructured<2> >();
vtkm::cont::CellSetStructured<2> inCellSet;
InDataSet.GetCellSet(0).CopyTo(inCellSet);
vtkm::worklet::DispatcherMapTopology<TriangulateCell,DeviceAdapter> dispatcher;
dispatcher.Invoke(inCellSet,
vtkm::cont::make_ArrayHandleGroupVec<3>(connectivity));
}
else if (cellSet.GetDimensionality() == 3)
{
vtkm::cont::CellSetStructured<3> &inCellSet =
InDataSet.GetCellSet(0).template CastTo<vtkm::cont::CellSetStructured<3> >();
vtkm::cont::CellSetStructured<3> inCellSet;
InDataSet.GetCellSet(0).CopyTo(inCellSet);
vtkm::worklet::DispatcherMapTopology<TetrahedralizeCell,DeviceAdapter> dispatcher;
dispatcher.Invoke(inCellSet,
vtkm::cont::make_ArrayHandleGroupVec<4>(connectivity));

@ -48,8 +48,8 @@ void TestCellAverageRegular3D()
dataSet.GetCellSet(),
result.GetData());
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle =
result.GetData().CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG());
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle;
result.GetData().CopyTo(resultArrayHandle);
vtkm::Float32 expected[4] = { 60.1875f, 70.2125f, 120.3375f, 130.3625f };
for (int i = 0; i < 4; ++i)
@ -77,8 +77,8 @@ void TestCellAverageRegular2D()
dataSet.GetCellSet(),
result.GetData());
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle =
result.GetData().CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG());
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle;
result.GetData().CopyTo(resultArrayHandle);
vtkm::Float32 expected[2] = { 30.1f, 40.1f };
for (int i = 0; i < 2; ++i)
@ -106,8 +106,8 @@ void TestCellAverageExplicit()
dataSet.GetCellSet(),
result.GetData());
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle =
result.GetData().CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG());
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle;
result.GetData().CopyTo(resultArrayHandle);
vtkm::Float32 expected[2] = { 20.1333f, 35.2f };
for (int i = 0; i < 2; ++i)

@ -148,13 +148,17 @@ void TestClippingExplicit()
"Got incorrect conectivity");
VTKM_TEST_ASSERT(
TestArrayHandle(coords.CastToArrayHandle(Coord3D(),
VTKM_DEFAULT_STORAGE_TAG()), expectedCoords, fieldSize),
"Got incorrect coords");
TestArrayHandle(
coords.CastToTypeStorage<Coord3D,VTKM_DEFAULT_STORAGE_TAG>(),
expectedCoords,
fieldSize),
"Got incorrect coordinates");
VTKM_TEST_ASSERT(
TestArrayHandle(scalars.CastToArrayHandle(vtkm::Float32(),
VTKM_DEFAULT_STORAGE_TAG()), expectedScalars, fieldSize),
TestArrayHandle(
scalars.CastToTypeStorage<vtkm::Float32,VTKM_DEFAULT_STORAGE_TAG>(),
expectedScalars,
fieldSize),
"Got incorrect scalars");
}
@ -195,13 +199,17 @@ void TestClippingStrucutred()
"Got incorrect conectivity");
VTKM_TEST_ASSERT(
TestArrayHandle(coords.CastToArrayHandle(Coord3D(),
VTKM_DEFAULT_STORAGE_TAG()), expectedCoords, fieldSize),
"Got incorrect coords");
TestArrayHandle(
coords.CastToTypeStorage<Coord3D,VTKM_DEFAULT_STORAGE_TAG>(),
expectedCoords,
fieldSize),
"Got incorrect coordinates");
VTKM_TEST_ASSERT(
TestArrayHandle(scalars.CastToArrayHandle(vtkm::Float32(),
VTKM_DEFAULT_STORAGE_TAG()), expectedScalars, fieldSize),
TestArrayHandle(
scalars.CastToTypeStorage<vtkm::Float32,VTKM_DEFAULT_STORAGE_TAG>(),
expectedScalars,
fieldSize),
"Got incorrect scalars");
}
@ -247,13 +255,17 @@ void TestClippingWithImplicitFunction()
"Got incorrect conectivity");
VTKM_TEST_ASSERT(
TestArrayHandle(coords.CastToArrayHandle(Coord3D(),
VTKM_DEFAULT_STORAGE_TAG()), expectedCoords, fieldSize),
"Got incorrect coords");
TestArrayHandle(
coords.CastToTypeStorage<Coord3D,VTKM_DEFAULT_STORAGE_TAG>(),
expectedCoords,
fieldSize),
"Got incorrect coordinates");
VTKM_TEST_ASSERT(
TestArrayHandle(scalars.CastToArrayHandle(vtkm::Float32(),
VTKM_DEFAULT_STORAGE_TAG()), expectedScalars, fieldSize),
TestArrayHandle(
scalars.CastToTypeStorage<vtkm::Float32,VTKM_DEFAULT_STORAGE_TAG>(),
expectedScalars,
fieldSize),
"Got incorrect scalars");
}

@ -30,8 +30,8 @@ namespace {
vtkm::cont::DataSet RunExternalFaces(vtkm::cont::DataSet &ds)
{
vtkm::cont::CellSetExplicit<> &cellset =
ds.GetCellSet(0).CastTo<vtkm::cont::CellSetExplicit<> >();
vtkm::cont::CellSetExplicit<> cellset;
ds.GetCellSet(0).CopyTo(cellset);
vtkm::cont::ArrayHandle<vtkm::UInt8> shapes = cellset.GetShapesArray(
vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell());
@ -112,8 +112,8 @@ void TestExternalFaces()
//Run the External Faces worklet
vtkm::cont::DataSet new_ds = RunExternalFaces(ds);
vtkm::cont::CellSetExplicit<> &new_cs =
new_ds.GetCellSet(0).CastTo<vtkm::cont::CellSetExplicit<> >();
vtkm::cont::CellSetExplicit<> new_cs;
new_ds.GetCellSet(0).CopyTo(new_cs);
vtkm::Id numExtFaces_out = new_cs.GetNumberOfCells();

@ -284,9 +284,9 @@ vtkm::cont::DataSet MakeTestDataSet()
//
// Print the histogram result and tally
//
void PrintHistogram(vtkm::cont::ArrayHandle<vtkm::Id> bins,
void PrintHistogram(vtkm::cont::ArrayHandle<vtkm::Id> bins,
vtkm::Id numberOfBins,
vtkm::Float32 minValue,
vtkm::Float32 minValue,
vtkm::Float32 delta)
{
vtkm::cont::ArrayHandle<vtkm::Id>::PortalConstControl binPortal = bins.GetPortalConstControl();
@ -321,14 +321,14 @@ void TestFieldHistogram()
vtkm::cont::DataSet ds = MakeTestDataSet();
// Get point data
vtkm::cont::ArrayHandle<vtkm::Float32> p_poisson =
ds.GetField("p_poisson").GetData().CastToArrayHandle<vtkm::Float32, VTKM_DEFAULT_STORAGE_TAG>();
vtkm::cont::ArrayHandle<vtkm::Float32> p_normal =
ds.GetField("p_normal").GetData().CastToArrayHandle<vtkm::Float32, VTKM_DEFAULT_STORAGE_TAG>();
vtkm::cont::ArrayHandle<vtkm::Float32> p_chiSquare =
ds.GetField("p_chiSquare").GetData().CastToArrayHandle<vtkm::Float32, VTKM_DEFAULT_STORAGE_TAG>();
vtkm::cont::ArrayHandle<vtkm::Float32> p_uniform =
ds.GetField("p_uniform").GetData().CastToArrayHandle<vtkm::Float32, VTKM_DEFAULT_STORAGE_TAG>();
vtkm::cont::ArrayHandle<vtkm::Float32> p_poisson;
ds.GetField("p_poisson").GetData().CopyTo(p_poisson);
vtkm::cont::ArrayHandle<vtkm::Float32> p_normal;
ds.GetField("p_normal").GetData().CopyTo(p_normal);
vtkm::cont::ArrayHandle<vtkm::Float32> p_chiSquare;
ds.GetField("p_chiSquare").GetData().CopyTo(p_chiSquare);
vtkm::cont::ArrayHandle<vtkm::Float32> p_uniform;
ds.GetField("p_uniform").GetData().CopyTo(p_uniform);
// Run data
vtkm::worklet::FieldHistogram<vtkm::Float32, VTKM_DEFAULT_DEVICE_ADAPTER_TAG>().

@ -48,7 +48,7 @@ vtkm::cont::DataSet Make2DRegularStatDataSet0()
// Create cell scalar
vtkm::Float32 data[nVerts] = {4,1,10,6,8,2,9,3,5,7};
dataSet.AddField(vtkm::cont::Field("data", 1, vtkm::cont::Field::ASSOC_CELL_SET,
dataSet.AddField(vtkm::cont::Field("data", 1, vtkm::cont::Field::ASSOC_CELL_SET,
"cells", data, nCells));
vtkm::cont::CellSetStructured<dimension> cellSet("cells");
@ -298,7 +298,7 @@ vtkm::cont::DataSet Make2DRegularStatDataSet1()
vtkm::cont::CoordinateSystem("coordinates", 1, coordinates));
// Set point scalars
dataSet.AddField(vtkm::cont::Field("p_poisson", 1, vtkm::cont::Field::ASSOC_POINTS,
dataSet.AddField(vtkm::cont::Field("p_poisson", 1, vtkm::cont::Field::ASSOC_POINTS,
poisson, nVerts));
dataSet.AddField(vtkm::cont::Field("p_normal", 1, vtkm::cont::Field::ASSOC_POINTS,
normal, nVerts));
@ -361,8 +361,8 @@ void TestFieldSimple()
vtkm::cont::DataSet ds = Make2DRegularStatDataSet0();
// Cell data
vtkm::cont::ArrayHandle<vtkm::Float32> data =
ds.GetField("data").GetData().CastToArrayHandle<vtkm::Float32, VTKM_DEFAULT_STORAGE_TAG>();
vtkm::cont::ArrayHandle<vtkm::Float32> data;
ds.GetField("data").GetData().CopyTo(data);
// Run
vtkm::worklet::FieldStatistics<vtkm::Float32, VTKM_DEFAULT_DEVICE_ADAPTER_TAG>().Run(data, statinfo);
@ -392,14 +392,14 @@ void TestFieldStandardDistributions()
vtkm::cont::DataSet ds = Make2DRegularStatDataSet1();
// Point data
vtkm::cont::ArrayHandle<vtkm::Float32> p_poisson =
ds.GetField("p_poisson").GetData().CastToArrayHandle<vtkm::Float32, VTKM_DEFAULT_STORAGE_TAG>();
vtkm::cont::ArrayHandle<vtkm::Float32> p_normal =
ds.GetField("p_normal").GetData().CastToArrayHandle<vtkm::Float32, VTKM_DEFAULT_STORAGE_TAG>();
vtkm::cont::ArrayHandle<vtkm::Float32> p_chiSquare =
ds.GetField("p_chiSquare").GetData().CastToArrayHandle<vtkm::Float32, VTKM_DEFAULT_STORAGE_TAG>();
vtkm::cont::ArrayHandle<vtkm::Float32> p_uniform =
ds.GetField("p_uniform").GetData().CastToArrayHandle<vtkm::Float32, VTKM_DEFAULT_STORAGE_TAG>();
vtkm::cont::ArrayHandle<vtkm::Float32> p_poisson;
ds.GetField("p_poisson").GetData().CopyTo(p_poisson);
vtkm::cont::ArrayHandle<vtkm::Float32> p_normal;
ds.GetField("p_normal").GetData().CopyTo(p_normal);
vtkm::cont::ArrayHandle<vtkm::Float32> p_chiSquare;
ds.GetField("p_chiSquare").GetData().CopyTo(p_chiSquare);
vtkm::cont::ArrayHandle<vtkm::Float32> p_uniform;
ds.GetField("p_uniform").GetData().CopyTo(p_uniform);
// Run Poisson data
vtkm::worklet::FieldStatistics<vtkm::Float32, VTKM_DEFAULT_DEVICE_ADAPTER_TAG>().Run(p_poisson, statinfo);

@ -240,9 +240,10 @@ void TestMarchingCubesUniformGrid()
vtkm::cont::DataSet dataSet = MakeIsosurfaceTestDataSet(dims);
typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
typedef vtkm::cont::CellSetStructured<3> CellSet;
vtkm::cont::CellSetStructured<3> cellSet;
dataSet.GetCellSet().CopyTo(cellSet);
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataSet.GetField("nodevar").GetData().CastToArrayHandle(fieldArray);
dataSet.GetField("nodevar").GetData().CopyTo(fieldArray);
vtkm::worklet::MarchingCubes<vtkm::Float32,DeviceAdapter> isosurfaceFilter;
@ -250,7 +251,7 @@ void TestMarchingCubesUniformGrid()
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,3> > normalsArray;
vtkm::cont::ArrayHandle<vtkm::Float32> scalarsArray;
isosurfaceFilter.Run(0.5,
dataSet.GetCellSet().CastTo(CellSet()),
cellSet,
dataSet.GetCoordinateSystem(),
fieldArray,
verticesArray,
@ -282,7 +283,6 @@ void TestMarchingCubesExplicit()
typedef vtkm::worklet::MarchingCubes<vtkm::Float32,DeviceTag> MarchingCubes;
typedef vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,3> > Vec3Handle;
typedef vtkm::cont::ArrayHandle<vtkm::Float32> DataHandle;
typedef DataSetGenerator::CellSet CellSet;
DataSetGenerator dataSetGenerator;
@ -292,17 +292,19 @@ void TestMarchingCubesExplicit()
vtkm::cont::DataSet dataSet =
dataSetGenerator.Make3DRadiantDataSet(Dimension);
DataSetGenerator::CellSet cellSet;
dataSet.GetCellSet().CopyTo(cellSet);
vtkm::cont::Field contourField = dataSet.GetField("distanceToOrigin");
DataSetGenerator::DataArrayHandle contourArray = contourField.GetData()
.CastToArrayHandle(DataSetGenerator::DataArrayHandle::ValueType(),
DataSetGenerator::DataArrayHandle::StorageTag());
DataSetGenerator::DataArrayHandle contourArray;
contourField.GetData().CopyTo(contourArray);
Vec3Handle vertices;
Vec3Handle normals;
MarchingCubes marchingCubes;
marchingCubes.Run(contourValue,
dataSet.GetCellSet().CastTo(CellSet()),
cellSet,
dataSet.GetCoordinateSystem(),
contourArray,
vertices,
@ -312,9 +314,8 @@ void TestMarchingCubesExplicit()
vtkm::cont::Field projectedField = dataSet.GetField("distanceToOther");
DataSetGenerator::DataArrayHandle projectedArray = projectedField.GetData()
.CastToArrayHandle(DataSetGenerator::DataArrayHandle::ValueType(),
DataSetGenerator::DataArrayHandle::StorageTag());
DataSetGenerator::DataArrayHandle projectedArray;
projectedField.GetData().CopyTo(projectedArray);
marchingCubes.MapFieldOntoIsosurface(projectedArray,
scalars);

@ -94,12 +94,10 @@ void TestPointElevation()
dispatcher.Invoke(dataSet.GetCoordinateSystem().GetData(),
dataSet.GetField("elevation").GetData());
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,3> > coordinates =
dataSet.GetCoordinateSystem().GetData().
CastToArrayHandle(vtkm::Vec<vtkm::Float32,3>(),VTKM_DEFAULT_STORAGE_TAG());
vtkm::cont::ArrayHandle<vtkm::Float32> result =
dataSet.GetField("elevation").GetData().
CastToArrayHandle(vtkm::Float32(),VTKM_DEFAULT_STORAGE_TAG());
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,3> > coordinates;
dataSet.GetCoordinateSystem().GetData().CopyTo(coordinates);
vtkm::cont::ArrayHandle<vtkm::Float32> result;
dataSet.GetField("elevation").GetData().CopyTo(result);
for (vtkm::Id i = 0; i < result.GetNumberOfValues(); ++i)
{

@ -42,7 +42,7 @@ vtkm::Vec<T,3> Normalize(vtkm::Vec<T,3> v)
return one / magnitude * v;
}
float data[125*3] =
float data[125*3] =
{
-0.00603248f, -0.0966396f, -0.000732792f,
0.000530014f, -0.0986189f, -0.000806706f,
@ -221,8 +221,8 @@ void TestStreamLineUniformGrid()
timeStep);
// Check output
vtkm::cont::CellSetExplicit<> &outCellSet =
outDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetExplicit<> >();
vtkm::cont::CellSetExplicit<> outCellSet;
outDataSet.GetCellSet(0).CopyTo(outCellSet);
const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray =
outDataSet.GetCoordinateSystem(0).GetData();

@ -185,7 +185,8 @@ void TestExplicitGrid2D()
tetrahedralizeFilter(inDataSet, outDataSet);
tetrahedralizeFilter.Run();
vtkm::cont::CellSetSingleType<> cellSet = outDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::CellSetSingleType<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::cont::CoordinateSystem coordinates = outDataSet.GetCoordinateSystem(0);
const vtkm::cont::DynamicArrayHandleCoordinateSystem coordArray = coordinates.GetData();
std::cout << "Number of output triangles " << cellSet.GetNumberOfCells() << std::endl;
@ -224,7 +225,8 @@ void TestExplicitGrid3D()
tetrahedralizeFilter(inDataSet, outDataSet);
tetrahedralizeFilter.Run();
vtkm::cont::CellSetSingleType<> cellSet = outDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::CellSetSingleType<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::cont::CoordinateSystem coordinates = outDataSet.GetCoordinateSystem(0);
const vtkm::cont::DynamicArrayHandleCoordinateSystem coordArray = coordinates.GetData();
std::cout << "Number of output tetrahedra " << cellSet.GetNumberOfCells() << std::endl;

@ -108,11 +108,12 @@ void TestUniformGrid2D()
outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0));
// Convert uniform hexahedra to tetrahedra
vtkm::worklet::TetrahedralizeFilterUniformGrid<DeviceAdapter>
vtkm::worklet::TetrahedralizeFilterUniformGrid<DeviceAdapter>
tetrahedralizeFilter(inDataSet, outDataSet);
tetrahedralizeFilter.Run();
vtkm::cont::CellSetSingleType<> &cellSet = outDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::CellSetSingleType<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::cont::CoordinateSystem coordinates = outDataSet.GetCoordinateSystem(0);
const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray = coordinates.GetData();
std::cout << "Number of output triangles " << cellSet.GetNumberOfCells() << std::endl;
@ -120,7 +121,7 @@ void TestUniformGrid2D()
std::cout << "Number of output components " << coordArray.GetNumberOfComponents() << std::endl;
vtkm::cont::ArrayHandle<vtkm::Float64> bounds = coordinates.GetBounds(DeviceAdapter());
std::cout << "Bounds ("
std::cout << "Bounds ("
<< bounds.GetPortalControl().Get(0) << "," << bounds.GetPortalControl().Get(1) << ") ("
<< bounds.GetPortalControl().Get(2) << "," << bounds.GetPortalControl().Get(3) << ") ("
<< bounds.GetPortalControl().Get(4) << "," << bounds.GetPortalControl().Get(5) << ")" << std::endl;
@ -158,11 +159,12 @@ void TestUniformGrid3D()
outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0));
// Convert uniform hexahedra to tetrahedra
vtkm::worklet::TetrahedralizeFilterUniformGrid<DeviceAdapter>
vtkm::worklet::TetrahedralizeFilterUniformGrid<DeviceAdapter>
tetrahedralizeFilter(inDataSet, outDataSet);
tetrahedralizeFilter.Run();
vtkm::cont::CellSetSingleType<> &cellSet = outDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::CellSetSingleType<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::cont::CoordinateSystem coordinates = outDataSet.GetCoordinateSystem(0);
const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray = coordinates.GetData();
std::cout << "Number of output tetrahedra " << cellSet.GetNumberOfCells() << std::endl;
@ -170,7 +172,7 @@ void TestUniformGrid3D()
std::cout << "Number of output components " << coordArray.GetNumberOfComponents() << std::endl;
vtkm::cont::ArrayHandle<vtkm::Float64> bounds = coordinates.GetBounds(DeviceAdapter());
std::cout << "Bounds ("
std::cout << "Bounds ("
<< bounds.GetPortalControl().Get(0) << "," << bounds.GetPortalControl().Get(1) << ") ("
<< bounds.GetPortalControl().Get(2) << "," << bounds.GetPortalControl().Get(3) << ") ("
<< bounds.GetPortalControl().Get(4) << "," << bounds.GetPortalControl().Get(5) << ")" << std::endl;

@ -68,7 +68,8 @@ public:
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DRegularDataSet0();
CellSetType cellset = dataset.GetCellSet(0).CastTo(CellSetType());
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
vtkm::worklet::Threshold threshold;
OutCellSetType outCellSet = threshold.Run(cellset,
@ -81,7 +82,7 @@ public:
VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 1, "Wrong number of cells");
OutCellFieldArrayHandleType cellFieldArray;
cellField.GetData().CastToArrayHandle(cellFieldArray);
cellField.GetData().CopyTo(cellFieldArray);
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 1 &&
cellFieldArray.GetPortalConstControl().Get(0) == 200.1f,
@ -101,7 +102,8 @@ public:
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DRegularDataSet0();
CellSetType cellset = dataset.GetCellSet(0).CastTo(CellSetType());
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
vtkm::worklet::Threshold threshold;
OutCellSetType outCellSet = threshold.Run(cellset,
@ -114,7 +116,7 @@ public:
VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 2, "Wrong number of cells");
OutCellFieldArrayHandleType cellFieldArray;
cellField.GetData().CastToArrayHandle(cellFieldArray);
cellField.GetData().CopyTo(cellFieldArray);
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 2 &&
cellFieldArray.GetPortalConstControl().Get(0) == 100.1f &&
@ -135,7 +137,8 @@ public:
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet0();
CellSetType cellset = dataset.GetCellSet(0).CastTo(CellSetType());
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
vtkm::worklet::Threshold threshold;
OutCellSetType outCellSet = threshold.Run(cellset,
@ -148,7 +151,7 @@ public:
VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 1, "Wrong number of cells");
OutCellFieldArrayHandleType cellFieldArray;
cellField.GetData().CastToArrayHandle(cellFieldArray);
cellField.GetData().CopyTo(cellFieldArray);
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 1 &&
cellFieldArray.GetPortalConstControl().Get(0) == 100.1f,

@ -52,10 +52,8 @@ void TestVertexClustering()
VTKM_TEST_ASSERT(outDataSet.GetNumberOfCoordinateSystems() == 1,
"Number of output coordinate systems mismatch");
typedef vtkm::Vec<vtkm::Float64, 3> PointType;
typedef vtkm::cont::ArrayHandle<PointType > PointArray;
PointArray pointArray =
outDataSet.GetCoordinateSystem(0).GetData().
CastToArrayHandle<PointArray::ValueType, PointArray::StorageTag>();
vtkm::cont::ArrayHandle<PointType> pointArray;
outDataSet.GetCoordinateSystem(0).GetData().CopyTo(pointArray);
VTKM_TEST_ASSERT(pointArray.GetNumberOfValues() == output_points,
"Number of output points mismatch" );
for (vtkm::Id i = 0; i < pointArray.GetNumberOfValues(); ++i)
@ -70,7 +68,8 @@ void TestVertexClustering()
typedef vtkm::cont::CellSetSingleType<> CellSetType;
VTKM_TEST_ASSERT(outDataSet.GetNumberOfCellSets() == 1, "Number of output cellsets mismatch");
CellSetType cellSet = outDataSet.GetCellSet(0).CastTo<CellSetType>();
CellSetType cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
VTKM_TEST_ASSERT(
cellSet.GetConnectivityArray(vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell()).GetNumberOfValues() == output_pointIds,
"Number of connectivity array elements mismatch");

@ -179,8 +179,7 @@ TestMaxPointOrCell()
//Make sure we got the right answer.
vtkm::cont::ArrayHandle<vtkm::Float32> res;
res = dataSet.GetField("outcellvar").GetData().
CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG());
dataSet.GetField("outcellvar").GetData().CopyTo(res);
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(0), 100.1f),
"Wrong result for PointToCellMax worklet");
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(1), 100.2f),
@ -218,8 +217,7 @@ TestAvgPointToCell()
//make sure we got the right answer.
vtkm::cont::ArrayHandle<vtkm::Float32> res;
res = dataSet.GetField("outcellvar").GetData().CastToArrayHandle(vtkm::Float32(),
VTKM_DEFAULT_STORAGE_TAG());
dataSet.GetField("outcellvar").GetData().CopyTo(res);
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(0), 20.1333f),
"Wrong result for PointToCellAverage worklet");
@ -258,8 +256,7 @@ TestAvgCellToPoint()
//make sure we got the right answer.
vtkm::cont::ArrayHandle<vtkm::Float32> res;
res = dataSet.GetField("outpointvar").GetData().CastToArrayHandle(vtkm::Float32(),
VTKM_DEFAULT_STORAGE_TAG());
dataSet.GetField("outpointvar").GetData().CopyTo(res);
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(0), 100.1f),
"Wrong result for CellToPointAverage worklet");

@ -210,8 +210,7 @@ TestMaxPointOrCell()
//make sure we got the right answer.
vtkm::cont::ArrayHandle<vtkm::Float32> res;
res = dataSet.GetField("outcellvar").GetData().
CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG());
dataSet.GetField("outcellvar").GetData().CopyTo(res);
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(0), 100.1f),
"Wrong result for MaxPointOrCell worklet");
@ -253,8 +252,7 @@ TestAvgPointToCell()
//make sure we got the right answer.
vtkm::cont::ArrayHandle<vtkm::Float32> res;
res = dataSet.GetField("outcellvar").GetData().
CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG());
dataSet.GetField("outcellvar").GetData().CopyTo(res);
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(0), 30.1f),
"Wrong result for PointToCellAverage worklet");
@ -297,8 +295,7 @@ TestAvgCellToPoint()
//make sure we got the right answer.
vtkm::cont::ArrayHandle<vtkm::Float32> res;
res = dataSet.GetField("outpointvar").GetData().CastToArrayHandle(vtkm::Float32(),
VTKM_DEFAULT_STORAGE_TAG());
dataSet.GetField("outpointvar").GetData().CopyTo(res);
VTKM_TEST_ASSERT(test_equal(res.GetPortalConstControl().Get(0), 100.1f),
"Wrong result for CellToPointAverage worklet");