Commit bc474bd5 authored by Dave Pugmire's avatar Dave Pugmire
Browse files

Add iterative explicit dataset builder class.

parent 019ac8e2
......@@ -165,6 +165,95 @@ DataSetBuilderExplicit::Create(const std::vector<vtkm::Vec<T,3> > &coords,
return dataSet;
}
class DataSetIterativeBuilderExplicit
{
public:
VTKM_CONT_EXPORT
DataSetIterativeBuilderExplicit() {}
VTKM_CONT_EXPORT
void Begin(const std::string &_coordNm="coords",
const std::string &_cellNm="cells")
{
coordNm = _coordNm;
cellNm = _cellNm;
points.resize(0);
shapes.resize(0);
numIdx.resize(0);
connectivity.resize(0);
}
//Define points.
VTKM_CONT_EXPORT
vtkm::cont::DataSet Create();
VTKM_CONT_EXPORT
vtkm::Id AddPoint(const vtkm::Vec<vtkm::Float32, 3> &pt)
{
points.push_back(pt);
vtkm::Id id = static_cast<vtkm::Id>(points.size());
return id;
}
VTKM_CONT_EXPORT
vtkm::Id AddPoint(const vtkm::Float32 &x,
const vtkm::Float32 &y,
const vtkm::Float32 &z=0)
{
points.push_back(vtkm::make_Vec(x,y,z));
vtkm::Id id = static_cast<vtkm::Id>(points.size());
return id;
}
template<typename T>
VTKM_CONT_EXPORT
vtkm::Id AddPoint(const T &x, const T &y, const T &z=0)
{
return AddPoint(static_cast<vtkm::Float32>(x),
static_cast<vtkm::Float32>(y),
static_cast<vtkm::Float32>(z));
}
template<typename T>
VTKM_CONT_EXPORT
vtkm::Id AddPoint(const vtkm::Vec<T,3> &pt)
{
return AddPoint(static_cast<vtkm::Vec<vtkm::Float32,3> >(pt));
}
//Define cells.
VTKM_CONT_EXPORT
void AddCell(const vtkm::UInt8 &shape, const std::vector<vtkm::Id> &conn)
{
shapes.push_back(shape);
numIdx.push_back(static_cast<vtkm::IdComponent>(conn.size()));
connectivity.insert(connectivity.end(), conn.begin(), conn.end());
}
VTKM_CONT_EXPORT
void AddCell(const vtkm::UInt8 &shape, const vtkm::Id *conn, const vtkm::IdComponent &n)
{
shapes.push_back(shape);
numIdx.push_back(n);
for (int i = 0; i < n; i++)
connectivity.push_back(conn[i]);
}
private:
std::string coordNm, cellNm;
std::vector<vtkm::Vec<vtkm::Float32,3> > points;
std::vector<vtkm::UInt8> shapes;
std::vector<vtkm::IdComponent> numIdx;
std::vector<vtkm::Id> connectivity;
};
vtkm::cont::DataSet
DataSetIterativeBuilderExplicit::Create()
{
DataSetBuilderExplicit dsb;
return dsb.Create(points, shapes, numIdx, connectivity, coordNm, cellNm);
}
}
}
......
......@@ -46,6 +46,8 @@ public:
VTKM_CONT_EXPORT
vtkm::cont::DataSet Make3DExplicitDataSet0();
VTKM_CONT_EXPORT
vtkm::cont::DataSet Make3DExplicitDataSet1();
VTKM_CONT_EXPORT
vtkm::cont::DataSet Make3DExplicitDataSetCowNose(double *pBounds = NULL);
};
......@@ -140,6 +142,38 @@ MakeTestDataSet::Make3DExplicitDataSet0()
return dataSet;
}
vtkm::cont::DataSet
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);
id3 = dsb.AddPoint(2,1,0);
id4 = dsb.AddPoint(2,2,0);
vtkm::Id ids0[3] = {id0, id1, id2};
dsb.AddCell(vtkm::CELL_SHAPE_TRIANGLE, ids0, 3);
vtkm::Id ids1[4] = {id2, id1, id3, id4};
dsb.AddCell(vtkm::CELL_SHAPE_QUAD, ids1, 4);
dataSet = dsb.Create();
vtkm::Float32 vars[5] = {10.1f, 20.1f, 30.2f, 40.2f, 50.3f};
vtkm::Float32 cellvar[2] = {100.1f, 100.2f};
vtkm::cont::DataSetFieldAdd dsf;
dsf.AddPointField(dataSet, "pointvar", vars, 5);
dsf.AddCellField(dataSet, "cellvar", cellvar, 2, "cells");
return dataSet;
}
/*
vtkm::cont::DataSet
MakeTestDataSet::Make3DExplicitDataSet1()
......
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