From e7456fa120d9294e224549447e79ba91cb425a55 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 15 Jan 2016 15:42:51 -0500 Subject: [PATCH] Update vtkm tests and examples to use DataSetBuilders. --- .../tetrahedra/TetrahedralizeExplicitGrid.cxx | 55 ++++----- .../tetrahedra/TriangulateExplicitGrid.cxx | 49 ++++---- vtkm/cont/CellSetExplicit.h | 46 ------- vtkm/cont/CellSetSingleType.h | 30 ----- vtkm/cont/testing/TestingDataSetSingleType.h | 44 +++---- .../testing/UnitTestDataSetPermutation.cxx | 41 +++---- vtkm/worklet/testing/UnitTestClipping.cxx | 63 +++++----- .../worklet/testing/UnitTestExternalFaces.cxx | 34 ++---- .../UnitTestTetrahedralizeExplicitGrid.cxx | 113 +++++++----------- 9 files changed, 166 insertions(+), 309 deletions(-) diff --git a/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx b/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx index 73ee4da6d..795ab2c30 100644 --- a/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx +++ b/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -66,33 +67,26 @@ int mouse_state = 1; // vtkm::cont::DataSet MakeTetrahedralizeExplicitDataSet() { - vtkm::cont::DataSet dataSet; - - const int nVerts = 18; typedef vtkm::Vec CoordType; - CoordType coordinates[nVerts] = { - CoordType(0, 0, 0), - CoordType(1, 0, 0), - CoordType(2, 0, 0), - CoordType(3, 0, 0), - CoordType(0, 1, 0), - CoordType(1, 1, 0), - CoordType(2, 1, 0), - CoordType(2.5, 1, 0), - CoordType(0, 2, 0), - CoordType(1, 2, 0), - CoordType(0.5, 0.5, 1), - CoordType(1, 0, 1), - CoordType(2, 0, 1), - CoordType(3, 0, 1), - CoordType(1, 1, 1), - CoordType(2, 1, 1), - CoordType(2.5, 1, 1), - CoordType(0.5, 1.5, 1), - }; - - dataSet.AddCoordinateSystem( - vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts)); + std::vector< CoordType > coordinates; + coordinates.push_back( CoordType(0, 0, 0) ); + coordinates.push_back( CoordType(1, 0, 0) ); + coordinates.push_back( CoordType(2, 0, 0) ); + coordinates.push_back( CoordType(3, 0, 0) ); + coordinates.push_back( CoordType(0, 1, 0) ); + coordinates.push_back( CoordType(1, 1, 0) ); + coordinates.push_back( CoordType(2, 1, 0) ); + coordinates.push_back( CoordType(2.5, 1, 0) ); + coordinates.push_back( CoordType(0, 2, 0) ); + coordinates.push_back( CoordType(1, 2, 0) ); + coordinates.push_back( CoordType(0.5, 0.5, 1) ); + coordinates.push_back( CoordType(1, 0, 1) ); + coordinates.push_back( CoordType(2, 0, 1) ); + coordinates.push_back( CoordType(3, 0, 1) ); + coordinates.push_back( CoordType(1, 1, 1) ); + coordinates.push_back( CoordType(2, 1, 1) ); + coordinates.push_back( CoordType(2.5, 1, 1) ); + coordinates.push_back( CoordType(0.5, 1.5, 1) ); std::vector shapes; shapes.push_back(vtkm::CELL_SHAPE_TETRA); @@ -134,13 +128,8 @@ vtkm::cont::DataSet MakeTetrahedralizeExplicitDataSet() conn.push_back(8); conn.push_back(17); - static const vtkm::IdComponent ndim = 3; - vtkm::cont::CellSetExplicit<> cellSet(nVerts, "cells", ndim); - cellSet.FillViaCopy(shapes, numindices, conn); - - dataSet.AddCellSet(cellSet); - - return dataSet; + vtkm::cont::DataSetBuilderExplicit builder; + return builder.Create(coordinates, shapes, numindices, conn); } // diff --git a/examples/tetrahedra/TriangulateExplicitGrid.cxx b/examples/tetrahedra/TriangulateExplicitGrid.cxx index f64b2fa64..cdc9df2dd 100644 --- a/examples/tetrahedra/TriangulateExplicitGrid.cxx +++ b/examples/tetrahedra/TriangulateExplicitGrid.cxx @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -63,27 +64,23 @@ vtkm::cont::DataSet MakeTriangulateExplicitDataSet() const int nVerts = 16; typedef vtkm::Vec CoordType; - CoordType coordinates[nVerts] = { - CoordType(0, 0, 0), // 0 - CoordType(1, 0, 0), // 1 - CoordType(2, 0, 0), // 2 - CoordType(3, 0, 0), // 3 - CoordType(0, 1, 0), // 4 - CoordType(1, 1, 0), // 5 - CoordType(2, 1, 0), // 6 - CoordType(3, 1, 0), // 7 - CoordType(0, 2, 0), // 8 - CoordType(1, 2, 0), // 9 - CoordType(2, 2, 0), // 10 - CoordType(3, 2, 0), // 11 - CoordType(0, 3, 0), // 12 - CoordType(3, 3, 0), // 13 - CoordType(1, 4, 0), // 14 - CoordType(2, 4, 0), // 15 - }; - - dataSet.AddCoordinateSystem( - vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts)); + std::vector< CoordType > coordinates; + coordinates.push_back( CoordType(0, 0, 0) ); // 0 + coordinates.push_back( CoordType(1, 0, 0) ); // 1 + coordinates.push_back( CoordType(2, 0, 0) ); // 2 + coordinates.push_back( CoordType(3, 0, 0) ); // 3 + coordinates.push_back( CoordType(0, 1, 0) ); // 4 + coordinates.push_back( CoordType(1, 1, 0) ); // 5 + coordinates.push_back( CoordType(2, 1, 0) ); // 6 + coordinates.push_back( CoordType(3, 1, 0) ); // 7 + coordinates.push_back( CoordType(0, 2, 0) ); // 8 + coordinates.push_back( CoordType(1, 2, 0) ); // 9 + coordinates.push_back( CoordType(2, 2, 0) ); // 10 + coordinates.push_back( CoordType(3, 2, 0) ); // 11 + coordinates.push_back( CoordType(0, 3, 0) ); // 12 + coordinates.push_back( CoordType(3, 3, 0) ); // 13 + coordinates.push_back( CoordType(1, 4, 0) ); // 14 + coordinates.push_back( CoordType(2, 4, 0) ); // 15 std::vector shapes; shapes.push_back(vtkm::CELL_SHAPE_TRIANGLE); @@ -139,13 +136,9 @@ vtkm::cont::DataSet MakeTriangulateExplicitDataSet() conn.push_back(14); conn.push_back(12); - static const vtkm::IdComponent ndim = 2; - vtkm::cont::CellSetExplicit<> cellSet(nVerts, "cells", ndim); - cellSet.FillViaCopy(shapes, numindices, conn); - - dataSet.AddCellSet(cellSet); - - return dataSet; + vtkm::cont::DataSet ds; + vtkm::cont::DataSetBuilderExplicit builder; + return builder.Create(coordinates, shapes, numindices, conn); } // diff --git a/vtkm/cont/CellSetExplicit.h b/vtkm/cont/CellSetExplicit.h index 166c40f4c..4a089f0e7 100644 --- a/vtkm/cont/CellSetExplicit.h +++ b/vtkm/cont/CellSetExplicit.h @@ -236,52 +236,6 @@ public: this->NumberOfCells = this->ConnectivityLength = -1; } - /// Second method to add cells -- all at once. - /// Copies the data from the vectors, so they can be released. - VTKM_CONT_EXPORT - void FillViaCopy(const std::vector &cellTypes, - const std::vector &numIndices, - const std::vector &connectivity, - const std::vector &offsets = std::vector() ) - { - - this->PointToCell.Shapes.Allocate( static_cast(cellTypes.size()) ); - std::copy(cellTypes.begin(), cellTypes.end(), - vtkm::cont::ArrayPortalToIteratorBegin( - this->PointToCell.Shapes.GetPortalControl())); - - this->PointToCell.NumIndices.Allocate( static_cast(numIndices.size()) ); - std::copy(numIndices.begin(), numIndices.end(), - vtkm::cont::ArrayPortalToIteratorBegin( - this->PointToCell.NumIndices.GetPortalControl())); - - this->PointToCell.Connectivity.Allocate( static_cast(connectivity.size()) ); - std::copy(connectivity.begin(), connectivity.end(), - vtkm::cont::ArrayPortalToIteratorBegin( - this->PointToCell.Connectivity.GetPortalControl())); - - this->PointToCell.ElementsValid = true; - - if(offsets.size() == cellTypes.size()) - { - this->PointToCell.IndexOffsets.Allocate( static_cast(offsets.size()) ); - std::copy(offsets.begin(), offsets.end(), - vtkm::cont::ArrayPortalToIteratorBegin( - this->PointToCell.IndexOffsets.GetPortalControl())); - this->PointToCell.IndexOffsetsValid = true; - } - else - { - this->PointToCell.IndexOffsetsValid = false; - if (offsets.size() != 0) - { - throw vtkm::cont::ErrorControlBadValue( - "Explicit cell offsets array unexpected size. " - "Use an empty array to automatically generate."); - } - } - } - /// Second method to add cells -- all at once. /// Assigns the array handles to the explicit connectivity. This is /// the way you can fill the memory from another system without copying diff --git a/vtkm/cont/CellSetSingleType.h b/vtkm/cont/CellSetSingleType.h index 25e66e786..ed92e4b28 100644 --- a/vtkm/cont/CellSetSingleType.h +++ b/vtkm/cont/CellSetSingleType.h @@ -154,36 +154,6 @@ public: this->PointToCell.IndexOffsetsValid = true; } - /// Second method to add cells -- all at once. - /// Copies the data from the vectors, so they can be released. - VTKM_CONT_EXPORT - void FillViaCopy(const std::vector &connectivity) - { - vtkm::IdComponent numberOfPointsPerCell = this->DetermineNumberOfPoints(); - const vtkm::Id connectSize = static_cast(connectivity.size()); - - const vtkm::Id length = connectSize / numberOfPointsPerCell; - const vtkm::UInt8 shapeTypeValue = static_cast(this->CellTypeAsId); - this->PointToCell.Shapes = - vtkm::cont::make_ArrayHandleConstant(shapeTypeValue, length); - this->PointToCell.NumIndices = - vtkm::cont::make_ArrayHandleConstant(numberOfPointsPerCell, - length); - this->PointToCell.IndexOffsets = - vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), - static_cast(numberOfPointsPerCell), - length ); - - - this->PointToCell.Connectivity.Allocate( connectSize ); - std::copy(connectivity.begin(), connectivity.end(), - vtkm::cont::ArrayPortalToIteratorBegin( - this->PointToCell.Connectivity.GetPortalControl())); - - this->PointToCell.ElementsValid = true; - this->PointToCell.IndexOffsetsValid = true; - } - private: template< typename CellShapeTag> void DetermineNumberOfPoints(CellShapeTag, diff --git a/vtkm/cont/testing/TestingDataSetSingleType.h b/vtkm/cont/testing/TestingDataSetSingleType.h index 2c0b3cabb..fc28dc7af 100644 --- a/vtkm/cont/testing/TestingDataSetSingleType.h +++ b/vtkm/cont/testing/TestingDataSetSingleType.h @@ -23,6 +23,8 @@ #include #include +#include +#include #include #include @@ -62,27 +64,13 @@ private: static inline vtkm::cont::DataSet make_SingleTypeDataSet() { - using vtkm::cont::Field; - - vtkm::cont::DataSet dataSet; - - const int nVerts = 5; typedef vtkm::Vec CoordType; - CoordType coordinates[nVerts] = { - CoordType(0, 0, 0), - CoordType(1, 0, 0), - CoordType(1, 1, 0), - CoordType(2, 1, 0), - CoordType(2, 2, 0) - }; - - //Set coordinate system - dataSet.AddCoordinateSystem( - vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts)); - - //Set point scalar - vtkm::Float32 vars[nVerts] = {10.1f, 20.1f, 30.2f, 40.2f, 50.3f}; - dataSet.AddField(Field("pointvar", 1, vtkm::cont::Field::ASSOC_POINTS, vars, nVerts)); + std::vector< CoordType > coordinates; + coordinates.push_back( CoordType(0, 0, 0) ); + coordinates.push_back( CoordType(1, 0, 0) ); + coordinates.push_back( CoordType(1, 1, 0) ); + coordinates.push_back( CoordType(2, 1, 0) ); + coordinates.push_back( CoordType(2, 2, 0) ); std::vector conn; // First Cell @@ -98,13 +86,19 @@ private: conn.push_back(3); conn.push_back(4); - vtkm::cont::CellSetSingleType<> cellSet(vtkm::CellShapeTagTriangle(), - "cells"); - cellSet.FillViaCopy(conn); + vtkm::cont::DataSet ds; + vtkm::cont::DataSetBuilderExplicit builder; + ds = builder.Create(coordinates, vtkm::CellShapeTagTriangle(), conn); - dataSet.AddCellSet(cellSet); - return dataSet; + //Set point scalar + const int nVerts = 5; + vtkm::Float32 vars[nVerts] = {10.1f, 20.1f, 30.2f, 40.2f, 50.3f}; + + vtkm::cont::DataSetFieldAdd fieldAdder; + fieldAdder.AddPointField(ds, "pointvar", vars, nVerts); + + return ds; } static void TestDataSet_SingleType() diff --git a/vtkm/cont/testing/UnitTestDataSetPermutation.cxx b/vtkm/cont/testing/UnitTestDataSetPermutation.cxx index 8342056b8..691ce5a4d 100644 --- a/vtkm/cont/testing/UnitTestDataSetPermutation.cxx +++ b/vtkm/cont/testing/UnitTestDataSetPermutation.cxx @@ -54,27 +54,13 @@ bool TestArrayHandle(const vtkm::cont::ArrayHandle &ah, const T *exp inline vtkm::cont::DataSet make_SingleTypeDataSet() { - using vtkm::cont::Field; - - vtkm::cont::DataSet dataSet; - - const int nVerts = 5; typedef vtkm::Vec CoordType; - CoordType coordinates[nVerts] = { - CoordType(0, 0, 0), - CoordType(1, 0, 0), - CoordType(1, 1, 0), - CoordType(2, 1, 0), - CoordType(2, 2, 0) - }; - - //Set coordinate system - dataSet.AddCoordinateSystem( - vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts)); - - //Set point scalar - vtkm::Float32 vars[nVerts] = {10.1f, 20.1f, 30.2f, 40.2f, 50.3f}; - dataSet.AddField(Field("pointvar", 1, vtkm::cont::Field::ASSOC_POINTS, vars, nVerts)); + std::vector< CoordType > coordinates; + coordinates.push_back( CoordType(0, 0, 0) ); + coordinates.push_back( CoordType(1, 0, 0) ); + coordinates.push_back( CoordType(1, 1, 0) ); + coordinates.push_back( CoordType(2, 1, 0) ); + coordinates.push_back( CoordType(2, 2, 0) ); std::vector conn; // First Cell @@ -90,13 +76,18 @@ inline vtkm::cont::DataSet make_SingleTypeDataSet() conn.push_back(3); conn.push_back(4); - vtkm::cont::CellSetSingleType<> cellSet(vtkm::CellShapeTagTriangle(), - "cells"); - cellSet.FillViaCopy(conn); + vtkm::cont::DataSet ds; + vtkm::cont::DataSetBuilderExplicit builder; + ds = builder.Create(coordinates, vtkm::CellShapeTagTriangle(), conn); - dataSet.AddCellSet(cellSet); + //Set point scalar + const int nVerts = 5; + vtkm::Float32 vars[nVerts] = {10.1f, 20.1f, 30.2f, 40.2f, 50.3f}; - return dataSet; + vtkm::cont::DataSetFieldAdd fieldAdder; + fieldAdder.AddPointField(ds, "pointvar", vars, nVerts); + + return ds; } void TestDataSet_Explicit() diff --git a/vtkm/worklet/testing/UnitTestClipping.cxx b/vtkm/worklet/testing/UnitTestClipping.cxx index 5faa1b722..de20d642a 100644 --- a/vtkm/worklet/testing/UnitTestClipping.cxx +++ b/vtkm/worklet/testing/UnitTestClipping.cxx @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -58,42 +61,39 @@ bool TestArrayHandle(const vtkm::cont::ArrayHandle &ah, const T *exp vtkm::cont::DataSet MakeTestDatasetExplicit() { - static const vtkm::Id numVerts = 4; - static const vtkm::Id numCells = 2; - static const Coord3D coords[numVerts] = { - Coord3D(0.0f, 0.0f, 0.0f), - Coord3D(1.0f, 0.0f, 0.0f), - Coord3D(1.0f, 1.0f, 0.0f), - Coord3D(0.0f, 1.0f, 0.0f), - }; - static vtkm::Float32 values[] = { 1.0, 2.0, 1.0, 0.0 }; - static vtkm::UInt8 shapes[] = { vtkm::CELL_SHAPE_TRIANGLE, vtkm::CELL_SHAPE_TRIANGLE }; - static vtkm::IdComponent numInds[] = { 3, 3 }; - static vtkm::Id connectivity[] = { 0, 1, 3, 3, 1, 2 }; + std::vector coords; + coords.push_back( Coord3D(0.0f, 0.0f, 0.0f) ); + coords.push_back( Coord3D(1.0f, 0.0f, 0.0f) ); + coords.push_back( Coord3D(1.0f, 1.0f, 0.0f) ); + coords.push_back( Coord3D(0.0f, 1.0f, 0.0f) ); + + std::vector connectivity; + connectivity.push_back(0); + connectivity.push_back(1); + connectivity.push_back(3); + connectivity.push_back(3); + connectivity.push_back(1); + connectivity.push_back(2); vtkm::cont::DataSet ds; - ds.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", 1, coords, numVerts)); - ds.AddField(vtkm::cont::Field("scalars", 1, vtkm::cont::Field::ASSOC_POINTS, values, - numVerts)); + vtkm::cont::DataSetBuilderExplicit builder; + ds = builder.Create(coords, vtkm::CellShapeTagTriangle(), connectivity); - std::vector shapesVec(shapes, shapes + numCells); - std::vector numIndsVec(numInds, numInds + numCells); - std::vector connectivityVec(connectivity, connectivity + (numCells * 3)); - - vtkm::cont::CellSetExplicit<> cs(numVerts, "cells", 3); - cs.FillViaCopy(shapesVec, numIndsVec, connectivityVec); - - ds.AddCellSet(cs); + std::vector values; + values.push_back(1.0); + values.push_back(2.0); + values.push_back(1.0); + values.push_back(0.0); + vtkm::cont::DataSetFieldAdd fieldAdder; + fieldAdder.AddPointField(ds, "scalars", values); return ds; } vtkm::cont::DataSet MakeTestDatasetStructured() { - static const vtkm::Vec origin(0.0f, 0.0f, 0.0f); - static const vtkm::Vec spacing(1.0f, 1.0f, 1.0f); static const vtkm::Id xdim = 3, ydim = 3; - static const vtkm::Id3 dim(xdim, ydim, 1); + static const vtkm::Id2 dim(xdim, ydim); static const vtkm::Id numVerts = xdim * ydim; vtkm::Float32 scalars[numVerts]; @@ -104,14 +104,11 @@ vtkm::cont::DataSet MakeTestDatasetStructured() scalars[4] = 0.0f; vtkm::cont::DataSet ds; - ds.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", 1, dim, origin, spacing)); + vtkm::cont::DataSetBuilderRegular builder; + ds = builder.Create(dim); - ds.AddField(vtkm::cont::Field("scalars", 1, vtkm::cont::Field::ASSOC_POINTS, - scalars, numVerts)); - - vtkm::cont::CellSetStructured<2> cs("cells"); - cs.SetPointDimensions(vtkm::make_Vec(dim[0], dim[1])); - ds.AddCellSet(cs); + vtkm::cont::DataSetFieldAdd fieldAdder; + fieldAdder.AddPointField(ds, "scalars", scalars, numVerts); return ds; } diff --git a/vtkm/worklet/testing/UnitTestExternalFaces.cxx b/vtkm/worklet/testing/UnitTestExternalFaces.cxx index b86957abf..fad1cb823 100644 --- a/vtkm/worklet/testing/UnitTestExternalFaces.cxx +++ b/vtkm/worklet/testing/UnitTestExternalFaces.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -70,24 +71,18 @@ vtkm::cont::DataSet RunExternalFaces(vtkm::cont::DataSet &ds) void TestExternalFaces() { //--------------Construct a VTK-m Test Dataset---------------- - - vtkm::cont::DataSet ds; - const int nVerts = 8; //A cube that is tetrahedralized typedef vtkm::Vec CoordType; - CoordType coordinates[nVerts] = { - CoordType(0, 0, 0), - CoordType(1, 0, 0), - CoordType(1, 1, 0), - CoordType(0, 1, 0), - CoordType(0, 0, 1), - CoordType(1, 0, 1), - CoordType(1, 1, 1), - CoordType(0, 1, 1) - }; - - ds.AddCoordinateSystem( - vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts)); + vtkm::cont::ArrayHandle< CoordType > coordinates; + coordinates.Allocate(nVerts); + coordinates.GetPortalControl().Set(0, CoordType(0.0f, 0.0f, 0.0f) ); + coordinates.GetPortalControl().Set(1, CoordType(1.0f, 0.0f, 0.0f) ); + coordinates.GetPortalControl().Set(2, CoordType(1.0f, 1.0f, 0.0f) ); + coordinates.GetPortalControl().Set(3, CoordType(0.0f, 1.0f, 0.0f) ); + coordinates.GetPortalControl().Set(4, CoordType(0.0f, 0.0f, 1.0f) ); + coordinates.GetPortalControl().Set(5, CoordType(1.0f, 0.0f, 1.0f) ); + coordinates.GetPortalControl().Set(6, CoordType(1.0f, 1.0f, 1.0f) ); + coordinates.GetPortalControl().Set(7, CoordType(0.0f, 1.0f, 1.0f) ); //Construct the VTK-m shapes and numIndices connectivity arrays const int nCells = 6; //The tetrahedrons of the cube @@ -95,7 +90,6 @@ void TestExternalFaces() {4,7,6,3}, {4,6,3,2}, {4,0,3,2}, {4,6,5,2}, {4,5,0,2}, {1,0,5,2} }; - vtkm::cont::CellSetExplicit<> cs(nVerts, "cells", nCells); vtkm::cont::ArrayHandle shapes; vtkm::cont::ArrayHandle numIndices; @@ -113,10 +107,8 @@ void TestExternalFaces() conn.GetPortalControl().Set(index++, cellVerts[j][k]); } - cs.Fill(shapes, numIndices, conn); - - //Add the VTK-m cell set - ds.AddCellSet(cs); + vtkm::cont::DataSetBuilderExplicit builder; + vtkm::cont::DataSet ds = builder.Create(coordinates, shapes, numIndices, conn); //Run the External Faces worklet vtkm::cont::DataSet new_ds = RunExternalFaces(ds); diff --git a/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx b/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx index 6e4328fb2..12de07f3f 100644 --- a/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx +++ b/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx @@ -22,6 +22,7 @@ #include #include +#include #include namespace { @@ -31,32 +32,25 @@ namespace { // vtkm::cont::DataSet MakeTriangulateExplicitDataSet() { - vtkm::cont::DataSet dataSet; - - const int nVerts = 16; typedef vtkm::Vec CoordType; - CoordType coordinates[nVerts] = - { - CoordType(0, 0, 0), // 0 - CoordType(1, 0, 0), // 1 - CoordType(2, 0, 0), // 2 - CoordType(3, 0, 0), // 3 - CoordType(0, 1, 0), // 4 - CoordType(1, 1, 0), // 5 - CoordType(2, 1, 0), // 6 - CoordType(3, 1, 0), // 7 - CoordType(0, 2, 0), // 8 - CoordType(1, 2, 0), // 9 - CoordType(2, 2, 0), // 10 - CoordType(3, 2, 0), // 11 - CoordType(0, 3, 0), // 12 - CoordType(3, 3, 0), // 13 - CoordType(1, 4, 0), // 14 - CoordType(2, 4, 0), // 15 - }; + std::vector coordinates; + coordinates.push_back( CoordType(0, 0, 0) ); // 0 + coordinates.push_back( CoordType(1, 0, 0) ); // 1 + coordinates.push_back( CoordType(2, 0, 0) ); // 2 + coordinates.push_back( CoordType(3, 0, 0) ); // 3 + coordinates.push_back( CoordType(0, 1, 0) ); // 4 + coordinates.push_back( CoordType(1, 1, 0) ); // 5 + coordinates.push_back( CoordType(2, 1, 0) ); // 6 + coordinates.push_back( CoordType(3, 1, 0) ); // 7 + coordinates.push_back( CoordType(0, 2, 0) ); // 8 + coordinates.push_back( CoordType(1, 2, 0) ); // 9 + coordinates.push_back( CoordType(2, 2, 0) ); // 10 + coordinates.push_back( CoordType(3, 2, 0) ); // 11 + coordinates.push_back( CoordType(0, 3, 0) ); // 12 + coordinates.push_back( CoordType(3, 3, 0) ); // 13 + coordinates.push_back( CoordType(1, 4, 0) ); // 14 + coordinates.push_back( CoordType(2, 4, 0) ); // 15 - dataSet.AddCoordinateSystem( - vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts)); std::vector shapes; shapes.push_back(vtkm::CELL_SHAPE_TRIANGLE); @@ -112,13 +106,8 @@ vtkm::cont::DataSet MakeTriangulateExplicitDataSet() conn.push_back(14); conn.push_back(12); - static const vtkm::IdComponent ndim = 2; - vtkm::cont::CellSetExplicit<> cellSet(nVerts, "cells", ndim); - cellSet.FillViaCopy(shapes, numindices, conn); - - dataSet.AddCellSet(cellSet); - - return dataSet; + vtkm::cont::DataSetBuilderExplicit builder; + return builder.Create(coordinates, shapes, numindices, conn); } // @@ -126,34 +115,26 @@ vtkm::cont::DataSet MakeTriangulateExplicitDataSet() // vtkm::cont::DataSet MakeTetrahedralizeExplicitDataSet() { - vtkm::cont::DataSet dataSet; - - const int nVerts = 18; typedef vtkm::Vec CoordType; - CoordType coordinates[nVerts] = - { - CoordType(0, 0, 0), - CoordType(1, 0, 0), - CoordType(2, 0, 0), - CoordType(3, 0, 0), - CoordType(0, 1, 0), - CoordType(1, 1, 0), - CoordType(2, 1, 0), - CoordType(2.5, 1, 0), - CoordType(0, 2, 0), - CoordType(1, 2, 0), - CoordType(0.5, 0.5, 1), - CoordType(1, 0, 1), - CoordType(2, 0, 1), - CoordType(3, 0, 1), - CoordType(1, 1, 1), - CoordType(2, 1, 1), - CoordType(2.5, 1, 1), - CoordType(0.5, 1.5, 1), - }; - - dataSet.AddCoordinateSystem( - vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts)); + std::vector coordinates; + coordinates.push_back( CoordType(0, 0, 0) ); + coordinates.push_back( CoordType(1, 0, 0) ); + coordinates.push_back( CoordType(2, 0, 0) ); + coordinates.push_back( CoordType(3, 0, 0) ); + coordinates.push_back( CoordType(0, 1, 0) ); + coordinates.push_back( CoordType(1, 1, 0) ); + coordinates.push_back( CoordType(2, 1, 0) ); + coordinates.push_back( CoordType(2.5, 1, 0) ); + coordinates.push_back( CoordType(0, 2, 0) ); + coordinates.push_back( CoordType(1, 2, 0) ); + coordinates.push_back( CoordType(0.5, 0.5, 1) ); + coordinates.push_back( CoordType(1, 0, 1) ); + coordinates.push_back( CoordType(2, 0, 1) ); + coordinates.push_back( CoordType(3, 0, 1) ); + coordinates.push_back( CoordType(1, 1, 1) ); + coordinates.push_back( CoordType(2, 1, 1) ); + coordinates.push_back( CoordType(2.5, 1, 1) ); + coordinates.push_back( CoordType(0.5, 1.5, 1) ); std::vector shapes; shapes.push_back(vtkm::CELL_SHAPE_TETRA); @@ -195,13 +176,9 @@ vtkm::cont::DataSet MakeTetrahedralizeExplicitDataSet() conn.push_back(8); conn.push_back(17); - static const vtkm::IdComponent ndim = 3; - vtkm::cont::CellSetExplicit<> cellSet(nVerts, "cells", ndim); - cellSet.FillViaCopy(shapes, numindices, conn); + vtkm::cont::DataSetBuilderExplicit builder; + return builder.Create(coordinates, shapes, numindices, conn); - dataSet.AddCellSet(cellSet); - - return dataSet; } } @@ -226,7 +203,7 @@ void TestExplicitGrid2D() outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); // Convert explicit cells to triangles - vtkm::worklet::TetrahedralizeFilterExplicitGrid + vtkm::worklet::TetrahedralizeFilterExplicitGrid tetrahedralizeFilter(inDataSet, outDataSet); tetrahedralizeFilter.Run(); @@ -238,7 +215,7 @@ void TestExplicitGrid2D() 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) << ")" << std::endl; @@ -265,7 +242,7 @@ void TestExplicitGrid3D() outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); // Convert explicit cells to triangles - vtkm::worklet::TetrahedralizeFilterExplicitGrid + vtkm::worklet::TetrahedralizeFilterExplicitGrid tetrahedralizeFilter(inDataSet, outDataSet); tetrahedralizeFilter.Run(); @@ -277,7 +254,7 @@ void TestExplicitGrid3D() 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;