2015-07-09 03:10:19 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
#include <vtkm/worklet/ExternalFaces.h>
|
|
|
|
|
2015-08-14 18:30:47 +00:00
|
|
|
namespace {
|
2015-07-09 03:10:19 +00:00
|
|
|
|
2015-07-14 20:33:55 +00:00
|
|
|
vtkm::cont::DataSet RunExternalFaces(vtkm::cont::DataSet &ds)
|
2015-07-09 03:10:19 +00:00
|
|
|
{
|
|
|
|
|
2015-08-19 14:44:07 +00:00
|
|
|
vtkm::cont::CellSetExplicit<> &cellset =
|
2015-08-08 19:33:15 +00:00
|
|
|
ds.GetCellSet(0).CastTo<vtkm::cont::CellSetExplicit<> >();
|
2015-07-19 00:50:36 +00:00
|
|
|
|
2015-08-19 14:44:07 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> shapes = cellset.GetShapesArray();
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> numIndices = cellset.GetNumIndicesArray();
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> conn = cellset.GetConnectivityArray();
|
2015-07-19 00:50:36 +00:00
|
|
|
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> output_shapes;
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> output_numIndices;
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> output_conn;
|
|
|
|
|
|
|
|
//Run the External Faces worklet
|
|
|
|
vtkm::worklet::ExternalFaces<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>().run(
|
|
|
|
shapes,
|
|
|
|
numIndices,
|
|
|
|
conn,
|
|
|
|
output_shapes,
|
|
|
|
output_numIndices,
|
|
|
|
output_conn);
|
|
|
|
|
|
|
|
vtkm::cont::DataSet new_ds;
|
|
|
|
new_ds.AddField(ds.GetField("x"));
|
|
|
|
new_ds.AddField(ds.GetField("y"));
|
|
|
|
new_ds.AddField(ds.GetField("z"));
|
|
|
|
new_ds.AddCoordinateSystem(vtkm::cont::CoordinateSystem("x","y","z"));
|
2015-08-10 22:32:07 +00:00
|
|
|
|
|
|
|
vtkm::cont::CellSetExplicit<> new_cs("cells",
|
|
|
|
static_cast<vtkm::IdComponent>(output_shapes.GetNumberOfValues()));
|
2015-08-19 14:44:07 +00:00
|
|
|
new_cs.Fill(output_shapes, output_numIndices, output_conn);
|
2015-07-19 00:50:36 +00:00
|
|
|
new_ds.AddCellSet(new_cs);
|
|
|
|
|
|
|
|
return new_ds;
|
2015-07-09 03:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestExternalFaces()
|
|
|
|
{
|
2015-07-19 00:50:36 +00:00
|
|
|
//--------------Construct a VTK-m Test Dataset----------------
|
|
|
|
|
|
|
|
vtkm::cont::DataSet ds;
|
|
|
|
|
|
|
|
const int nVerts = 8; //A cube that is tetrahedralized
|
|
|
|
vtkm::Float32 xVals[nVerts] = {0, 1, 1, 0, 0, 1, 1, 0};
|
|
|
|
vtkm::Float32 yVals[nVerts] = {0, 0, 1, 1, 0, 0, 1, 1};
|
|
|
|
vtkm::Float32 zVals[nVerts] = {0, 0, 0, 0, 1, 1, 1, 1};
|
|
|
|
ds.AddField(vtkm::cont::Field("x", 1, vtkm::cont::Field::ASSOC_POINTS, xVals, nVerts));
|
|
|
|
ds.AddField(vtkm::cont::Field("y", 1, vtkm::cont::Field::ASSOC_POINTS, yVals, nVerts));
|
|
|
|
ds.AddField(vtkm::cont::Field("z", 1, vtkm::cont::Field::ASSOC_POINTS, zVals, nVerts));
|
|
|
|
ds.AddCoordinateSystem(vtkm::cont::CoordinateSystem("x","y","z"));
|
|
|
|
|
|
|
|
//Construct the VTK-m shapes and numIndices connectivity arrays
|
|
|
|
const int nCells = 6; //The tetrahedrons of the cube
|
|
|
|
int cellVerts[nCells][4] = {{4,7,6,3}, {4,6,3,2}, {4,0,3,2},
|
|
|
|
{4,6,5,2}, {4,5,0,2}, {1,0,5,2}};
|
2015-08-10 22:32:07 +00:00
|
|
|
vtkm::cont::CellSetExplicit<> cs("cells", nCells);
|
|
|
|
|
2015-07-19 00:50:36 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> shapes;
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> numIndices;
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> conn;
|
|
|
|
shapes.Allocate(static_cast<vtkm::Id>(nCells));
|
|
|
|
numIndices.Allocate(static_cast<vtkm::Id>(nCells));
|
|
|
|
conn.Allocate(static_cast<vtkm::Id>(4 * nCells));
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
for(int j = 0; j < nCells; j++)
|
|
|
|
{
|
|
|
|
shapes.GetPortalControl().Set(j, static_cast<vtkm::Id>(vtkm::VTKM_TETRA));
|
|
|
|
numIndices.GetPortalControl().Set(j, 4);
|
|
|
|
for(int k = 0; k < 4; k++)
|
|
|
|
conn.GetPortalControl().Set(index++, static_cast<vtkm::Id>(cellVerts[j][k]));
|
|
|
|
}
|
|
|
|
|
2015-08-19 14:44:07 +00:00
|
|
|
cs.Fill(shapes, numIndices, conn);
|
2015-07-19 00:50:36 +00:00
|
|
|
|
|
|
|
//Add the VTK-m cell set
|
|
|
|
ds.AddCellSet(cs);
|
|
|
|
|
|
|
|
//Run the External Faces worklet
|
|
|
|
vtkm::cont::DataSet new_ds = RunExternalFaces(ds);
|
2015-08-08 19:33:15 +00:00
|
|
|
vtkm::cont::CellSetExplicit<> &new_cs =
|
|
|
|
new_ds.GetCellSet(0).CastTo<vtkm::cont::CellSetExplicit<> >();
|
2015-07-19 00:50:36 +00:00
|
|
|
|
2015-08-19 14:44:07 +00:00
|
|
|
vtkm::Id numExtFaces_out = new_cs.GetNumberOfCells();
|
2015-07-19 00:50:36 +00:00
|
|
|
|
|
|
|
//Validate the number of external faces (output) returned by the worklet
|
|
|
|
const vtkm::Id numExtFaces_actual = 12;
|
|
|
|
VTKM_TEST_ASSERT(numExtFaces_out == numExtFaces_actual, "Number of External Faces mismatch");
|
2015-07-09 03:10:19 +00:00
|
|
|
|
|
|
|
} // TestExternalFaces
|
|
|
|
|
2015-08-14 18:30:47 +00:00
|
|
|
}
|
2015-07-09 03:10:19 +00:00
|
|
|
|
|
|
|
int UnitTestExternalFaces(int, char *[])
|
|
|
|
{
|
2015-07-19 00:50:36 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestExternalFaces);
|
2015-07-09 03:10:19 +00:00
|
|
|
}
|