mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 02:25:42 +00:00
Correct for gcc and pgi compilers and CastTo. Add CellSetSingleType for output.
This commit is contained in:
parent
c87b4f50da
commit
5a7b3668ee
@ -21,7 +21,6 @@
|
||||
#include <vtkm/worklet/TetrahedralizeExplicitGrid.h>
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/Math.h>
|
||||
#include <vtkm/cont/CellSetExplicit.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
@ -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<DeviceAdapter> *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::cont::CellSetExplicit<> >();
|
||||
vtkm::Id numberOfPoints = cellSet.GetNumberOfPoints();
|
||||
vtkm::cont::CellSetSingleType<> cellSet =
|
||||
outDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
|
||||
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::cont::CellSetExplicit<> >();
|
||||
|
||||
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));
|
||||
|
||||
|
@ -35,6 +35,7 @@ typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
|
||||
// Takes input uniform grid and outputs unstructured grid of triangles
|
||||
vtkm::worklet::TetrahedralizeFilterExplicitGrid<DeviceAdapter> *tetrahedralizeFilter;
|
||||
vtkm::cont::DataSet outDataSet;
|
||||
vtkm::Id numberOfInPoints;
|
||||
|
||||
// Point location of vertices from a CastAndCall but needs a static cast eventually
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float64, 3> > 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::cont::CellSetExplicit<> >();
|
||||
vtkm::Id numberOfPoints = cellSet.GetNumberOfPoints();
|
||||
vtkm::cont::CellSetSingleType<> cellSet =
|
||||
outDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
|
||||
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::cont::CellSetExplicit<> >();
|
||||
|
||||
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));
|
||||
|
||||
|
@ -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<typename CellShapeTag, typename CellNodeVecType>
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(const vtkm::Id &offset,
|
||||
const vtkm::Id &numIndices,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Id> &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<> >();
|
||||
vtkm::cont::CellSetExplicit<> &cellSet =
|
||||
this->OutDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetExplicit<> >();
|
||||
InDataSet.GetCellSet(0).template CastTo<vtkm::cont::CellSetExplicit<> >();
|
||||
vtkm::cont::CellSetSingleType<> &cellSet =
|
||||
OutDataSet.GetCellSet(0).template CastTo<vtkm::cont::CellSetSingleType<> >();
|
||||
|
||||
// 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<vtkm::Id> numOutCellArray;
|
||||
vtkm::IdComponent verticesPerOutCell;
|
||||
vtkm::UInt8 shapeOutCell;
|
||||
|
||||
if (dimensionality == 2) {
|
||||
if (dimensionality == 2)
|
||||
{
|
||||
verticesPerOutCell = 3;
|
||||
shapeOutCell = vtkm::CELL_SHAPE_TRIANGLE;
|
||||
vtkm::worklet::DispatcherMapField<TrianglesPerCell> trianglesPerCellDispatcher;
|
||||
trianglesPerCellDispatcher.Invoke(inShapes, inNumIndices, numOutCellArray);
|
||||
|
||||
} else if (dimensionality == 3) {
|
||||
}
|
||||
else if (dimensionality == 3)
|
||||
{
|
||||
verticesPerOutCell = 4;
|
||||
shapeOutCell = vtkm::CELL_SHAPE_TETRA;
|
||||
vtkm::worklet::DispatcherMapField<TetrahedraPerCell> 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<vtkm::UInt8> shapes;
|
||||
vtkm::cont::ArrayHandle<vtkm::IdComponent> numIndices;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> 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<TriangulateCell> triangulateCellDispatcher;
|
||||
triangulateCellDispatcher.Invoke(
|
||||
cellOffset,
|
||||
inNumIndices,
|
||||
inCellSet,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Id>(connectivity, numberOfOutIndices));
|
||||
} else if (dimensionality == 3) {
|
||||
}
|
||||
else if (dimensionality == 3)
|
||||
{
|
||||
vtkm::worklet::DispatcherMapTopology<TetrahedralizeCell> tetrahedralizeCellDispatcher;
|
||||
tetrahedralizeCellDispatcher.Invoke(
|
||||
cellOffset,
|
||||
inNumIndices,
|
||||
inCellSet,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Id>(connectivity, numberOfOutIndices));
|
||||
}
|
||||
|
||||
// Add cells to output cellset
|
||||
cellSet.Fill(shapes, numIndices, connectivity);
|
||||
cellSet.Fill(connectivity);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -21,9 +21,7 @@
|
||||
#include <vtkm/worklet/TetrahedralizeExplicitGrid.h>
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
|
||||
#include <vtkm/cont/CellSetExplicit.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace {
|
||||
@ -37,7 +35,8 @@ vtkm::cont::DataSet MakeTriangulateExplicitDataSet()
|
||||
|
||||
const int nVerts = 16;
|
||||
typedef vtkm::Vec<vtkm::Float32,3> 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<vtkm::Float32,3> 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::CellSetExplicit<> >();
|
||||
vtkm::cont::CellSetSingleType<> cellSet = outDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
|
||||
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::CellSetExplicit<> >();
|
||||
vtkm::cont::CellSetSingleType<> cellSet = outDataSet.GetCellSet(0).CastTo<vtkm::cont::CellSetSingleType<> >();
|
||||
vtkm::cont::CoordinateSystem coordinates = outDataSet.GetCoordinateSystem(0);
|
||||
const vtkm::cont::DynamicArrayHandleCoordinateSystem coordArray = coordinates.GetData();
|
||||
std::cout << "Number of output tetrahedra " << cellSet.GetNumberOfCells() << std::endl;
|
||||
|
Loading…
Reference in New Issue
Block a user