diff --git a/examples/isosurface/IsosurfaceUniformGrid.cxx b/examples/isosurface/IsosurfaceUniformGrid.cxx index e07674f67..92d6db2a6 100644 --- a/examples/isosurface/IsosurfaceUniformGrid.cxx +++ b/examples/isosurface/IsosurfaceUniformGrid.cxx @@ -241,12 +241,12 @@ int main(int argc, char* argv[]) vtkm::cont::DataSet dataSet = MakeIsosurfaceTestDataSet(dims); vtkm::cont::ArrayHandle fieldArray; - dataSet.GetField("nodevar").GetData().CastToArrayHandle(fieldArray); + dataSet.GetField("nodevar").GetData().CopyTo(fieldArray); isosurfaceFilter = new vtkm::worklet::MarchingCubes(); isosurfaceFilter->Run(0.5, - dataSet.GetCellSet().CastTo(CellSet()), + dataSet.GetCellSet().Cast(), dataSet.GetCoordinateSystem(), fieldArray, verticesArray, diff --git a/examples/streamline/StreamLineUniformGrid.cxx b/examples/streamline/StreamLineUniformGrid.cxx index f84d1ac76..67fc5746e 100644 --- a/examples/streamline/StreamLineUniformGrid.cxx +++ b/examples/streamline/StreamLineUniformGrid.cxx @@ -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<> 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(); diff --git a/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx b/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx index e0169b6d1..7e65dc3bc 100644 --- a/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx +++ b/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx @@ -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<> 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<> inCellSet; + inDataSet.GetCellSet(0).CopyTo(inCellSet); numberOfInPoints = inCellSet.GetNumberOfPoints(); diff --git a/examples/tetrahedra/TetrahedralizeUniformGrid.cxx b/examples/tetrahedra/TetrahedralizeUniformGrid.cxx index edad118d5..7c5cacf9b 100644 --- a/examples/tetrahedra/TetrahedralizeUniformGrid.cxx +++ b/examples/tetrahedra/TetrahedralizeUniformGrid.cxx @@ -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<> cellSet; + tetDataSet.GetCellSet(0).CopyTo(cellSet); const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray = tetDataSet.GetCoordinateSystem(0).GetData(); diff --git a/examples/tetrahedra/TriangulateExplicitGrid.cxx b/examples/tetrahedra/TriangulateExplicitGrid.cxx index e62260532..5baa0e607 100644 --- a/examples/tetrahedra/TriangulateExplicitGrid.cxx +++ b/examples/tetrahedra/TriangulateExplicitGrid.cxx @@ -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<> 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<> inCellSet; + inDataSet.GetCellSet(0).CopyTo(inCellSet); numberOfInPoints = inCellSet.GetNumberOfPoints(); diff --git a/examples/tetrahedra/TriangulateUniformGrid.cxx b/examples/tetrahedra/TriangulateUniformGrid.cxx index fcad73171..67de81349 100644 --- a/examples/tetrahedra/TriangulateUniformGrid.cxx +++ b/examples/tetrahedra/TriangulateUniformGrid.cxx @@ -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<> cellSet; + tetDataSet.GetCellSet(0).CopyTo(cellSet); const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray = tetDataSet.GetCoordinateSystem(0).GetData(); diff --git a/vtkm/cont/DynamicArrayHandle.h b/vtkm/cont/DynamicArrayHandle.h index dbebf23c4..5ac189149 100644 --- a/vtkm/cont/DynamicArrayHandle.h +++ b/vtkm/cont/DynamicArrayHandle.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -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 +VTKM_CONT_EXPORT +vtkm::cont::ArrayHandle * +DynamicArrayHandleTryCast( + vtkm::cont::detail::PolymorphicArrayHandleContainerBase *arrayContainer) +{ + vtkm::cont::detail::PolymorphicArrayHandleContainer * + downcastContainer = dynamic_cast< + vtkm::cont::detail::PolymorphicArrayHandleContainer *>( + arrayContainer); + if (downcastContainer != NULL) + { + return &downcastContainer->Array; + } + else + { + return NULL; + } +} + +template +VTKM_CONT_EXPORT +vtkm::cont::ArrayHandle * +DynamicArrayHandleTryCast( + boost::shared_ptr + arrayContainer) +{ + return detail::DynamicArrayHandleTryCast(arrayContainer.get()); +} + } // namespace detail /// \brief Holds an array handle without having to specify template parameters. @@ -199,51 +232,85 @@ public: /// template VTKM_CONT_EXPORT - bool IsTypeAndStorage(Type = Type(), Storage = Storage()) const { - return (this->TryCastContainer() != NULL); + bool IsTypeAndStorage() const { + return ( + detail::DynamicArrayHandleTryCast(this->ArrayContainer) + != NULL); } /// Returns true if this array matches the array handle type passed in. /// template 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(); + } + + /// Returns true if the array held in this object is the same (or equivalent) + /// type as the object given. + /// + template + VTKM_CONT_EXPORT + bool IsSameType(const ArrayHandleType &) + { + VTKM_IS_ARRAY_HANDLE(ArrayHandleType); + return this->IsArrayHandleType(); } /// 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 VTKM_CONT_EXPORT vtkm::cont::ArrayHandle - CastToArrayHandle(Type = Type(), Storage = Storage()) const { - vtkm::cont::detail::PolymorphicArrayHandleContainer *container - = this->TryCastContainer(); - if (container == NULL) + CastToTypeStorage() const { + vtkm::cont::ArrayHandle *downcastArray = + detail::DynamicArrayHandleTryCast(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 + 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(); } /// 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 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(); } /// Changes the types to try casting to when resolving this dynamic array, @@ -348,16 +415,6 @@ private: ArrayContainer; friend struct detail::DynamicArrayHandleCopyHelper; - - template - VTKM_CONT_EXPORT - vtkm::cont::detail::PolymorphicArrayHandleContainer * - TryCastContainer() const { - return - dynamic_cast< - vtkm::cont::detail::PolymorphicArrayHandleContainer *>( - this->ArrayContainer.get()); - } }; typedef vtkm::cont::DynamicArrayHandleBase< @@ -389,9 +446,9 @@ private: void DoCast(Storage, boost::mpl::bool_) { if (!this->FoundCast && - this->Array.IsTypeAndStorage(Type(), Storage())) + this->Array.template IsTypeAndStorage()) { - this->Function(this->Array.CastToArrayHandle(Type(), Storage())); + this->Function(this->Array.template CastToTypeStorage()); this->FoundCast = true; } } diff --git a/vtkm/cont/DynamicCellSet.h b/vtkm/cont/DynamicCellSet.h index 8f614de40..26063f8f1 100644 --- a/vtkm/cont/DynamicCellSet.h +++ b/vtkm/cont/DynamicCellSet.h @@ -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 +VTKM_CONT_EXPORT +CellSetType * +DynamicCellSetTryCast( + vtkm::cont::internal::SimplePolymorphicContainerBase *cellSetContainer) +{ + vtkm::cont::internal::SimplePolymorphicContainer * + downcastContainer = dynamic_cast< + vtkm::cont::internal::SimplePolymorphicContainer *>( + cellSetContainer); + if (downcastContainer != NULL) + { + return &downcastContainer->Item; + } + else + { + return NULL; + } +} + +template +VTKM_CONT_EXPORT +CellSetType * +DynamicCellSetTryCast( + boost::shared_ptr + cellSetContainer) +{ + return detail::DynamicCellSetTryCast(cellSetContainer.get()); +} + } // namespace detail /// \brief Holds a cell set without having to specify concrete type. @@ -132,8 +165,18 @@ public: /// template VTKM_CONT_EXPORT - bool IsType(CellSetType = CellSetType()) const { - return (this->TryCast() != NULL); + bool IsType() const { + return (detail::DynamicCellSetTryCast(this->CellSetContainer) + != NULL); + } + + /// Returns true if this cell set is the same (or equivalent) type as the + /// object provided. + /// + template + VTKM_CONT_EXPORT + bool IsSameType(const CellSetType &) const { + return this->IsType(); } /// 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 VTKM_CONT_EXPORT - const CellSetType &CastTo(CellSetType = CellSetType()) const { - const vtkm::cont::internal::SimplePolymorphicContainer * - container = this->TryCast(); - if (container == NULL) + CellSetType &Cast() const { + CellSetType *cellSetPointer = + detail::DynamicCellSetTryCast(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 VTKM_CONT_EXPORT - CellSetType &CastTo(CellSetType = CellSetType()) { - vtkm::cont::internal::SimplePolymorphicContainer * - container = this->TryCast(); - if (container == NULL) - { - throw vtkm::cont::ErrorControlBadValue("Bad cast of dynamic cell set."); - } - return container->Item; + void CopyTo(CellSetType &cellSet) const { + cellSet = this->Cast(); } /// Changes the cell set types to try casting to when resolving this dynamic @@ -217,16 +263,6 @@ private: CellSetContainer; friend struct detail::DynamicCellSetCopyHelper; - - template - VTKM_CONT_EXPORT - vtkm::cont::internal::SimplePolymorphicContainer * - TryCast() const { - return - dynamic_cast< - vtkm::cont::internal::SimplePolymorphicContainer *>( - this->CellSetContainer.get()); - } }; namespace detail { @@ -234,22 +270,23 @@ namespace detail { template 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 VTKM_CONT_EXPORT void operator()(CellSetType) { if (!this->FoundCast) { - const CellSetType *cellSet = - dynamic_cast(this->AbstractCellSet); + CellSetType *cellSet = + detail::DynamicCellSetTryCast(this->CellSetContainer); if (cellSet != NULL) { this->Function(*cellSet); @@ -259,22 +296,6 @@ struct DynamicCellSetTryCellSet } }; -template -VTKM_CONT_EXPORT -void CastAndCallCellSet( - const Functor &f, - const vtkm::cont::DynamicCellSetBase &cellSet) -{ - typedef detail::DynamicCellSetTryCellSet 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 @@ -282,7 +303,14 @@ template VTKM_CONT_EXPORT void DynamicCellSetBase::CastAndCall(const Functor &f) const { - detail::CastAndCallCellSet(f, *this); + typedef detail::DynamicCellSetTryCellSet 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; diff --git a/vtkm/cont/testing/TestingDataSetExplicit.h b/vtkm/cont/testing/TestingDataSetExplicit.h index caef0ac45..367c49520 100644 --- a/vtkm/cont/testing/TestingDataSetExplicit.h +++ b/vtkm/cont/testing/TestingDataSetExplicit.h @@ -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<> cellset; + ds.GetCellSet(0).CopyTo(cellset); + cellset.BuildConnectivity(DeviceAdapterTag(), vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint()); diff --git a/vtkm/cont/testing/TestingDataSetSingleType.h b/vtkm/cont/testing/TestingDataSetSingleType.h index fc28dc7af..1c9c10754 100644 --- a/vtkm/cont/testing/TestingDataSetSingleType.h +++ b/vtkm/cont/testing/TestingDataSetSingleType.h @@ -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<> cellset; + dataSet.GetCellSet(0).CopyTo(cellset); //verify that we can compute the cell to point connectivity diff --git a/vtkm/cont/testing/UnitTestDataSetBuilderRectilinear.cxx b/vtkm/cont/testing/UnitTestDataSetBuilderRectilinear.cxx index 38175803d..1ad12aba3 100644 --- a/vtkm/cont/testing/UnitTestDataSetBuilderRectilinear.cxx +++ b/vtkm/cont/testing/UnitTestDataSetBuilderRectilinear.cxx @@ -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(); + 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(); + 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 &arr, case 2: xi = static_cast(i*2); break; case 3: xi = static_cast(i*0.1f); break; case 4: xi = static_cast(i*i); break; + default: VTKM_TEST_FAIL("Bad internal test state: invalid fill method."); } arr[i] = xi; } diff --git a/vtkm/cont/testing/UnitTestDataSetBuilderRegular.cxx b/vtkm/cont/testing/UnitTestDataSetBuilderRegular.cxx index 7e4a18f6d..b23a035ea 100644 --- a/vtkm/cont/testing/UnitTestDataSetBuilderRegular.cxx +++ b/vtkm/cont/testing/UnitTestDataSetBuilderRegular.cxx @@ -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(); + 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(); + 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"); } diff --git a/vtkm/cont/testing/UnitTestDataSetPermutation.cxx b/vtkm/cont/testing/UnitTestDataSetPermutation.cxx index 691ce5a4d..8b371bdf0 100644 --- a/vtkm/cont/testing/UnitTestDataSetPermutation.cxx +++ b/vtkm/cont/testing/UnitTestDataSetPermutation.cxx @@ -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(); + vtkm::cont::CellSetSingleType<> cellSet; + dataSet.GetCellSet(0).CopyTo(cellSet); //verify that we can create a subset of a singlset typedef vtkm::cont::CellSetPermutation, @@ -155,8 +155,8 @@ void TestDataSet_Structured2D() vtkm::cont::make_ArrayHandle(validIds); - typedef vtkm::cont::CellSetStructured<2> CellSetType; - CellSetType cellSet = dataSet.GetCellSet(0).CastTo(); + vtkm::cont::CellSetStructured<2> cellSet; + dataSet.GetCellSet(0).CopyTo(cellSet); //verify that we can create a subset of a 2d RegularDataSet vtkm::cont::CellSetPermutation, @@ -202,8 +202,8 @@ void TestDataSet_Structured3D() vtkm::cont::ArrayHandle validCellIds = vtkm::cont::make_ArrayHandle(validIds); - typedef vtkm::cont::CellSetStructured<3> CellSetType; - CellSetType cellSet = dataSet.GetCellSet(0).CastTo(); + vtkm::cont::CellSetStructured<3> cellSet; + dataSet.GetCellSet(0).CopyTo(cellSet); //verify that we can create a subset of a 2d RegularDataSet vtkm::cont::CellSetPermutation, diff --git a/vtkm/cont/testing/UnitTestDataSetRectilinear.cxx b/vtkm/cont/testing/UnitTestDataSetRectilinear.cxx index 47f88355d..335c93134 100644 --- a/vtkm/cont/testing/UnitTestDataSetRectilinear.cxx +++ b/vtkm/cont/testing/UnitTestDataSetRectilinear.cxx @@ -50,8 +50,8 @@ TwoDimRectilinearTest() vtkm::cont::DataSet dataSet = testDataSet.Make2DRectilinearDataSet0(); - typedef vtkm::cont::CellSetStructured<2> CellSetType; - CellSetType cellSet = dataSet.GetCellSet(0).CastTo(); + 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(); + vtkm::cont::CellSetStructured<3> cellSet; + dataSet.GetCellSet(0).CopyTo(cellSet); VTKM_TEST_ASSERT(dataSet.GetNumberOfCellSets() == 1, "Incorrect number of cell sets"); diff --git a/vtkm/cont/testing/UnitTestDataSetRegular.cxx b/vtkm/cont/testing/UnitTestDataSetRegular.cxx index bd9212c8f..07576bec0 100644 --- a/vtkm/cont/testing/UnitTestDataSetRegular.cxx +++ b/vtkm/cont/testing/UnitTestDataSetRegular.cxx @@ -49,8 +49,10 @@ TwoDimRegularTest() vtkm::cont::DataSet dataSet = testDataSet.Make2DRegularDataSet0(); - typedef vtkm::cont::CellSetStructured<2> CellSetType; - CellSetType cellSet = dataSet.GetCellSet(0).CastTo(); + 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(); + 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"); diff --git a/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx b/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx index 043343e6f..ad2367e44 100644 --- a/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx @@ -179,18 +179,18 @@ void CheckCastToArrayHandle(const ArrayHandleType &array) vtkm::cont::DynamicArrayHandle dynamicArray = array; VTKM_TEST_ASSERT( - !dynamicArray.IsArrayHandleType(vtkm::cont::ArrayHandle()), + !dynamicArray.IsArrayHandleType >(), "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(); 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 staticArray = - newArray.CastToArrayHandle(T(), VTKM_DEFAULT_STORAGE_TAG()); + vtkm::cont::ArrayHandle staticArray; + newArray.CopyTo(staticArray); std::cout << "Fill the new array with invalid values and make sure the original" << std::endl << "is uneffected." << std::endl; diff --git a/vtkm/cont/testing/UnitTestDynamicCellSet.cxx b/vtkm/cont/testing/UnitTestDynamicCellSet.cxx index e088fab37..dd73c57f3 100644 --- a/vtkm/cont/testing/UnitTestDynamicCellSet.cxx +++ b/vtkm/cont/testing/UnitTestDynamicCellSet.cxx @@ -54,12 +54,14 @@ void CheckDynamicCellSet( const CellSetType &cellSet, vtkm::cont::DynamicCellSetBase dynamicCellSet) { - VTKM_TEST_ASSERT(dynamicCellSet.IsType(cellSet), + VTKM_TEST_ASSERT(dynamicCellSet.template IsType(), "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(), "DynamicCellSet reports wrong type."); - dynamicCellSet.CastTo(cellSet); + dynamicCellSet.template Cast(); CheckCalled = false; dynamicCellSet.CastAndCall(CheckFunctor()); @@ -75,11 +77,11 @@ void TryNewInstance( vtkm::cont::DynamicCellSetBase newCellSet = originalCellSet.NewInstance(); - VTKM_TEST_ASSERT(newCellSet.IsType(CellSetType()), + VTKM_TEST_ASSERT(newCellSet.template IsType(), "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."); } diff --git a/vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx b/vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx index 2e9874f68..edb67a437 100644 --- a/vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx +++ b/vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx @@ -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 >(), "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 >(), "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 >(), "Incorrect cellset type"); } diff --git a/vtkm/io/writer/VTKDataSetWriter.h b/vtkm/io/writer/VTKDataSetWriter.h index 30f4f4a32..277698ff2 100644 --- a/vtkm/io/writer/VTKDataSetWriter.h +++ b/vtkm/io/writer/VTKDataSetWriter.h @@ -369,24 +369,28 @@ public: vtkm::cont::DynamicCellSet cs = ds.GetCellSet(csindex); if (cs.IsType >()) { - WriteDataSetAsUnstructured(out, ds, - cs.CastTo >()); + WriteDataSetAsUnstructured(out, + ds, + cs.Cast >()); } else if (cs.IsType >()) { - WriteDataSetAsStructured(out, ds, - cs.CastTo >()); + WriteDataSetAsStructured(out, + ds, + cs.Cast >()); } else if (cs.IsType >()) { - WriteDataSetAsStructured(out, ds, - cs.CastTo >()); + WriteDataSetAsStructured(out, + ds, + cs.Cast >()); } else if (cs.IsType >()) { // these function just like explicit cell sets - WriteDataSetAsUnstructured(out, ds, - cs.CastTo >()); + WriteDataSetAsUnstructured(out, + ds, + cs.Cast >()); } else { diff --git a/vtkm/worklet/StreamLineUniformGrid.h b/vtkm/worklet/StreamLineUniformGrid.h index db5511ca4..50a103a15 100644 --- a/vtkm/worklet/StreamLineUniformGrid.h +++ b/vtkm/worklet/StreamLineUniformGrid.h @@ -345,13 +345,12 @@ public: typedef typename vtkm::cont::DeviceAdapterAlgorithm DeviceAlgorithm; // Get information from input dataset - vtkm::cont::CellSetStructured<3> &inCellSet = - InDataSet.GetCellSet(0).template CastTo >(); + vtkm::cont::CellSetStructured<3> inCellSet; + InDataSet.GetCellSet(0).CopyTo(inCellSet); vtkm::Id3 vdims= inCellSet.GetSchedulingRange(vtkm::TopologyElementTagPoint()); - vtkm::cont::ArrayHandle > fieldArray = - InDataSet.GetField("vecData").GetData(). - CastToArrayHandle, VTKM_DEFAULT_STORAGE_TAG>(); + vtkm::cont::ArrayHandle > fieldArray; + InDataSet.GetField("vecData").GetData().CopyTo(fieldArray); // Generate random seeds for starting streamlines std::vector > seeds; diff --git a/vtkm/worklet/TetrahedralizeExplicitGrid.h b/vtkm/worklet/TetrahedralizeExplicitGrid.h index 8c3e5af85..eb66b9b08 100644 --- a/vtkm/worklet/TetrahedralizeExplicitGrid.h +++ b/vtkm/worklet/TetrahedralizeExplicitGrid.h @@ -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<> inCellSet; + InDataSet.GetCellSet(0).CopyTo(inCellSet); vtkm::cont::CellSetSingleType<> &cellSet = - OutDataSet.GetCellSet(0).template CastTo >(); + this->OutDataSet.GetCellSet(0).template Cast >(); // Input dataset vertices and cell counts vtkm::Id dimensionality = inCellSet.GetDimensionality(); diff --git a/vtkm/worklet/TetrahedralizeUniformGrid.h b/vtkm/worklet/TetrahedralizeUniformGrid.h index 1189517ef..b0fbdc2b1 100644 --- a/vtkm/worklet/TetrahedralizeUniformGrid.h +++ b/vtkm/worklet/TetrahedralizeUniformGrid.h @@ -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<> &cellSet = + this->OutDataSet.GetCellSet(0).template Cast >(); vtkm::cont::ArrayHandle connectivity; if (cellSet.GetDimensionality() == 2) { - vtkm::cont::CellSetStructured<2> &inCellSet = - InDataSet.GetCellSet(0).template CastTo >(); + vtkm::cont::CellSetStructured<2> inCellSet; + InDataSet.GetCellSet(0).CopyTo(inCellSet); vtkm::worklet::DispatcherMapTopology 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> inCellSet; + InDataSet.GetCellSet(0).CopyTo(inCellSet); vtkm::worklet::DispatcherMapTopology dispatcher; dispatcher.Invoke(inCellSet, vtkm::cont::make_ArrayHandleGroupVec<4>(connectivity)); diff --git a/vtkm/worklet/testing/UnitTestCellAverage.cxx b/vtkm/worklet/testing/UnitTestCellAverage.cxx index 574a3e2c8..38609ce38 100644 --- a/vtkm/worklet/testing/UnitTestCellAverage.cxx +++ b/vtkm/worklet/testing/UnitTestCellAverage.cxx @@ -48,8 +48,8 @@ void TestCellAverageRegular3D() dataSet.GetCellSet(), result.GetData()); - vtkm::cont::ArrayHandle resultArrayHandle = - result.GetData().CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG()); + vtkm::cont::ArrayHandle 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 resultArrayHandle = - result.GetData().CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG()); + vtkm::cont::ArrayHandle 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 resultArrayHandle = - result.GetData().CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG()); + vtkm::cont::ArrayHandle resultArrayHandle; + result.GetData().CopyTo(resultArrayHandle); vtkm::Float32 expected[2] = { 20.1333f, 35.2f }; for (int i = 0; i < 2; ++i) diff --git a/vtkm/worklet/testing/UnitTestClipping.cxx b/vtkm/worklet/testing/UnitTestClipping.cxx index 28761f8c2..e7bcb28a8 100644 --- a/vtkm/worklet/testing/UnitTestClipping.cxx +++ b/vtkm/worklet/testing/UnitTestClipping.cxx @@ -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(), + expectedCoords, + fieldSize), + "Got incorrect coordinates"); VTKM_TEST_ASSERT( - TestArrayHandle(scalars.CastToArrayHandle(vtkm::Float32(), - VTKM_DEFAULT_STORAGE_TAG()), expectedScalars, fieldSize), + TestArrayHandle( + scalars.CastToTypeStorage(), + 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(), + expectedCoords, + fieldSize), + "Got incorrect coordinates"); VTKM_TEST_ASSERT( - TestArrayHandle(scalars.CastToArrayHandle(vtkm::Float32(), - VTKM_DEFAULT_STORAGE_TAG()), expectedScalars, fieldSize), + TestArrayHandle( + scalars.CastToTypeStorage(), + 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(), + expectedCoords, + fieldSize), + "Got incorrect coordinates"); VTKM_TEST_ASSERT( - TestArrayHandle(scalars.CastToArrayHandle(vtkm::Float32(), - VTKM_DEFAULT_STORAGE_TAG()), expectedScalars, fieldSize), + TestArrayHandle( + scalars.CastToTypeStorage(), + expectedScalars, + fieldSize), "Got incorrect scalars"); } diff --git a/vtkm/worklet/testing/UnitTestExternalFaces.cxx b/vtkm/worklet/testing/UnitTestExternalFaces.cxx index fad1cb823..3dd2fc61a 100644 --- a/vtkm/worklet/testing/UnitTestExternalFaces.cxx +++ b/vtkm/worklet/testing/UnitTestExternalFaces.cxx @@ -30,8 +30,8 @@ namespace { vtkm::cont::DataSet RunExternalFaces(vtkm::cont::DataSet &ds) { - vtkm::cont::CellSetExplicit<> &cellset = - ds.GetCellSet(0).CastTo >(); + vtkm::cont::CellSetExplicit<> cellset; + ds.GetCellSet(0).CopyTo(cellset); vtkm::cont::ArrayHandle 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<> new_cs; + new_ds.GetCellSet(0).CopyTo(new_cs); vtkm::Id numExtFaces_out = new_cs.GetNumberOfCells(); diff --git a/vtkm/worklet/testing/UnitTestFieldHistogram.cxx b/vtkm/worklet/testing/UnitTestFieldHistogram.cxx index 823c12372..dd6c7e424 100644 --- a/vtkm/worklet/testing/UnitTestFieldHistogram.cxx +++ b/vtkm/worklet/testing/UnitTestFieldHistogram.cxx @@ -284,9 +284,9 @@ vtkm::cont::DataSet MakeTestDataSet() // // Print the histogram result and tally // -void PrintHistogram(vtkm::cont::ArrayHandle bins, +void PrintHistogram(vtkm::cont::ArrayHandle bins, vtkm::Id numberOfBins, - vtkm::Float32 minValue, + vtkm::Float32 minValue, vtkm::Float32 delta) { vtkm::cont::ArrayHandle::PortalConstControl binPortal = bins.GetPortalConstControl(); @@ -321,14 +321,14 @@ void TestFieldHistogram() vtkm::cont::DataSet ds = MakeTestDataSet(); // Get point data - vtkm::cont::ArrayHandle p_poisson = - ds.GetField("p_poisson").GetData().CastToArrayHandle(); - vtkm::cont::ArrayHandle p_normal = - ds.GetField("p_normal").GetData().CastToArrayHandle(); - vtkm::cont::ArrayHandle p_chiSquare = - ds.GetField("p_chiSquare").GetData().CastToArrayHandle(); - vtkm::cont::ArrayHandle p_uniform = - ds.GetField("p_uniform").GetData().CastToArrayHandle(); + vtkm::cont::ArrayHandle p_poisson; + ds.GetField("p_poisson").GetData().CopyTo(p_poisson); + vtkm::cont::ArrayHandle p_normal; + ds.GetField("p_normal").GetData().CopyTo(p_normal); + vtkm::cont::ArrayHandle p_chiSquare; + ds.GetField("p_chiSquare").GetData().CopyTo(p_chiSquare); + vtkm::cont::ArrayHandle p_uniform; + ds.GetField("p_uniform").GetData().CopyTo(p_uniform); // Run data vtkm::worklet::FieldHistogram(). diff --git a/vtkm/worklet/testing/UnitTestFieldStatistics.cxx b/vtkm/worklet/testing/UnitTestFieldStatistics.cxx index 98abb58fa..cfa4c2a81 100644 --- a/vtkm/worklet/testing/UnitTestFieldStatistics.cxx +++ b/vtkm/worklet/testing/UnitTestFieldStatistics.cxx @@ -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 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 data = - ds.GetField("data").GetData().CastToArrayHandle(); + vtkm::cont::ArrayHandle data; + ds.GetField("data").GetData().CopyTo(data); // Run vtkm::worklet::FieldStatistics().Run(data, statinfo); @@ -392,14 +392,14 @@ void TestFieldStandardDistributions() vtkm::cont::DataSet ds = Make2DRegularStatDataSet1(); // Point data - vtkm::cont::ArrayHandle p_poisson = - ds.GetField("p_poisson").GetData().CastToArrayHandle(); - vtkm::cont::ArrayHandle p_normal = - ds.GetField("p_normal").GetData().CastToArrayHandle(); - vtkm::cont::ArrayHandle p_chiSquare = - ds.GetField("p_chiSquare").GetData().CastToArrayHandle(); - vtkm::cont::ArrayHandle p_uniform = - ds.GetField("p_uniform").GetData().CastToArrayHandle(); + vtkm::cont::ArrayHandle p_poisson; + ds.GetField("p_poisson").GetData().CopyTo(p_poisson); + vtkm::cont::ArrayHandle p_normal; + ds.GetField("p_normal").GetData().CopyTo(p_normal); + vtkm::cont::ArrayHandle p_chiSquare; + ds.GetField("p_chiSquare").GetData().CopyTo(p_chiSquare); + vtkm::cont::ArrayHandle p_uniform; + ds.GetField("p_uniform").GetData().CopyTo(p_uniform); // Run Poisson data vtkm::worklet::FieldStatistics().Run(p_poisson, statinfo); diff --git a/vtkm/worklet/testing/UnitTestMarchingCubes.cxx b/vtkm/worklet/testing/UnitTestMarchingCubes.cxx index a55ef99ef..ab4390674 100644 --- a/vtkm/worklet/testing/UnitTestMarchingCubes.cxx +++ b/vtkm/worklet/testing/UnitTestMarchingCubes.cxx @@ -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 fieldArray; - dataSet.GetField("nodevar").GetData().CastToArrayHandle(fieldArray); + dataSet.GetField("nodevar").GetData().CopyTo(fieldArray); vtkm::worklet::MarchingCubes isosurfaceFilter; @@ -250,7 +251,7 @@ void TestMarchingCubesUniformGrid() vtkm::cont::ArrayHandle > normalsArray; vtkm::cont::ArrayHandle scalarsArray; isosurfaceFilter.Run(0.5, - dataSet.GetCellSet().CastTo(CellSet()), + cellSet, dataSet.GetCoordinateSystem(), fieldArray, verticesArray, @@ -282,7 +283,6 @@ void TestMarchingCubesExplicit() typedef vtkm::worklet::MarchingCubes MarchingCubes; typedef vtkm::cont::ArrayHandle > Vec3Handle; typedef vtkm::cont::ArrayHandle 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); diff --git a/vtkm/worklet/testing/UnitTestPointElevation.cxx b/vtkm/worklet/testing/UnitTestPointElevation.cxx index ee30c8074..5d6942408 100644 --- a/vtkm/worklet/testing/UnitTestPointElevation.cxx +++ b/vtkm/worklet/testing/UnitTestPointElevation.cxx @@ -94,12 +94,10 @@ void TestPointElevation() dispatcher.Invoke(dataSet.GetCoordinateSystem().GetData(), dataSet.GetField("elevation").GetData()); - vtkm::cont::ArrayHandle > coordinates = - dataSet.GetCoordinateSystem().GetData(). - CastToArrayHandle(vtkm::Vec(),VTKM_DEFAULT_STORAGE_TAG()); - vtkm::cont::ArrayHandle result = - dataSet.GetField("elevation").GetData(). - CastToArrayHandle(vtkm::Float32(),VTKM_DEFAULT_STORAGE_TAG()); + vtkm::cont::ArrayHandle > coordinates; + dataSet.GetCoordinateSystem().GetData().CopyTo(coordinates); + vtkm::cont::ArrayHandle result; + dataSet.GetField("elevation").GetData().CopyTo(result); for (vtkm::Id i = 0; i < result.GetNumberOfValues(); ++i) { diff --git a/vtkm/worklet/testing/UnitTestStreamLineUniformGrid.cxx b/vtkm/worklet/testing/UnitTestStreamLineUniformGrid.cxx index 885765d3e..904a84ca2 100644 --- a/vtkm/worklet/testing/UnitTestStreamLineUniformGrid.cxx +++ b/vtkm/worklet/testing/UnitTestStreamLineUniformGrid.cxx @@ -42,7 +42,7 @@ vtkm::Vec Normalize(vtkm::Vec 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<> outCellSet; + outDataSet.GetCellSet(0).CopyTo(outCellSet); const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray = outDataSet.GetCoordinateSystem(0).GetData(); diff --git a/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx b/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx index 0de0b78f9..8a58afa92 100644 --- a/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx +++ b/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx @@ -185,7 +185,8 @@ void TestExplicitGrid2D() tetrahedralizeFilter(inDataSet, outDataSet); tetrahedralizeFilter.Run(); - vtkm::cont::CellSetSingleType<> cellSet = outDataSet.GetCellSet(0).CastTo >(); + 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<> 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; diff --git a/vtkm/worklet/testing/UnitTestTetrahedralizeUniformGrid.cxx b/vtkm/worklet/testing/UnitTestTetrahedralizeUniformGrid.cxx index f1c795c60..16957dfe3 100644 --- a/vtkm/worklet/testing/UnitTestTetrahedralizeUniformGrid.cxx +++ b/vtkm/worklet/testing/UnitTestTetrahedralizeUniformGrid.cxx @@ -108,11 +108,12 @@ void TestUniformGrid2D() outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); // Convert uniform hexahedra to tetrahedra - vtkm::worklet::TetrahedralizeFilterUniformGrid + vtkm::worklet::TetrahedralizeFilterUniformGrid tetrahedralizeFilter(inDataSet, outDataSet); tetrahedralizeFilter.Run(); - vtkm::cont::CellSetSingleType<> &cellSet = outDataSet.GetCellSet(0).CastTo >(); + 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 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 + vtkm::worklet::TetrahedralizeFilterUniformGrid tetrahedralizeFilter(inDataSet, outDataSet); tetrahedralizeFilter.Run(); - vtkm::cont::CellSetSingleType<> &cellSet = outDataSet.GetCellSet(0).CastTo >(); + 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 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; diff --git a/vtkm/worklet/testing/UnitTestThreshold.cxx b/vtkm/worklet/testing/UnitTestThreshold.cxx index 6e8e417d7..915f758d8 100644 --- a/vtkm/worklet/testing/UnitTestThreshold.cxx +++ b/vtkm/worklet/testing/UnitTestThreshold.cxx @@ -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, diff --git a/vtkm/worklet/testing/UnitTestVertexClustering.cxx b/vtkm/worklet/testing/UnitTestVertexClustering.cxx index 589cda39d..af217e11a 100644 --- a/vtkm/worklet/testing/UnitTestVertexClustering.cxx +++ b/vtkm/worklet/testing/UnitTestVertexClustering.cxx @@ -52,10 +52,8 @@ void TestVertexClustering() VTKM_TEST_ASSERT(outDataSet.GetNumberOfCoordinateSystems() == 1, "Number of output coordinate systems mismatch"); typedef vtkm::Vec PointType; - typedef vtkm::cont::ArrayHandle PointArray; - PointArray pointArray = - outDataSet.GetCoordinateSystem(0).GetData(). - CastToArrayHandle(); + vtkm::cont::ArrayHandle 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 cellSet; + outDataSet.GetCellSet(0).CopyTo(cellSet); VTKM_TEST_ASSERT( cellSet.GetConnectivityArray(vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell()).GetNumberOfValues() == output_pointIds, "Number of connectivity array elements mismatch"); diff --git a/vtkm/worklet/testing/UnitTestWorkletMapTopologyExplicit.cxx b/vtkm/worklet/testing/UnitTestWorkletMapTopologyExplicit.cxx index c99a1616e..11734f4a9 100644 --- a/vtkm/worklet/testing/UnitTestWorkletMapTopologyExplicit.cxx +++ b/vtkm/worklet/testing/UnitTestWorkletMapTopologyExplicit.cxx @@ -179,8 +179,7 @@ TestMaxPointOrCell() //Make sure we got the right answer. vtkm::cont::ArrayHandle 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 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 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"); diff --git a/vtkm/worklet/testing/UnitTestWorkletMapTopologyRegular.cxx b/vtkm/worklet/testing/UnitTestWorkletMapTopologyRegular.cxx index 2b5cdc0b3..c3d66449f 100644 --- a/vtkm/worklet/testing/UnitTestWorkletMapTopologyRegular.cxx +++ b/vtkm/worklet/testing/UnitTestWorkletMapTopologyRegular.cxx @@ -210,8 +210,7 @@ TestMaxPointOrCell() //make sure we got the right answer. vtkm::cont::ArrayHandle 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 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 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");