2017-03-16 20:53:16 +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.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtkm_m_worklet_ExtractGeometry_h
|
|
|
|
#define vtkm_m_worklet_ExtractGeometry_h
|
|
|
|
|
2017-03-20 20:40:53 +00:00
|
|
|
#include <vtkm/worklet/DispatcherMapTopology.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/worklet/WorkletMapTopology.h>
|
2017-03-20 20:40:53 +00:00
|
|
|
|
2017-03-16 20:53:16 +00:00
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/cont/CellSetPermutation.h>
|
2017-03-16 20:53:16 +00:00
|
|
|
#include <vtkm/cont/CoordinateSystem.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/cont/DataSet.h>
|
2017-03-29 16:11:09 +00:00
|
|
|
#include <vtkm/cont/ImplicitFunction.h>
|
2017-03-16 20:53:16 +00:00
|
|
|
|
|
|
|
namespace vtkm {
|
|
|
|
namespace worklet {
|
|
|
|
|
2017-03-20 20:40:53 +00:00
|
|
|
class ExtractGeometry
|
2017-03-16 20:53:16 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-03-20 20:40:53 +00:00
|
|
|
struct BoolType : vtkm::ListTagBase<bool> {};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Worklet to identify cells within volume of interest
|
|
|
|
class ExtractCellsByVOI : public vtkm::worklet::WorkletMapPointToCell
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef void ControlSignature(CellSetIn cellset,
|
|
|
|
WholeArrayIn<Vec3> coordinates,
|
2017-03-30 17:22:07 +00:00
|
|
|
FieldOutCell<BoolType> passFlags);
|
2017-03-20 20:40:53 +00:00
|
|
|
typedef _3 ExecutionSignature(PointCount, PointIndices, _2);
|
|
|
|
|
2017-03-30 17:22:07 +00:00
|
|
|
VTKM_CONT
|
2017-03-30 18:23:00 +00:00
|
|
|
ExtractCellsByVOI() : Function() {}
|
|
|
|
|
2017-03-20 20:40:53 +00:00
|
|
|
VTKM_CONT
|
2017-05-04 19:13:53 +00:00
|
|
|
ExtractCellsByVOI(const vtkm::exec::ImplicitFunction &function,
|
|
|
|
bool extractInside,
|
|
|
|
bool extractBoundaryCells,
|
|
|
|
bool extractOnlyBoundaryCells) :
|
|
|
|
Function(function),
|
|
|
|
ExtractInside(extractInside),
|
|
|
|
ExtractBoundaryCells(extractBoundaryCells),
|
|
|
|
ExtractOnlyBoundaryCells(extractOnlyBoundaryCells) {}
|
2017-03-20 20:40:53 +00:00
|
|
|
|
|
|
|
template <typename ConnectivityInVec, typename InVecFieldPortalType>
|
2017-03-30 17:22:07 +00:00
|
|
|
VTKM_EXEC
|
|
|
|
bool operator()( vtkm::Id numIndices,
|
2017-03-20 20:40:53 +00:00
|
|
|
const ConnectivityInVec &connectivityIn,
|
|
|
|
const InVecFieldPortalType &coordinates) const
|
|
|
|
{
|
2017-05-04 21:04:54 +00:00
|
|
|
// Count points inside/outside volume of interest
|
2017-05-04 19:13:53 +00:00
|
|
|
vtkm::IdComponent inCnt = 0;
|
|
|
|
vtkm::IdComponent outCnt = 0;
|
2017-03-29 21:13:34 +00:00
|
|
|
for (vtkm::IdComponent indx = 0; indx < numIndices; indx++)
|
2017-03-20 20:40:53 +00:00
|
|
|
{
|
2017-03-29 20:04:58 +00:00
|
|
|
vtkm::Id ptId = connectivityIn[indx];
|
2017-03-20 20:40:53 +00:00
|
|
|
vtkm::Vec<FloatDefault,3> coordinate = coordinates.Get(ptId);
|
|
|
|
vtkm::FloatDefault value = this->Function.Value(coordinate);
|
2017-05-04 19:13:53 +00:00
|
|
|
if (value <= 0)
|
|
|
|
inCnt++;
|
|
|
|
if (value >= 0)
|
|
|
|
outCnt++;
|
2017-03-20 20:40:53 +00:00
|
|
|
}
|
2017-05-04 19:13:53 +00:00
|
|
|
|
2017-05-04 21:04:54 +00:00
|
|
|
// Decide if cell is extracted
|
2017-05-04 19:13:53 +00:00
|
|
|
bool passFlag = false;
|
|
|
|
if (inCnt == numIndices &&
|
2017-05-04 21:04:54 +00:00
|
|
|
ExtractInside &&
|
|
|
|
!ExtractOnlyBoundaryCells)
|
2017-05-04 19:13:53 +00:00
|
|
|
{
|
|
|
|
passFlag = true;
|
|
|
|
}
|
|
|
|
else if (outCnt == numIndices &&
|
2017-05-04 21:04:54 +00:00
|
|
|
!ExtractInside &&
|
|
|
|
!ExtractOnlyBoundaryCells)
|
2017-05-04 19:13:53 +00:00
|
|
|
{
|
|
|
|
passFlag = true;
|
|
|
|
}
|
|
|
|
else if (inCnt > 0 && outCnt > 0 &&
|
|
|
|
(ExtractBoundaryCells || ExtractOnlyBoundaryCells))
|
|
|
|
{
|
|
|
|
passFlag = true;
|
|
|
|
}
|
|
|
|
return passFlag;
|
2017-03-20 20:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-03-29 16:11:09 +00:00
|
|
|
vtkm::exec::ImplicitFunction Function;
|
2017-05-04 19:13:53 +00:00
|
|
|
bool ExtractInside;
|
|
|
|
bool ExtractBoundaryCells;
|
|
|
|
bool ExtractOnlyBoundaryCells;
|
2017-03-20 20:40:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Extract cells by ids permutes input data
|
|
|
|
template <typename CellSetType,
|
|
|
|
typename DeviceAdapter>
|
2017-03-21 21:14:35 +00:00
|
|
|
vtkm::cont::CellSetPermutation<CellSetType> Run(
|
2017-03-29 22:24:42 +00:00
|
|
|
const CellSetType &cellSet,
|
2017-03-16 20:53:16 +00:00
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Id> &cellIds,
|
2017-03-28 22:07:56 +00:00
|
|
|
DeviceAdapter)
|
2017-03-16 20:53:16 +00:00
|
|
|
{
|
2017-03-20 20:40:53 +00:00
|
|
|
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithm;
|
|
|
|
typedef vtkm::cont::CellSetPermutation<CellSetType> OutputType;
|
|
|
|
|
|
|
|
DeviceAlgorithm::Copy(cellIds, this->ValidCellIds);
|
|
|
|
|
|
|
|
return OutputType(this->ValidCellIds, cellSet, cellSet.GetName());
|
2017-03-16 20:53:16 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 20:40:53 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Extract cells by implicit function permutes input data
|
|
|
|
template <typename CellSetType,
|
2017-03-16 20:53:16 +00:00
|
|
|
typename DeviceAdapter>
|
2017-03-21 21:14:35 +00:00
|
|
|
vtkm::cont::CellSetPermutation<CellSetType> Run(
|
2017-03-29 22:24:42 +00:00
|
|
|
const CellSetType &cellSet,
|
2017-03-16 20:53:16 +00:00
|
|
|
const vtkm::cont::CoordinateSystem &coordinates,
|
2017-03-29 16:11:09 +00:00
|
|
|
const vtkm::cont::ImplicitFunction &implicitFunction,
|
2017-05-04 19:13:53 +00:00
|
|
|
bool extractInside,
|
|
|
|
bool extractBoundaryCells,
|
|
|
|
bool extractOnlyBoundaryCells,
|
2017-03-29 16:11:09 +00:00
|
|
|
DeviceAdapter device)
|
2017-03-16 20:53:16 +00:00
|
|
|
{
|
2017-03-20 20:40:53 +00:00
|
|
|
typedef vtkm::cont::CellSetPermutation<CellSetType> OutputType;
|
2017-03-17 23:00:59 +00:00
|
|
|
|
2017-03-20 20:40:53 +00:00
|
|
|
// Worklet output will be a boolean passFlag array
|
2017-03-30 17:22:07 +00:00
|
|
|
vtkm::cont::ArrayHandle<bool> passFlags;
|
2017-03-29 22:24:42 +00:00
|
|
|
|
2017-05-04 19:13:53 +00:00
|
|
|
ExtractCellsByVOI worklet(implicitFunction.PrepareForExecution(device),
|
|
|
|
extractInside,
|
|
|
|
extractBoundaryCells,
|
|
|
|
extractOnlyBoundaryCells);
|
2017-03-29 16:11:09 +00:00
|
|
|
DispatcherMapTopology<ExtractCellsByVOI, DeviceAdapter> dispatcher(worklet);
|
2017-03-20 20:40:53 +00:00
|
|
|
dispatcher.Invoke(cellSet,
|
|
|
|
coordinates,
|
|
|
|
passFlags);
|
|
|
|
|
|
|
|
vtkm::cont::ArrayHandleCounting<vtkm::Id> indices =
|
|
|
|
vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues());
|
|
|
|
vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>
|
|
|
|
::CopyIf(indices, passFlags, this->ValidCellIds);
|
|
|
|
|
|
|
|
return OutputType(this->ValidCellIds, cellSet, cellSet.GetName());
|
2017-03-17 23:00:59 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 20:40:53 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Permute cell data to match permuted cells
|
|
|
|
class PermuteCellData
|
2017-03-17 23:00:59 +00:00
|
|
|
{
|
2017-03-20 20:40:53 +00:00
|
|
|
public:
|
|
|
|
PermuteCellData(const vtkm::cont::ArrayHandle<vtkm::Id> validCellIds,
|
|
|
|
vtkm::cont::DynamicArrayHandle &data)
|
|
|
|
: ValidCellIds(validCellIds), Data(&data)
|
|
|
|
{ }
|
2017-03-17 23:00:59 +00:00
|
|
|
|
2017-03-20 20:40:53 +00:00
|
|
|
template <typename ArrayHandleType>
|
|
|
|
void operator()(const ArrayHandleType &input) const
|
|
|
|
{
|
|
|
|
*(this->Data) = vtkm::cont::DynamicArrayHandle(
|
|
|
|
vtkm::cont::make_ArrayHandlePermutation(this->ValidCellIds, input));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> ValidCellIds;
|
|
|
|
vtkm::cont::DynamicArrayHandle *Data;
|
|
|
|
};
|
|
|
|
|
|
|
|
vtkm::cont::Field ProcessCellField(const vtkm::cont::Field field) const
|
2017-03-17 23:00:59 +00:00
|
|
|
{
|
2017-03-20 20:40:53 +00:00
|
|
|
if (field.GetAssociation() != vtkm::cont::Field::ASSOC_CELL_SET)
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("Expecting cell field.");
|
|
|
|
}
|
|
|
|
|
|
|
|
vtkm::cont::DynamicArrayHandle data;
|
|
|
|
CastAndCall(field, PermuteCellData(this->ValidCellIds, data));
|
|
|
|
|
|
|
|
return vtkm::cont::Field(field.GetName(), field.GetAssociation(),
|
|
|
|
field.GetAssocCellSet(), data);
|
2017-03-17 23:00:59 +00:00
|
|
|
}
|
2017-03-20 20:40:53 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> ValidCellIds;
|
2017-03-16 20:53:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
} // namespace vtkm::worklet
|
|
|
|
|
|
|
|
#endif // vtkm_m_worklet_ExtractGeometry_h
|