diff --git a/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx b/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx index d6665c642..bfad811e5 100644 --- a/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx +++ b/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx @@ -305,8 +305,7 @@ int main(int argc, char* argv[]) numberOfInPoints = inCellSet.GetNumberOfPoints(); // Create the output dataset explicit cell set with same coordinate system - vtkm::cont::CellSetSingleType<> cellSet( - vtkm::CellShapeTagTetra(), numberOfInPoints, "cells"); + vtkm::cont::CellSetSingleType<> cellSet("cells"); outDataSet.AddCellSet(cellSet); outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); diff --git a/examples/tetrahedra/TetrahedralizeUniformGrid.cxx b/examples/tetrahedra/TetrahedralizeUniformGrid.cxx index 47d7f26f9..12b23bf46 100644 --- a/examples/tetrahedra/TetrahedralizeUniformGrid.cxx +++ b/examples/tetrahedra/TetrahedralizeUniformGrid.cxx @@ -293,8 +293,7 @@ int main(int argc, char* argv[]) numberOfInPoints = (dims[0] + 1) * (dims[1] + 1) * (dims[2] + 1); // Create the output dataset explicit cell set with same coordinate system - vtkm::cont::CellSetSingleType<> cellSet( - vtkm::CellShapeTagTetra(), numberOfInPoints, "cells"); + vtkm::cont::CellSetSingleType<> cellSet("cells"); tetDataSet.AddCellSet(cellSet); tetDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); diff --git a/examples/tetrahedra/TriangulateExplicitGrid.cxx b/examples/tetrahedra/TriangulateExplicitGrid.cxx index 0305ac74c..b1f7304b0 100644 --- a/examples/tetrahedra/TriangulateExplicitGrid.cxx +++ b/examples/tetrahedra/TriangulateExplicitGrid.cxx @@ -226,7 +226,7 @@ int main(int argc, char* argv[]) numberOfInPoints = inCellSet.GetNumberOfPoints(); // Create the output dataset explicit cell set with same coordinate system - vtkm::cont::CellSetSingleType<> cellSet(vtkm::CellShapeTagTriangle(), "cells");; + vtkm::cont::CellSetSingleType<> cellSet("cells");; outDataSet.AddCellSet(cellSet); outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); diff --git a/examples/tetrahedra/TriangulateUniformGrid.cxx b/examples/tetrahedra/TriangulateUniformGrid.cxx index b80a68231..07d9c62bc 100644 --- a/examples/tetrahedra/TriangulateUniformGrid.cxx +++ b/examples/tetrahedra/TriangulateUniformGrid.cxx @@ -201,7 +201,7 @@ int main(int argc, char* argv[]) vtkm::cont::DataSet inDataSet = MakeTriangulateTestDataSet(dims); // Create the output dataset explicit cell set with same coordinate system - vtkm::cont::CellSetSingleType<> cellSet(vtkm::CellShapeTagTriangle(), "cells"); + vtkm::cont::CellSetSingleType<> cellSet("cells"); tetDataSet.AddCellSet(cellSet); tetDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); diff --git a/vtkm/cont/CellSetExplicit.h b/vtkm/cont/CellSetExplicit.h index 517ca01c0..71b32f785 100644 --- a/vtkm/cont/CellSetExplicit.h +++ b/vtkm/cont/CellSetExplicit.h @@ -106,12 +106,11 @@ public: typedef typename PointToCellConnectivityType::IndexOffsetArrayType IndexOffsetArrayType; VTKM_CONT - CellSetExplicit(vtkm::Id numpoints = 0, - const std::string &name = std::string()) + CellSetExplicit(const std::string &name = std::string()) : CellSet(name), - ConnectivityLength(-1), - NumberOfCells(-1), - NumberOfPoints(numpoints) + ConnectivityAdded(-1), + NumberOfCellsAdded(-1), + NumberOfPoints(0) { } @@ -120,8 +119,8 @@ public: : CellSet(src), PointToCell(src.PointToCell), CellToPoint(src.CellToPoint), - ConnectivityLength(src.ConnectivityLength), - NumberOfCells(src.NumberOfCells), + ConnectivityAdded(src.ConnectivityAdded), + NumberOfCellsAdded(src.NumberOfCellsAdded), NumberOfPoints(src.NumberOfPoints) { } @@ -131,8 +130,8 @@ public: this->CellSet::operator=(src); this->PointToCell = src.PointToCell; this->CellToPoint = src.CellToPoint; - this->ConnectivityLength = src.ConnectivityLength; - this->NumberOfCells = src.NumberOfCells; + this->ConnectivityAdded = src.ConnectivityAdded; + this->NumberOfCellsAdded = src.NumberOfCellsAdded; this->NumberOfPoints = src.NumberOfPoints; return *this; } @@ -168,7 +167,7 @@ public: } VTKM_CONT - vtkm::Id GetCellShape(vtkm::Id cellIndex) const + vtkm::UInt8 GetCellShape(vtkm::Id cellIndex) const { return this->PointToCell.Shapes.GetPortalConstControl().Get(cellIndex); } @@ -188,54 +187,88 @@ public: /// First method to add cells -- one at a time. VTKM_CONT - void PrepareToAddCells(vtkm::Id numShapes, vtkm::Id connectivityMaxLen) + void PrepareToAddCells(vtkm::Id numCells, vtkm::Id connectivityMaxLen) { - this->PointToCell.Shapes.Allocate(numShapes); - this->PointToCell.NumIndices.Allocate(numShapes); + this->PointToCell.Shapes.Allocate(numCells); + this->PointToCell.NumIndices.Allocate(numCells); this->PointToCell.Connectivity.Allocate(connectivityMaxLen); - this->PointToCell.IndexOffsets.Allocate(numShapes); - this->NumberOfCells = 0; - this->ConnectivityLength = 0; + this->PointToCell.IndexOffsets.Allocate(numCells); + this->NumberOfCellsAdded = 0; + this->ConnectivityAdded = 0; } - template + template VTKM_CONT void AddCell(vtkm::UInt8 cellType, vtkm::IdComponent numVertices, - const IndexableType &ids) + const IdVecType &ids) { - this->PointToCell.Shapes.GetPortalControl().Set(this->NumberOfCells, cellType); - this->PointToCell.NumIndices.GetPortalControl().Set(this->NumberOfCells, numVertices); - for (vtkm::IdComponent i=0; i < numVertices; ++i) + using Traits = vtkm::VecTraits; + VTKM_STATIC_ASSERT_MSG( + (std::is_same::value), + "CellSetSingleType::AddCell requires vtkm::Id for indices."); + + if (Traits::GetNumberOfComponents(ids) < numVertices) + { + throw vtkm::cont::ErrorControlBadValue( + "Not enough indices given to CellSetSingleType::AddCell."); + } + + if (this->NumberOfCellsAdded >= this->PointToCell.Shapes.GetNumberOfValues()) + { + throw vtkm::cont::ErrorControlBadValue( + "Added more cells then expected."); + } + if (this->ConnectivityAdded+numVertices > + this->PointToCell.Connectivity.GetNumberOfValues()) + { + throw vtkm::cont::ErrorControlBadValue( + "Connectivity increased passed estimated maximum connectivity."); + } + + this->PointToCell.Shapes.GetPortalControl().Set(this->NumberOfCellsAdded, cellType); + this->PointToCell.NumIndices.GetPortalControl().Set(this->NumberOfCellsAdded, numVertices); + for (vtkm::IdComponent iVec=0; iVec < numVertices; ++iVec) { this->PointToCell.Connectivity.GetPortalControl().Set( - this->ConnectivityLength+i,ids[i]); + this->ConnectivityAdded+iVec, Traits::GetComponent(ids,iVec)); } this->PointToCell.IndexOffsets.GetPortalControl().Set( - this->NumberOfCells, this->ConnectivityLength); - this->NumberOfCells++; - this->ConnectivityLength += numVertices; + this->NumberOfCellsAdded, this->ConnectivityAdded); + this->NumberOfCellsAdded++; + this->ConnectivityAdded += numVertices; } VTKM_CONT - void CompleteAddingCells() + void CompleteAddingCells(vtkm::Id numPoints) { - this->PointToCell.Connectivity.Shrink(ConnectivityLength); + this->NumberOfPoints = numPoints; + this->PointToCell.Connectivity.Shrink(ConnectivityAdded); this->PointToCell.ElementsValid = true; this->PointToCell.IndexOffsetsValid = true; - this->NumberOfCells = this->ConnectivityLength = -1; + + if (this->NumberOfCellsAdded != this->GetNumberOfCells()) + { + throw vtkm::cont::ErrorControlBadValue( + "Did not add as many cells as expected."); + } + + this->NumberOfCellsAdded = -1; + this->ConnectivityAdded = -1; } /// 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 VTKM_CONT - void Fill(const vtkm::cont::ArrayHandle &cellTypes, + void Fill(vtkm::Id numPoints, + const vtkm::cont::ArrayHandle &cellTypes, const vtkm::cont::ArrayHandle &numIndices, const vtkm::cont::ArrayHandle &connectivity, const vtkm::cont::ArrayHandle &offsets = vtkm::cont::ArrayHandle() ) { + this->NumberOfPoints = numPoints; this->PointToCell.Shapes = cellTypes; this->PointToCell.NumIndices = numIndices; this->PointToCell.Connectivity = connectivity; @@ -509,8 +542,8 @@ protected: // These are used in the AddCell and related methods to incrementally add // cells. They need to be protected as subclasses of CellSetExplicit // need to set these values when implementing Fill() - vtkm::Id ConnectivityLength; - vtkm::Id NumberOfCells; + vtkm::Id ConnectivityAdded; + vtkm::Id NumberOfCellsAdded; vtkm::Id NumberOfPoints; }; diff --git a/vtkm/cont/CellSetSingleType.h b/vtkm/cont/CellSetSingleType.h index 457e154b0..cd1d0fa67 100644 --- a/vtkm/cont/CellSetSingleType.h +++ b/vtkm/cont/CellSetSingleType.h @@ -54,47 +54,29 @@ class CellSetSingleType : public: - template - VTKM_CONT - CellSetSingleType(CellShapeTag, vtkm::Id numpoints, const std::string &name = std::string()) - : Superclass(numpoints, name), - CellTypeAsId(CellShapeTag::Id) - { - } - - template - VTKM_CONT - CellSetSingleType(CellShapeTag, const std::string &name = std::string()) - : Superclass(0, name), - CellTypeAsId(CellShapeTag::Id) - { - } - - VTKM_CONT - CellSetSingleType(vtkm::Id numpoints, - const std::string &name = std::string()) - : Superclass(numpoints, name), - CellTypeAsId(CellShapeTagEmpty::Id) - { - } - VTKM_CONT CellSetSingleType(const std::string &name = std::string()) - : Superclass(0, name), - CellTypeAsId(CellShapeTagEmpty::Id) + : Superclass(name), + ExpectedNumberOfCellsAdded(-1), + CellShapeAsId(CellShapeTagEmpty::Id), + NumberOfPointsPerCell(0) { } VTKM_CONT CellSetSingleType(const Thisclass &src) - : Superclass(src), CellTypeAsId(src.CellTypeAsId) + : Superclass(src), + ExpectedNumberOfCellsAdded(-1), + CellShapeAsId(src.CellShapeAsId), + NumberOfPointsPerCell(src.NumberOfPointsPerCell) { } VTKM_CONT Thisclass &operator=(const Thisclass &src) { this->Superclass::operator=(src); - this->CellTypeAsId = src.CellTypeAsId; + this->CellShapeAsId = src.CellShapeAsId; + this->NumberOfPointsPerCell = src.NumberOfPointsPerCell; return *this; } @@ -102,69 +84,133 @@ public: /// First method to add cells -- one at a time. VTKM_CONT - void PrepareToAddCells(vtkm::Id numShapes, vtkm::Id connectivityMaxLen) + void PrepareToAddCells(vtkm::Id numCells, + vtkm::Id connectivityMaxLen) { - vtkm::IdComponent numberOfPointsPerCell = this->DetermineNumberOfPoints(); - const vtkm::UInt8 shapeTypeValue = static_cast(this->CellTypeAsId); - this->PointToCell.Shapes = - vtkm::cont::make_ArrayHandleConstant(shapeTypeValue, numShapes); - this->PointToCell.NumIndices = - vtkm::cont::make_ArrayHandleConstant(numberOfPointsPerCell, - numShapes); - this->PointToCell.IndexOffsets = - vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), - static_cast(numberOfPointsPerCell), - numShapes ); + this->CellShapeAsId = vtkm::CELL_SHAPE_EMPTY; this->PointToCell.Connectivity.Allocate(connectivityMaxLen); - this->NumberOfCells = 0; - this->ConnectivityLength = 0; + this->NumberOfCellsAdded = 0; + this->ConnectivityAdded = 0; + this->ExpectedNumberOfCellsAdded = numCells; } /// Second method to add cells -- one at a time. - template + template VTKM_CONT - void AddCell(vtkm::UInt8 vtkmNotUsed(cellType), + void AddCell(vtkm::UInt8 shapeId, vtkm::IdComponent numVertices, - const vtkm::Vec &ids) + const IdVecType &ids) { - for (vtkm::IdComponent i=0; i < numVertices; ++i) + using Traits = vtkm::VecTraits; + VTKM_STATIC_ASSERT_MSG( + (std::is_same::value), + "CellSetSingleType::AddCell requires vtkm::Id for indices."); + + if (Traits::GetNumberOfComponents(ids) < numVertices) + { + throw vtkm::cont::ErrorControlBadValue( + "Not enough indices given to CellSetSingleType::AddCell."); + } + + if (this->ConnectivityAdded+numVertices > + this->PointToCell.Connectivity.GetNumberOfValues()) + { + throw vtkm::cont::ErrorControlBadValue( + "Connectivity increased passed estimated maximum connectivity."); + } + + if (this->CellShapeAsId == vtkm::CELL_SHAPE_EMPTY) + { + if (shapeId == vtkm::CELL_SHAPE_EMPTY) + { + throw vtkm::cont::ErrorControlBadValue( + "Cannot create cells of type empty."); + } + this->CellShapeAsId = shapeId; + this->CheckNumberOfPointsPerCell(numVertices); + this->NumberOfPointsPerCell = numVertices; + } + else + { + if (shapeId != this->GetCellShape(0)) + { + throw vtkm::cont::ErrorControlBadValue( + "Cannot have differing shapes in CellSetSingleType."); + } + if (numVertices != this->NumberOfPointsPerCell) + { + throw vtkm::cont::ErrorControlBadValue( + "Inconsistent number of points in cells for CellSetSingleType."); + } + } + for (vtkm::IdComponent iVert=0; iVert < numVertices; ++iVert) { this->PointToCell.Connectivity.GetPortalControl().Set( - this->ConnectivityLength+i,ids[i]); + this->ConnectivityAdded+iVert, Traits::GetComponent(ids,iVert)); } - this->NumberOfCells++; - this->ConnectivityLength += numVertices; + this->NumberOfCellsAdded++; + this->ConnectivityAdded += numVertices; } /// Third and final method to add cells -- one at a time. VTKM_CONT - void CompleteAddingCells() + void CompleteAddingCells(vtkm::Id numPoints) { - this->PointToCell.Connectivity.Shrink(this->ConnectivityLength); + this->NumberOfPoints = numPoints; + this->PointToCell.Connectivity.Shrink(this->ConnectivityAdded); + + vtkm::Id numCells = this->NumberOfCellsAdded; + + this->PointToCell.Shapes = + vtkm::cont::make_ArrayHandleConstant(this->GetCellShape(0), numCells); + this->PointToCell.NumIndices = + vtkm::cont::make_ArrayHandleConstant(this->NumberOfPointsPerCell, + numCells); + this->PointToCell.IndexOffsets = + vtkm::cont::make_ArrayHandleCounting( + vtkm::Id(0), + static_cast(this->NumberOfPointsPerCell), + numCells); + this->PointToCell.ElementsValid = true; this->PointToCell.IndexOffsetsValid = true; - this->NumberOfCells = this->ConnectivityLength = -1; + + if (this->ExpectedNumberOfCellsAdded != this->GetNumberOfCells()) + { + throw vtkm::cont::ErrorControlBadValue( + "Did not add the expected number of cells."); + } + + this->NumberOfCellsAdded = -1; + this->ConnectivityAdded = -1; + this->ExpectedNumberOfCellsAdded = -1; } //This is the way you can fill the memory from another system without copying VTKM_CONT - void Fill(const vtkm::cont::ArrayHandle &connectivity) + void Fill(vtkm::Id numPoints, + vtkm::UInt8 shapeId, + vtkm::IdComponent numberOfPointsPerCell, + const vtkm::cont::ArrayHandle + &connectivity) { - vtkm::IdComponent numberOfPointsPerCell = this->DetermineNumberOfPoints(); - const vtkm::Id length = connectivity.GetNumberOfValues() / numberOfPointsPerCell; - const vtkm::UInt8 shapeTypeValue = static_cast(this->CellTypeAsId); + this->NumberOfPoints = numPoints; + this->CellShapeAsId = shapeId; + this->CheckNumberOfPointsPerCell(numberOfPointsPerCell); + const vtkm::Id numCells = + connectivity.GetNumberOfValues() / numberOfPointsPerCell; + VTKM_ASSERT((connectivity.GetNumberOfValues() % numberOfPointsPerCell) == 0); this->PointToCell.Shapes = - vtkm::cont::make_ArrayHandleConstant(shapeTypeValue, length); + vtkm::cont::make_ArrayHandleConstant(shapeId, numCells); this->PointToCell.NumIndices = vtkm::cont::make_ArrayHandleConstant(numberOfPointsPerCell, - length); + numCells); this->PointToCell.IndexOffsets = vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), static_cast(numberOfPointsPerCell), - length ); + numCells ); this->PointToCell.Connectivity = connectivity; this->PointToCell.ElementsValid = true; @@ -172,14 +218,20 @@ public: } VTKM_CONT - vtkm::Id GetCellTypeAsId() const + vtkm::Id GetCellShapeAsId() const { - return this->CellTypeAsId; + return this->CellShapeAsId; + } + + VTKM_CONT + vtkm::UInt8 GetCellShape(vtkm::Id vtkmNotUsed(cellIndex)) const + { + return static_cast(this->CellShapeAsId); } virtual void PrintSummary(std::ostream &out) const { - out << " ExplicitSingleCellSet: " << this->Name << " Type "<CellTypeAsId<Name << " Type "<CellShapeAsId<PointToCell.PrintSummary(out); out << " CellToPoint: " << std::endl; @@ -188,38 +240,45 @@ public: private: template< typename CellShapeTag> - void DetermineNumberOfPoints(CellShapeTag, - vtkm::CellTraitsTagSizeFixed, - vtkm::IdComponent& numberOfPoints) const + void CheckNumberOfPointsPerCell(CellShapeTag, + vtkm::CellTraitsTagSizeFixed, + vtkm::IdComponent numVertices) const { - numberOfPoints = vtkm::CellTraits::NUM_POINTS; + if (numVertices != vtkm::CellTraits::NUM_POINTS) + { + throw vtkm::cont::ErrorControlBadValue( + "Passed invalid number of points for cell shape."); + } } template< typename CellShapeTag> - void DetermineNumberOfPoints(CellShapeTag, - vtkm::CellTraitsTagSizeVariable, - vtkm::IdComponent& numberOfPoints) const - { //variable length cells can't be used with this class - numberOfPoints = -1; + void CheckNumberOfPointsPerCell(CellShapeTag, + vtkm::CellTraitsTagSizeVariable, + vtkm::IdComponent vtkmNotUsed(numVertices)) const + { + // Technically, a shape with a variable number of points probably has a + // minimum number of points, but we are not being sophisticated enough to + // check that. Instead, just pass the check by returning without error. } - vtkm::IdComponent DetermineNumberOfPoints() const + void CheckNumberOfPointsPerCell(vtkm::IdComponent numVertices) const { - vtkm::IdComponent numberOfPointsPerCell = -1; - switch (this->CellTypeAsId) + switch (this->CellShapeAsId) { - vtkmGenericCellShapeMacro( this->DetermineNumberOfPoints(CellShapeTag(), - vtkm::CellTraits::IsSizeFixed(), - numberOfPointsPerCell) ); + vtkmGenericCellShapeMacro( + this->CheckNumberOfPointsPerCell(CellShapeTag(), + vtkm::CellTraits::IsSizeFixed(), + numVertices) ); default: throw vtkm::cont::ErrorControlBadValue( "CellSetSingleType unable to determine the cell type"); } - return numberOfPointsPerCell; } - vtkm::Id CellTypeAsId; + vtkm::Id ExpectedNumberOfCellsAdded; + vtkm::Id CellShapeAsId; + vtkm::IdComponent NumberOfPointsPerCell; }; } diff --git a/vtkm/cont/DataSetBuilderExplicit.h b/vtkm/cont/DataSetBuilderExplicit.h index b95d63fc2..48c65cd62 100644 --- a/vtkm/cont/DataSetBuilderExplicit.h +++ b/vtkm/cont/DataSetBuilderExplicit.h @@ -155,6 +155,7 @@ public: vtkm::cont::DataSet Create(const std::vector > &coords, CellShapeTag tag, + vtkm::IdComponent numberOfPointsPerCell, const std::vector &connectivity, const std::string &coordsNm="coords", const std::string &cellNm="cells"); @@ -165,12 +166,14 @@ public: vtkm::cont::DataSet Create(const vtkm::cont::ArrayHandle > &coords, CellShapeTag tag, + vtkm::IdComponent numberOfPointsPerCell, const vtkm::cont::ArrayHandle &connectivity, const std::string &coordsNm="coords", const std::string &cellNm="cells") { return DataSetBuilderExplicit::BuildDataSet(coords, tag, + numberOfPointsPerCell, connectivity, coordsNm, cellNm); @@ -206,6 +209,7 @@ private: vtkm::cont::DataSet BuildDataSet(const vtkm::cont::ArrayHandle > &coords, CellShapeTag tag, + vtkm::IdComponent numberOfPointsPerCell, const vtkm::cont::ArrayHandle &connectivity, const std::string &coordsNm, const std::string &cellNm); @@ -266,9 +270,9 @@ DataSetBuilderExplicit::BuildDataSet( vtkm::cont::CoordinateSystem(coordsNm, make_ArrayHandleCompositeVector(X,0, Y,0, Z,0))); vtkm::Id nPts = X.GetNumberOfValues(); - vtkm::cont::CellSetExplicit<> cellSet(nPts, cellNm); + vtkm::cont::CellSetExplicit<> cellSet(cellNm); - cellSet.Fill(shapes, numIndices, connectivity); + cellSet.Fill(nPts, shapes, numIndices, connectivity); dataSet.AddCellSet(cellSet); return dataSet; @@ -313,9 +317,9 @@ DataSetBuilderExplicit::BuildDataSet(const vtkm::cont::ArrayHandle(coords.GetNumberOfValues()); - vtkm::cont::CellSetExplicit<> cellSet(nPts, cellNm); + vtkm::cont::CellSetExplicit<> cellSet(cellNm); - cellSet.Fill(shapes, numIndices, connectivity); + cellSet.Fill(nPts, shapes, numIndices, connectivity); dataSet.AddCellSet(cellSet); return dataSet; @@ -326,6 +330,7 @@ inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::Create(const std::vector > &coords, CellShapeTag tag, + vtkm::IdComponent numberOfPointsPerCell, const std::vector &connectivity, const std::string &coordsNm, const std::string &cellNm) @@ -336,7 +341,8 @@ DataSetBuilderExplicit::Create(const std::vector > &coords, vtkm::cont::ArrayHandle Cc; DataSetBuilderExplicit::CopyInto(connectivity, Cc); - return DataSetBuilderExplicit::Create(coordsArray, tag, Cc, coordsNm, cellNm); + return DataSetBuilderExplicit::Create( + coordsArray, tag, numberOfPointsPerCell, Cc, coordsNm, cellNm); } template @@ -344,6 +350,7 @@ inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::BuildDataSet(const vtkm::cont::ArrayHandle > &coords, CellShapeTag tag, + vtkm::IdComponent numberOfPointsPerCell, const vtkm::cont::ArrayHandle &connectivity, const std::string &coordsNm, const std::string &cellNm) @@ -351,9 +358,12 @@ DataSetBuilderExplicit::BuildDataSet(const vtkm::cont::ArrayHandle cellSet(tag, coords.GetNumberOfValues(), cellNm); + vtkm::cont::CellSetSingleType<> cellSet(cellNm); - cellSet.Fill(connectivity); + cellSet.Fill(coords.GetNumberOfValues(), + tag.Id, + numberOfPointsPerCell, + connectivity); dataSet.AddCellSet(cellSet); return dataSet; @@ -469,94 +479,6 @@ DataSetBuilderExplicitIterative::Create() } -#if 0 -template -vtkm::cont::DataSet -DataSetBuilderExplicit::Create(const std::vector &xVals, - const std::vector &yVals, - const std::vector &connectivity, - const std::string &coordsNm, - const std::string &cellNm) -{ - VTKM_CONT_ASSERT(xVals.size() == yVals.size() && xVals.size() > 0); - vtkm::cont::DataSet dataSet; - - typedef vtkm::Vec CoordType; - std::vector coords(xVals.size()); - - for (size_t i=0; i < coords.size(); i++) - { - coords[i][0] = xVals[i]; - coords[i][1] = yVals[i]; - coords[i][2] = 0; - } - dataSet.AddCoordinateSystem( - vtkm::cont::CoordinateSystem(coordsNm, coords)); - - vtkm::cont::CellSetSingleType< > cellSet(CellType(), cellNm); - cellSet.FillViaCopy(connectivity); - dataSet.AddCellSet(cellSet); - - return dataSet; -} - -template -vtkm::cont::DataSet -DataSetBuilderExplicit::Create(const std::vector &xVals, - const std::vector &yVals, - const std::vector &zVals, - const std::vector &connectivity, - const std::string &coordsNm, - const std::string &cellNm) -{ - VTKM_CONT_ASSERT(xVals.size() == yVals.size() && - yVals.size() == zVals.size() && - xVals.size() > 0); - vtkm::cont::DataSet dataSet; - - typedef vtkm::Vec CoordType; - std::vector coords(xVals.size()); - - vtkm::Id nPts = static_cast(coords.size()); - for (vtkm::Id i=0; i < nPts; i++) - { - coords[i][0] = xVals[i]; - coords[i][1] = yVals[i]; - coords[i][2] = zVals[i]; - } - dataSet.AddCoordinateSystem( - vtkm::cont::CoordinateSystem(coordsNm, coords)); - - vtkm::cont::CellSetSingleType< > cellSet(CellType(), cellNm); - cellSet.FillViaCopy(connectivity); - dataSet.AddCellSet(cellSet); - - return dataSet; -} - -template -vtkm::cont::DataSet -DataSetBuilderExplicit::Create(const std::vector > &coords, - const std::vector &connectivity, - const std::string &coordsNm, - const std::string &cellNm) -{ - vtkm::cont::DataSet dataSet; - - vtkm::cont::ArrayHandle > coordsArray; - CopyInto(coords, coordsArray); - - dataSet.AddCoordinateSystem( - vtkm::cont::CoordinateSystem(coordsNm, coordsArray)); - - vtkm::cont::CellSetSingleType< > cellSet(CellType(), cellNm); - cellSet.FillViaCopy(connectivity); - dataSet.AddCellSet(cellSet); - - return dataSet; -} -#endif - } } diff --git a/vtkm/cont/arg/testing/UnitTestTransportCellSetIn.cxx b/vtkm/cont/arg/testing/UnitTestTransportCellSetIn.cxx index 5654abe50..2ad2e1c21 100644 --- a/vtkm/cont/arg/testing/UnitTestTransportCellSetIn.cxx +++ b/vtkm/cont/arg/testing/UnitTestTransportCellSetIn.cxx @@ -64,11 +64,11 @@ void TransportWholeCellSetIn(Device) { //build a fake cell set const int nVerts = 5; - vtkm::cont::CellSetExplicit<> contObject(nVerts, "cells"); + vtkm::cont::CellSetExplicit<> contObject("cells"); contObject.PrepareToAddCells(2, 7); contObject.AddCell(vtkm::CELL_SHAPE_TRIANGLE, 3, vtkm::make_Vec(0,1,2)); contObject.AddCell(vtkm::CELL_SHAPE_QUAD, 4, vtkm::make_Vec(2,1,3,4)); - contObject.CompleteAddingCells(); + contObject.CompleteAddingCells(nVerts); typedef vtkm::TopologyElementTagPoint FromType; typedef vtkm::TopologyElementTagCell ToType; diff --git a/vtkm/cont/testing/MakeTestDataSet.h b/vtkm/cont/testing/MakeTestDataSet.h index 59a602ee5..12ee85483 100644 --- a/vtkm/cont/testing/MakeTestDataSet.h +++ b/vtkm/cont/testing/MakeTestDataSet.h @@ -92,14 +92,18 @@ MakeTestDataSet::Make1DExplicitDataSet0() coords[3] = CoordType(1.2f,0.f,0.f); coords[4] = CoordType(4.0f,0.f,0.f); + // Each line connects two consecutive vertices std::vector conn; - for (int i = 0; i < nVerts; i++) - conn.push_back(i); + for (int i = 0; i < nVerts-1; i++) + { + conn.push_back(i); + conn.push_back(i+1); + } vtkm::cont::DataSet dataSet; vtkm::cont::DataSetBuilderExplicit dsb; - dataSet = dsb.Create(coords, vtkm::CellShapeTagLine(), conn, "coordinates", "cells"); + dataSet = dsb.Create(coords, vtkm::CellShapeTagLine(), 2, conn, "coordinates", "cells"); vtkm::cont::DataSetFieldAdd dsf; vtkm::Float32 var[nVerts] = {-1.0f, .5f, -.2f, 1.7f, .8f}; @@ -382,11 +386,11 @@ MakeTestDataSet::Make3DExplicitDataSet1() dataSet.AddCoordinateSystem( vtkm::cont::CoordinateSystem("coordinates", coordinates, nVerts)); - vtkm::cont::CellSetExplicit<> cellSet(nVerts, "cells"); + vtkm::cont::CellSetExplicit<> cellSet("cells"); cellSet.PrepareToAddCells(2, 7); cellSet.AddCell(vtkm::CELL_SHAPE_TRIANGLE, 3, make_Vec(0,1,2)); cellSet.AddCell(vtkm::CELL_SHAPE_QUAD, 4, make_Vec(2,1,3,4)); - cellSet.CompleteAddingCells(); + cellSet.CompleteAddingCells(nVerts); dataSet.AddCellSet(cellSet); //Set point scalar @@ -428,7 +432,7 @@ MakeTestDataSet::Make3DExplicitDataSet2() vtkm::Float32 cellvar[2] = {100.1f}; dataSet.AddField(Field("cellvar", vtkm::cont::Field::ASSOC_CELL_SET, "cells", cellvar, 1)); - vtkm::cont::CellSetExplicit<> cellSet(nVerts,"cells"); + vtkm::cont::CellSetExplicit<> cellSet("cells"); vtkm::Vec ids; ids[0] = 0; ids[1] = 1; @@ -441,7 +445,7 @@ MakeTestDataSet::Make3DExplicitDataSet2() cellSet.PrepareToAddCells(1, 8); cellSet.AddCell(vtkm::CELL_SHAPE_HEXAHEDRON, 8, ids); - cellSet.CompleteAddingCells(); + cellSet.CompleteAddingCells(nVerts); //todo this need to be a reference/shared_ptr style class dataSet.AddCellSet(cellSet); @@ -482,7 +486,7 @@ MakeTestDataSet::Make3DExplicitDataSet4() vtkm::Float32 cellvar[2] = {100.1f, 110.f}; dataSet.AddField(Field("cellvar", vtkm::cont::Field::ASSOC_CELL_SET, "cells", cellvar, 2)); - vtkm::cont::CellSetExplicit<> cellSet(nVerts,"cells"); + vtkm::cont::CellSetExplicit<> cellSet("cells"); vtkm::Vec ids; ids[0] = 0; ids[1] = 4; @@ -504,7 +508,7 @@ MakeTestDataSet::Make3DExplicitDataSet4() ids[6] = 10; ids[7] = 9; cellSet.AddCell(vtkm::CELL_SHAPE_HEXAHEDRON, 8, ids); - cellSet.CompleteAddingCells(); + cellSet.CompleteAddingCells(nVerts); //todo this need to be a reference/shared_ptr style class dataSet.AddCellSet(cellSet); @@ -537,7 +541,7 @@ MakeTestDataSet::Make3DExplicitDataSet3() vtkm::Float32 cellvar[2] = {100.1f}; dataSet.AddField(Field("cellvar", vtkm::cont::Field::ASSOC_CELL_SET, "cells", cellvar, 1)); - vtkm::cont::CellSetExplicit<> cellSet(nVerts,"cells"); + vtkm::cont::CellSetExplicit<> cellSet("cells"); vtkm::Vec ids; ids[0] = 0; ids[1] = 1; @@ -546,7 +550,7 @@ MakeTestDataSet::Make3DExplicitDataSet3() cellSet.PrepareToAddCells(1, 4); cellSet.AddCell(vtkm::CELL_SHAPE_TETRA, 4, ids); - cellSet.CompleteAddingCells(); + cellSet.CompleteAddingCells(nVerts); //todo this need to be a reference/shared_ptr style class dataSet.AddCellSet(cellSet); @@ -594,7 +598,7 @@ MakeTestDataSet::Make3DExplicitDataSet5() cellvar, nCells)); - vtkm::cont::CellSetExplicit<> cellSet(nVerts,"cells"); + vtkm::cont::CellSetExplicit<> cellSet("cells"); vtkm::Vec ids; cellSet.PrepareToAddCells(nCells, 23); @@ -630,7 +634,7 @@ MakeTestDataSet::Make3DExplicitDataSet5() ids[5] = 6; cellSet.AddCell(vtkm::CELL_SHAPE_WEDGE, 6, ids); - cellSet.CompleteAddingCells(); + cellSet.CompleteAddingCells(nVerts); //todo this need to be a reference/shared_ptr style class dataSet.AddCellSet(cellSet); @@ -663,8 +667,8 @@ MakeTestDataSet::Make3DExplicitDataSetCowNose() CoordType(0.0108188,0.152774,0.167914), CoordType(5.41687e-05,0.00137834,0.175119) }; - const int nPointIds = 57; - vtkm::Id pointId[nPointIds] = { + const int connectivitySize = 57; + vtkm::Id pointId[connectivitySize] = { 0, 1, 3, 2, 3, 1, 4, 5, 0, @@ -692,16 +696,14 @@ MakeTestDataSet::Make3DExplicitDataSetCowNose() vtkm::cont::CoordinateSystem("coordinates", coordinates, nVerts)); vtkm::cont::ArrayHandle connectivity; - connectivity.Allocate(nPointIds); + connectivity.Allocate(connectivitySize); - for(vtkm::Id i=0; i < nPointIds; ++i) + for(vtkm::Id i=0; i < connectivitySize; ++i) { connectivity.GetPortalControl().Set(i, pointId[i]); } - vtkm::cont::CellSetSingleType< > cellSet(vtkm::CellShapeTagTriangle(), - nVerts, - "cells"); - cellSet.Fill(connectivity); + vtkm::cont::CellSetSingleType< > cellSet("cells"); + cellSet.Fill(nVerts, vtkm::CELL_SHAPE_TRIANGLE, 3, connectivity); dataSet.AddCellSet(cellSet); return dataSet; diff --git a/vtkm/cont/testing/TestingDataSetSingleType.h b/vtkm/cont/testing/TestingDataSetSingleType.h index 9845e435c..ab4a92959 100644 --- a/vtkm/cont/testing/TestingDataSetSingleType.h +++ b/vtkm/cont/testing/TestingDataSetSingleType.h @@ -88,7 +88,7 @@ private: vtkm::cont::DataSet ds; vtkm::cont::DataSetBuilderExplicit builder; - ds = builder.Create(coordinates, vtkm::CellShapeTagTriangle(), conn); + ds = builder.Create(coordinates, vtkm::CellShapeTagTriangle(), 3, conn); //Set point scalar diff --git a/vtkm/cont/testing/UnitTestDataSetPermutation.cxx b/vtkm/cont/testing/UnitTestDataSetPermutation.cxx index f90be965e..ff8b7836f 100644 --- a/vtkm/cont/testing/UnitTestDataSetPermutation.cxx +++ b/vtkm/cont/testing/UnitTestDataSetPermutation.cxx @@ -78,7 +78,7 @@ inline vtkm::cont::DataSet make_SingleTypeDataSet() vtkm::cont::DataSet ds; vtkm::cont::DataSetBuilderExplicit builder; - ds = builder.Create(coordinates, vtkm::CellShapeTagTriangle(), conn); + ds = builder.Create(coordinates, vtkm::CellShapeTagTriangle(), 3, conn); //Set point scalar const int nVerts = 5; diff --git a/vtkm/filter/ExternalFaces.hxx b/vtkm/filter/ExternalFaces.hxx index 077ad55a8..9891daf78 100644 --- a/vtkm/filter/ExternalFaces.hxx +++ b/vtkm/filter/ExternalFaces.hxx @@ -63,9 +63,11 @@ public: output_shapes, output_numIndices, output_conn, DeviceAdapter()); - vtkm::cont::CellSetExplicit<> output_cs(cellset.GetNumberOfPoints(), - cellset.GetName()); - output_cs.Fill(output_shapes, output_numIndices, output_conn); + vtkm::cont::CellSetExplicit<> output_cs(cellset.GetName()); + output_cs.Fill(cellset.GetNumberOfPoints(), + output_shapes, + output_numIndices, + output_conn); this->Output->AddCellSet(output_cs); *this->Valid = true; diff --git a/vtkm/filter/testing/UnitTestClipFilter.cxx b/vtkm/filter/testing/UnitTestClipFilter.cxx index 4aa7a3a33..c28cbb08c 100644 --- a/vtkm/filter/testing/UnitTestClipFilter.cxx +++ b/vtkm/filter/testing/UnitTestClipFilter.cxx @@ -47,7 +47,7 @@ vtkm::cont::DataSet MakeTestDatasetExplicit() vtkm::cont::DataSet ds; vtkm::cont::DataSetBuilderExplicit builder; - ds = builder.Create(coords, vtkm::CellShapeTagTriangle(), connectivity, "coords"); + ds = builder.Create(coords, vtkm::CellShapeTagTriangle(), 3, connectivity, "coords"); std::vector values; values.push_back(1.0); diff --git a/vtkm/filter/testing/UnitTestExternalFacesFilter.cxx b/vtkm/filter/testing/UnitTestExternalFacesFilter.cxx index 33eac5499..126f0d5cf 100644 --- a/vtkm/filter/testing/UnitTestExternalFacesFilter.cxx +++ b/vtkm/filter/testing/UnitTestExternalFacesFilter.cxx @@ -52,7 +52,7 @@ void TestExternalFacesExplicitGrid() {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"); + vtkm::cont::CellSetExplicit<> cellSet("cells"); vtkm::cont::ArrayHandle shapes; vtkm::cont::ArrayHandle numIndices; @@ -70,10 +70,10 @@ void TestExternalFacesExplicitGrid() conn.GetPortalControl().Set(index++, cellVerts[j][k]); } - cs.Fill(shapes, numIndices, conn); + cellSet.Fill(nVerts, shapes, numIndices, conn); //Add the VTK-m cell set - ds.AddCellSet(cs); + ds.AddCellSet(cellSet); //Run the External Faces filter vtkm::filter::ExternalFaces externalFaces; @@ -82,10 +82,10 @@ void TestExternalFacesExplicitGrid() //Validate the number of external faces (output) returned by the worklet VTKM_TEST_ASSERT(result.IsValid(), "Results should be valid"); - vtkm::cont::CellSetExplicit<> &new_cs = + vtkm::cont::CellSetExplicit<> &new_cellSet = result.GetDataSet().GetCellSet(0).Cast >(); - const vtkm::Id numExtFaces_out = new_cs.GetNumberOfCells(); + const vtkm::Id numExtFaces_out = new_cellSet.GetNumberOfCells(); const vtkm::Id numExtFaces_actual = 12; VTKM_TEST_ASSERT(numExtFaces_out == numExtFaces_actual, "Number of External Faces mismatch"); } diff --git a/vtkm/filter/testing/UnitTestMarchingCubesFilter.cxx b/vtkm/filter/testing/UnitTestMarchingCubesFilter.cxx index 2ce0741a5..5e37d9a92 100644 --- a/vtkm/filter/testing/UnitTestMarchingCubesFilter.cxx +++ b/vtkm/filter/testing/UnitTestMarchingCubesFilter.cxx @@ -245,8 +245,11 @@ inline vtkm::cont::DataSet MakeRadiantDataSet::Make3DRadiantDataSet(vtkm::IdComp vtkm::cont::Field("distanceToOther", vtkm::cont::Field::ASSOC_POINTS, vtkm::cont::DynamicArrayHandle(distanceToOther))); - CellSet cellSet(HexTag(), coordinates.GetNumberOfValues(), "cells"); - cellSet.Fill(connectivity); + CellSet cellSet("cells"); + cellSet.Fill(coordinates.GetNumberOfValues(), + HexTag::Id, + HexTraits::NUM_POINTS, + connectivity); dataSet.AddCellSet(cellSet); diff --git a/vtkm/filter/testing/UnitTestPointElevationFilter.cxx b/vtkm/filter/testing/UnitTestPointElevationFilter.cxx index 6f1019603..6ca0e202e 100644 --- a/vtkm/filter/testing/UnitTestPointElevationFilter.cxx +++ b/vtkm/filter/testing/UnitTestPointElevationFilter.cxx @@ -48,7 +48,7 @@ vtkm::cont::DataSet MakePointElevationTestDataSet() dataSet.AddCoordinateSystem( vtkm::cont::CoordinateSystem("coordinates", coordinates)); - vtkm::cont::CellSetExplicit<> cellSet(vtkm::Id(coordinates.size()), "cells"); + vtkm::cont::CellSetExplicit<> cellSet("cells"); cellSet.PrepareToAddCells(numCells, numCells * 4); for (vtkm::Id j = 0; j < dim - 1; ++j) { @@ -62,7 +62,7 @@ vtkm::cont::DataSet MakePointElevationTestDataSet() (j + 1) * dim + i)); } } - cellSet.CompleteAddingCells(); + cellSet.CompleteAddingCells(vtkm::Id(coordinates.size())); dataSet.AddCellSet(cellSet); return dataSet; diff --git a/vtkm/io/reader/VTKPolyDataReader.h b/vtkm/io/reader/VTKPolyDataReader.h index 1ec45481c..61046a384 100644 --- a/vtkm/io/reader/VTKPolyDataReader.h +++ b/vtkm/io/reader/VTKPolyDataReader.h @@ -98,6 +98,9 @@ private: // Read the points this->ReadPoints(); + vtkm::Id numPoints = + this->DataSet.GetCoordinateSystem().GetData().GetNumberOfValues(); + // Read the cellset std::vector > connectivityArrays; std::vector > numIndicesArrays; @@ -155,22 +158,18 @@ private: if (vtkm::io::internal::IsSingleShape(shapes)) { - vtkm::cont::CellSetSingleType<> cs; - switch(shapes.GetPortalConstControl().Get(0)) - { - vtkmGenericCellShapeMacro( - (cs = vtkm::cont::CellSetSingleType<>(CellShapeTag(), 0, "cells"))); - default: - break; - } - cs.Fill(connectivity); - this->DataSet.AddCellSet(cs); + vtkm::cont::CellSetSingleType<> cellSet("cells"); + cellSet.Fill(numPoints, + shapes.GetPortalConstControl().Get(0), + numIndices.GetPortalConstControl().Get(0), + connectivity); + this->DataSet.AddCellSet(cellSet); } else { - vtkm::cont::CellSetExplicit<> cs(0, "cells"); - cs.Fill(shapes, numIndices, connectivity); - this->DataSet.AddCellSet(cs); + vtkm::cont::CellSetExplicit<> cellSet("cells"); + cellSet.Fill(numPoints, shapes, numIndices, connectivity); + this->DataSet.AddCellSet(cellSet); } // Read points and cell attributes diff --git a/vtkm/io/reader/VTKUnstructuredGridReader.h b/vtkm/io/reader/VTKUnstructuredGridReader.h index 4a784c50b..6a63730bb 100644 --- a/vtkm/io/reader/VTKUnstructuredGridReader.h +++ b/vtkm/io/reader/VTKUnstructuredGridReader.h @@ -58,6 +58,9 @@ private: // Read the points this->ReadPoints(); + vtkm::Id numPoints = + this->DataSet.GetCoordinateSystem().GetData().GetNumberOfValues(); + // Read the cellset vtkm::cont::ArrayHandle connectivity; vtkm::cont::ArrayHandle numIndices; @@ -75,21 +78,18 @@ private: if (vtkm::io::internal::IsSingleShape(shapes)) { - vtkm::cont::CellSetSingleType<> cs; - switch(shapes.GetPortalConstControl().Get(0)) - { - vtkmGenericCellShapeMacro((cs = vtkm::cont::CellSetSingleType<>(CellShapeTag(), 0, "cells"))); - default: - break; - } - cs.Fill(connectivity); - this->DataSet.AddCellSet(cs); + vtkm::cont::CellSetSingleType<> cellSet("cells"); + cellSet.Fill(numPoints, + shapes.GetPortalConstControl().Get(0), + numIndices.GetPortalConstControl().Get(0), + connectivity); + this->DataSet.AddCellSet(cellSet); } else { - vtkm::cont::CellSetExplicit<> cs(0, "cells"); - cs.Fill(shapes, numIndices, connectivity); - this->DataSet.AddCellSet(cs); + vtkm::cont::CellSetExplicit<> cellSet("cells"); + cellSet.Fill(numPoints, shapes, numIndices, connectivity); + this->DataSet.AddCellSet(cellSet); } // Read points and cell attributes diff --git a/vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx b/vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx index d2ec0031c..719e822e9 100644 --- a/vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx +++ b/vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx @@ -396,6 +396,8 @@ void TestReadingPolyData(Format format) "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetCoordinateSystem().GetData().GetNumberOfValues() == 8, "Incorrect number of points"); + VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 8, + "Incorrect number of points (from cell set)"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfCells() == 6, "Incorrect number of cells"); VTKM_TEST_ASSERT(ds.GetCellSet().IsType >(), @@ -414,6 +416,8 @@ void TestReadingStructuredPoints(Format format) "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetCoordinateSystem().GetData().GetNumberOfValues() == 72, "Incorrect number of points"); + VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 72, + "Incorrect number of points (from cell set)"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfCells() == 30, "Incorrect number of cells"); VTKM_TEST_ASSERT(ds.GetCellSet().IsType >(), @@ -432,6 +436,8 @@ void TestReadingStructuredPointsVisIt(Format format) "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetCoordinateSystem().GetData().GetNumberOfValues() == 64, "Incorrect number of points"); + VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 64, + "Incorrect number of points (from cell set)"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfCells() == 27, "Incorrect number of cells"); VTKM_TEST_ASSERT(ds.GetCellSet().IsType >(), @@ -452,6 +458,8 @@ void TestReadingUnstructuredGrid(Format format) "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetCoordinateSystem().GetData().GetNumberOfValues() == 26, "Incorrect number of points"); + VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 26, + "Incorrect number of points (from cell set)"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfCells() == 15, "Incorrect number of cells"); VTKM_TEST_ASSERT(ds.GetCellSet().IsType >(), @@ -469,6 +477,8 @@ void TestReadingUnstructuredGridVisIt(Format format) "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetCoordinateSystem().GetData().GetNumberOfValues() == 26, "Incorrect number of points"); + VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 26, + "Incorrect number of points (from cell set)"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfCells() == 15, "Incorrect number of cells"); VTKM_TEST_ASSERT(ds.GetCellSet().IsType >(), @@ -488,6 +498,8 @@ void TestReadingRectilinearGrid1(Format format) "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetCoordinateSystem().GetData().GetNumberOfValues() == 125, "Incorrect number of points"); + VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 125, + "Incorrect number of points (from cell set)"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfCells() == 64, "Incorrect number of cells"); VTKM_TEST_ASSERT(ds.GetCellSet().IsType >(), @@ -507,6 +519,8 @@ void TestReadingRectilinearGrid2(Format format) "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetCoordinateSystem().GetData().GetNumberOfValues() == 24, "Incorrect number of points"); + VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 24, + "Incorrect number of points (from cell set)"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfCells() == 6, "Incorrect number of cells"); VTKM_TEST_ASSERT(ds.GetCellSet().IsType >(), diff --git a/vtkm/rendering/MapperGL.cxx b/vtkm/rendering/MapperGL.cxx index 9e4fe1a5c..1bb7e0f24 100644 --- a/vtkm/rendering/MapperGL.cxx +++ b/vtkm/rendering/MapperGL.cxx @@ -409,7 +409,7 @@ void MapperGL::RenderCells(const vtkm::cont::DynamicCellSet &cellset, RenderStructuredLineSegments(numVerts, verts, sf); } else if (cellset.IsSameType(vtkm::cont::CellSetSingleType<>()) && - cellset.Cast >().GetCellTypeAsId() == + cellset.Cast >().GetCellShapeAsId() == vtkm::CELL_SHAPE_LINE) { vtkm::cont::ArrayHandle< vtkm::Vec > verts; diff --git a/vtkm/worklet/CellDeepCopy.h b/vtkm/worklet/CellDeepCopy.h index ee5f289fc..579aaa992 100644 --- a/vtkm/worklet/CellDeepCopy.h +++ b/vtkm/worklet/CellDeepCopy.h @@ -111,8 +111,12 @@ struct CellDeepCopy vtkm::cont::make_ArrayHandleGroupVecVariable(connectivity, offsets)); vtkm::cont::CellSetExplicit - newCellSet(inCellSet.GetNumberOfPoints(), inCellSet.GetName()); - newCellSet.Fill(shapes, numIndices, connectivity, offsets); + newCellSet(inCellSet.GetName()); + newCellSet.Fill(inCellSet.GetNumberOfPoints(), + shapes, + numIndices, + connectivity, + offsets); outCellSet = newCellSet; } diff --git a/vtkm/worklet/Clip.h b/vtkm/worklet/Clip.h index 13657792b..d8afb1e5b 100644 --- a/vtkm/worklet/Clip.h +++ b/vtkm/worklet/Clip.h @@ -515,7 +515,10 @@ public: vtkm::cont::CellSetExplicit<> output; - output.Fill(shapes, numIndices, connectivity); + output.Fill(this->NewPointsOffset + uniqueNewPoints.GetNumberOfValues(), + shapes, + numIndices, + connectivity); return output; } diff --git a/vtkm/worklet/ExternalFaces.h b/vtkm/worklet/ExternalFaces.h index 898036106..40e009487 100644 --- a/vtkm/worklet/ExternalFaces.h +++ b/vtkm/worklet/ExternalFaces.h @@ -337,7 +337,11 @@ public: IdPermutationHandleType faceConn(connIndices, conn); PermutedCellSetExplicit permutedCellSet; - permutedCellSet.Fill(pt1, pt2, faceConn); + // Warning: This cell set is created with 0 points, which simply means that + // if you call GetNumberOfPoints it will return 0, which is of course not + // consistent with the indices. We are getting away with this because this + // is a temporary cell set that is not scheduled on points. + permutedCellSet.Fill(0, pt1, pt2, faceConn); vtkm::cont::ArrayHandle > faceVertices; vtkm::worklet::DispatcherMapTopology faceHashDispatcher; diff --git a/vtkm/worklet/MarchingCubes.h b/vtkm/worklet/MarchingCubes.h index b974d0644..da8a84f7b 100644 --- a/vtkm/worklet/MarchingCubes.h +++ b/vtkm/worklet/MarchingCubes.h @@ -633,11 +633,6 @@ vtkm::cont::CellSetSingleType< > } } - //assign the connectivity to the cell set - CellShapeTagTriangle triangleTag; - vtkm::cont::CellSetSingleType< > outputCells( triangleTag ); - outputCells.Fill( connectivity ); - //generate the vertices's ApplyToField applyToField; vtkm::worklet::DispatcherMapField coordinateSystem, vertices); + //assign the connectivity to the cell set + vtkm::cont::CellSetSingleType< > outputCells("contour"); + outputCells.Fill( vertices.GetNumberOfValues(), + vtkm::CELL_SHAPE_TRIANGLE, + 3, + connectivity ); + return outputCells; } diff --git a/vtkm/worklet/RemoveUnusedPoints.h b/vtkm/worklet/RemoveUnusedPoints.h index 3cd2a3502..5b6084943 100644 --- a/vtkm/worklet/RemoveUnusedPoints.h +++ b/vtkm/worklet/RemoveUnusedPoints.h @@ -191,8 +191,9 @@ public: vtkm::Id numberOfPoints = this->PointScatter->GetOutputToInputMap().GetNumberOfValues(); vtkm::cont::CellSetExplicit - outCellSet(numberOfPoints, inCellSet.GetName()); - outCellSet.Fill(inCellSet.GetShapesArray(FromTopology(),ToTopology()), + outCellSet(inCellSet.GetName()); + outCellSet.Fill(numberOfPoints, + inCellSet.GetShapesArray(FromTopology(),ToTopology()), inCellSet.GetNumIndicesArray(FromTopology(),ToTopology()), newConnectivityArray, inCellSet.GetIndexOffsetArray(FromTopology(),ToTopology())); diff --git a/vtkm/worklet/StreamLineUniformGrid.h b/vtkm/worklet/StreamLineUniformGrid.h index 2276e009c..e2fc349a1 100644 --- a/vtkm/worklet/StreamLineUniformGrid.h +++ b/vtkm/worklet/StreamLineUniformGrid.h @@ -425,7 +425,8 @@ public: vtkm::cont::DataSet OutDataSet; vtkm::cont::CellSetExplicit<> outCellSet; - outCellSet.Fill(cellTypes, numIndices, connectivity); + outCellSet.Fill( + coordinates.GetNumberOfValues(), cellTypes, numIndices, connectivity); OutDataSet.AddCellSet(outCellSet); OutDataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", coordinates)); diff --git a/vtkm/worklet/TetrahedralizeExplicitGrid.h b/vtkm/worklet/TetrahedralizeExplicitGrid.h index a75b05336..89015134e 100644 --- a/vtkm/worklet/TetrahedralizeExplicitGrid.h +++ b/vtkm/worklet/TetrahedralizeExplicitGrid.h @@ -171,7 +171,11 @@ public: vtkm::cont::make_ArrayHandleGroupVec<4>(outConnectivity)); // Add cells to output cellset - cellSet.Fill(outConnectivity); + cellSet.Fill( + this->OutDataSet.GetCoordinateSystem().GetData().GetNumberOfValues(), + vtkm::CellShapeTagTetra::Id, + 4, + outConnectivity); } }; diff --git a/vtkm/worklet/TetrahedralizeUniformGrid.h b/vtkm/worklet/TetrahedralizeUniformGrid.h index c898f4902..136e12c59 100644 --- a/vtkm/worklet/TetrahedralizeUniformGrid.h +++ b/vtkm/worklet/TetrahedralizeUniformGrid.h @@ -143,7 +143,11 @@ public: vtkm::cont::make_ArrayHandleGroupVec<4>(connectivity)); // Add cells to output cellset - cellSet.Fill(connectivity); + cellSet.Fill( + this->OutDataSet.GetCoordinateSystem().GetData().GetNumberOfValues(), + vtkm::CellShapeTagTetra::Id, + 4, + connectivity); } }; diff --git a/vtkm/worklet/TriangulateExplicitGrid.h b/vtkm/worklet/TriangulateExplicitGrid.h index 4ce9d8b1f..0901fb086 100644 --- a/vtkm/worklet/TriangulateExplicitGrid.h +++ b/vtkm/worklet/TriangulateExplicitGrid.h @@ -174,7 +174,11 @@ public: vtkm::cont::make_ArrayHandleGroupVec<3>(outConnectivity)); // Add cells to output cellset - cellSet.Fill(outConnectivity); + cellSet.Fill( + this->OutDataSet.GetCoordinateSystem().GetData().GetNumberOfValues(), + vtkm::CellShapeTagTriangle::Id, + 3, + outConnectivity); } }; diff --git a/vtkm/worklet/TriangulateUniformGrid.h b/vtkm/worklet/TriangulateUniformGrid.h index cb696a5de..bc2b09753 100644 --- a/vtkm/worklet/TriangulateUniformGrid.h +++ b/vtkm/worklet/TriangulateUniformGrid.h @@ -121,7 +121,11 @@ public: vtkm::cont::make_ArrayHandleGroupVec<3>(connectivity)); // Add cells to output cellset - cellSet.Fill(connectivity); + cellSet.Fill( + this->OutDataSet.GetCoordinateSystem().GetData().GetNumberOfValues(), + vtkm::CellShapeTagTriangle::Id, + 3, + connectivity); } }; diff --git a/vtkm/worklet/VertexClustering.h b/vtkm/worklet/VertexClustering.h index 4af858222..596edc2d6 100644 --- a/vtkm/worklet/VertexClustering.h +++ b/vtkm/worklet/VertexClustering.h @@ -477,9 +477,11 @@ public: output.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", repPointArray)); - vtkm::cont::CellSetSingleType< > triangles(vtkm::CellShapeTagTriangle(), - 0, "cells"); - triangles.Fill( internal::copyFromVec(pointId3Array, DeviceAdapter()) ); + vtkm::cont::CellSetSingleType< > triangles("cells"); + triangles.Fill( repPointArray.GetNumberOfValues(), + vtkm::CellShapeTagTriangle::Id, + 3, + internal::copyFromVec(pointId3Array, DeviceAdapter()) ); output.AddCellSet( triangles ); #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK diff --git a/vtkm/worklet/testing/UnitTestClipping.cxx b/vtkm/worklet/testing/UnitTestClipping.cxx index f69474c5d..78e1aacb7 100644 --- a/vtkm/worklet/testing/UnitTestClipping.cxx +++ b/vtkm/worklet/testing/UnitTestClipping.cxx @@ -77,7 +77,7 @@ vtkm::cont::DataSet MakeTestDatasetExplicit() vtkm::cont::DataSet ds; vtkm::cont::DataSetBuilderExplicit builder; - ds = builder.Create(coords, vtkm::CellShapeTagTriangle(), connectivity, "coords"); + ds = builder.Create(coords, vtkm::CellShapeTagTriangle(), 3, connectivity, "coords"); std::vector values; values.push_back(1.0); @@ -143,6 +143,9 @@ void TestClippingExplicit() }; vtkm::Float32 expectedScalars[] = { 1, 2, 1, 0, 0.5, 0.5, 0.5 }; + VTKM_TEST_ASSERT(outputCellSet.GetNumberOfPoints() == fieldSize, + "Wrong number of points in cell set."); + VTKM_TEST_ASSERT( TestArrayHandle(outputCellSet.GetConnectivityArray( vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell()), @@ -197,6 +200,9 @@ void TestClippingStrucutred() }; vtkm::Float32 expectedScalars[] = { 1, 1, 1, 1, 0, 1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5 }; + VTKM_TEST_ASSERT(outputCellSet.GetNumberOfPoints() == fieldSize, + "Wrong number of points in cell set."); + VTKM_TEST_ASSERT( TestArrayHandle(outputCellSet.GetConnectivityArray( vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell()), diff --git a/vtkm/worklet/testing/UnitTestExternalFaces.cxx b/vtkm/worklet/testing/UnitTestExternalFaces.cxx index 8d3dfa37d..d987bb3fa 100644 --- a/vtkm/worklet/testing/UnitTestExternalFaces.cxx +++ b/vtkm/worklet/testing/UnitTestExternalFaces.cxx @@ -61,8 +61,11 @@ vtkm::cont::DataSet RunExternalFaces(vtkm::cont::DataSet &ds) } - vtkm::cont::CellSetExplicit<> new_cs(cellset.GetNumberOfPoints(),"cells"); - new_cs.Fill(output_shapes, output_numIndices, output_conn); + vtkm::cont::CellSetExplicit<> new_cs("cells"); + new_cs.Fill(cellset.GetNumberOfPoints(), + output_shapes, + output_numIndices, + output_conn); new_ds.AddCellSet(new_cs); return new_ds; diff --git a/vtkm/worklet/testing/UnitTestMarchingCubes.cxx b/vtkm/worklet/testing/UnitTestMarchingCubes.cxx index cb6c480af..6279fa1ce 100644 --- a/vtkm/worklet/testing/UnitTestMarchingCubes.cxx +++ b/vtkm/worklet/testing/UnitTestMarchingCubes.cxx @@ -198,7 +198,7 @@ inline vtkm::cont::DataSet MakeRadiantDataSet::Make3DRadiantDataSet(vtkm::IdComp const vtkm::IdComponent nCells = dim*dim*dim; -vtkm::Float32 spacing = vtkm::Float32(1./dim); + vtkm::Float32 spacing = vtkm::Float32(1./dim); CoordinateArrayHandle coordinates(vtkm::Id3(dim+1,dim+1,dim+1), CoordType(-.5,-.5,-.5), CoordType(spacing,spacing,spacing)); @@ -222,8 +222,11 @@ vtkm::Float32 spacing = vtkm::Float32(1./dim); vtkm::cont::Field("distanceToOther", vtkm::cont::Field::ASSOC_POINTS, vtkm::cont::DynamicArrayHandle(distanceToOther))); - CellSet cellSet(HexTag(), (dim+1)*(dim+1)*(dim+1), "cells"); - cellSet.Fill(connectivity); + CellSet cellSet("cells"); + cellSet.Fill((dim+1)*(dim+1)*(dim+1), + HexTag::Id, + HexTraits::NUM_POINTS, + connectivity); dataSet.AddCellSet(cellSet); diff --git a/vtkm/worklet/testing/UnitTestPointElevation.cxx b/vtkm/worklet/testing/UnitTestPointElevation.cxx index f6e61bcf0..b9378264e 100644 --- a/vtkm/worklet/testing/UnitTestPointElevation.cxx +++ b/vtkm/worklet/testing/UnitTestPointElevation.cxx @@ -53,7 +53,7 @@ vtkm::cont::DataSet MakePointElevationTestDataSet() dataSet.AddCoordinateSystem( vtkm::cont::CoordinateSystem("coordinates", coordinates)); - vtkm::cont::CellSetExplicit<> cellSet(vtkm::Id(coordinates.size()), "cells"); + vtkm::cont::CellSetExplicit<> cellSet("cells"); cellSet.PrepareToAddCells(numCells, numCells * 4); for (vtkm::Id j = 0; j < dim - 1; ++j) { @@ -67,7 +67,7 @@ vtkm::cont::DataSet MakePointElevationTestDataSet() (j + 1) * dim + i)); } } - cellSet.CompleteAddingCells(); + cellSet.CompleteAddingCells(vtkm::Id(coordinates.size())); dataSet.AddCellSet(cellSet); return dataSet; diff --git a/vtkm/worklet/testing/UnitTestRemoveUnusedPoints.cxx b/vtkm/worklet/testing/UnitTestRemoveUnusedPoints.cxx index 855eb2dcf..3bf6299fb 100644 --- a/vtkm/worklet/testing/UnitTestRemoveUnusedPoints.cxx +++ b/vtkm/worklet/testing/UnitTestRemoveUnusedPoints.cxx @@ -27,11 +27,11 @@ namespace { vtkm::cont::CellSetExplicit<> CreateInputCellSet() { - vtkm::cont::CellSetExplicit<> cellSet(11, "cells"); + vtkm::cont::CellSetExplicit<> cellSet("cells"); cellSet.PrepareToAddCells(2, 7); cellSet.AddCell(vtkm::CELL_SHAPE_TRIANGLE,3,vtkm::make_Vec(0,2,4)); cellSet.AddCell(vtkm::CELL_SHAPE_QUAD,4,vtkm::make_Vec(4,2,6,8)); - cellSet.CompleteAddingCells(); + cellSet.CompleteAddingCells(11); return cellSet; } diff --git a/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx b/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx index 1456d90d6..36c4bd637 100644 --- a/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx +++ b/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx @@ -177,7 +177,7 @@ void TestExplicitGrid2D() // Create the output dataset explicit cell set with same coordinate system vtkm::cont::DataSet outDataSet; - vtkm::cont::CellSetSingleType<> outCellSet(vtkm::CellShapeTagTriangle(), "cells"); + vtkm::cont::CellSetSingleType<> outCellSet("cells"); outDataSet.AddCellSet(outCellSet); outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); @@ -215,7 +215,7 @@ void TestExplicitGrid3D() // Create the output dataset explicit cell set with same coordinate system vtkm::cont::DataSet outDataSet; - vtkm::cont::CellSetSingleType<> outCellSet(vtkm::CellShapeTagTetra(), "cells"); + vtkm::cont::CellSetSingleType<> outCellSet("cells"); outDataSet.AddCellSet(outCellSet); outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); diff --git a/vtkm/worklet/testing/UnitTestTetrahedralizeUniformGrid.cxx b/vtkm/worklet/testing/UnitTestTetrahedralizeUniformGrid.cxx index b6f1f64e5..ba70a9188 100644 --- a/vtkm/worklet/testing/UnitTestTetrahedralizeUniformGrid.cxx +++ b/vtkm/worklet/testing/UnitTestTetrahedralizeUniformGrid.cxx @@ -104,7 +104,7 @@ void TestUniformGrid2D() // Create the output dataset explicit cell set with same coordinate system vtkm::cont::DataSet outDataSet; - vtkm::cont::CellSetSingleType<> outCellSet(vtkm::CellShapeTagTriangle(), "cells"); + vtkm::cont::CellSetSingleType<> outCellSet("cells"); outDataSet.AddCellSet(outCellSet); outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); @@ -152,7 +152,7 @@ void TestUniformGrid3D() // Create the output dataset explicit cell set with same coordinate system vtkm::cont::DataSet outDataSet; - vtkm::cont::CellSetSingleType<> outCellSet(vtkm::CellShapeTagTetra(), "cells"); + vtkm::cont::CellSetSingleType<> outCellSet("cells"); outDataSet.AddCellSet(outCellSet); outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0));