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

Add tests for DataSetBuilderExplicit.

Added cont/testing/ExplicitTestData.h which includes several explicit datasets.  These datasets come from VTK data generated in VisIt.  The new unit tests build datasets in several different ways and do some basic validation.

Add some new methods for DataSetFieldAdd class to improve usability.
parent b4d04fff
......@@ -39,32 +39,7 @@ public:
DataSetBuilderExplicit() {}
//Single cell explicits.
template<typename T, typename CellType>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(const std::vector<T> &xVals,
const std::vector<T> &yVals,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm="coords",
const std::string &cellNm="cells");
template<typename T, typename CellType>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(const std::vector<T> &xVals,
const std::vector<T> &yVals,
const std::vector<T> &zVals,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm="coords",
const std::string &cellNm="cells");
template<typename T, typename CellType>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(const std::vector<vtkm::Vec<T,3> > &coords,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm="coords",
const std::string &cellNm="cells");
//TODO
//Zoo explicit cell
template<typename T>
......@@ -76,7 +51,13 @@ public:
const std::vector<vtkm::IdComponent> &numIndices,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm="coords",
const std::string &cellNm="cells");
const std::string &cellNm="cells")
{
std::vector<T> zVals(xVals.size(),0);
return Create(xVals,yVals,zVals,
shapes,numIndices,connectivity,
coordsNm,cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
......@@ -90,6 +71,24 @@ public:
const std::string &coordsNm="coords",
const std::string &cellNm="cells");
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(const vtkm::cont::ArrayHandle<T> &xVals,
const vtkm::cont::ArrayHandle<T> &yVals,
const vtkm::cont::ArrayHandle<T> &zVals,
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="coords",
const std::string &cellNm="cells")
{
return BuildDataSet(xVals,yVals,zVals,
shapes,numIndices,connectivity,
coordsNm,cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
......@@ -99,162 +98,108 @@ public:
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm="coords",
const std::string &cellNm="cells");
private:
};
template<typename T, typename CellType>
vtkm::cont::DataSet
DataSetBuilderExplicit::Create(const std::vector<T> &xVals,
const std::vector<T> &yVals,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm,
const std::string &cellNm)
{
VTKM_CONT_ASSERT(xVals.size() == yVals.size() && xVals.size() > 0);
vtkm::cont::DataSet dataSet;
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
std::vector<CoordType> coords(xVals.size());
for (size_t i=0; i < coords.size(); i++)
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(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="coords",
const std::string &cellNm="cells")
{
coords[i][0] = xVals[i];
coords[i][1] = yVals[i];
coords[i][2] = 0;
return BuildDataSet(coords, shapes, numIndices, connectivity,
coordsNm, cellNm);
}
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem(coordsNm, 1, coords));
vtkm::cont::CellSetSingleType< > cellSet(CellType(), cellNm);
cellSet.FillViaCopy(connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
}
template<typename T, typename CellType>
vtkm::cont::DataSet
DataSetBuilderExplicit::Create(const std::vector<T> &xVals,
const std::vector<T> &yVals,
const std::vector<T> &zVals,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm,
const std::string &cellNm)
{
VTKM_CONT_ASSERT(xVals.size() == yVals.size() &&
yVals.size() == zVals.size() &&
xVals.size() > 0);
vtkm::cont::DataSet dataSet;
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++)
{
coords[i][0] = xVals[i];
coords[i][1] = yVals[i];
coords[i][2] = zVals[i];
}
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem(coordsNm, 1, coords));
vtkm::cont::CellSetSingleType< > cellSet(CellType(), cellNm);
cellSet.FillViaCopy(connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
}
template<typename T, typename CellType>
vtkm::cont::DataSet
DataSetBuilderExplicit::Create(const std::vector<vtkm::Vec<T,3> > &coords,
const std::vector<vtkm::Id> &connectivity,
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::CellSetSingleType< > cellSet(CellType(), cellNm);
cellSet.FillViaCopy(connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
}
private:
template<typename T>
vtkm::cont::DataSet
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,
const std::string &coordsNm,
const std::string &cellNm);
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
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);
};
template<typename T>
vtkm::cont::DataSet
DataSetBuilderExplicit::Create(const std::vector<T> &xVals,
const std::vector<T> &yVals,
const std::vector<T> &zVals,
const std::vector<vtkm::UInt8> &shapes,
const std::vector<vtkm::IdComponent> &numIndices,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm,
const std::string &cellNm)
{
VTKM_CONT_ASSERT(xVals.size() == yVals.size() && xVals.size() > 0);
vtkm::cont::DataSet dataSet;
VTKM_ASSERT_CONT(xVals.size() == yVals.size() &&
yVals.size() == zVals.size() &&
xVals.size() > 0);
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
std::vector<CoordType> coords(xVals.size());
for (size_t i=0; i < xVals.size(); i++)
{
coords[i][0] = xVals[i];
coords[i][1] = yVals[i];
coords[i][2] = 0;
}
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem(coordsNm, 1, coords));
vtkm::cont::ArrayHandle<T> Xc, Yc, Zc;
DFA::Copy(vtkm::cont::make_ArrayHandle(xVals), Xc);
DFA::Copy(vtkm::cont::make_ArrayHandle(yVals), Yc);
DFA::Copy(vtkm::cont::make_ArrayHandle(zVals), Zc);
vtkm::Id nPts = static_cast<vtkm::Id>(coords.size());
vtkm::cont::CellSetExplicit<> cellSet(nPts, cellNm, 2);
cellSet.FillViaCopy(shapes, numIndices, connectivity);
dataSet.AddCellSet(cellSet);
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 dataSet;
return BuildDataSet(Xc,Yc,Zc, Sc,Nc,Cc, coordsNm, cellNm);
}
template<typename T>
vtkm::cont::DataSet
DataSetBuilderExplicit::Create(const std::vector<T> &xVals,
const std::vector<T> &yVals,
const std::vector<T> &zVals,
const std::vector<vtkm::UInt8> &shapes,
const std::vector<vtkm::IdComponent> &numIndices,
const std::vector<vtkm::Id> &connectivity,
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,
const std::string &coordsNm,
const std::string &cellNm)
{
VTKM_CONT_ASSERT(xVals.size() == yVals.size() &&
yVals.size() == zVals.size() &&
xVals.size() > 0);
VTKM_ASSERT_CONT(X.GetNumberOfValues() == Y.GetNumberOfValues() &&
Y.GetNumberOfValues() == Z.GetNumberOfValues() &&
X.GetNumberOfValues() > 0 &&
shapes.GetNumberOfValues() == numIndices.GetNumberOfValues());
vtkm::cont::DataSet dataSet;
//Temp code until ArrayHandleCompositeVector is fully working...
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
std::vector<CoordType> coords(xVals.size());
for (size_t i=0; i < coords.size(); i++)
std::size_t nPts = X.GetNumberOfValues();
std::vector<CoordType> coords(nPts);
for (std::size_t i = 0; i < nPts; i++)
{
coords[i][0] = xVals[i];
coords[i][1] = yVals[i];
coords[i][2] = zVals[i];
coords[i][0] = X.GetPortalConstControl().Get(i);
coords[i][1] = Y.GetPortalConstControl().Get(i);
coords[i][2] = Z.GetPortalConstControl().Get(i);
}
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem(coordsNm, 1, coords));
vtkm::Id nPts = static_cast<vtkm::Id>(coords.size());
vtkm::cont::CellSetExplicit<> cellSet(nPts, cellNm, 2);
cellSet.FillViaCopy(shapes, numIndices, connectivity);
vtkm::cont::CellSetExplicit<> cellSet(nPts, cellNm, 3);
cellSet.Fill(shapes, numIndices, connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
......@@ -277,11 +222,36 @@ DataSetBuilderExplicit::Create(const std::vector<vtkm::Vec<T,3> > &coords,
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem(coordsNm, 1, coordsArray));
vtkm::Id nPts = static_cast<vtkm::Id>(coords.size());
vtkm::cont::CellSetExplicit<> cellSet(nPts, cellNm, 2);
cellSet.FillViaCopy(shapes, numIndices, connectivity);
dataSet.AddCellSet(cellSet);
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);
}
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)
{
vtkm::cont::DataSet dataSet;
dataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem(coordsNm,
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;
}
......@@ -295,12 +265,12 @@ public:
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);
this->coordNm = _coordNm;
this->cellNm = _cellNm;
this->points.resize(0);
this->shapes.resize(0);
this->numIdx.resize(0);
this->connectivity.resize(0);
}
//Define points.
......@@ -342,21 +312,33 @@ public:
//Define cells.
VTKM_CONT_EXPORT
void AddCell(vtkm::UInt8 shape)
{
this->shapes.push_back(shape);
this->numIdx.push_back(0);
}
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()));
this->shapes.push_back(shape);
this->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);
this->shapes.push_back(shape);
this->numIdx.push_back(n);
for (int i = 0; i < n; i++)
connectivity.push_back(conn[i]);
}
VTKM_CONT_EXPORT
void AddCellPoint(vtkm::Id pointIndex)
{
VTKM_ASSERT_CONT(this->numIdx.size() > 0);
this->connectivity.push_back(pointIndex);
this->numIdx.back() += 1;
}
private:
std::string coordNm, cellNm;
......@@ -375,6 +357,95 @@ DataSetBuilderExplicitIterative::Create()
}
#if 0
template<typename T, typename CellType>
vtkm::cont::DataSet
DataSetBuilderExplicit::Create(const std::vector<T> &xVals,
const std::vector<T> &yVals,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm,
const std::string &cellNm)
{
VTKM_CONT_ASSERT(xVals.size() == yVals.size() && xVals.size() > 0);
vtkm::cont::DataSet dataSet;
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];
coords[i][1] = yVals[i];
coords[i][2] = 0;
}
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem(coordsNm, 1, coords));
vtkm::cont::CellSetSingleType< > cellSet(CellType(), cellNm);
cellSet.FillViaCopy(connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
}
template<typename T, typename CellType>
vtkm::cont::DataSet
DataSetBuilderExplicit::Create(const std::vector<T> &xVals,
const std::vector<T> &yVals,
const std::vector<T> &zVals,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm,
const std::string &cellNm)
{
VTKM_CONT_ASSERT(xVals.size() == yVals.size() &&
yVals.size() == zVals.size() &&
xVals.size() > 0);
vtkm::cont::DataSet dataSet;
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++)
{
coords[i][0] = xVals[i];
coords[i][1] = yVals[i];
coords[i][2] = zVals[i];
}
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem(coordsNm, 1, coords));
vtkm::cont::CellSetSingleType< > cellSet(CellType(), cellNm);
cellSet.FillViaCopy(connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
}
template<typename T, typename CellType>
vtkm::cont::DataSet
DataSetBuilderExplicit::Create(const std::vector<vtkm::Vec<T,3> > &coords,
const std::vector<vtkm::Id> &connectivity,
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::CellSetSingleType< > cellSet(CellType(), cellNm);
cellSet.FillViaCopy(connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
}
#endif
}
}
......
......@@ -97,6 +97,43 @@ public:
dataSet.AddField(Field(fieldName, 1, vtkm::cont::Field::ASSOC_CELL_SET,
cellSetName, field, n));
}
template <typename T, typename Storage>
VTKM_CONT_EXPORT
void AddCellField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
vtkm::cont::ArrayHandle<T, Storage> &field,
vtkm::Id cellSetIndex = 0)
{
std::string cellSetName =
dataSet.GetCellSet(cellSetIndex).GetCellSet().GetName();
this->AddCellField(dataSet, fieldName, field, cellSetName);
}
template<typename T>
VTKM_CONT_EXPORT
void AddCellField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
const std::vector<T> &field,
vtkm::Id cellSetIndex = 0)
{
std::string cellSetName =
dataSet.GetCellSet(cellSetIndex).GetCellSet().GetName();
this->AddCellField(dataSet, fieldName, field, cellSetName);
}
template<typename T>
VTKM_CONT_EXPORT
void AddCellField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
const T *field, const vtkm::Id &n,
vtkm::Id cellSetIndex = 0)
{
std::string cellSetName =
dataSet.GetCellSet(cellSetIndex).GetCellSet().GetName();
this->AddCellField(dataSet, fieldName, field, n, cellSetName);
}
};
}
......
......@@ -19,6 +19,7 @@
##============================================================================
set(headers
ExplicitTestData.h
MakeTestDataSet.h
Testing.h
TestingArrayHandles.h
......@@ -45,6 +46,7 @@ set(unit_tests
UnitTestArrayPortalToIterators.cxx
UnitTestContTesting.cxx
UnitTestComputeBoundsSerial.cxx
UnitTestDataSetBuilderExplicit.cxx
UnitTestDataSetBuilderRectilinear.cxx
UnitTestDataSetBuilderRegular.cxx
UnitTestDataSetRegular.cxx
......
This diff is collapsed.
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//
//=============================================================================
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/Assert.h>
#include <vtkm/cont/testing/Testing.h>