Commit d626f731 authored by Kenneth Moreland's avatar Kenneth Moreland
Browse files

Make DataSetBuilder methods static

This makes is slightly easier to use as you do not actually have to
construct the DataSetBuilder object but just call its static method.

The DataSetBuilderExplicitIterative methods are not static because they
use state of the builder object to create the data.
parent 33cc8a2b
......@@ -35,6 +35,8 @@ namespace cont {
class DataSetBuilderExplicit
{
template<typename T>
VTKM_CONT_EXPORT
static
void CopyInto(const std::vector<T>& input,
vtkm::cont::ArrayHandle<T>& output )
{
......@@ -52,6 +54,7 @@ public:
//Zoo explicit cell
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const std::vector<T> &xVals,
const std::vector<T> &yVals,
......@@ -63,13 +66,14 @@ public:
const std::string &cellNm="cells")
{
std::vector<T> zVals(xVals.size(),0);
return Create(xVals,yVals,zVals,
shapes,numIndices,connectivity,
dimensionality, coordsNm,cellNm);
return DataSetBuilderExplicit::Create(xVals,yVals,zVals,
shapes,numIndices,connectivity,
dimensionality, coordsNm,cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const std::vector<T> &xVals,
const std::vector<T> &yVals,
......@@ -83,6 +87,7 @@ public:
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const vtkm::cont::ArrayHandle<T> &xVals,
const vtkm::cont::ArrayHandle<T> &yVals,
......@@ -94,14 +99,16 @@ public:
const std::string &coordsNm="coords",
const std::string &cellNm="cells")
{
return BuildDataSet(xVals,yVals,zVals,
shapes,numIndices,connectivity,
dimensionality, coordsNm,cellNm);
return DataSetBuilderExplicit::BuildDataSet(
xVals,yVals,zVals,
shapes,numIndices,connectivity,
dimensionality, coordsNm,cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const std::vector<vtkm::Vec<T,3> > &coords,
const std::vector<vtkm::UInt8> &shapes,
......@@ -113,6 +120,7 @@ public:
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const vtkm::cont::ArrayHandle<vtkm::Vec<T,3> > &coords,
const vtkm::cont::ArrayHandle<vtkm::UInt8> &shapes,
......@@ -122,12 +130,18 @@ public:
const std::string &coordsNm="coords",
const std::string &cellNm="cells")
{
return BuildDataSet(coords, shapes, numIndices, connectivity,
dimensionality, coordsNm, cellNm);
return DataSetBuilderExplicit::BuildDataSet(coords,
shapes,
numIndices,
connectivity,
dimensionality,
coordsNm,
cellNm);
}
template<typename T, typename CellShapeTag>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const std::vector<vtkm::Vec<T,3> > &coords,
CellShapeTag tag,
......@@ -137,6 +151,7 @@ public:
template<typename T, typename CellShapeTag>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const vtkm::cont::ArrayHandle<vtkm::Vec<T,3> > &coords,
CellShapeTag tag,
......@@ -144,11 +159,16 @@ public:
const std::string &coordsNm="coords",
const std::string &cellNm="cells")
{
return BuildDataSet(coords, tag, connectivity, coordsNm, cellNm);
return DataSetBuilderExplicit::BuildDataSet(coords,
tag,
connectivity,
coordsNm,
cellNm);
}
private:
template<typename T>
static
vtkm::cont::DataSet
BuildDataSet(const vtkm::cont::ArrayHandle<T> &X,
const vtkm::cont::ArrayHandle<T> &Y,
......@@ -162,6 +182,7 @@ private:
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
BuildDataSet(const vtkm::cont::ArrayHandle<vtkm::Vec<T,3> > &coords,
const vtkm::cont::ArrayHandle<vtkm::UInt8> &shapes,
......@@ -173,6 +194,7 @@ private:
template<typename T, typename CellShapeTag>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
BuildDataSet(const vtkm::cont::ArrayHandle<vtkm::Vec<T,3> > &coords,
CellShapeTag tag,
......@@ -198,31 +220,33 @@ DataSetBuilderExplicit::Create(const std::vector<T> &xVals,
xVals.size() > 0);
vtkm::cont::ArrayHandle<T> Xc, Yc, Zc;
this->CopyInto(xVals, Xc);
this->CopyInto(yVals, Yc);
this->CopyInto(zVals, Zc);
DataSetBuilderExplicit::CopyInto(xVals, Xc);
DataSetBuilderExplicit::CopyInto(yVals, Yc);
DataSetBuilderExplicit::CopyInto(zVals, Zc);
vtkm::cont::ArrayHandle<vtkm::UInt8> Sc;
vtkm::cont::ArrayHandle<vtkm::IdComponent> Nc;
vtkm::cont::ArrayHandle<vtkm::Id> Cc;
this->CopyInto(shapes, Sc);
this->CopyInto(numIndices, Nc);
this->CopyInto(connectivity, Cc);
DataSetBuilderExplicit::CopyInto(shapes, Sc);
DataSetBuilderExplicit::CopyInto(numIndices, Nc);
DataSetBuilderExplicit::CopyInto(connectivity, Cc);
return BuildDataSet(Xc,Yc,Zc, Sc,Nc,Cc, dimensionality, coordsNm, cellNm);
return DataSetBuilderExplicit::BuildDataSet(
Xc,Yc,Zc, Sc,Nc,Cc, dimensionality, coordsNm, cellNm);
}
template<typename T>
vtkm::cont::DataSet
DataSetBuilderExplicit::BuildDataSet(const vtkm::cont::ArrayHandle<T> &X,
const vtkm::cont::ArrayHandle<T> &Y,
const vtkm::cont::ArrayHandle<T> &Z,
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)
DataSetBuilderExplicit::BuildDataSet(
const vtkm::cont::ArrayHandle<T> &X,
const vtkm::cont::ArrayHandle<T> &Y,
const vtkm::cont::ArrayHandle<T> &Z,
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_ASSERT_CONT(X.GetNumberOfValues() == Y.GetNumberOfValues() &&
Y.GetNumberOfValues() == Z.GetNumberOfValues() &&
......@@ -253,16 +277,17 @@ DataSetBuilderExplicit::Create(const std::vector<vtkm::Vec<T,3> > &coords,
const std::string &cellNm)
{
vtkm::cont::ArrayHandle<Vec<T,3> > coordsArray;
CopyInto(coords, coordsArray);
DataSetBuilderExplicit::CopyInto(coords, coordsArray);
vtkm::cont::ArrayHandle<vtkm::UInt8> Sc;
vtkm::cont::ArrayHandle<vtkm::IdComponent> Nc;
vtkm::cont::ArrayHandle<vtkm::Id> Cc;
this->CopyInto(shapes, Sc);
this->CopyInto(numIndices, Nc);
this->CopyInto(connectivity, Cc);
DataSetBuilderExplicit::CopyInto(shapes, Sc);
DataSetBuilderExplicit::CopyInto(numIndices, Nc);
DataSetBuilderExplicit::CopyInto(connectivity, Cc);
return Create(coordsArray, Sc, Nc, Cc, dimensionality, coordsNm, cellNm);
return DataSetBuilderExplicit::Create(
coordsArray, Sc, Nc, Cc, dimensionality, coordsNm, cellNm);
}
template<typename T>
......@@ -298,12 +323,12 @@ DataSetBuilderExplicit::Create(const std::vector<vtkm::Vec<T,3> > &coords,
const std::string &cellNm)
{
vtkm::cont::ArrayHandle<Vec<T,3> > coordsArray;
this->CopyInto(coords, coordsArray);
DataSetBuilderExplicit::CopyInto(coords, coordsArray);
vtkm::cont::ArrayHandle<vtkm::Id> Cc;
this->CopyInto(connectivity, Cc);
DataSetBuilderExplicit::CopyInto(connectivity, Cc);
return Create(coordsArray, tag, Cc, coordsNm, cellNm);
return DataSetBuilderExplicit::Create(coordsArray, tag, Cc, coordsNm, cellNm);
}
template<typename T, typename CellShapeTag>
......
......@@ -32,6 +32,8 @@ namespace cont {
class DataSetBuilderRectilinear
{
template<typename T, typename U>
VTKM_CONT_EXPORT
static
void CopyInto(const std::vector<T>& input,
vtkm::cont::ArrayHandle<U>& output )
{
......@@ -41,6 +43,8 @@ class DataSetBuilderRectilinear
}
template<typename T, typename U>
VTKM_CONT_EXPORT
static
void CopyInto(const vtkm::cont::ArrayHandle<T>& input,
vtkm::cont::ArrayHandle<U>& output )
{
......@@ -51,6 +55,8 @@ class DataSetBuilderRectilinear
}
template<typename T, typename U>
VTKM_CONT_EXPORT
static
void CopyInto(const T* input, vtkm::Id len,
vtkm::cont::ArrayHandle<U>& output )
{
......@@ -65,45 +71,52 @@ public:
//2D grids.
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(vtkm::Id nx, vtkm::Id ny,
T *xvals, T *yvals,
std::string coordNm="coords", std::string cellNm="cells")
{
T zvals = 0;
return Create(2, nx,ny, 1, xvals, yvals, &zvals, coordNm, cellNm);
return DataSetBuilderRectilinear::Create(
2, nx,ny, 1, xvals, yvals, &zvals, coordNm, cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(int dim, vtkm::Id nx, vtkm::Id ny, vtkm::Id nz,
T *xvals, T *yvals, T *zvals,
std::string coordNm, std::string cellNm)
{
VTKM_ASSERT_CONT(nx>1 && ny>1 &&
((dim==2 && nz==1)||(dim==3 && nz>=1)));
((dim==2 && nz==1)||(dim==3 && nz>=1)));
vtkm::cont::ArrayHandle<vtkm::FloatDefault> Xc, Yc, Zc;
CopyInto(xvals,nx,Xc);
CopyInto(yvals,ny,Yc);
CopyInto(zvals,nz,Zc);
DataSetBuilderRectilinear::CopyInto(xvals,nx,Xc);
DataSetBuilderRectilinear::CopyInto(yvals,ny,Yc);
DataSetBuilderRectilinear::CopyInto(zvals,nz,Zc);
return BuildDataSet(dim, Xc,Yc,Zc, coordNm, cellNm);
return DataSetBuilderRectilinear::BuildDataSet(
dim, Xc,Yc,Zc, coordNm, cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const std::vector<T> &xvals, const std::vector<T> &yvals,
std::string coordNm="coords", std::string cellNm="cells")
{
std::vector<T> zvals(1,0);
return BuildDataSet(2, xvals,yvals,zvals, coordNm,cellNm);
return DataSetBuilderRectilinear::BuildDataSet(
2, xvals,yvals,zvals, coordNm,cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const vtkm::cont::ArrayHandle<T> &xvals,
const vtkm::cont::ArrayHandle<T> &yvals,
......@@ -114,33 +127,39 @@ public:
vtkm::cont::ArrayHandle<T> zvals;
zvals.Allocate(1);
zvals.GetPortalControl().Set(0,0.0);
return BuildDataSet(2, xvals,yvals,zvals, coordNm, cellNm);
return DataSetBuilderRectilinear::BuildDataSet(
2, xvals,yvals,zvals, coordNm, cellNm);
}
//3D grids.
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(vtkm::Id nx, vtkm::Id ny, vtkm::Id nz,
T *xvals, T *yvals, T *zvals,
std::string coordNm="coords", std::string cellNm="cells")
{
return Create(3, nx,ny,nz, xvals, yvals, zvals, coordNm, cellNm);
return DataSetBuilderRectilinear::Create(
3, nx,ny,nz, xvals, yvals, zvals, coordNm, cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const std::vector<T> &xvals,
const std::vector<T> &yvals,
const std::vector<T> &zvals,
std::string coordNm="coords", std::string cellNm="cells")
{
return BuildDataSet(3, xvals, yvals, zvals, coordNm, cellNm);
return DataSetBuilderRectilinear::BuildDataSet(
3, xvals, yvals, zvals, coordNm, cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const vtkm::cont::ArrayHandle<T> &xvals,
const vtkm::cont::ArrayHandle<T> &yvals,
......@@ -150,12 +169,14 @@ public:
VTKM_ASSERT_CONT(xvals.GetNumberOfValues()>1 &&
yvals.GetNumberOfValues()>1 &&
zvals.GetNumberOfValues()>1);
return BuildDataSet(3, xvals,yvals,zvals, coordNm, cellNm);
return DataSetBuilderRectilinear::BuildDataSet(
3, xvals,yvals,zvals, coordNm, cellNm);
}
private:
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
BuildDataSet(int dim,
const std::vector<T> &xvals,
......@@ -164,18 +185,20 @@ private:
std::string coordNm, std::string cellNm)
{
VTKM_ASSERT_CONT(xvals.size()>1 && yvals.size()>1 &&
((dim==2 && zvals.size()==1)||(dim==3 && zvals.size()>=1)));
((dim==2 && zvals.size()==1)||(dim==3 && zvals.size()>=1)));
vtkm::cont::ArrayHandle<vtkm::FloatDefault> Xc, Yc, Zc;
this->CopyInto(xvals, Xc);
this->CopyInto(yvals, Yc);
this->CopyInto(zvals, Zc);
DataSetBuilderRectilinear::CopyInto(xvals, Xc);
DataSetBuilderRectilinear::CopyInto(yvals, Yc);
DataSetBuilderRectilinear::CopyInto(zvals, Zc);
return BuildDataSet(dim, Xc,Yc,Zc, coordNm, cellNm);
return DataSetBuilderRectilinear::BuildDataSet(
dim, Xc,Yc,Zc, coordNm, cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
BuildDataSet(int dim,
const vtkm::cont::ArrayHandle<T> &X,
......@@ -192,9 +215,9 @@ private:
vtkm::cont::ArrayHandle<vtkm::FloatDefault> > coords;
vtkm::cont::ArrayHandle<vtkm::FloatDefault> Xc, Yc, Zc;
this->CopyInto(X, Xc);
this->CopyInto(Y, Yc);
this->CopyInto(Z, Zc);
DataSetBuilderRectilinear::CopyInto(X, Xc);
DataSetBuilderRectilinear::CopyInto(Y, Yc);
DataSetBuilderRectilinear::CopyInto(Z, Zc);
coords = vtkm::cont::make_ArrayHandleCartesianProduct(Xc,Yc,Zc);
vtkm::cont::CoordinateSystem cs(coordNm, 1, coords);
......
......@@ -35,36 +35,41 @@ public:
//2D uniform grids.
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const vtkm::Id2 &dimensions,
const vtkm::Vec<vtkm::FloatDefault,2> &origin = vtkm::Vec<vtkm::FloatDefault,2>(0.0f),
const vtkm::Vec<vtkm::FloatDefault,2> &spacing = vtkm::Vec<vtkm::FloatDefault,2>(1.0f),
std::string coordNm="coords", std::string cellNm="cells")
{
return CreateDS(2,
dimensions[0],dimensions[1],1, origin[0],origin[1],0.0f,
spacing[0],spacing[1],1.0f,
coordNm, cellNm);
return DataSetBuilderUniform::CreateDS(2,
dimensions[0],dimensions[1],1,
origin[0],origin[1],0.0f,
spacing[0],spacing[1],1.0f,
coordNm, cellNm);
}
//3D uniform grids.
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
Create(const vtkm::Id3 &dimensions,
const vtkm::Vec<vtkm::FloatDefault,3> &origin = vtkm::Vec<vtkm::FloatDefault,3>(0.0f),
const vtkm::Vec<vtkm::FloatDefault,3> &spacing = vtkm::Vec<vtkm::FloatDefault,3>(1.0f),
std::string coordNm="coords", std::string cellNm="cells")
{
return CreateDS(3,
dimensions[0],dimensions[1],dimensions[2],
origin[0],origin[1],origin[2],
spacing[0],spacing[1],spacing[2],
coordNm, cellNm);
return DataSetBuilderUniform::CreateDS(
3,
dimensions[0],dimensions[1],dimensions[2],
origin[0],origin[1],origin[2],
spacing[0],spacing[1],spacing[2],
coordNm, cellNm);
}
private:
template<typename T>
VTKM_CONT_EXPORT
static
vtkm::cont::DataSet
CreateDS(int dim, vtkm::Id nx, vtkm::Id ny, vtkm::Id nz,
T originX, T originY, T originZ,
......
......@@ -36,6 +36,7 @@ public:
//Point centered fields.
template <typename T, typename Storage>
VTKM_CONT_EXPORT
static
void AddPointField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
vtkm::cont::ArrayHandle<T, Storage> &field)
......@@ -46,6 +47,7 @@ public:
template<typename T>
VTKM_CONT_EXPORT
static
void AddPointField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
const std::vector<T> &field)
......@@ -53,9 +55,10 @@ public:
dataSet.AddField(Field(fieldName, 1, vtkm::cont::Field::ASSOC_POINTS,
field));
}
template<typename T>
VTKM_CONT_EXPORT
static
void AddPointField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
const T *field, const vtkm::Id &n)
......@@ -67,6 +70,7 @@ public:
//Cell centered field
template <typename T, typename Storage>
VTKM_CONT_EXPORT
static
void AddCellField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
vtkm::cont::ArrayHandle<T, Storage> &field,
......@@ -78,6 +82,7 @@ public:
template<typename T>
VTKM_CONT_EXPORT
static
void AddCellField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
const std::vector<T> &field,
......@@ -86,9 +91,10 @@ public:
dataSet.AddField(Field(fieldName, 1, vtkm::cont::Field::ASSOC_CELL_SET,
cellSetName, field));
}
template<typename T>
VTKM_CONT_EXPORT
static
void AddCellField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
const T *field, const vtkm::Id &n,
......@@ -100,6 +106,7 @@ public:
template <typename T, typename Storage>
VTKM_CONT_EXPORT
static
void AddCellField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
vtkm::cont::ArrayHandle<T, Storage> &field,
......@@ -107,10 +114,11 @@ public:
{
std::string cellSetName =
dataSet.GetCellSet(cellSetIndex).GetCellSet().GetName();
this->AddCellField(dataSet, fieldName, field, cellSetName);
DataSetFieldAdd::AddCellField(dataSet, fieldName, field, cellSetName);
}
template<typename T>
VTKM_CONT_EXPORT
static
void AddCellField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
const std::vector<T> &field,
......@@ -118,11 +126,12 @@ public:
{
std::string cellSetName =
dataSet.GetCellSet(cellSetIndex).GetCellSet().GetName();
this->AddCellField(dataSet, fieldName, field, cellSetName);
DataSetFieldAdd::AddCellField(dataSet, fieldName, field, cellSetName);
}
template<typename T>
VTKM_CONT_EXPORT
static
void AddCellField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
const T *field, const vtkm::Id &n,
......@@ -130,7 +139,7 @@ public:
{
std::string cellSetName =
dataSet.GetCellSet(cellSetIndex).GetCellSet().GetName();
this->AddCellField(dataSet, fieldName, field, n, cellSetName);
DataSetFieldAdd::AddCellField(dataSet, fieldName, field, n, cellSetName);
}
......
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