Commit 449c425a authored by Robert Maynard's avatar Robert Maynard
Browse files

Allow DataSetBuilderExplicit to create CellSetSingleType.

If you have only a single cell shape, you can now efficiently create
a vtkm::cont::DataSet whose CellSet is vtkm::cont::CellSetSingleType.
parent e39c7819
......@@ -113,7 +113,28 @@ public:
return BuildDataSet(coords, shapes, numIndices, connectivity,
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
......@@ -135,6 +156,15 @@ private:
const vtkm::cont::ArrayHandle<vtkm::Id> &connectivity,
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>
......@@ -189,7 +219,7 @@ DataSetBuilderExplicit::BuildDataSet(const vtkm::cont::ArrayHandle<T> &X,
make_ArrayHandleCompositeVector(X,0, Y,0, Z,0)));
vtkm::Id nPts = X.GetNumberOfValues();
vtkm::cont::CellSetExplicit<> cellSet(nPts, cellNm, 3);
cellSet.Fill(shapes, numIndices, connectivity);
dataSet.AddCellSet(cellSet);
......@@ -205,21 +235,16 @@ DataSetBuilderExplicit::Create(const std::vector<vtkm::Vec<T,3> > &coords,
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);
}
......@@ -227,25 +252,65 @@ 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,
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);
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::Id nPts = static_cast<vtkm::Id>(coords.GetNumberOfValues());
vtkm::cont::CellSetSingleType<> cellSet(tag, cellNm);
cellSet.Fill(connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
}
class DataSetBuilderExplicitIterative
{
public:
......@@ -330,7 +395,7 @@ public:
this->connectivity.push_back(pointIndex);
this->numIdx.back() += 1;
}
private:
std::string coordNm, cellNm;
......@@ -363,7 +428,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 +461,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);
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment