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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2015-07-09 03:10:19 +00:00
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
|
|
|
// Copyright 2014 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2015-07-09 03:10:19 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
2016-01-15 20:42:51 +00:00
|
|
|
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
2017-08-03 15:19:22 +00:00
|
|
|
#include <vtkm/cont/DataSetBuilderUniform.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
2017-01-19 01:02:52 +00:00
|
|
|
|
2016-12-06 00:30:57 +00:00
|
|
|
#include <vtkm/cont/internal/DeviceAdapterError.h>
|
2017-01-19 01:02:52 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
2015-07-09 03:10:19 +00:00
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
2017-01-19 01:02:52 +00:00
|
|
|
|
2015-07-09 03:10:19 +00:00
|
|
|
#include <vtkm/worklet/ExternalFaces.h>
|
|
|
|
|
2016-12-06 00:30:57 +00:00
|
|
|
#include <algorithm>
|
2017-01-19 01:02:52 +00:00
|
|
|
#include <iostream>
|
2016-12-06 00:30:57 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2015-07-09 03:10:19 +00:00
|
|
|
|
2016-12-06 00:30:57 +00:00
|
|
|
// For this test, we want using the default device adapter to be an error
|
|
|
|
// to make sure that all the code is using the device adapter we specify.
|
|
|
|
using MyDeviceAdapter = VTKM_DEFAULT_DEVICE_ADAPTER_TAG;
|
|
|
|
#undef VTKM_DEFAULT_DEVICE_ADAPTER_TAG
|
|
|
|
#define VTKM_DEFAULT_DEVICE_ADAPTER_TAG ::vtkm::cont::DeviceAdapterTagError
|
2015-07-09 03:10:19 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::DataSet RunExternalFaces(vtkm::cont::DataSet& inDataSet)
|
2016-12-06 00:30:57 +00:00
|
|
|
{
|
2017-08-03 15:19:22 +00:00
|
|
|
const vtkm::cont::DynamicCellSet& inCellSet = inDataSet.GetCellSet(0);
|
2015-08-26 12:49:17 +00:00
|
|
|
|
2016-12-06 00:30:57 +00:00
|
|
|
vtkm::cont::CellSetExplicit<> outCellSet("cells");
|
2015-08-26 12:49:17 +00:00
|
|
|
|
|
|
|
//Run the External Faces worklet
|
2017-08-03 15:19:22 +00:00
|
|
|
if (inCellSet.IsSameType(vtkm::cont::CellSetStructured<3>()))
|
2017-08-17 21:48:47 +00:00
|
|
|
{
|
2017-08-03 15:19:22 +00:00
|
|
|
vtkm::worklet::ExternalFaces().Run(inCellSet.Cast<vtkm::cont::CellSetStructured<3>>(),
|
|
|
|
inDataSet.GetCoordinateSystem(),
|
2018-08-30 15:53:18 +00:00
|
|
|
outCellSet);
|
2017-08-17 21:48:47 +00:00
|
|
|
}
|
2017-08-03 15:19:22 +00:00
|
|
|
else
|
2017-08-17 21:48:47 +00:00
|
|
|
{
|
2018-08-30 15:53:18 +00:00
|
|
|
vtkm::worklet::ExternalFaces().Run(inCellSet.Cast<vtkm::cont::CellSetExplicit<>>(), outCellSet);
|
2017-08-17 21:48:47 +00:00
|
|
|
}
|
2015-08-26 12:49:17 +00:00
|
|
|
|
2016-12-06 00:30:57 +00:00
|
|
|
vtkm::cont::DataSet outDataSet;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < inDataSet.GetNumberOfCoordinateSystems(); ++i)
|
2015-08-26 12:49:17 +00:00
|
|
|
{
|
2016-12-06 00:30:57 +00:00
|
|
|
outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(i));
|
2015-08-26 12:49:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 00:30:57 +00:00
|
|
|
outDataSet.AddCellSet(outCellSet);
|
2015-08-26 12:49:17 +00:00
|
|
|
|
2016-12-06 00:30:57 +00:00
|
|
|
return outDataSet;
|
2015-07-09 03:10:19 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 01:02:52 +00:00
|
|
|
void TestExternalFaces1()
|
2015-07-09 03:10:19 +00:00
|
|
|
{
|
2017-01-19 01:02:52 +00:00
|
|
|
std::cout << "Test 1" << std::endl;
|
|
|
|
|
2015-08-26 12:49:17 +00:00
|
|
|
//--------------Construct a VTK-m Test Dataset----------------
|
|
|
|
const int nVerts = 8; //A cube that is tetrahedralized
|
2018-02-22 13:29:13 +00:00
|
|
|
using CoordType = vtkm::Vec<vtkm::Float32, 3>;
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandle<CoordType> coordinates;
|
2016-01-15 20:42:51 +00:00
|
|
|
coordinates.Allocate(nVerts);
|
2017-05-18 14:29:41 +00:00
|
|
|
coordinates.GetPortalControl().Set(0, CoordType(0.0f, 0.0f, 0.0f));
|
|
|
|
coordinates.GetPortalControl().Set(1, CoordType(1.0f, 0.0f, 0.0f));
|
|
|
|
coordinates.GetPortalControl().Set(2, CoordType(1.0f, 1.0f, 0.0f));
|
|
|
|
coordinates.GetPortalControl().Set(3, CoordType(0.0f, 1.0f, 0.0f));
|
|
|
|
coordinates.GetPortalControl().Set(4, CoordType(0.0f, 0.0f, 1.0f));
|
|
|
|
coordinates.GetPortalControl().Set(5, CoordType(1.0f, 0.0f, 1.0f));
|
|
|
|
coordinates.GetPortalControl().Set(6, CoordType(1.0f, 1.0f, 1.0f));
|
|
|
|
coordinates.GetPortalControl().Set(7, CoordType(0.0f, 1.0f, 1.0f));
|
2015-08-26 12:49:17 +00:00
|
|
|
|
|
|
|
//Construct the VTK-m shapes and numIndices connectivity arrays
|
2017-05-18 14:29:41 +00:00
|
|
|
const int nCells = 6; //The tetrahedrons of the cube
|
|
|
|
vtkm::IdComponent 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-26 12:49:17 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::UInt8> shapes;
|
2015-09-01 21:51:21 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::IdComponent> numIndices;
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> conn;
|
2015-08-26 12:49:17 +00:00
|
|
|
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;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (int j = 0; j < nCells; j++)
|
2015-08-26 12:49:17 +00:00
|
|
|
{
|
2015-09-01 21:51:21 +00:00
|
|
|
shapes.GetPortalControl().Set(j, static_cast<vtkm::UInt8>(vtkm::CELL_SHAPE_TETRA));
|
2015-08-26 12:49:17 +00:00
|
|
|
numIndices.GetPortalControl().Set(j, 4);
|
2017-05-18 14:29:41 +00:00
|
|
|
for (int k = 0; k < 4; k++)
|
2015-09-01 21:51:21 +00:00
|
|
|
conn.GetPortalControl().Set(index++, cellVerts[j][k]);
|
2015-08-26 12:49:17 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 20:42:51 +00:00
|
|
|
vtkm::cont::DataSetBuilderExplicit builder;
|
|
|
|
vtkm::cont::DataSet ds = builder.Create(coordinates, shapes, numIndices, conn);
|
2015-08-26 12:49:17 +00:00
|
|
|
|
|
|
|
//Run the External Faces worklet
|
|
|
|
vtkm::cont::DataSet new_ds = RunExternalFaces(ds);
|
2016-01-14 19:01:05 +00:00
|
|
|
vtkm::cont::CellSetExplicit<> new_cs;
|
|
|
|
new_ds.GetCellSet(0).CopyTo(new_cs);
|
2015-08-26 12:49:17 +00:00
|
|
|
|
|
|
|
vtkm::Id numExtFaces_out = new_cs.GetNumberOfCells();
|
|
|
|
|
|
|
|
//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
|
|
|
|
2017-01-19 01:02:52 +00:00
|
|
|
} // TestExternalFaces1
|
|
|
|
|
|
|
|
void TestExternalFaces2()
|
|
|
|
{
|
|
|
|
std::cout << "Test 2" << std::endl;
|
|
|
|
|
|
|
|
vtkm::cont::testing::MakeTestDataSet dataSetMaker;
|
|
|
|
vtkm::cont::DataSet inDataSet = dataSetMaker.Make3DExplicitDataSet5();
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
// vtkm::io::writer::VTKDataSetWriter writer("vtkm_explicit_data_5.vtk");
|
|
|
|
// writer.WriteDataSet(inDataSet);
|
2017-01-19 01:02:52 +00:00
|
|
|
|
|
|
|
// Expected faces
|
|
|
|
const vtkm::IdComponent MAX_POINTS_PER_FACE = 4;
|
|
|
|
const vtkm::Id NUM_FACES = 12;
|
|
|
|
const vtkm::Id ExpectedExternalFaces[NUM_FACES][MAX_POINTS_PER_FACE] = {
|
2017-05-18 14:29:41 +00:00
|
|
|
{ 0, 3, 7, 4 }, { 0, 1, 2, 3 }, { 0, 4, 5, 1 }, { 3, 2, 6, 7 },
|
|
|
|
{ 1, 5, 8, -1 }, { 6, 2, 8, -1 }, { 2, 1, 8, -1 }, { 8, 10, 6, -1 },
|
|
|
|
{ 5, 10, 8, -1 }, { 4, 7, 9, -1 }, { 7, 6, 10, 9 }, { 9, 10, 5, 4 }
|
2017-01-19 01:02:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
vtkm::cont::DataSet outDataSet = RunExternalFaces(inDataSet);
|
|
|
|
vtkm::cont::CellSetExplicit<> outCellSet;
|
|
|
|
outDataSet.GetCellSet(0).CopyTo(outCellSet);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == NUM_FACES, "Got wrong number of faces.");
|
2017-01-19 01:02:52 +00:00
|
|
|
|
|
|
|
bool foundFaces[NUM_FACES];
|
|
|
|
for (vtkm::Id faceId = 0; faceId < NUM_FACES; faceId++)
|
|
|
|
{
|
|
|
|
foundFaces[faceId] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (vtkm::Id dataFaceId = 0; dataFaceId < NUM_FACES; dataFaceId++)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<vtkm::Id, MAX_POINTS_PER_FACE> dataIndices(-1);
|
2017-01-19 01:02:52 +00:00
|
|
|
outCellSet.GetIndices(dataFaceId, dataIndices);
|
|
|
|
std::cout << "Looking for face " << dataIndices << std::endl;
|
|
|
|
bool foundFace = false;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::Id expectedFaceId = 0; expectedFaceId < NUM_FACES; expectedFaceId++)
|
2017-01-19 01:02:52 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<vtkm::Id, MAX_POINTS_PER_FACE> expectedIndices;
|
|
|
|
vtkm::make_VecC(ExpectedExternalFaces[expectedFaceId], 4).CopyInto(expectedIndices);
|
2017-01-19 01:02:52 +00:00
|
|
|
if (expectedIndices == dataIndices)
|
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(!foundFaces[expectedFaceId], "Found face twice.");
|
|
|
|
std::cout << " found" << std::endl;
|
|
|
|
foundFace = true;
|
|
|
|
foundFaces[expectedFaceId] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VTKM_TEST_ASSERT(foundFace, "Face not found.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 15:19:22 +00:00
|
|
|
void TestExternalFaces3()
|
|
|
|
{
|
|
|
|
std::cout << "Test 3" << std::endl;
|
|
|
|
|
|
|
|
vtkm::cont::DataSetBuilderUniform dataSetBuilder;
|
|
|
|
vtkm::cont::DataSet dataSet = dataSetBuilder.Create(vtkm::Id3(6, 6, 5));
|
|
|
|
|
|
|
|
//Run the External Faces worklet
|
|
|
|
vtkm::cont::DataSet new_ds = RunExternalFaces(dataSet);
|
|
|
|
vtkm::cont::CellSetExplicit<> new_cs;
|
|
|
|
new_ds.GetCellSet(0).CopyTo(new_cs);
|
|
|
|
|
|
|
|
vtkm::Id numExtFaces_out = new_cs.GetNumberOfCells();
|
|
|
|
|
|
|
|
//Validate the number of external faces (output) returned by the worklet
|
|
|
|
const vtkm::Id numExtFaces_actual = 130;
|
|
|
|
VTKM_TEST_ASSERT(numExtFaces_out == numExtFaces_actual, "Number of External Faces mismatch");
|
|
|
|
}
|
|
|
|
|
2017-01-19 01:02:52 +00:00
|
|
|
void TestExternalFaces()
|
|
|
|
{
|
2018-10-17 19:17:29 +00:00
|
|
|
// Ignore the device passed in.
|
|
|
|
vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(MyDeviceAdapter());
|
2017-01-19 01:02:52 +00:00
|
|
|
TestExternalFaces1();
|
|
|
|
TestExternalFaces2();
|
2017-08-03 15:19:22 +00:00
|
|
|
TestExternalFaces3();
|
2017-01-19 01:02:52 +00:00
|
|
|
}
|
2015-08-14 18:30:47 +00:00
|
|
|
}
|
2015-07-09 03:10:19 +00:00
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
int UnitTestExternalFaces(int argc, char* argv[])
|
2015-07-09 03:10:19 +00:00
|
|
|
{
|
2018-10-17 19:17:29 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestExternalFaces, argc, argv);
|
2015-07-09 03:10:19 +00:00
|
|
|
}
|