2015-06-19 18:24:10 +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 <vtkm/cont/DataSet.h>
|
2015-08-28 13:16:45 +00:00
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
2015-06-19 18:24:10 +00:00
|
|
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
2015-08-28 13:16:45 +00:00
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
2015-06-19 18:24:10 +00:00
|
|
|
|
2015-08-28 13:16:45 +00:00
|
|
|
#include <vtkm/worklet/DispatcherMapField.h>
|
2015-06-19 20:30:53 +00:00
|
|
|
#include <vtkm/worklet/VertexClustering.h>
|
2015-06-25 17:16:16 +00:00
|
|
|
|
2015-06-19 18:24:10 +00:00
|
|
|
|
|
|
|
void TestVertexClustering()
|
|
|
|
{
|
2016-01-20 17:05:48 +00:00
|
|
|
const vtkm::Id3 divisions(3, 3, 3);
|
2015-06-19 18:24:10 +00:00
|
|
|
vtkm::cont::testing::MakeTestDataSet maker;
|
2016-01-20 17:05:48 +00:00
|
|
|
vtkm::cont::DataSet dataSet = maker.Make3DExplicitDataSetCowNose();
|
|
|
|
|
|
|
|
//compute the bounds before calling the algorithm
|
2017-02-24 21:39:37 +00:00
|
|
|
vtkm::Bounds bounds = dataSet.GetCoordinateSystem().GetBounds();
|
2015-06-19 20:30:53 +00:00
|
|
|
|
|
|
|
// run
|
2016-01-14 20:42:27 +00:00
|
|
|
vtkm::worklet::VertexClustering clustering;
|
2015-08-28 13:16:45 +00:00
|
|
|
vtkm::cont::DataSet outDataSet = clustering.Run(dataSet.GetCellSet(),
|
2016-08-05 19:24:17 +00:00
|
|
|
dataSet.GetCoordinateSystem(),
|
2016-01-20 17:05:48 +00:00
|
|
|
bounds,
|
2016-01-14 20:42:27 +00:00
|
|
|
divisions,
|
|
|
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
2015-06-19 20:30:53 +00:00
|
|
|
|
|
|
|
// test
|
2015-06-29 22:10:25 +00:00
|
|
|
const vtkm::Id output_pointIds = 9;
|
2015-07-02 21:06:56 +00:00
|
|
|
vtkm::Id output_pointId[output_pointIds] = {0,1,3, 1,5,4, 1,2,5};
|
2015-06-29 22:10:25 +00:00
|
|
|
const vtkm::Id output_points = 6;
|
2015-08-17 18:47:46 +00:00
|
|
|
vtkm::Float64 output_point[output_points][3] = {{0.0174716003,0.0501927994,0.0930275023}, {0.0320714004,0.14704667,0.0952706337}, {0.0268670674,0.246195346,0.119720004}, {0.00215422804,0.0340906903,0.180881709}, {0.0108188,0.152774006,0.167914003}, {0.0202241503,0.225427493,0.140208006}};
|
2015-06-24 18:52:41 +00:00
|
|
|
|
2015-08-17 18:47:46 +00:00
|
|
|
VTKM_TEST_ASSERT(outDataSet.GetNumberOfCoordinateSystems() == 1,
|
|
|
|
"Number of output coordinate systems mismatch");
|
|
|
|
typedef vtkm::Vec<vtkm::Float64, 3> PointType;
|
2016-01-14 19:01:05 +00:00
|
|
|
vtkm::cont::ArrayHandle<PointType> pointArray;
|
|
|
|
outDataSet.GetCoordinateSystem(0).GetData().CopyTo(pointArray);
|
2015-08-17 18:47:46 +00:00
|
|
|
VTKM_TEST_ASSERT(pointArray.GetNumberOfValues() == output_points,
|
|
|
|
"Number of output points mismatch" );
|
2015-06-29 21:14:50 +00:00
|
|
|
for (vtkm::Id i = 0; i < pointArray.GetNumberOfValues(); ++i)
|
2015-06-24 18:52:41 +00:00
|
|
|
{
|
|
|
|
const PointType &p1 = pointArray.GetPortalConstControl().Get(i);
|
2015-08-17 18:47:46 +00:00
|
|
|
PointType p2 = vtkm::make_Vec(output_point[i][0],
|
|
|
|
output_point[i][1],
|
|
|
|
output_point[i][2]);
|
2015-06-24 18:52:41 +00:00
|
|
|
std::cout << "point: " << p1 << " " << p2 << std::endl;
|
2015-06-25 17:16:16 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(p1, p2), "Point Array mismatch");
|
2015-06-24 18:52:41 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 13:22:49 +00:00
|
|
|
typedef vtkm::cont::CellSetSingleType<> CellSetType;
|
2015-07-28 23:33:52 +00:00
|
|
|
VTKM_TEST_ASSERT(outDataSet.GetNumberOfCellSets() == 1, "Number of output cellsets mismatch");
|
2016-01-14 19:01:05 +00:00
|
|
|
CellSetType cellSet;
|
|
|
|
outDataSet.GetCellSet(0).CopyTo(cellSet);
|
2015-08-02 21:59:44 +00:00
|
|
|
VTKM_TEST_ASSERT(
|
2015-09-02 16:26:37 +00:00
|
|
|
cellSet.GetConnectivityArray(vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell()).GetNumberOfValues() == output_pointIds,
|
2015-08-02 21:59:44 +00:00
|
|
|
"Number of connectivity array elements mismatch");
|
2015-09-02 16:26:37 +00:00
|
|
|
for (vtkm::Id i=0; i<cellSet.GetConnectivityArray(vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell()).GetNumberOfValues(); i++)
|
2015-06-24 18:52:41 +00:00
|
|
|
{
|
2015-09-02 16:26:37 +00:00
|
|
|
vtkm::Id id1 = cellSet.GetConnectivityArray(vtkm::TopologyElementTagPoint(),vtkm::TopologyElementTagCell()).GetPortalConstControl().Get(i) ;
|
2015-06-24 18:52:41 +00:00
|
|
|
vtkm::Id id2 = output_pointId[i] ;
|
|
|
|
std::cout << "pointid: " << id1 << " " << id2 << std::endl;
|
2015-07-02 21:06:56 +00:00
|
|
|
//VTKM_TEST_ASSERT( id1 == id2, "Connectivity Array mismatch" ) ;
|
2015-06-24 18:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // TestVertexClustering
|
2015-06-19 20:30:53 +00:00
|
|
|
|
2015-06-19 18:24:10 +00:00
|
|
|
|
|
|
|
int UnitTestVertexClustering(int, char *[])
|
|
|
|
{
|
|
|
|
return vtkm::cont::testing::Testing::Run(TestVertexClustering);
|
|
|
|
}
|