2017-03-21 21:14:35 +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).
|
2017-03-21 21:14:35 +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,
|
2017-03-21 21:14:35 +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.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtkm_m_worklet_ExtractPoints_h
|
|
|
|
#define vtkm_m_worklet_ExtractPoints_h
|
|
|
|
|
|
|
|
#include <vtkm/worklet/DispatcherMapTopology.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/worklet/WorkletMapTopology.h>
|
2017-03-21 21:14:35 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/CoordinateSystem.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/cont/DataSet.h>
|
2017-10-23 13:38:33 +00:00
|
|
|
#include <vtkm/cont/ImplicitFunctionHandle.h>
|
2017-03-21 21:14:35 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
2017-03-21 21:14:35 +00:00
|
|
|
|
|
|
|
class ExtractPoints
|
|
|
|
{
|
|
|
|
public:
|
2017-05-18 14:29:41 +00:00
|
|
|
struct BoolType : vtkm::ListTagBase<bool>
|
|
|
|
{
|
|
|
|
};
|
2017-03-21 21:14:35 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Worklet to identify points within volume of interest
|
2017-03-29 20:04:58 +00:00
|
|
|
class ExtractPointsByVOI : public vtkm::worklet::WorkletMapCellToPoint
|
2017-03-21 21:14:35 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-05-25 21:18:41 +00:00
|
|
|
using ControlSignature = void(CellSetIn cellset,
|
2017-05-26 17:53:28 +00:00
|
|
|
FieldInPoint<Vec3> coordinates,
|
2017-03-29 20:04:58 +00:00
|
|
|
FieldOutPoint<BoolType> passFlags);
|
2018-05-25 21:18:41 +00:00
|
|
|
using ExecutionSignature = _3(_2);
|
2017-03-21 21:14:35 +00:00
|
|
|
|
|
|
|
VTKM_CONT
|
2017-10-23 13:38:33 +00:00
|
|
|
ExtractPointsByVOI(const vtkm::ImplicitFunction* function, bool extractInside)
|
2017-05-18 14:29:41 +00:00
|
|
|
: Function(function)
|
|
|
|
, passValue(extractInside)
|
|
|
|
, failValue(!extractInside)
|
|
|
|
{
|
|
|
|
}
|
2017-03-21 21:14:35 +00:00
|
|
|
|
2017-03-30 17:22:07 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
bool operator()(const vtkm::Vec<vtkm::Float64, 3>& coordinate) const
|
2017-03-21 21:14:35 +00:00
|
|
|
{
|
2017-05-03 21:07:06 +00:00
|
|
|
bool pass = passValue;
|
2017-10-23 13:38:33 +00:00
|
|
|
vtkm::Float64 value = this->Function->Value(coordinate);
|
2017-03-21 21:14:35 +00:00
|
|
|
if (value > 0)
|
2017-05-03 21:07:06 +00:00
|
|
|
pass = failValue;
|
2017-03-21 21:14:35 +00:00
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-10-23 13:38:33 +00:00
|
|
|
const vtkm::ImplicitFunction* Function;
|
2017-05-03 21:07:06 +00:00
|
|
|
bool passValue;
|
|
|
|
bool failValue;
|
2017-03-21 21:14:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Extract points by id creates new cellset of vertex cells
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellSetType, typename DeviceAdapter>
|
|
|
|
vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Id>& pointIds,
|
|
|
|
DeviceAdapter)
|
2017-03-21 21:14:35 +00:00
|
|
|
{
|
2018-02-22 13:29:13 +00:00
|
|
|
using DeviceAlgorithm = typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
|
2017-03-21 21:14:35 +00:00
|
|
|
DeviceAlgorithm::Copy(pointIds, this->ValidPointIds);
|
|
|
|
|
|
|
|
// Make CellSetSingleType with VERTEX at each point id
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> outCellSet(cellSet.GetName());
|
2017-05-26 17:53:28 +00:00
|
|
|
outCellSet.Fill(
|
|
|
|
cellSet.GetNumberOfPoints(), vtkm::CellShapeTagVertex::Id, 1, this->ValidPointIds);
|
2017-03-21 21:14:35 +00:00
|
|
|
|
|
|
|
return outCellSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Extract points by implicit function
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellSetType, typename CoordinateType, typename DeviceAdapter>
|
2017-05-26 17:53:28 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
|
|
|
|
const CoordinateType& coordinates,
|
2017-10-23 13:38:33 +00:00
|
|
|
const vtkm::cont::ImplicitFunctionHandle& implicitFunction,
|
2017-05-26 17:53:28 +00:00
|
|
|
bool extractInside,
|
|
|
|
DeviceAdapter device)
|
2017-03-21 21:14:35 +00:00
|
|
|
{
|
2018-02-22 13:29:13 +00:00
|
|
|
using DeviceAlgorithm = typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
|
2017-03-21 21:14:35 +00:00
|
|
|
|
|
|
|
// Worklet output will be a boolean passFlag array
|
2017-03-29 16:11:09 +00:00
|
|
|
vtkm::cont::ArrayHandle<bool> passFlags;
|
2017-03-29 20:04:58 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
ExtractPointsByVOI worklet(implicitFunction.PrepareForExecution(device), extractInside);
|
2017-03-29 16:11:09 +00:00
|
|
|
DispatcherMapTopology<ExtractPointsByVOI, DeviceAdapter> dispatcher(worklet);
|
2017-03-29 20:04:58 +00:00
|
|
|
dispatcher.Invoke(cellSet, coordinates, passFlags);
|
2017-03-21 21:14:35 +00:00
|
|
|
|
|
|
|
vtkm::cont::ArrayHandleCounting<vtkm::Id> indices =
|
|
|
|
vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues());
|
|
|
|
DeviceAlgorithm::CopyIf(indices, passFlags, this->ValidPointIds);
|
|
|
|
|
|
|
|
// Make CellSetSingleType with VERTEX at each point id
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> outCellSet(cellSet.GetName());
|
2017-05-26 17:53:28 +00:00
|
|
|
outCellSet.Fill(
|
|
|
|
cellSet.GetNumberOfPoints(), vtkm::CellShapeTagVertex::Id, 1, this->ValidPointIds);
|
2017-03-21 21:14:35 +00:00
|
|
|
|
|
|
|
return outCellSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> ValidPointIds;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // namespace vtkm::worklet
|
|
|
|
|
|
|
|
#endif // vtkm_m_worklet_ExtractPoints_h
|