Add ExtractCells by Id and by ImplicitFunction

This commit is contained in:
Patricia Kroll Fasel - 090207 2017-03-16 13:44:01 -06:00
parent 8598711c09
commit 9583e627dc
9 changed files with 611 additions and 124 deletions

@ -29,6 +29,7 @@ set(headers
DispatcherReduceByKey.h
DispatcherStreamingMapField.h
ExternalFaces.h
ExtractCells.h
ExtractPoints.h
FieldHistogram.h
FieldStatistics.h

231
vtkm/worklet/ExtractCells.h Normal file

@ -0,0 +1,231 @@
//============================================================================
// 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 vtkm_m_worklet_ExtractCells_h
#define vtkm_m_worklet_ExtractCells_h
#include <vtkm/worklet/ScatterCounting.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/ImplicitFunctions.h>
namespace vtkm {
namespace worklet {
class ExtractCells : public vtkm::worklet::WorkletMapPointToCell
{
public:
ExtractCells() {}
// Set mask for any cell whose points are inside volume of interest
template<typename ImplicitFunction>
class ExtractCellsWithImplicitFunction : public vtkm::worklet::WorkletMapField
{
public:
typedef void ControlSignature(FieldIn<IdComponentType> numIndices,
FieldIn<IdType> indexOffset,
WholeArrayIn<IdType> connectivity,
WholeArrayIn<Vec3> coordinates,
FieldOut<IdComponentType> mask);
typedef _5 ExecutionSignature(_1, _2, _3, _4);
VTKM_CONT
ExtractCellsWithImplicitFunction(const ImplicitFunction &function) : Function(function) {}
template <typename InFieldPortalType, typename InVecFieldPortalType>
VTKM_CONT
vtkm::IdComponent operator()(const vtkm::IdComponent &numIndices,
const vtkm::Id &indexOffset,
const InFieldPortalType &connectivity,
const InVecFieldPortalType &coordinates) const
{
// If any point is outside volume of interest, cell is also
vtkm::IdComponent mask = 1;
for (vtkm::Id indx = indexOffset; indx < (indexOffset+numIndices); indx++)
{
vtkm::Id ptId = connectivity.Get(indx);
vtkm::Vec<FloatDefault,3> coordinate = coordinates.Get(ptId);
vtkm::FloatDefault value = this->Function.Value(coordinate);
if (value > 0)
mask = 0;
}
return mask;
}
private:
ImplicitFunction Function;
};
// Worklet to build new connectivity array from original cellset
// Point ids are the same because usused points are not removed
class BuildConnectivity : public vtkm::worklet::WorkletMapField
{
public:
typedef void ControlSignature(FieldIn<IdComponentType> numIndices,
FieldIn<IdType> inIndexOffset,
FieldIn<IdType> outIndexOffset,
WholeArrayIn<IdType> inConnectivity,
WholeArrayOut<IdType> outConnectivity);
typedef void ExecutionSignature(_1, _2, _3, _4, _5);
VTKM_CONT
BuildConnectivity() {}
template <typename InPortalType, typename OutPortalType>
VTKM_CONT
void operator()(const vtkm::IdComponent &numIndices,
const vtkm::Id &inIndexOffset,
const vtkm::Id &outIndexOffset,
const InPortalType &inConnectivity,
OutPortalType &outConnectivity) const
{
vtkm::Id inIndex = inIndexOffset;
vtkm::Id outIndex = outIndexOffset;
for (vtkm::IdComponent indx = 0; indx < numIndices; indx++)
{
outConnectivity.Set(outIndex++, inConnectivity.Get(inIndex++));
}
}
};
// Extract cells by id and building new connectivity using original point ids
template <typename DeviceAdapter>
vtkm::cont::CellSetExplicit<> DoExtract(const vtkm::cont::CellSetExplicit<> &cellSet,
const vtkm::cont::ArrayHandle<vtkm::Id> &cellIds,
DeviceAdapter device)
{
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithm;
vtkm::cont::ArrayHandlePermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::ArrayHandle<vtkm::UInt8> >
permuteShapes(cellIds,
cellSet.GetShapesArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell()));
vtkm::cont::ArrayHandlePermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::ArrayHandle<vtkm::IdComponent> >
permuteNumIndices(cellIds,
cellSet.GetNumIndicesArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell()));
vtkm::cont::ArrayHandlePermutation<vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::ArrayHandle<vtkm::Id> >
permuteIndexOffsets(cellIds,
cellSet.GetIndexOffsetArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell()));
// Output cell set components
vtkm::cont::ArrayHandle<vtkm::UInt8> outShapes;
DeviceAlgorithm::Copy(permuteShapes, outShapes);
vtkm::cont::ArrayHandle<vtkm::IdComponent> outNumIndices;
DeviceAlgorithm::Copy(permuteNumIndices, outNumIndices);
vtkm::cont::ArrayHandle<vtkm::IdComponent> inOffset;
DeviceAlgorithm::Copy(permuteIndexOffsets, inOffset);
// Calculate the offset of the output indices
vtkm::cont::ArrayHandle<vtkm::IdComponent> outIndexOffsets;
DeviceAlgorithm::ScanExclusive(outNumIndices, outIndexOffsets);
// Size of connectivity
vtkm::Id sizeConnectivity = DeviceAlgorithm::Reduce(outNumIndices, 0);
// Using the input connectivity, empty output connectivity, and index offset, and numIndices
vtkm::cont::ArrayHandle<vtkm::Id> outConnectivity;
outConnectivity.Allocate(sizeConnectivity);
// Build new cells
BuildConnectivity buildConnectivityWorklet;
vtkm::worklet::DispatcherMapField<BuildConnectivity,DeviceAdapter>
buildConnectivityDispatcher(buildConnectivityWorklet);
buildConnectivityDispatcher.Invoke(outNumIndices,
inOffset,
outIndexOffsets,
cellSet.GetConnectivityArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell()),
outConnectivity);
// Build the output cell set
vtkm::cont::CellSetExplicit< > outCellSet("cells");
outCellSet.Fill(cellIds.GetNumberOfValues(),
outShapes,
outNumIndices,
outConnectivity);
return outCellSet;
}
// Extract by cell ids
template <typename DeviceAdapter>
vtkm::cont::CellSetExplicit<> Run(const vtkm::cont::CellSetExplicit<> &cellSet,
const vtkm::cont::ArrayHandle<vtkm::Id> &cellIds,
DeviceAdapter device)
{
return DoExtract(cellSet, cellIds, device);
}
// Extract by ImplicitFunction volume of interest
template <typename ImplicitFunction,
typename DeviceAdapter>
vtkm::cont::CellSetExplicit<> Run(
const vtkm::cont::CellSetExplicit<> &cellSet,
const ImplicitFunction &implicitFunction,
const vtkm::cont::CoordinateSystem &coordinates,
DeviceAdapter device)
{
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithm;
// Mask array to mark if a cell is within the volume of interest
vtkm::cont::ArrayHandle<vtkm::IdComponent> maskArray;
vtkm::Id numberOfInputCells = cellSet.GetNumberOfCells();
DeviceAlgorithm::Copy(vtkm::cont::ArrayHandleConstant<vtkm::IdComponent>(0, numberOfInputCells),
maskArray);
// Worklet output will be a boolean passFlag array
typedef ExtractCellsWithImplicitFunction<ImplicitFunction> ExtractCellsWorklet;
ExtractCellsWorklet worklet(implicitFunction);
DispatcherMapField<ExtractCellsWorklet, DeviceAdapter> dispatcher(worklet);
dispatcher.Invoke(cellSet.GetNumIndicesArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell()),
cellSet.GetIndexOffsetArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell()),
cellSet.GetConnectivityArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell()),
coordinates,
maskArray);
vtkm::worklet::ScatterCounting CellScatter(maskArray, DeviceAdapter(), true);
vtkm::cont::ArrayHandle<vtkm::Id> cellIds = CellScatter.GetOutputToInputMap();
// With the cell ids call the ExtractCellById code
return DoExtract(cellSet, cellIds, device);
}
};
}
} // namespace vtkm::worklet
#endif // vtkm_m_worklet_ExtractCells_h

@ -55,11 +55,9 @@ public:
vtkm::IdComponent operator()(const vtkm::Vec<vtkm::Float64,3> &coordinate) const
{
vtkm::Float64 value = this->Function.Value(coordinate);
vtkm::Float64 gradient = this->Function.Value(coordinate);
vtkm::IdComponent mask = 0;
if (value <= 0)
mask = 1;
std::cout << "Coord " << coordinate[0] << " , " << coordinate[1] << " , " << coordinate[2] << " value " << value << " mask " << mask << " GRADIENT " << gradient << std::endl;
return mask;
}
@ -67,6 +65,24 @@ std::cout << "Coord " << coordinate[0] << " , " << coordinate[1] << " , " << coo
ImplicitFunction Function;
};
template <typename CellSetType,
typename DeviceAdapter>
vtkm::cont::CellSetSingleType<> Run(
const CellSetType &cellSet,
const vtkm::cont::ArrayHandle<vtkm::Id> &pointIds,
const vtkm::cont::CoordinateSystem &coordinates,
DeviceAdapter device)
{
// Make CellSetSingleType with VERTEX at each point id
vtkm::cont::CellSetSingleType< > outCellSet("cells");
outCellSet.Fill(pointIds.GetNumberOfValues(),
vtkm::CellShapeTagVertex::Id,
1,
pointIds);
return outCellSet;
}
template <typename CellSetType,
typename ImplicitFunction,
typename DeviceAdapter>

@ -37,8 +37,6 @@ namespace worklet {
class ThresholdPoints : public vtkm::worklet::WorkletMapPointToCell
{
public:
struct BoolType : vtkm::ListTagBase<bool> { };
template <typename UnaryPredicate>
class ThresholdPointField : public vtkm::worklet::WorkletMapField
{

@ -25,6 +25,7 @@ set(unit_tests
UnitTestClipping.cxx
UnitTestContourTreeUniform.cxx
UnitTestExternalFaces.cxx
UnitTestExtractCells.cxx
UnitTestExtractPoints.cxx
UnitTestFieldHistogram.cxx
UnitTestFieldStatistics.cxx

@ -0,0 +1,250 @@
//============================================================================
// 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 <vtkm/worklet/ExtractCells.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/cont/ArrayPortalToIterators.h>
#include <vtkm/cont/CellSet.h>
#include <algorithm>
#include <iostream>
#include <vector>
using vtkm::cont::testing::MakeTestDataSet;
template <typename DeviceAdapter>
class TestingExtractCells
{
public:
/*
void TestExtractCellsStructuredWithSphere() const
{
std::cout << "Testing extract cells with implicit function (sphere):" << std::endl;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
// Implicit function
vtkm::Vec<vtkm::FloatDefault, 3> center(2, 2, 2);
vtkm::FloatDefault radius(1.8);
vtkm::Sphere sphere(center, radius);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output data set with cell set containing extracted cells
vtkm::worklet::ExtractCells extractCells;
OutCellSetType outCellSet;
vtkm::cont::CellSetSingleType<> outputCellSet =
outCellSet = extractCells.Run(
dataset.GetCellSet(0),
sphere,
dataset.GetCoordinateSystem("coords"),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27), "Wrong result for ExtractCells");
}
*/
/*
void TestExtractCellsStructuredWithBox() const
{
std::cout << "Testing extract cells with implicit function (box):" << std::endl;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
// Implicit function
vtkm::Vec<vtkm::FloatDefault, 3> minPoint(1.0, 1.0, 1.0);
vtkm::Vec<vtkm::FloatDefault, 3> maxPoint(3.0, 3.0, 3.0);
vtkm::Box box(minPoint, maxPoint);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output data set with cell set containing extracted points
vtkm::worklet::ExtractPoints extractPoints;
OutCellSetType outCellSet;
vtkm::cont::CellSetSingleType<> outputCellSet =
outCellSet = extractPoints.Run(dataset.GetCellSet(0),
box,
dataset.GetCoordinateSystem("coords"),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27), "Wrong result for ExtractPoints");
}
*/
/*
void TestExtractPointsStructuredById() const
{
std::cout << "Testing extract points structured by id:" << std::endl;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
// Points to extract
const int nPoints = 18;
vtkm::Id pointids[nPoints] = {0, 1, 2, 3, 4, 5, 10, 15, 20, 25, 50, 75, 100};
vtkm::cont::ArrayHandle<vtkm::Id> pointIds =
vtkm::cont::make_ArrayHandle(pointids, nPoints);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output data set with cell set containing extracted points
vtkm::worklet::ExtractPoints extractPoints;
OutCellSetType outCellSet;
vtkm::cont::CellSetSingleType<> outputCellSet =
outCellSet = extractPoints.Run(dataset.GetCellSet(0),
pointIds,
dataset.GetCoordinateSystem("coords"),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nPoints), "Wrong result for ExtractPoints");
}
*/
void TestExtractCellsExplicitById() const
{
std::cout << "Testing extract cell explicit by id:" << std::endl;
typedef vtkm::cont::CellSetExplicit<> OutCellSetType;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
vtkm::cont::CellSetExplicit<> cellSet;
dataset.GetCellSet(0).CopyTo(cellSet);
// Cells to extract
const int nCells = 2;
vtkm::Id cellids[nCells] = {1, 2};
vtkm::cont::ArrayHandle<vtkm::Id> cellIds =
vtkm::cont::make_ArrayHandle(cellids, nCells);
// Output dataset contains input coordinate system and input point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
// Output data set with cell set containing extracted cells and all points
vtkm::worklet::ExtractCells extractCells;
OutCellSetType outCellSet = extractCells.Run(
cellSet,
cellIds,
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells), "Wrong result for ExtractCells");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetConnectivityArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell()).
GetNumberOfValues(), 9), "Wrong result for ExtractCells");
}
void TestExtractCellsExplicitWithBox() const
{
std::cout << "Testing extract cells with implicit function (box) on explicit:" << std::endl;
typedef vtkm::cont::CellSetExplicit<> OutCellSetType;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
vtkm::cont::CellSetExplicit<> cellSet;
dataset.GetCellSet(0).CopyTo(cellSet);
// Implicit function
vtkm::Vec<vtkm::FloatDefault, 3> minPoint(0.5, 0.0, 0.0);
vtkm::Vec<vtkm::FloatDefault, 3> maxPoint(2.0, 2.0, 2.0);
vtkm::Box box(minPoint, maxPoint);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
// Output data set with cell set containing extracted cells and all points
vtkm::worklet::ExtractCells extractCells;
OutCellSetType outCellSet = extractCells.Run(
cellSet,
box,
dataset.GetCoordinateSystem("coordinates"),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 2), "Wrong result for ExtractCells");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetConnectivityArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell()).
GetNumberOfValues(), 9), "Wrong result for ExtractCells");
}
void operator()() const
{
//this->TestExtractCellsStructuredWithSphere();
//this->TestExtractCellsStructuredWithBox();
//this->TestExtractCellsStructuredById();
this->TestExtractCellsExplicitById();
this->TestExtractCellsExplicitWithBox();
}
};
int UnitTestExtractCells(int, char *[])
{
return vtkm::cont::testing::Testing::Run(
TestingExtractCells<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>());
}

@ -36,17 +36,14 @@ template <typename DeviceAdapter>
class TestingExtractPoints
{
public:
void TestExtractPointsWithSphere() const
void TestExtractPointsStructuredWithSphere() const
{
std::cout << "Testing extract points with implicit function (sphere):" << std::endl;
typedef vtkm::cont::CellSetStructured<3> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
// Implicit function
vtkm::Vec<vtkm::FloatDefault, 3> center(2, 2, 2);
@ -56,14 +53,6 @@ public:
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output data set with cell set containing extracted points
vtkm::worklet::ExtractPoints extractPoints;
@ -78,17 +67,14 @@ public:
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27), "Wrong result for ExtractPoints");
}
void TestExtractPointsWithBox() const
void TestExtractPointsStructuredWithBox() const
{
std::cout << "Testing extract points with implicit function (box):" << std::endl;
typedef vtkm::cont::CellSetStructured<3> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
// Implicit function
vtkm::Vec<vtkm::FloatDefault, 3> minPoint(1.0, 1.0, 1.0);
@ -98,14 +84,6 @@ public:
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output data set with cell set containing extracted points
vtkm::worklet::ExtractPoints extractPoints;
@ -119,10 +97,109 @@ public:
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27), "Wrong result for ExtractPoints");
}
void TestExtractPointsExplicitWithBox() const
{
std::cout << "Testing extract points with implicit function (box) on explicit:" << std::endl;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
// Implicit function
vtkm::Vec<vtkm::FloatDefault, 3> minPoint(0.0, 0.0, 0.0);
vtkm::Vec<vtkm::FloatDefault, 3> maxPoint(1.0, 1.0, 1.0);
vtkm::Box box(minPoint, maxPoint);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
// Output data set with cell set containing extracted points
vtkm::worklet::ExtractPoints extractPoints;
OutCellSetType outCellSet;
vtkm::cont::CellSetSingleType<> outputCellSet =
outCellSet = extractPoints.Run(dataset.GetCellSet(0),
box,
dataset.GetCoordinateSystem("coordinates"),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for ExtractPoints");
}
void TestExtractPointsStructuredById() const
{
std::cout << "Testing extract points structured by id:" << std::endl;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
// Points to extract
const int nPoints = 18;
vtkm::Id pointids[nPoints] = {0, 1, 2, 3, 4, 5, 10, 15, 20, 25, 50, 75, 100};
vtkm::cont::ArrayHandle<vtkm::Id> pointIds =
vtkm::cont::make_ArrayHandle(pointids, nPoints);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
// Output data set with cell set containing extracted points
vtkm::worklet::ExtractPoints extractPoints;
OutCellSetType outCellSet;
vtkm::cont::CellSetSingleType<> outputCellSet =
outCellSet = extractPoints.Run(dataset.GetCellSet(0),
pointIds,
dataset.GetCoordinateSystem("coords"),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nPoints), "Wrong result for ExtractPoints");
}
void TestExtractPointsExplicitById() const
{
std::cout << "Testing extract points explicit by id:" << std::endl;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
// Points to extract
const int nPoints = 6;
vtkm::Id pointids[nPoints] = {0, 4,5, 7, 9, 10};
vtkm::cont::ArrayHandle<vtkm::Id> pointIds =
vtkm::cont::make_ArrayHandle(pointids, nPoints);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
// Output data set with cell set containing extracted points
vtkm::worklet::ExtractPoints extractPoints;
OutCellSetType outCellSet;
vtkm::cont::CellSetSingleType<> outputCellSet =
outCellSet = extractPoints.Run(dataset.GetCellSet(0),
pointIds,
dataset.GetCoordinateSystem("coordinates"),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nPoints), "Wrong result for ExtractPoints");
}
void operator()() const
{
this->TestExtractPointsWithSphere();
this->TestExtractPointsWithBox();
this->TestExtractPointsStructuredWithSphere();
this->TestExtractPointsStructuredWithBox();
this->TestExtractPointsExplicitWithBox();
this->TestExtractPointsStructuredById();
this->TestExtractPointsExplicitById();
}
};

@ -42,30 +42,18 @@ public:
{
std::cout << "Testing mask points stride on 2D uniform dataset" << std::endl;
typedef vtkm::cont::CellSetStructured<2> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1();
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
// Output dataset contains input coordinate system and point data
// Output dataset contains input coordinate system
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output dataset gets new cell set of points that pass subsampling
vtkm::worklet::MaskPoints maskPoints;
OutCellSetType outCellSet;
outCellSet = maskPoints.Run(cellset,
outCellSet = maskPoints.Run(dataset.GetCellSet(0),
2,
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
@ -77,30 +65,18 @@ public:
{
std::cout << "Testing mask points stride on 3D uniform dataset" << std::endl;
typedef vtkm::cont::CellSetStructured<3> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output dataset gets new cell set of points that meet threshold predicate
vtkm::worklet::MaskPoints maskPoints;
OutCellSetType outCellSet;
outCellSet = maskPoints.Run(cellset,
outCellSet = maskPoints.Run(dataset.GetCellSet(0),
5,
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
@ -112,30 +88,18 @@ public:
{
std::cout << "Testing mask points stride on 3D explicit dataset" << std::endl;
typedef vtkm::cont::CellSetExplicit<> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output dataset gets new cell set of points that meet threshold predicate
vtkm::worklet::MaskPoints maskPoints;
OutCellSetType outCellSet;
outCellSet = maskPoints.Run(cellset,
outCellSet = maskPoints.Run(dataset.GetCellSet(0),
3,
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);

@ -107,132 +107,81 @@ public:
{
std::cout << "Testing threshold on 2D uniform dataset" << std::endl;
typedef vtkm::cont::CellSetStructured<2> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1();
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataset.GetField("pointvar").GetData().CopyTo(fieldArray);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output dataset gets new cell set of points that meet threshold predicate
vtkm::worklet::ThresholdPoints threshold;
OutCellSetType outCellSet;
outCellSet = threshold.Run(cellset,
outCellSet = threshold.Run(dataset.GetCellSet(0),
fieldArray,
ValuesBetween(40.0f, 71.0f),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 11), "Wrong result for ThresholdPoints");
vtkm::cont::Field pointField = outDataSet.GetField("pointvar");
vtkm::cont::ArrayHandle<vtkm::Float32> pointFieldArray;
pointField.GetData().CopyTo(pointFieldArray);
VTKM_TEST_ASSERT(pointFieldArray.GetPortalConstControl().Get(12) == 50.0f, "Wrong point field data");
}
void TestUniform3D() const
{
std::cout << "Testing threshold on 3D uniform dataset" << std::endl;
typedef vtkm::cont::CellSetStructured<3> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataset.GetField("pointvar").GetData().CopyTo(fieldArray);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output dataset gets new cell set of points that meet threshold predicate
vtkm::worklet::ThresholdPoints threshold;
OutCellSetType outCellSet;
outCellSet = threshold.Run(cellset,
outCellSet = threshold.Run(dataset.GetCellSet(0),
fieldArray,
ValuesAbove(1.0f),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27), "Wrong result for ThresholdPoints");
vtkm::cont::Field pointField = outDataSet.GetField("pointvar");
vtkm::cont::ArrayHandle<vtkm::Float32> pointFieldArray;
pointField.GetData().CopyTo(pointFieldArray);
VTKM_TEST_ASSERT(pointFieldArray.GetPortalConstControl().Get(31) == 99.0f, "Wrong point field data");
}
void TestExplicit3D() const
{
std::cout << "Testing threshold on 3D explicit dataset" << std::endl;
typedef vtkm::cont::CellSetExplicit<> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
CellSetType cellset;
dataset.GetCellSet(0).CopyTo(cellset);
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataset.GetField("pointvar").GetData().CopyTo(fieldArray);
// Output dataset contains input coordinate system and point data
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataset.GetCoordinateSystem(0));
for (vtkm::Id indx = 0; indx < dataset.GetNumberOfFields(); indx++)
{
vtkm::cont::Field field = dataset.GetField(indx);
if (field.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS)
{
outDataSet.AddField(field);
}
}
// Output dataset gets new cell set of points that meet threshold predicate
vtkm::worklet::ThresholdPoints threshold;
OutCellSetType outCellSet;
outCellSet = threshold.Run(cellset,
outCellSet = threshold.Run(dataset.GetCellSet(0),
fieldArray,
ValuesBelow(50.0f),
DeviceAdapter());
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 6), "Wrong result for ThresholdPoints");
vtkm::cont::Field pointField = outDataSet.GetField("pointvar");
vtkm::cont::ArrayHandle<vtkm::Float32> pointFieldArray;
pointField.GetData().CopyTo(pointFieldArray);
VTKM_TEST_ASSERT(pointFieldArray.GetPortalConstControl().Get(3) == 40.2f, "Wrong point field data");
}
void operator()() const