2017-03-21 21:14:35 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2017-03-21 21:14:35 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
#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
|
|
|
|
2018-08-30 15:53:18 +00:00
|
|
|
#include <vtkm/cont/Algorithm.h>
|
|
|
|
#include <vtkm/cont/ArrayCopy.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>
|
2021-02-19 00:25:11 +00:00
|
|
|
|
|
|
|
#include <vtkm/ImplicitFunction.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:
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Worklet to identify points within volume of interest
|
2019-07-30 16:53:51 +00:00
|
|
|
class ExtractPointsByVOI : public vtkm::worklet::WorkletVisitPointsWithCells
|
2017-03-21 21:14:35 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-05-25 21:18:41 +00:00
|
|
|
using ControlSignature = void(CellSetIn cellset,
|
2019-01-10 18:59:25 +00:00
|
|
|
FieldInPoint coordinates,
|
2018-08-30 15:53:18 +00:00
|
|
|
ExecObject function,
|
2019-01-10 18:59:25 +00:00
|
|
|
FieldOutPoint passFlags);
|
2018-08-30 15:53:18 +00:00
|
|
|
using ExecutionSignature = _4(_2, _3);
|
2017-03-21 21:14:35 +00:00
|
|
|
|
|
|
|
VTKM_CONT
|
2018-08-30 15:53:18 +00:00
|
|
|
ExtractPointsByVOI(bool extractInside)
|
|
|
|
: passValue(extractInside)
|
2017-05-18 14:29:41 +00:00
|
|
|
, failValue(!extractInside)
|
|
|
|
{
|
|
|
|
}
|
2017-03-21 21:14:35 +00:00
|
|
|
|
2021-02-19 00:25:11 +00:00
|
|
|
template <typename ImplicitFunction>
|
|
|
|
VTKM_EXEC bool operator()(const vtkm::Vec3f_64& coordinate,
|
|
|
|
const ImplicitFunction& function) const
|
2017-03-21 21:14:35 +00:00
|
|
|
{
|
2017-05-03 21:07:06 +00:00
|
|
|
bool pass = passValue;
|
2021-02-19 00:25:11 +00:00
|
|
|
vtkm::Float64 value = function.Value(coordinate);
|
2017-03-21 21:14:35 +00:00
|
|
|
if (value > 0)
|
2018-08-30 15:53:18 +00:00
|
|
|
{
|
2017-05-03 21:07:06 +00:00
|
|
|
pass = failValue;
|
2018-08-30 15:53:18 +00:00
|
|
|
}
|
2017-03-21 21:14:35 +00:00
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
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
|
2018-08-30 15:53:18 +00:00
|
|
|
template <typename CellSetType>
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
|
2018-08-30 15:53:18 +00:00
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Id>& pointIds)
|
2017-03-21 21:14:35 +00:00
|
|
|
{
|
2018-08-30 15:53:18 +00:00
|
|
|
vtkm::cont::ArrayCopy(pointIds, this->ValidPointIds);
|
2017-03-21 21:14:35 +00:00
|
|
|
|
|
|
|
// Make CellSetSingleType with VERTEX at each point id
|
2019-08-13 21:28:37 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> outCellSet;
|
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
|
2021-02-19 00:25:11 +00:00
|
|
|
template <typename CellSetType, typename CoordinateType, typename ImplicitFunction>
|
2017-05-26 17:53:28 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
|
|
|
|
const CoordinateType& coordinates,
|
2021-02-19 00:25:11 +00:00
|
|
|
const ImplicitFunction& implicitFunction,
|
2018-08-30 15:53:18 +00:00
|
|
|
bool extractInside)
|
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
|
|
|
|
2018-08-30 15:53:18 +00:00
|
|
|
ExtractPointsByVOI worklet(extractInside);
|
2018-08-28 20:36:50 +00:00
|
|
|
DispatcherMapTopology<ExtractPointsByVOI> dispatcher(worklet);
|
2018-08-30 15:53:18 +00:00
|
|
|
dispatcher.Invoke(cellSet, coordinates, implicitFunction, 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());
|
2018-08-30 15:53:18 +00:00
|
|
|
vtkm::cont::Algorithm::CopyIf(indices, passFlags, this->ValidPointIds);
|
2017-03-21 21:14:35 +00:00
|
|
|
|
|
|
|
// Make CellSetSingleType with VERTEX at each point id
|
2019-08-13 21:28:37 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> outCellSet;
|
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
|