Commit 8214be00 authored by Dave Pugmire's avatar Dave Pugmire
Browse files

Add dataset builder classes.

parent 665b3489
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_cont_DataSetBuilderExplicit_h
#define vtk_m_cont_DataSetBuilderExplicit_h
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/Assert.h>
namespace vtkm {
namespace cont {
//Coordinates builder??
//Need a singlecellset handler.
class DataSetBuilderExplicit
{
public:
VTKM_CONT_EXPORT
DataSetBuilderExplicit() {}
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(const std::vector<T> &xVals,
const std::vector<T> &yVals,
const std::vector<vtkm::UInt8> &shapes,
const std::vector<vtkm::IdComponent> &numIndices,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm="coords",
const std::string &cellNm="cells");
template<typename T>
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::UInt8> &shapes,
const std::vector<vtkm::IdComponent> &numIndices,
const std::vector<vtkm::Id> &connectivity,
const std::string &coordsNm="coords",
const std::string &cellNm="cells");
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
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,
const std::string &coordsNm="coords",
const std::string &cellNm="cells");
private:
};
template<typename T>
vtkm::cont::DataSet
DataSetBuilderExplicit::Create(const std::vector<T> &xVals,
const std::vector<T> &yVals,
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;
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
std::vector<CoordType> coords(xVals.size());
size_t nPts = xVals.size();
for (size_t i=0; i < nPts; 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::CellSetExplicit<> cellSet((vtkm::Id)nPts, cellNm, 2);
cellSet.FillViaCopy(shapes, numIndices, connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
}
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() &&
yVals.size() == zVals.size() &&
xVals.size() > 0);
vtkm::cont::DataSet dataSet;
typedef vtkm::Vec<vtkm::Float32,3> CoordType;
std::vector<CoordType> coords(xVals.size());
size_t nPts = xVals.size();
for (size_t 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::CellSetExplicit<> cellSet((vtkm::Id)nPts, cellNm, 3);
cellSet.FillViaCopy(shapes, numIndices, connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
}
template<typename T>
vtkm::cont::DataSet
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,
const std::string &coordsNm,
const std::string &cellNm)
{
vtkm::cont::DataSet dataSet;
size_t nPts = coords.size();
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem(coordsNm, 1, coords));
vtkm::cont::CellSetExplicit<> cellSet((vtkm::Id)nPts, cellNm, 3);
cellSet.FillViaCopy(shapes, numIndices, connectivity);
dataSet.AddCellSet(cellSet);
return dataSet;
}
}
}
#endif //vtk_m_cont_DataSetBuilderExplicit_h
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_cont_DataSetBuilderRegular_h
#define vtk_m_cont_DataSetBuilderRegular_h
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/Assert.h>
namespace vtkm {
namespace cont {
class DataSetBuilderRegular
{
public:
VTKM_CONT_EXPORT
DataSetBuilderRegular() {}
//2D regular grids.
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(vtkm::Id nx, vtkm::Id ny,
std::string coordNm="coords", std::string cellNm="cells")
{
return Create(2, nx, ny, 1, 0,0,0, 1,1,1, coordNm, cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(vtkm::Id nx, vtkm::Id ny,
T originX, T originY, T spacingX, T spacingY,
std::string coordNm="coords", std::string cellNm="cells")
{
Create(2, nx,ny,1, originX,originY,0,
spacingX,spacingY,1,
coordNm, cellNm);
}
//3D regular grids.
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(vtkm::Id nx, vtkm::Id ny, vtkm::Id nz,
std::string coordNm="coords", std::string cellNm="cells")
{
return Create(3, nx, ny, nz, 0,0,0, 1,1,1, coordNm, cellNm);
}
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(vtkm::Id nx, vtkm::Id ny, vtkm::Id nz,
T originX, T originY, T originZ, T spacingX, T spacingY, T spacingZ,
std::string coordNm="coords", std::string cellNm="cells")
{
return Create(3, nx,ny,nz, originX,originY,originZ,
spacingX,spacingY,spacingZ,
coordNm, cellNm);
}
private:
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::DataSet
Create(int dim, vtkm::Id nx, vtkm::Id ny, vtkm::Id nz,
T originX, T originY, T originZ, T spacingX, T spacingY, T spacingZ,
std::string coordNm, std::string cellNm)
{
VTKM_ASSERT_CONT(nx>1 && ny>1 && ((dim==2 && nz==1)||(dim==3 && nz>1)));
vtkm::cont::DataSet dataSet;
vtkm::cont::ArrayHandleUniformPointCoordinates
coords(vtkm::Id3(nx, ny, nz),
vtkm::Vec<T,3>(originX, originY,originZ),
vtkm::Vec<T,3>(spacingX, spacingY,spacingZ));
vtkm::cont::CoordinateSystem cs(coordNm, 1, coords);
dataSet.AddCoordinateSystem(cs);
if (dim == 2)
{
vtkm::cont::CellSetStructured<2> cellSet(cellNm);
cellSet.SetPointDimensions(vtkm::make_Vec(nx,ny));
dataSet.AddCellSet(cellSet);
}
else
{
vtkm::cont::CellSetStructured<3> cellSet(cellNm);
cellSet.SetPointDimensions(vtkm::make_Vec(nx,ny,nz));
dataSet.AddCellSet(cellSet);
}
return dataSet;
}
};
} // namespace cont
} // namespace vtkm
#endif //vtk_m_cont_DataSetBuilderRegular_h
//============================================================================
// 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 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 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.
//============================================================================
#ifndef vtk_m_cont_DataSetFieldAdd_h
#define vtk_m_cont_DataSetFieldAdd_h
namespace vtkm {
namespace cont {
class DataSetFieldAdd
{
public:
VTKM_CONT_EXPORT
DataSetFieldAdd() {}
//Point centered fields.
template <typename T, typename Storage>
VTKM_CONT_EXPORT
void AddPointField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
vtkm::cont::ArrayHandle<T, Storage> &field)
{
dataSet.AddField(Field(fieldName, 1, vtkm::cont::Field::ASSOC_POINTS,
field));
}
template<typename T>
VTKM_CONT_EXPORT
void AddPointField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
const std::vector<T> &field)
{
dataSet.AddField(Field(fieldName, 1, vtkm::cont::Field::ASSOC_POINTS,
field));
}
template<typename T>
VTKM_CONT_EXPORT
void AddPointField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
const T *field, const vtkm::Id &n)
{
dataSet.AddField(Field(fieldName, 1, vtkm::cont::Field::ASSOC_POINTS,
field, n));
}
//Cell centered field
template <typename T, typename Storage>
VTKM_CONT_EXPORT
void AddCellField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
vtkm::cont::ArrayHandle<T, Storage> &field,
const std::string &cellSetName)
{
dataSet.AddField(Field(fieldName, 1, vtkm::cont::Field::ASSOC_CELL_SET,
cellSetName, field));
}
template<typename T>
VTKM_CONT_EXPORT
void AddCellField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
const std::vector<T> &field,
const std::string &cellSetName)
{
dataSet.AddField(Field(fieldName, 1, vtkm::cont::Field::ASSOC_CELL_SET,
cellSetName, field));
}
template<typename T>
VTKM_CONT_EXPORT
void AddCellField(vtkm::cont::DataSet &dataSet,
const std::string &fieldName,
const T *field, const vtkm::Id &n,
const std::string &cellSetName)
{
dataSet.AddField(Field(fieldName, 1, vtkm::cont::Field::ASSOC_CELL_SET,
cellSetName, field, n));
}
};
}
}//namespace vtkm::cont
#endif //vtk_m_cont_DataSetFieldAdd_h
......@@ -31,7 +31,7 @@ bool TestArrayHandle(const vtkm::cont::ArrayHandle<T, Storage> &ah, const T *exp
{
if (size != ah.GetNumberOfValues())
{
return false;
return false;
}
for (vtkm::Id i = 0; i < size; ++i)
......@@ -49,9 +49,7 @@ bool TestArrayHandle(const vtkm::cont::ArrayHandle<T, Storage> &ah, const T *exp
void TestDataSet_Explicit()
{
vtkm::cont::testing::MakeTestDataSet tds;
vtkm::cont::DataSet ds = tds.Make3DExplicitDataSet1();
ds.PrintSummary(std::cout);
vtkm::cont::DataSet ds = tds.Make3DExplicitDataSet0();
VTKM_TEST_ASSERT(ds.GetNumberOfCellSets() == 1,
"Incorrect number of cell sets");
......@@ -66,7 +64,6 @@ void TestDataSet_Explicit()
try
{
//const vtkm::cont::Field &f2 =
ds.GetField("cellvar", vtkm::cont::Field::ASSOC_CELL_SET);
}
catch (...)
......@@ -76,14 +73,11 @@ void TestDataSet_Explicit()
try
{
//const vtkm::cont::Field &f3 =
ds.GetField("cellvar", vtkm::cont::Field::ASSOC_POINTS);
VTKM_TEST_FAIL("Failed to get expected error for association mismatch.");
ds.GetField("pointvar", vtkm::cont::Field::ASSOC_POINTS);
}
catch (vtkm::cont::ErrorControlBadValue error)
catch (...)
{
std::cout << "Caught expected error for association mismatch: "
<< std::endl << " " << error.GetMessage() << std::endl;
VTKM_TEST_FAIL("Failed to get expected error for association mismatch.");
}
VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1,
......
......@@ -49,8 +49,6 @@ TwoDimRegularTest()
vtkm::cont::DataSet dataSet = testDataSet.Make2DRegularDataSet0();
dataSet.PrintSummary(std::cout);
typedef vtkm::cont::CellSetStructured<2> CellSetType;
CellSetType cellSet = dataSet.GetCellSet(0).CastTo<CellSetType>();
......@@ -66,30 +64,22 @@ TwoDimRegularTest()
"Incorrect number of cells");
// test various field-getting methods and associations
const vtkm::cont::Field &f1 = dataSet.GetField("pointvar");
VTKM_TEST_ASSERT(f1.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS,
"Association of 'pointvar' was not ASSOC_POINTS");
try
{
//const vtkm::cont::Field &f2 =
dataSet.GetField("cellvar", vtkm::cont::Field::ASSOC_CELL_SET);
dataSet.GetField("cellvar", vtkm::cont::Field::ASSOC_CELL_SET);
}
catch (...)
{
VTKM_TEST_FAIL("Failed to get field 'cellvar' with ASSOC_CELL_SET.");
VTKM_TEST_FAIL("Failed to get field 'cellvar' with ASSOC_CELL_SET.");
}
try
{
//const vtkm::cont::Field &f3 =
dataSet.GetField("cellvar", vtkm::cont::Field::ASSOC_POINTS);
VTKM_TEST_FAIL("Failed to get expected error for association mismatch.");
dataSet.GetField("pointvar", vtkm::cont::Field::ASSOC_POINTS);
}
catch (vtkm::cont::ErrorControlBadValue error)
catch (...)
{
std::cout << "Caught expected error for association mismatch: "
<< std::endl << " " << error.GetMessage() << std::endl;
VTKM_TEST_FAIL("Failed to get field 'pointvar' with ASSOC_POINT_SET.");
}
vtkm::Id numCells = cellSet.GetNumberOfCells();
......@@ -167,8 +157,6 @@ ThreeDimRegularTest()
vtkm::cont::DataSet dataSet = testDataSet.Make3DRegularDataSet0();
dataSet.PrintSummary(std::cout);
typedef vtkm::cont::CellSetStructured<3> CellSetType;
CellSetType cellSet = dataSet.GetCellSet(0).CastTo<CellSetType>();
......@@ -187,34 +175,25 @@ ThreeDimRegularTest()
VTKM_TEST_ASSERT(cellSet.GetNumberOfCells() == 4,
"Incorrect number of cells");
// test various field-getting methods and associations
const vtkm::cont::Field &f1 = dataSet.GetField("pointvar");
VTKM_TEST_ASSERT(f1.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS,
"Association of 'pointvar' was not ASSOC_POINTS");
try
{
//const vtkm::cont::Field &f2 =
dataSet.GetField("cellvar", vtkm::cont::Field::ASSOC_CELL_SET);
dataSet.GetField("cellvar", vtkm::cont::Field::ASSOC_CELL_SET);
}
catch (...)
{
VTKM_TEST_FAIL("Failed to get field 'cellvar' with ASSOC_CELL_SET.");
VTKM_TEST_FAIL("Failed to get field 'cellvar' with ASSOC_CELL_SET.");
}
try
{
//const vtkm::cont::Field &f3 =
dataSet.GetField("cellvar", vtkm::cont::Field::ASSOC_POINTS);
VTKM_TEST_FAIL("Failed to get expected error for association mismatch.");
dataSet.GetField("pointvar", vtkm::cont::Field::ASSOC_POINTS);
}
catch (vtkm::cont::ErrorControlBadValue error)
catch (...)
{
std::cout << "Caught expected error for association mismatch: "
<< std::endl << " " << error.GetMessage() << std::endl;
VTKM_TEST_FAIL("Failed to get field 'pointvar' with ASSOC_POINT_SET.");
}
vtkm::Id numCells = cellSet.GetNumberOfCells();
vtkm::Id numCells = cellSet.GetNumberOfCells();
for (vtkm::Id cellIndex = 0; cellIndex < numCells; cellIndex++)
{
VTKM_TEST_ASSERT(cellSet.GetNumberOfPointsInCell(cellIndex) == 8,
......
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