Merge topic 'remove_fill_via_copy'

4bb3cce0 Use the DataSetBuilderExplicitIterative helper where it is useful.
eba2fb49 Fixed some warnings in the DataSetBuilder code.
dd312516 Fix issue found be moving over to  DataSetBuilderExplicit.
e7456fa1 Update vtkm tests and examples to use DataSetBuilders.
449c425a Allow DataSetBuilderExplicit to create CellSetSingleType.

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland <kmorel@sandia.gov>
Merge-request: !318
This commit is contained in:
Robert Maynard 2016-01-18 17:17:40 -05:00 committed by Kitware Robot
commit 61ed34e154
12 changed files with 419 additions and 531 deletions

@ -26,6 +26,7 @@
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/Math.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/testing/Testing.h>
@ -66,81 +67,60 @@ int mouse_state = 1;
//
vtkm::cont::DataSet MakeTetrahedralizeExplicitDataSet()
{
vtkm::cont::DataSet dataSet;
vtkm::cont::DataSetBuilderExplicitIterative builder;
builder.Begin(3);
const int nVerts = 18;
typedef vtkm::Vec<vtkm::Float32,3> 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),
};
builder.AddPoint( 0, 0, 0);
builder.AddPoint( 1, 0, 0);
builder.AddPoint( 2, 0, 0);
builder.AddPoint( 3, 0, 0);
builder.AddPoint( 0, 1, 0);
builder.AddPoint( 1, 1, 0);
builder.AddPoint( 2, 1, 0);
builder.AddPoint( 2.5, 1.0, 0.0);
builder.AddPoint( 0, 2, 0);
builder.AddPoint( 1, 2, 0);
builder.AddPoint( 0.5, 0.5, 1.0);
builder.AddPoint( 1, 0, 1);
builder.AddPoint( 2, 0, 1);
builder.AddPoint( 3, 0, 1);
builder.AddPoint( 1, 1, 1);
builder.AddPoint( 2, 1, 1);
builder.AddPoint( 2.5, 1.0, 1.0);
builder.AddPoint( 0.5, 1.5, 1.0);
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts));
builder.AddCell(vtkm::CELL_SHAPE_TETRA);
builder.AddCellPoint(0);
builder.AddCellPoint(1);
builder.AddCellPoint(5);
builder.AddCellPoint(10);
std::vector<vtkm::UInt8> shapes;
shapes.push_back(vtkm::CELL_SHAPE_TETRA);
shapes.push_back(vtkm::CELL_SHAPE_HEXAHEDRON);
shapes.push_back(vtkm::CELL_SHAPE_WEDGE);
shapes.push_back(vtkm::CELL_SHAPE_PYRAMID);
builder.AddCell(vtkm::CELL_SHAPE_HEXAHEDRON);
builder.AddCellPoint(1);
builder.AddCellPoint(2);
builder.AddCellPoint(6);
builder.AddCellPoint(5);
builder.AddCellPoint(11);
builder.AddCellPoint(12);
builder.AddCellPoint(15);
builder.AddCellPoint(14);
std::vector<vtkm::IdComponent> numindices;
numindices.push_back(4);
numindices.push_back(8);
numindices.push_back(6);
numindices.push_back(5);
builder.AddCell(vtkm::CELL_SHAPE_WEDGE);
builder.AddCellPoint(2);
builder.AddCellPoint(3);
builder.AddCellPoint(7);
builder.AddCellPoint(12);
builder.AddCellPoint(13);
builder.AddCellPoint(16);
std::vector<vtkm::Id> conn;
conn.push_back(0);
conn.push_back(1);
conn.push_back(5);
conn.push_back(10);
builder.AddCell(vtkm::CELL_SHAPE_PYRAMID);
builder.AddCellPoint(4);
builder.AddCellPoint(5);
builder.AddCellPoint(9);
builder.AddCellPoint(8);
builder.AddCellPoint(17);
conn.push_back(1);
conn.push_back(2);
conn.push_back(6);
conn.push_back(5);
conn.push_back(11);
conn.push_back(12);
conn.push_back(15);
conn.push_back(14);
conn.push_back(2);
conn.push_back(3);
conn.push_back(7);
conn.push_back(12);
conn.push_back(13);
conn.push_back(16);
conn.push_back(4);
conn.push_back(5);
conn.push_back(9);
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;
return builder.Create();
}
//

@ -25,6 +25,7 @@
#include <vtkm/worklet/TetrahedralizeExplicitGrid.h>
#include <vtkm/cont/CellSetExplicit.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/testing/Testing.h>
@ -59,93 +60,69 @@ vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float64, 3> > vertexArray;
//
vtkm::cont::DataSet MakeTriangulateExplicitDataSet()
{
vtkm::cont::DataSet dataSet;
vtkm::cont::DataSetBuilderExplicitIterative builder;
builder.Begin(2);
const int nVerts = 16;
typedef vtkm::Vec<vtkm::Float32,3> 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
};
builder.AddPoint(0, 0, 0); // 0
builder.AddPoint(1, 0, 0); // 1
builder.AddPoint(2, 0, 0); // 2
builder.AddPoint(3, 0, 0); // 3
builder.AddPoint(0, 1, 0); // 4
builder.AddPoint(1, 1, 0); // 5
builder.AddPoint(2, 1, 0); // 6
builder.AddPoint(3, 1, 0); // 7
builder.AddPoint(0, 2, 0); // 8
builder.AddPoint(1, 2, 0); // 9
builder.AddPoint(2, 2, 0); // 10
builder.AddPoint(3, 2, 0); // 11
builder.AddPoint(0, 3, 0); // 12
builder.AddPoint(3, 3, 0); // 13
builder.AddPoint(1, 4, 0); // 14
builder.AddPoint(2, 4, 0); // 15
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts));
builder.AddCell(vtkm::CELL_SHAPE_TRIANGLE);
builder.AddCellPoint(0);
builder.AddCellPoint(1);
builder.AddCellPoint(5);
std::vector<vtkm::UInt8> shapes;
shapes.push_back(vtkm::CELL_SHAPE_TRIANGLE);
shapes.push_back(vtkm::CELL_SHAPE_QUAD);
shapes.push_back(vtkm::CELL_SHAPE_QUAD);
shapes.push_back(vtkm::CELL_SHAPE_QUAD);
shapes.push_back(vtkm::CELL_SHAPE_TRIANGLE);
shapes.push_back(vtkm::CELL_SHAPE_QUAD);
shapes.push_back(vtkm::CELL_SHAPE_POLYGON);
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
builder.AddCellPoint(1);
builder.AddCellPoint(2);
builder.AddCellPoint(6);
builder.AddCellPoint(5);
std::vector<vtkm::IdComponent> numindices;
numindices.push_back(3);
numindices.push_back(4);
numindices.push_back(4);
numindices.push_back(4);
numindices.push_back(3);
numindices.push_back(4);
numindices.push_back(6);
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
builder.AddCellPoint(5);
builder.AddCellPoint(6);
builder.AddCellPoint(10);
builder.AddCellPoint(9);
std::vector<vtkm::Id> conn;
conn.push_back(0);
conn.push_back(1);
conn.push_back(5);
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
builder.AddCellPoint(4);
builder.AddCellPoint(5);
builder.AddCellPoint(9);
builder.AddCellPoint(8);
conn.push_back(1);
conn.push_back(2);
conn.push_back(6);
conn.push_back(5);
builder.AddCell(vtkm::CELL_SHAPE_TRIANGLE);
builder.AddCellPoint(2);
builder.AddCellPoint(3);
builder.AddCellPoint(7);
conn.push_back(5);
conn.push_back(6);
conn.push_back(10);
conn.push_back(9);
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
builder.AddCellPoint(6);
builder.AddCellPoint(7);
builder.AddCellPoint(11);
builder.AddCellPoint(10);
conn.push_back(4);
conn.push_back(5);
conn.push_back(9);
conn.push_back(8);
builder.AddCell(vtkm::CELL_SHAPE_POLYGON);
builder.AddCellPoint(9);
builder.AddCellPoint(10);
builder.AddCellPoint(13);
builder.AddCellPoint(15);
builder.AddCellPoint(14);
builder.AddCellPoint(12);
conn.push_back(2);
conn.push_back(3);
conn.push_back(7);
conn.push_back(6);
conn.push_back(7);
conn.push_back(11);
conn.push_back(10);
conn.push_back(9);
conn.push_back(10);
conn.push_back(13);
conn.push_back(15);
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;
return builder.Create();
}
//

@ -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<vtkm::UInt8> &cellTypes,
const std::vector<vtkm::IdComponent> &numIndices,
const std::vector<vtkm::Id> &connectivity,
const std::vector<vtkm::Id> &offsets = std::vector<vtkm::Id>() )
{
this->PointToCell.Shapes.Allocate( static_cast<vtkm::Id>(cellTypes.size()) );
std::copy(cellTypes.begin(), cellTypes.end(),
vtkm::cont::ArrayPortalToIteratorBegin(
this->PointToCell.Shapes.GetPortalControl()));
this->PointToCell.NumIndices.Allocate( static_cast<vtkm::IdComponent>(numIndices.size()) );
std::copy(numIndices.begin(), numIndices.end(),
vtkm::cont::ArrayPortalToIteratorBegin(
this->PointToCell.NumIndices.GetPortalControl()));
this->PointToCell.Connectivity.Allocate( static_cast<vtkm::Id>(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<vtkm::Id>(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

@ -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<vtkm::Id> &connectivity)
{
vtkm::IdComponent numberOfPointsPerCell = this->DetermineNumberOfPoints();
const vtkm::Id connectSize = static_cast<vtkm::Id>(connectivity.size());
const vtkm::Id length = connectSize / numberOfPointsPerCell;
const vtkm::UInt8 shapeTypeValue = static_cast<vtkm::UInt8>(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<vtkm::Id>(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,

@ -51,13 +51,14 @@ public:
const std::vector<vtkm::UInt8> &shapes,
const std::vector<vtkm::IdComponent> &numIndices,
const std::vector<vtkm::Id> &connectivity,
int dimensionality=3,
const std::string &coordsNm="coords",
const std::string &cellNm="cells")
{
std::vector<T> zVals(xVals.size(),0);
return Create(xVals,yVals,zVals,
shapes,numIndices,connectivity,
coordsNm,cellNm);
dimensionality, coordsNm,cellNm);
}
template<typename T>
@ -69,6 +70,7 @@ public:
const std::vector<vtkm::UInt8> &shapes,
const std::vector<vtkm::IdComponent> &numIndices,
const std::vector<vtkm::Id> &connectivity,
int dimensionality=3,
const std::string &coordsNm="coords",
const std::string &cellNm="cells");
@ -81,12 +83,13 @@ public:
const vtkm::cont::ArrayHandle<vtkm::UInt8> &shapes,
const vtkm::cont::ArrayHandle<vtkm::IdComponent> &numIndices,
const vtkm::cont::ArrayHandle<vtkm::Id> &connectivity,
int dimensionality=3,
const std::string &coordsNm="coords",
const std::string &cellNm="cells")
{
return BuildDataSet(xVals,yVals,zVals,
shapes,numIndices,connectivity,
coordsNm,cellNm);
dimensionality, coordsNm,cellNm);
}
@ -97,6 +100,7 @@ public:
const std::vector<vtkm::UInt8> &shapes,
const std::vector<vtkm::IdComponent> &numIndices,
const std::vector<vtkm::Id> &connectivity,
int dimensionality=3,
const std::string &coordsNm="coords",
const std::string &cellNm="cells");
@ -107,13 +111,35 @@ public:
const vtkm::cont::ArrayHandle<vtkm::UInt8> &shapes,
const vtkm::cont::ArrayHandle<vtkm::IdComponent> &numIndices,
const vtkm::cont::ArrayHandle<vtkm::Id> &connectivity,
int dimensionality=3,
const std::string &coordsNm="coords",
const std::string &cellNm="cells")
{
return BuildDataSet(coords, shapes, numIndices, connectivity,
coordsNm, cellNm);
dimensionality, coordsNm, cellNm);
}
template<typename T, typename CellShapeTag>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(const std::vector<vtkm::Vec<T,3> > &coords,
CellShapeTag tag,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm="coords",
const std::string &cellNm="cells");
template<typename T, typename CellShapeTag>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(const vtkm::cont::ArrayHandle<vtkm::Vec<T,3> > &coords,
CellShapeTag tag,
const vtkm::cont::ArrayHandle<vtkm::Id> &connectivity,
const std::string &coordsNm="coords",
const std::string &cellNm="cells")
{
return BuildDataSet(coords, tag, connectivity, coordsNm, cellNm);
}
private:
template<typename T>
vtkm::cont::DataSet
@ -123,6 +149,7 @@ private:
const vtkm::cont::ArrayHandle<vtkm::UInt8> &shapes,
const vtkm::cont::ArrayHandle<vtkm::IdComponent> &numIndices,
const vtkm::cont::ArrayHandle<vtkm::Id> &connectivity,
int dimensionality,
const std::string &coordsNm,
const std::string &cellNm);
@ -133,8 +160,18 @@ private:
const vtkm::cont::ArrayHandle<vtkm::UInt8> &shapes,
const vtkm::cont::ArrayHandle<vtkm::IdComponent> &numIndices,
const vtkm::cont::ArrayHandle<vtkm::Id> &connectivity,
int dimensionality,
const std::string &coordsNm,
const std::string &cellNm);
template<typename T, typename CellShapeTag>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
BuildDataSet(const vtkm::cont::ArrayHandle<vtkm::Vec<T,3> > &coords,
CellShapeTag tag,
const vtkm::cont::ArrayHandle<vtkm::Id> &connectivity,
const std::string &coordsNm,
const std::string &cellNm);
};
template<typename T>
@ -145,6 +182,7 @@ DataSetBuilderExplicit::Create(const std::vector<T> &xVals,
const std::vector<vtkm::UInt8> &shapes,
const std::vector<vtkm::IdComponent> &numIndices,
const std::vector<vtkm::Id> &connectivity,
int dimensionality,
const std::string &coordsNm,
const std::string &cellNm)
{
@ -164,7 +202,7 @@ DataSetBuilderExplicit::Create(const std::vector<T> &xVals,
DFA::Copy(vtkm::cont::make_ArrayHandle(numIndices), Nc);
DFA::Copy(vtkm::cont::make_ArrayHandle(connectivity), Cc);
return BuildDataSet(Xc,Yc,Zc, Sc,Nc,Cc, coordsNm, cellNm);
return BuildDataSet(Xc,Yc,Zc, Sc,Nc,Cc, dimensionality, coordsNm, cellNm);
}
template<typename T>
@ -175,6 +213,7 @@ DataSetBuilderExplicit::BuildDataSet(const vtkm::cont::ArrayHandle<T> &X,
const vtkm::cont::ArrayHandle<vtkm::UInt8> &shapes,
const vtkm::cont::ArrayHandle<vtkm::IdComponent> &numIndices,
const vtkm::cont::ArrayHandle<vtkm::Id> &connectivity,
int dimensionality,
const std::string &coordsNm,
const std::string &cellNm)
{
@ -188,8 +227,8 @@ DataSetBuilderExplicit::BuildDataSet(const vtkm::cont::ArrayHandle<T> &X,
vtkm::cont::CoordinateSystem(coordsNm, 1,
make_ArrayHandleCompositeVector(X,0, Y,0, Z,0)));
vtkm::Id nPts = X.GetNumberOfValues();
vtkm::cont::CellSetExplicit<> cellSet(nPts, cellNm, 3);
vtkm::cont::CellSetExplicit<> cellSet(nPts, cellNm, dimensionality);
cellSet.Fill(shapes, numIndices, connectivity);
dataSet.AddCellSet(cellSet);
@ -202,50 +241,86 @@ DataSetBuilderExplicit::Create(const std::vector<vtkm::Vec<T,3> > &coords,
const std::vector<vtkm::UInt8> &shapes,
const std::vector<vtkm::IdComponent> &numIndices,
const std::vector<vtkm::Id> &connectivity,
int dimensionality,
const std::string &coordsNm,
const std::string &cellNm)
{
vtkm::cont::DataSet dataSet;
vtkm::cont::ArrayHandle<Vec<T,3> > coordsArray;
DFA::Copy(vtkm::cont::make_ArrayHandle(coords), coordsArray);
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem(coordsNm, 1, coordsArray));
vtkm::cont::ArrayHandle<vtkm::UInt8> Sc;
vtkm::cont::ArrayHandle<vtkm::IdComponent> Nc;
vtkm::cont::ArrayHandle<vtkm::Id> Cc;
DFA::Copy(vtkm::cont::make_ArrayHandle(shapes), Sc);
DFA::Copy(vtkm::cont::make_ArrayHandle(numIndices), Nc);
DFA::Copy(vtkm::cont::make_ArrayHandle(connectivity), Cc);
return Create(coordsArray, Sc, Nc, Cc, coordsNm, cellNm);
return Create(coordsArray, Sc, Nc, Cc, dimensionality, coordsNm, cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
DataSetBuilderExplicit::BuildDataSet(const vtkm::cont::ArrayHandle<vtkm::Vec<T,3> > &coords,
const vtkm::cont::ArrayHandle<vtkm::UInt8> &shapes,
const vtkm::cont::ArrayHandle<vtkm::IdComponent> &numIndices,
const vtkm::cont::ArrayHandle<vtkm::Id> &connectivity,
const std::string &coordsNm,
const std::string &cellNm)
const vtkm::cont::ArrayHandle<vtkm::UInt8> &shapes,
const vtkm::cont::ArrayHandle<vtkm::IdComponent> &numIndices,
const vtkm::cont::ArrayHandle<vtkm::Id> &connectivity,
int dimensionality,
const std::string &coordsNm,
const std::string &cellNm)
{
vtkm::cont::DataSet dataSet;
dataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem(coordsNm,
1, coords));
1, coords));
vtkm::Id nPts = static_cast<vtkm::Id>(coords.GetNumberOfValues());
vtkm::cont::CellSetExplicit<> cellSet(nPts, cellNm, 3);
vtkm::cont::CellSetExplicit<> cellSet(nPts, cellNm, dimensionality);
cellSet.Fill(shapes, numIndices, connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
}
template<typename T, typename CellShapeTag>
vtkm::cont::DataSet
DataSetBuilderExplicit::Create(const std::vector<vtkm::Vec<T,3> > &coords,
CellShapeTag tag,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm,
const std::string &cellNm)
{
vtkm::cont::ArrayHandle<Vec<T,3> > coordsArray;
DFA::Copy(vtkm::cont::make_ArrayHandle(coords), coordsArray);
vtkm::cont::ArrayHandle<vtkm::Id> Cc;
DFA::Copy(vtkm::cont::make_ArrayHandle(connectivity), Cc);
return Create(coordsArray, tag, Cc, coordsNm, cellNm);
}
template<typename T, typename CellShapeTag>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
DataSetBuilderExplicit::BuildDataSet(const vtkm::cont::ArrayHandle<vtkm::Vec<T,3> > &coords,
CellShapeTag tag,
const vtkm::cont::ArrayHandle<vtkm::Id> &connectivity,
const std::string &coordsNm,
const std::string &cellNm)
{
vtkm::cont::DataSet dataSet;
dataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem(coordsNm,
1, coords));
vtkm::cont::CellSetSingleType<> cellSet(tag, cellNm);
cellSet.Fill(connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
}
class DataSetBuilderExplicitIterative
{
public:
@ -253,15 +328,17 @@ public:
DataSetBuilderExplicitIterative() {}
VTKM_CONT_EXPORT
void Begin(const std::string &_coordNm="coords",
const std::string &_cellNm="cells")
void Begin(int dim,
const std::string &coordName="coords",
const std::string &cellName="cells")
{
this->coordNm = _coordNm;
this->cellNm = _cellNm;
this->points.resize(0);
this->shapes.resize(0);
this->numIdx.resize(0);
this->connectivity.resize(0);
this->dimensionality = dim;
this->coordNm = coordName;
this->cellNm = cellName;
this->points.resize(0);
this->shapes.resize(0);
this->numIdx.resize(0);
this->connectivity.resize(0);
}
//Define points.
@ -330,9 +407,10 @@ public:
this->connectivity.push_back(pointIndex);
this->numIdx.back() += 1;
}
private:
std::string coordNm, cellNm;
int dimensionality;
std::vector<vtkm::Vec<vtkm::Float32,3> > points;
std::vector<vtkm::UInt8> shapes;
@ -344,7 +422,7 @@ vtkm::cont::DataSet
DataSetBuilderExplicitIterative::Create()
{
DataSetBuilderExplicit dsb;
return dsb.Create(points, shapes, numIdx, connectivity, coordNm, cellNm);
return dsb.Create(points, shapes, numIdx, connectivity, dimensionality, coordNm, cellNm);
}
@ -363,7 +441,7 @@ DataSetBuilderExplicit::Create(const std::vector<T> &xVals,
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
std::vector<CoordType> coords(xVals.size());
for (size_t i=0; i < coords.size(); i++)
{
coords[i][0] = xVals[i];
@ -396,7 +474,7 @@ DataSetBuilderExplicit::Create(const std::vector<T> &xVals,
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
std::vector<CoordType> coords(xVals.size());
vtkm::Id nPts = static_cast<vtkm::Id>(coords.size());
for (vtkm::Id i=0; i < nPts; i++)
{

@ -66,7 +66,7 @@ MakeTestDataSet::Make2DRegularDataSet0()
vtkm::cont::DataSetFieldAdd dsf;
const vtkm::Id nVerts = 6;
vtkm::Float32 var[nVerts] = {10.1f, 20.1f, 30.1f, 40.1f, 50.1f, 60.1f};
dsf.AddPointField(dataSet, "pointvar", var, nVerts);
vtkm::Float32 cellvar[2] = {100.1f, 200.1f};
@ -118,13 +118,13 @@ MakeTestDataSet::Make2DRectilinearDataSet0()
for (int i = 0; i < nVerts; i++)
var[i] = (vtkm::Float32)i;
dsf.AddPointField(dataSet, "pointvar", var, nVerts);
const vtkm::Id nCells = 2;
vtkm::Float32 cellvar[nCells];
for (int i = 0; i < nCells; i++)
cellvar[i] = (vtkm::Float32)i;
dsf.AddCellField(dataSet, "cellvar", cellvar, nCells, "cells");
return dataSet;
}
@ -151,13 +151,13 @@ MakeTestDataSet::Make3DRectilinearDataSet0()
for (int i = 0; i < nVerts; i++)
var[i] = (vtkm::Float32)i;
dsf.AddPointField(dataSet, "pointvar", var, nVerts);
const vtkm::Id nCells = 4;
vtkm::Float32 cellvar[nCells];
for (int i = 0; i < nCells; i++)
cellvar[i] = (vtkm::Float32)i;
dsf.AddCellField(dataSet, "cellvar", cellvar, nCells, "cells");
return dataSet;
}
@ -175,7 +175,7 @@ MakeTestDataSet::Make3DExplicitDataSet0()
coords[2] = CoordType(1, 1, 0);
coords[3] = CoordType(2, 1, 0);
coords[4] = CoordType(2, 2, 0);
//Connectivity
std::vector<vtkm::UInt8> shapes;
shapes.push_back(vtkm::CELL_SHAPE_TRIANGLE);
@ -197,7 +197,7 @@ MakeTestDataSet::Make3DExplicitDataSet0()
conn.push_back(4);
//Create the dataset.
dataSet = dsb.Create(coords, shapes, numindices, conn, "coordinates", "cells");
dataSet = dsb.Create(coords, shapes, numindices, conn, 2, "coordinates", "cells");
vtkm::Float32 vars[nVerts] = {10.1f, 20.1f, 30.2f, 40.2f, 50.3f};
vtkm::Float32 cellvar[2] = {100.1f, 100.2f};
@ -215,9 +215,9 @@ MakeTestDataSet::Make3DExplicitDataSet1()
vtkm::cont::DataSet dataSet;
vtkm::cont::DataSetIterativeBuilderExplicit dsb;
vtkm::Id id0, id1, id2, id3, id4;
dsb.Begin("coords", "cells");
id0 = dsb.AddPoint(0,0,0);
id1 = dsb.AddPoint(1,0,0);
id2 = dsb.AddPoint(1,1,0);

@ -23,6 +23,8 @@
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/DataSetFieldAdd.h>
#include <vtkm/cont/CellSetSingleType.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
@ -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<vtkm::Float32,3> 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<vtkm::Id> 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()

@ -93,7 +93,7 @@ void FillArray(std::vector<T> &arr,
arr.resize(static_cast<std::size_t>(size));
for (size_t i = 0; i < static_cast<std::size_t>(size); i++)
{
T xi;
T xi = static_cast<T>(i);
switch (fillMethod)
{

@ -54,27 +54,13 @@ bool TestArrayHandle(const vtkm::cont::ArrayHandle<T, Storage> &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<vtkm::Float32,3> 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<vtkm::Id> 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()

@ -25,6 +25,9 @@
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/DataSetBuilderRegular.h>
#include <vtkm/cont/DataSetFieldAdd.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/Field.h>
#include <vtkm/cont/testing/Testing.h>
@ -58,42 +61,39 @@ bool TestArrayHandle(const vtkm::cont::ArrayHandle<T, Storage> &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<Coord3D> 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<vtkm::Id> 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, "coords");
std::vector<vtkm::UInt8> shapesVec(shapes, shapes + numCells);
std::vector<vtkm::IdComponent> numIndsVec(numInds, numInds + numCells);
std::vector<vtkm::Id> connectivityVec(connectivity, connectivity + (numCells * 3));
vtkm::cont::CellSetExplicit<> cs(numVerts, "cells", 3);
cs.FillViaCopy(shapesVec, numIndsVec, connectivityVec);
ds.AddCellSet(cs);
std::vector<vtkm::Float32> 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<vtkm::Float32, 3> origin(0.0f, 0.0f, 0.0f);
static const vtkm::Vec<vtkm::Float32, 3> 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;
}
@ -127,7 +124,7 @@ void TestClippingExplicit()
vtkm::cont::DynamicArrayHandle coords =
clip.ProcessField(ds.GetCoordinateSystem("coordinates").GetData());
clip.ProcessField(ds.GetCoordinateSystem("coords").GetData());
vtkm::cont::DynamicArrayHandle scalars =
clip.ProcessField(ds.GetField("scalars").GetData());
@ -153,7 +150,7 @@ void TestClippingExplicit()
VTKM_TEST_ASSERT(
TestArrayHandle(coords.CastToArrayHandle(Coord3D(),
VTKM_DEFAULT_STORAGE_TAG()), expectedCoords, fieldSize),
"Got incorrect coordinates");
"Got incorrect coords");
VTKM_TEST_ASSERT(
TestArrayHandle(scalars.CastToArrayHandle(vtkm::Float32(),
@ -172,7 +169,7 @@ void TestClippingStrucutred()
vtkm::cont::DynamicArrayHandle coords =
clip.ProcessField(ds.GetCoordinateSystem("coordinates").GetData());
clip.ProcessField(ds.GetCoordinateSystem("coords").GetData());
vtkm::cont::DynamicArrayHandle scalars =
clip.ProcessField(ds.GetField("scalars").GetData());
@ -200,7 +197,7 @@ void TestClippingStrucutred()
VTKM_TEST_ASSERT(
TestArrayHandle(coords.CastToArrayHandle(Coord3D(),
VTKM_DEFAULT_STORAGE_TAG()), expectedCoords, fieldSize),
"Got incorrect coordinates");
"Got incorrect coords");
VTKM_TEST_ASSERT(
TestArrayHandle(scalars.CastToArrayHandle(vtkm::Float32(),
@ -219,11 +216,11 @@ void TestClippingWithImplicitFunction()
vtkm::worklet::Clip<DeviceAdapter> clip;
vtkm::cont::CellSetExplicit<> outputCellSet =
clip.Run(ds.GetCellSet(0), sphere, ds.GetCoordinateSystem("coordinates"));
clip.Run(ds.GetCellSet(0), sphere, ds.GetCoordinateSystem("coords"));
vtkm::cont::DynamicArrayHandle coords =
clip.ProcessField(ds.GetCoordinateSystem("coordinates").GetData());
clip.ProcessField(ds.GetCoordinateSystem("coords").GetData());
vtkm::cont::DynamicArrayHandle scalars =
clip.ProcessField(ds.GetField("scalars").GetData());
@ -252,7 +249,7 @@ void TestClippingWithImplicitFunction()
VTKM_TEST_ASSERT(
TestArrayHandle(coords.CastToArrayHandle(Coord3D(),
VTKM_DEFAULT_STORAGE_TAG()), expectedCoords, fieldSize),
"Got incorrect coordinates");
"Got incorrect coords");
VTKM_TEST_ASSERT(
TestArrayHandle(scalars.CastToArrayHandle(vtkm::Float32(),

@ -21,6 +21,7 @@
#include <iostream>
#include <algorithm>
#include <vtkm/cont/DeviceAdapter.h>
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/worklet/ExternalFaces.h>
@ -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<vtkm::Float32,3> 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<vtkm::UInt8> shapes;
vtkm::cont::ArrayHandle<vtkm::IdComponent> 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);

@ -22,6 +22,7 @@
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/testing/Testing.h>
namespace {
@ -31,94 +32,69 @@ namespace {
//
vtkm::cont::DataSet MakeTriangulateExplicitDataSet()
{
vtkm::cont::DataSet dataSet;
vtkm::cont::DataSetBuilderExplicitIterative builder;
builder.Begin(2);
const int nVerts = 16;
typedef vtkm::Vec<vtkm::Float32,3> 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
};
builder.AddPoint(0, 0, 0); // 0
builder.AddPoint(1, 0, 0); // 1
builder.AddPoint(2, 0, 0); // 2
builder.AddPoint(3, 0, 0); // 3
builder.AddPoint(0, 1, 0); // 4
builder.AddPoint(1, 1, 0); // 5
builder.AddPoint(2, 1, 0); // 6
builder.AddPoint(3, 1, 0); // 7
builder.AddPoint(0, 2, 0); // 8
builder.AddPoint(1, 2, 0); // 9
builder.AddPoint(2, 2, 0); // 10
builder.AddPoint(3, 2, 0); // 11
builder.AddPoint(0, 3, 0); // 12
builder.AddPoint(3, 3, 0); // 13
builder.AddPoint(1, 4, 0); // 14
builder.AddPoint(2, 4, 0); // 15
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts));
builder.AddCell(vtkm::CELL_SHAPE_TRIANGLE);
builder.AddCellPoint(0);
builder.AddCellPoint(1);
builder.AddCellPoint(5);
std::vector<vtkm::UInt8> shapes;
shapes.push_back(vtkm::CELL_SHAPE_TRIANGLE);
shapes.push_back(vtkm::CELL_SHAPE_QUAD);
shapes.push_back(vtkm::CELL_SHAPE_QUAD);
shapes.push_back(vtkm::CELL_SHAPE_QUAD);
shapes.push_back(vtkm::CELL_SHAPE_TRIANGLE);
shapes.push_back(vtkm::CELL_SHAPE_QUAD);
shapes.push_back(vtkm::CELL_SHAPE_POLYGON);
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
builder.AddCellPoint(1);
builder.AddCellPoint(2);
builder.AddCellPoint(6);
builder.AddCellPoint(5);
std::vector<vtkm::IdComponent> numindices;
numindices.push_back(3);
numindices.push_back(4);
numindices.push_back(4);
numindices.push_back(4);
numindices.push_back(3);
numindices.push_back(4);
numindices.push_back(6);
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
builder.AddCellPoint(5);
builder.AddCellPoint(6);
builder.AddCellPoint(10);
builder.AddCellPoint(9);
std::vector<vtkm::Id> conn;
conn.push_back(0);
conn.push_back(1);
conn.push_back(5);
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
builder.AddCellPoint(4);
builder.AddCellPoint(5);
builder.AddCellPoint(9);
builder.AddCellPoint(8);
conn.push_back(1);
conn.push_back(2);
conn.push_back(6);
conn.push_back(5);
builder.AddCell(vtkm::CELL_SHAPE_TRIANGLE);
builder.AddCellPoint(2);
builder.AddCellPoint(3);
builder.AddCellPoint(7);
conn.push_back(5);
conn.push_back(6);
conn.push_back(10);
conn.push_back(9);
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
builder.AddCellPoint(6);
builder.AddCellPoint(7);
builder.AddCellPoint(11);
builder.AddCellPoint(10);
conn.push_back(4);
conn.push_back(5);
conn.push_back(9);
conn.push_back(8);
builder.AddCell(vtkm::CELL_SHAPE_POLYGON);
builder.AddCellPoint(9);
builder.AddCellPoint(10);
builder.AddCellPoint(13);
builder.AddCellPoint(15);
builder.AddCellPoint(14);
builder.AddCellPoint(12);
conn.push_back(2);
conn.push_back(3);
conn.push_back(7);
conn.push_back(6);
conn.push_back(7);
conn.push_back(11);
conn.push_back(10);
conn.push_back(9);
conn.push_back(10);
conn.push_back(13);
conn.push_back(15);
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;
return builder.Create();
}
//
@ -126,82 +102,61 @@ vtkm::cont::DataSet MakeTriangulateExplicitDataSet()
//
vtkm::cont::DataSet MakeTetrahedralizeExplicitDataSet()
{
vtkm::cont::DataSet dataSet;
vtkm::cont::DataSetBuilderExplicitIterative builder;
builder.Begin(3);
const int nVerts = 18;
typedef vtkm::Vec<vtkm::Float32,3> 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),
};
builder.AddPoint(0, 0, 0);
builder.AddPoint(1, 0, 0);
builder.AddPoint(2, 0, 0);
builder.AddPoint(3, 0, 0);
builder.AddPoint(0, 1, 0);
builder.AddPoint(1, 1, 0);
builder.AddPoint(2, 1, 0);
builder.AddPoint(2.5, 1.0, 0.0);
builder.AddPoint(0, 2, 0);
builder.AddPoint(1, 2, 0);
builder.AddPoint(0.5, 0.5, 1.0);
builder.AddPoint(1, 0, 1);
builder.AddPoint(2, 0, 1);
builder.AddPoint(3, 0, 1);
builder.AddPoint(1, 1, 1);
builder.AddPoint(2, 1, 1);
builder.AddPoint(2.5, 1.0, 1.0);
builder.AddPoint(0.5, 1.5, 1.0);
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", 1, coordinates, nVerts));
builder.AddCell(vtkm::CELL_SHAPE_TETRA);
builder.AddCellPoint(0);
builder.AddCellPoint(1);
builder.AddCellPoint(5);
builder.AddCellPoint(10);
std::vector<vtkm::UInt8> shapes;
shapes.push_back(vtkm::CELL_SHAPE_TETRA);
shapes.push_back(vtkm::CELL_SHAPE_HEXAHEDRON);
shapes.push_back(vtkm::CELL_SHAPE_WEDGE);
shapes.push_back(vtkm::CELL_SHAPE_PYRAMID);
builder.AddCell(vtkm::CELL_SHAPE_HEXAHEDRON);
builder.AddCellPoint(1);
builder.AddCellPoint(2);
builder.AddCellPoint(6);
builder.AddCellPoint(5);
builder.AddCellPoint(11);
builder.AddCellPoint(12);
builder.AddCellPoint(15);
builder.AddCellPoint(14);
std::vector<vtkm::IdComponent> numindices;
numindices.push_back(4);
numindices.push_back(8);
numindices.push_back(6);
numindices.push_back(5);
builder.AddCell(vtkm::CELL_SHAPE_WEDGE);
builder.AddCellPoint(2);
builder.AddCellPoint(3);
builder.AddCellPoint(7);
builder.AddCellPoint(12);
builder.AddCellPoint(13);
builder.AddCellPoint(16);
std::vector<vtkm::Id> conn;
conn.push_back(0);
conn.push_back(1);
conn.push_back(5);
conn.push_back(10);
builder.AddCell(vtkm::CELL_SHAPE_PYRAMID);
builder.AddCellPoint(4);
builder.AddCellPoint(5);
builder.AddCellPoint(9);
builder.AddCellPoint(8);
builder.AddCellPoint(17);
conn.push_back(1);
conn.push_back(2);
conn.push_back(6);
conn.push_back(5);
conn.push_back(11);
conn.push_back(12);
conn.push_back(15);
conn.push_back(14);
return builder.Create();
conn.push_back(2);
conn.push_back(3);
conn.push_back(7);
conn.push_back(12);
conn.push_back(13);
conn.push_back(16);
conn.push_back(4);
conn.push_back(5);
conn.push_back(9);
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;
}
}
@ -226,7 +181,7 @@ void TestExplicitGrid2D()
outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0));
// Convert explicit cells to triangles
vtkm::worklet::TetrahedralizeFilterExplicitGrid<DeviceAdapter>
vtkm::worklet::TetrahedralizeFilterExplicitGrid<DeviceAdapter>
tetrahedralizeFilter(inDataSet, outDataSet);
tetrahedralizeFilter.Run();
@ -238,7 +193,7 @@ void TestExplicitGrid2D()
std::cout << "Number of output components " << coordArray.GetNumberOfComponents() << std::endl;
vtkm::cont::ArrayHandle<vtkm::Float64> 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 +220,7 @@ void TestExplicitGrid3D()
outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0));
// Convert explicit cells to triangles
vtkm::worklet::TetrahedralizeFilterExplicitGrid<DeviceAdapter>
vtkm::worklet::TetrahedralizeFilterExplicitGrid<DeviceAdapter>
tetrahedralizeFilter(inDataSet, outDataSet);
tetrahedralizeFilter.Run();
@ -277,7 +232,7 @@ void TestExplicitGrid3D()
std::cout << "Number of output components " << coordArray.GetNumberOfComponents() << std::endl;
vtkm::cont::ArrayHandle<vtkm::Float64> 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;