From 5a7b3668ee44d813ab3851f746323f0a23fb5587 Mon Sep 17 00:00:00 2001 From: Patricia Kroll Fasel - 090207 Date: Tue, 29 Sep 2015 11:20:05 -0600 Subject: [PATCH] Correct for gcc and pgi compilers and CastTo. Add CellSetSingleType for output. --- .../tetrahedra/TetrahedralizeExplicitGrid.cxx | 18 ++-- .../tetrahedra/TriangulateExplicitGrid.cxx | 24 ++---- vtkm/worklet/TetrahedralizeExplicitGrid.h | 85 +++++++++---------- .../UnitTestTetrahedralizeExplicitGrid.cxx | 16 ++-- 4 files changed, 62 insertions(+), 81 deletions(-) diff --git a/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx b/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx index 0a1124015..8dc12e444 100644 --- a/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx +++ b/examples/tetrahedra/TetrahedralizeExplicitGrid.cxx @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -39,6 +38,7 @@ typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter; // Default size of the example vtkm::Id3 dims(4,4,4); vtkm::Id cellsToDisplay = 64; +vtkm::Id numberOfInPoints; // Takes input uniform grid and outputs unstructured grid of tets vtkm::worklet::TetrahedralizeFilterExplicitGrid *tetrahedralizeFilter; @@ -169,9 +169,9 @@ void initializeGL() glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); - float white[] = { 0.8, 0.8, 0.8, 1.0 }; - float black[] = { 0.0, 0.0, 0.0, 1.0 }; - float lightPos[] = { 10.0, 10.0, 10.5, 1.0 }; + float white[] = { 0.8f, 0.8f, 0.8f, 1.0f }; + float black[] = { 0.0f, 0.0f, 0.0f, 1.0f }; + float lightPos[] = { 10.0f, 10.0f, 10.5f, 1.0f }; glLightfv(GL_LIGHT0, GL_AMBIENT, white); glLightfv(GL_LIGHT0, GL_DIFFUSE, white); @@ -211,8 +211,8 @@ void displayCall() glTranslatef(-0.5f, -0.5f, -0.5f); // Get cell set and the number of cells and vertices - vtkm::cont::CellSetExplicit<> cellSet = outDataSet.GetCellSet(0).CastTo >(); - vtkm::Id numberOfPoints = cellSet.GetNumberOfPoints(); + vtkm::cont::CellSetSingleType<> cellSet = + outDataSet.GetCellSet(0).CastTo >(); vtkm::Id numberOfCells = cellSet.GetNumberOfCells(); // Get the coordinate system and coordinate data @@ -221,7 +221,7 @@ void displayCall() // Need the actual vertex points from a static cast of the dynamic array but can't get it right // So use cast and call on a functor that stores that dynamic array into static array we created - vertexArray.Allocate(numberOfPoints); + vertexArray.Allocate(numberOfInPoints); coordArray.CastAndCall(GetVertexArray()); // Draw the five tetrahedra belonging to each hexadron @@ -316,10 +316,10 @@ int main(int argc, char* argv[]) vtkm::cont::CellSetExplicit<> &inCellSet = inDataSet.GetCellSet(0).CastTo >(); - vtkm::Id numberOfVertices = inCellSet.GetNumberOfPoints(); + numberOfInPoints = inCellSet.GetNumberOfPoints(); // Create the output dataset explicit cell set with same coordinate system - vtkm::cont::CellSetExplicit<> cellSet(numberOfVertices, "cells", 3); + vtkm::cont::CellSetSingleType<> cellSet(vtkm::CellShapeTagTetra(), "cells"); outDataSet.AddCellSet(cellSet); outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); diff --git a/examples/tetrahedra/TriangulateExplicitGrid.cxx b/examples/tetrahedra/TriangulateExplicitGrid.cxx index 73b806555..03a8b97e7 100644 --- a/examples/tetrahedra/TriangulateExplicitGrid.cxx +++ b/examples/tetrahedra/TriangulateExplicitGrid.cxx @@ -35,6 +35,7 @@ typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter; // Takes input uniform grid and outputs unstructured grid of triangles vtkm::worklet::TetrahedralizeFilterExplicitGrid *tetrahedralizeFilter; vtkm::cont::DataSet outDataSet; +vtkm::Id numberOfInPoints; // Point location of vertices from a CastAndCall but needs a static cast eventually vtkm::cont::ArrayHandle > vertexArray; @@ -159,19 +160,6 @@ private: } }; -void display(void) -{ - glClear(GL_COLOR_BUFFER_BIT); - glColor3f(1.0, 1.0, 1.0); - glBegin(GL_POLYGON); - glVertex3f(0.25, 0.25, 0.0); - glVertex3f(0.75, 0.25, 0.0); - glVertex3f(0.75, 0.75, 0.0); - glVertex3f(0.25, 0.25, 0.0); - glEnd(); - glFlush(); -} - // // Initialize the OpenGL state // @@ -193,8 +181,8 @@ void displayCall() glLineWidth(3.0f); // Get cell set and the number of cells and vertices - vtkm::cont::CellSetExplicit<> cellSet = outDataSet.GetCellSet(0).CastTo >(); - vtkm::Id numberOfPoints = cellSet.GetNumberOfPoints(); + vtkm::cont::CellSetSingleType<> cellSet = + outDataSet.GetCellSet(0).CastTo >(); vtkm::Id numberOfCells = cellSet.GetNumberOfCells(); // Get the coordinate system and coordinate data @@ -203,7 +191,7 @@ void displayCall() // Need the actual vertex points from a static cast of the dynamic array but can't get it right // So use cast and call on a functor that stores that dynamic array into static array we created - vertexArray.Allocate(numberOfPoints); + vertexArray.Allocate(numberOfInPoints); coordArray.CastAndCall(GetVertexArray()); // Draw the two triangles belonging to each quad @@ -248,10 +236,10 @@ int main(int argc, char* argv[]) vtkm::cont::CellSetExplicit<> &inCellSet = inDataSet.GetCellSet(0).CastTo >(); - vtkm::Id numberOfVertices = inCellSet.GetNumberOfPoints(); + numberOfInPoints = inCellSet.GetNumberOfPoints(); // Create the output dataset explicit cell set with same coordinate system - vtkm::cont::CellSetExplicit<> cellSet(numberOfVertices, "cells", 2);; + vtkm::cont::CellSetSingleType<> cellSet(vtkm::CellShapeTagTriangle(), "cells");; outDataSet.AddCellSet(cellSet); outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); diff --git a/vtkm/worklet/TetrahedralizeExplicitGrid.h b/vtkm/worklet/TetrahedralizeExplicitGrid.h index 2a5554e2a..c2083fcf8 100644 --- a/vtkm/worklet/TetrahedralizeExplicitGrid.h +++ b/vtkm/worklet/TetrahedralizeExplicitGrid.h @@ -82,9 +82,8 @@ public: { public: typedef void ControlSignature(FieldIn<> shapes, - FieldIn<> numIndices, FieldOut<> triangleCount); - typedef void ExecutionSignature(_1,_2,_3); + typedef void ExecutionSignature(_1,_2); typedef _1 InputDomain; VTKM_CONT_EXPORT @@ -92,7 +91,6 @@ public: VTKM_EXEC_EXPORT void operator()(const vtkm::UInt8 &shape, - const vtkm::IdComponent &numIndices, vtkm::Id &tetrahedraCount) const { if (shape == vtkm::CELL_SHAPE_TETRA) @@ -135,12 +133,14 @@ public: { // Offset is in triangles, 3 vertices per triangle needed vtkm::Id startIndex = offset * 3; - if (shape.Id == vtkm::CELL_SHAPE_TRIANGLE) { + if (shape.Id == vtkm::CELL_SHAPE_TRIANGLE) + { connectivity.Set(startIndex++, cellNodeIds[0]); connectivity.Set(startIndex++, cellNodeIds[1]); connectivity.Set(startIndex++, cellNodeIds[2]); - - } else if (shape.Id == vtkm::CELL_SHAPE_QUAD) { + } + else if (shape.Id == vtkm::CELL_SHAPE_QUAD) + { connectivity.Set(startIndex++, cellNodeIds[0]); connectivity.Set(startIndex++, cellNodeIds[1]); connectivity.Set(startIndex++, cellNodeIds[2]); @@ -148,9 +148,11 @@ public: connectivity.Set(startIndex++, cellNodeIds[0]); connectivity.Set(startIndex++, cellNodeIds[2]); connectivity.Set(startIndex++, cellNodeIds[3]); - - } else if (shape.Id == vtkm::CELL_SHAPE_POLYGON) { - for (vtkm::Id tri = 0; tri < numIndices-2; tri++) { + } + else if (shape.Id == vtkm::CELL_SHAPE_POLYGON) + { + for (vtkm::IdComponent tri = 0; tri < numIndices-2; tri++) + { connectivity.Set(startIndex++, cellNodeIds[0]); connectivity.Set(startIndex++, cellNodeIds[tri+1]); connectivity.Set(startIndex++, cellNodeIds[tri+2]); @@ -167,11 +169,10 @@ public: { public: typedef void ControlSignature(FieldInTo<> tetraOffset, - FieldInTo<> numIndices, TopologyIn topology, ExecObject connectivity); - typedef void ExecutionSignature(_1,_2,_4, CellShape, FromIndices); - typedef _3 InputDomain; + typedef void ExecutionSignature(_1,_3, CellShape, FromIndices); + typedef _2 InputDomain; VTKM_CONT_EXPORT TetrahedralizeCell() {} @@ -180,20 +181,21 @@ public: template VTKM_EXEC_EXPORT void operator()(const vtkm::Id &offset, - const vtkm::Id &numIndices, vtkm::exec::ExecutionWholeArray &connectivity, CellShapeTag shape, const CellNodeVecType &cellNodeIds) const { // Offset is in tetrahedra, 4 vertices per tetrahedron needed vtkm::Id startIndex = offset * 4; - if (shape.Id == vtkm::CELL_SHAPE_TETRA) { + if (shape.Id == vtkm::CELL_SHAPE_TETRA) + { connectivity.Set(startIndex++, cellNodeIds[0]); connectivity.Set(startIndex++, cellNodeIds[1]); connectivity.Set(startIndex++, cellNodeIds[2]); connectivity.Set(startIndex++, cellNodeIds[3]); - - } else if (shape.Id == vtkm::CELL_SHAPE_HEXAHEDRON) { + } + else if (shape.Id == vtkm::CELL_SHAPE_HEXAHEDRON) + { connectivity.Set(startIndex++, cellNodeIds[0]); connectivity.Set(startIndex++, cellNodeIds[1]); connectivity.Set(startIndex++, cellNodeIds[3]); @@ -218,8 +220,9 @@ public: connectivity.Set(startIndex++, cellNodeIds[6]); connectivity.Set(startIndex++, cellNodeIds[7]); connectivity.Set(startIndex++, cellNodeIds[4]); - - } else if (shape.Id == vtkm::CELL_SHAPE_WEDGE) { + } + else if (shape.Id == vtkm::CELL_SHAPE_WEDGE) + { connectivity.Set(startIndex++, cellNodeIds[0]); connectivity.Set(startIndex++, cellNodeIds[1]); connectivity.Set(startIndex++, cellNodeIds[2]); @@ -234,8 +237,9 @@ public: connectivity.Set(startIndex++, cellNodeIds[2]); connectivity.Set(startIndex++, cellNodeIds[3]); connectivity.Set(startIndex++, cellNodeIds[4]); - - } else if (shape.Id == vtkm::CELL_SHAPE_PYRAMID) { + } + else if (shape.Id == vtkm::CELL_SHAPE_PYRAMID) + { connectivity.Set(startIndex++, cellNodeIds[0]); connectivity.Set(startIndex++, cellNodeIds[1]); connectivity.Set(startIndex++, cellNodeIds[2]); @@ -270,9 +274,9 @@ public: // Cell sets belonging to input and output datasets vtkm::cont::CellSetExplicit<> &inCellSet = - this->InDataSet.GetCellSet(0).CastTo >(); - vtkm::cont::CellSetExplicit<> &cellSet = - this->OutDataSet.GetCellSet(0).CastTo >(); + InDataSet.GetCellSet(0).template CastTo >(); + vtkm::cont::CellSetSingleType<> &cellSet = + OutDataSet.GetCellSet(0).template CastTo >(); // Input dataset vertices and cell counts vtkm::Id numberOfInCells = inCellSet.GetNumberOfCells(); @@ -289,19 +293,18 @@ public: // Determine the number of output cells each input cell will generate vtkm::cont::ArrayHandle numOutCellArray; vtkm::IdComponent verticesPerOutCell; - vtkm::UInt8 shapeOutCell; - if (dimensionality == 2) { + if (dimensionality == 2) + { verticesPerOutCell = 3; - shapeOutCell = vtkm::CELL_SHAPE_TRIANGLE; vtkm::worklet::DispatcherMapField trianglesPerCellDispatcher; trianglesPerCellDispatcher.Invoke(inShapes, inNumIndices, numOutCellArray); - - } else if (dimensionality == 3) { + } + else if (dimensionality == 3) + { verticesPerOutCell = 4; - shapeOutCell = vtkm::CELL_SHAPE_TETRA; vtkm::worklet::DispatcherMapField tetrahedraPerCellDispatcher; - tetrahedraPerCellDispatcher.Invoke(inShapes, inNumIndices, numOutCellArray); + tetrahedraPerCellDispatcher.Invoke(inShapes, numOutCellArray); } // Number of output cells and number of vertices needed @@ -311,39 +314,29 @@ public: vtkm::Id numberOfOutIndices = numberOfOutCells * verticesPerOutCell; // Information needed to build the output cell set - vtkm::cont::ArrayHandle shapes; - vtkm::cont::ArrayHandle numIndices; vtkm::cont::ArrayHandle connectivity; - - shapes.Allocate(numberOfOutCells); - numIndices.Allocate(numberOfOutCells); connectivity.Allocate(numberOfOutIndices); - // Fill the arrays of shapes and number of indices needed by the cell set - for (vtkm::Id j = 0; j < numberOfOutCells; j++) { - shapes.GetPortalControl().Set(j, shapeOutCell); - numIndices.GetPortalControl().Set(j, verticesPerOutCell); - } - // Call worklet to compute the connectivity - if (dimensionality == 2) { + if (dimensionality == 2) + { vtkm::worklet::DispatcherMapTopology triangulateCellDispatcher; triangulateCellDispatcher.Invoke( cellOffset, inNumIndices, inCellSet, vtkm::exec::ExecutionWholeArray(connectivity, numberOfOutIndices)); - } else if (dimensionality == 3) { + } + else if (dimensionality == 3) + { vtkm::worklet::DispatcherMapTopology tetrahedralizeCellDispatcher; tetrahedralizeCellDispatcher.Invoke( cellOffset, - inNumIndices, inCellSet, vtkm::exec::ExecutionWholeArray(connectivity, numberOfOutIndices)); } - // Add cells to output cellset - cellSet.Fill(shapes, numIndices, connectivity); + cellSet.Fill(connectivity); } }; diff --git a/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx b/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx index 88d4b818d..05afd8f4d 100644 --- a/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx +++ b/vtkm/worklet/testing/UnitTestTetrahedralizeExplicitGrid.cxx @@ -21,9 +21,7 @@ #include #include -#include #include - #include namespace { @@ -37,7 +35,8 @@ vtkm::cont::DataSet MakeTriangulateExplicitDataSet() const int nVerts = 16; typedef vtkm::Vec CoordType; - CoordType coordinates[nVerts] = { + CoordType coordinates[nVerts] = + { CoordType(0, 0, 0), // 0 CoordType(1, 0, 0), // 1 CoordType(2, 0, 0), // 2 @@ -131,7 +130,8 @@ vtkm::cont::DataSet MakeTetrahedralizeExplicitDataSet() const int nVerts = 18; typedef vtkm::Vec CoordType; - CoordType coordinates[nVerts] = { + CoordType coordinates[nVerts] = + { CoordType(0, 0, 0), CoordType(1, 0, 0), CoordType(2, 0, 0), @@ -225,7 +225,7 @@ void TestExplicitGrid2D() // Create the output dataset explicit cell set with same coordinate system vtkm::cont::DataSet outDataSet; - vtkm::cont::CellSetExplicit<> outCellSet(numberOfVertices, "cells", 2); + vtkm::cont::CellSetSingleType<> outCellSet(vtkm::CellShapeTagTriangle(), "cells"); outDataSet.AddCellSet(outCellSet); outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); @@ -234,7 +234,7 @@ void TestExplicitGrid2D() tetrahedralizeFilter(inDataSet, outDataSet); tetrahedralizeFilter.Run(); - vtkm::cont::CellSetExplicit<> cellSet = outDataSet.GetCellSet(0).CastTo >(); + vtkm::cont::CellSetSingleType<> cellSet = outDataSet.GetCellSet(0).CastTo >(); vtkm::cont::CoordinateSystem coordinates = outDataSet.GetCoordinateSystem(0); const vtkm::cont::DynamicArrayHandleCoordinateSystem coordArray = coordinates.GetData(); std::cout << "Number of output triangles " << cellSet.GetNumberOfCells() << std::endl; @@ -269,7 +269,7 @@ void TestExplicitGrid3D() // Create the output dataset explicit cell set with same coordinate system vtkm::cont::DataSet outDataSet; - vtkm::cont::CellSetExplicit<> outCellSet(numberOfVertices, "cells", 3); + vtkm::cont::CellSetSingleType<> outCellSet(vtkm::CellShapeTagTetra(), "cells"); outDataSet.AddCellSet(outCellSet); outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0)); @@ -278,7 +278,7 @@ void TestExplicitGrid3D() tetrahedralizeFilter(inDataSet, outDataSet); tetrahedralizeFilter.Run(); - vtkm::cont::CellSetExplicit<> cellSet = outDataSet.GetCellSet(0).CastTo >(); + vtkm::cont::CellSetSingleType<> cellSet = outDataSet.GetCellSet(0).CastTo >(); vtkm::cont::CoordinateSystem coordinates = outDataSet.GetCoordinateSystem(0); const vtkm::cont::DynamicArrayHandleCoordinateSystem coordArray = coordinates.GetData(); std::cout << "Number of output tetrahedra " << cellSet.GetNumberOfCells() << std::endl;