Merge branch 'master' into density_estimate

This commit is contained in:
Li-Ta Lo 2022-01-22 09:07:52 -07:00
commit 71ec80a3bd
57 changed files with 1071 additions and 2039 deletions

@ -34,13 +34,13 @@
#include <vtkm/filter/PointAverage.h>
#include <vtkm/filter/PolicyBase.h>
#include <vtkm/filter/Tetrahedralize.h>
#include <vtkm/filter/Threshold.h>
#include <vtkm/filter/Triangulate.h>
#include <vtkm/filter/VectorMagnitude.h>
#include <vtkm/filter/VertexClustering.h>
#include <vtkm/filter/WarpScalar.h>
#include <vtkm/filter/WarpVector.h>
#include <vtkm/filter/entity_extraction/ExternalFaces.h>
#include <vtkm/filter/entity_extraction/Threshold.h>
#include <vtkm/filter/entity_extraction/ThresholdPoints.h>
#include <vtkm/io/VTKDataSetReader.h>
@ -193,7 +193,7 @@ void BenchThreshold(::benchmark::State& state)
vtkm::Float64 quarter = range.Length() / 4.;
vtkm::Float64 mid = range.Center();
vtkm::filter::Threshold filter;
vtkm::filter::entity_extraction::Threshold filter;
filter.SetActiveField(PointScalarsName, vtkm::cont::Field::Association::POINTS);
filter.SetLowerThreshold(mid - quarter);
filter.SetUpperThreshold(mid + quarter);

@ -66,7 +66,7 @@ std::string Testing::WriteDirPath(const std::string& filename)
void Testing::SetEnv(const std::string& var, const std::string& value)
{
static std::vector<std::pair<std::string, std::string>> envVars{};
#ifdef _MSC_VER
#ifdef _WIN32
auto iter = envVars.emplace(envVars.end(), var, value);
_putenv_s(iter->first.c_str(), iter->second.c_str());
#else
@ -76,7 +76,7 @@ void Testing::SetEnv(const std::string& var, const std::string& value)
void Testing::UnsetEnv(const std::string& var)
{
#ifdef _MSC_VER
#ifdef _WIN32
SetEnv(var, "");
#else
unsetenv(var.c_str());

@ -22,12 +22,24 @@ vtkm_add_instantiations(ClipWithImplicitFunctionInstantiations
)
set(deprecated_headers
CleanGrid.h
DotProduct.h
Entropy.h
ExternalFaces.h
ExtractGeometry.h
ExtractPoints.h
ExtractStructured.h
GenerateIds.h
GhostCellRemove.h
Histogram.h
Mask.h
MaskPoints.h
NDEntropy.h
NDHistogram.h
ParticleDensityCloudInCell.h
ParticleDensityNearestGridPoint.h
Threshold.h
ThresholdPoints.h
)
vtkm_declare_headers(${deprecated_headers})
@ -35,10 +47,6 @@ vtkm_declare_headers(${deprecated_headers})
set(common_headers
CellAverage.h
CellMeasures.h
CleanGrid.h
ExtractGeometry.h
ExtractPoints.h
ExtractStructured.h
FieldMetadata.h
FilterCell.h
FilterDataSet.h
@ -51,16 +59,12 @@ set(common_headers
PolicyBase.h
PolicyDefault.h
TaskQueue.h
Threshold.h
ThresholdPoints.h
Instantiations.h
)
set(common_header_template_sources
CellAverage.hxx
CellMeasures.hxx
ExtractGeometry.hxx
ExtractStructured.hxx
FilterDataSet.hxx
FilterDataSetWithField.hxx
FilterField.hxx
@ -68,15 +72,11 @@ set(common_header_template_sources
FilterParticleAdvection.hxx
FilterTemporalParticleAdvection.hxx
PointAverage.hxx
Threshold.hxx
)
set(common_sources_device
CellAverage.cxx
ExtractGeometry.cxx
ExtractStructured.cxx
PointAverage.cxx
Threshold.cxx
)
set(extra_headers
@ -88,20 +88,14 @@ set(extra_headers
CoordinateSystemTransform.h
CreateResult.h
CrossProduct.h
DotProduct.h
ExternalFaces.h
FieldSelection.h
FieldToColors.h
GenerateIds.h
GhostCellClassify.h
GhostCellRemove.h
ImageConnectivity.h
ImageDifference.h
ImageMedian.h
Lagrangian.h
LagrangianStructures.h
Mask.h
MaskPoints.h
MeshQuality.h
MIRFilter.h
ParticleAdvection.h
@ -142,13 +136,11 @@ set(extra_header_template_sources
CrossProduct.hxx
FieldToColors.hxx
GhostCellClassify.hxx
GhostCellRemove.hxx
ImageConnectivity.hxx
ImageDifference.hxx
ImageMedian.hxx
Lagrangian.hxx
LagrangianStructures.hxx
Mask.hxx
MeshQuality.hxx
MIRFilter.hxx
ParticleAdvection.hxx

@ -1,60 +0,0 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_ExtractGeometry_cxx
#include <vtkm/filter/ExtractGeometry.h>
#include <vtkm/filter/ExtractGeometry.hxx>
#include <vtkm/filter/MapFieldPermutation.h>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
ExtractGeometry::ExtractGeometry()
: vtkm::filter::FilterDataSet<ExtractGeometry>()
, ExtractInside(true)
, ExtractBoundaryCells(false)
, ExtractOnlyBoundaryCells(false)
{
}
bool ExtractGeometry::MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field)
{
if (field.IsFieldPoint())
{
result.AddField(field);
return true;
}
else if (field.IsFieldCell())
{
vtkm::cont::ArrayHandle<vtkm::Id> permutation = this->Worklet.GetValidCellIds();
return vtkm::filter::MapFieldPermutation(field, permutation, result);
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
return false;
}
}
//-----------------------------------------------------------------------------
template VTKM_FILTER_COMMON_TEMPLATE_EXPORT vtkm::cont::DataSet ExtractGeometry::DoExecute(
const vtkm::cont::DataSet& inData,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault> policy);
}
} // namespace vtkm::filter

@ -7,105 +7,34 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_ExtractGeometry_h
#define vtk_m_filter_ExtractGeometry_h
#include <vtkm/filter/vtkm_filter_common_export.h>
#include <vtkm/ImplicitFunction.h>
#include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/ExtractGeometry.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/entity_extraction/ExtractGeometry.h>
namespace vtkm
{
namespace filter
{
/// \brief Extract a subset of geometry based on an implicit function
///
/// Extracts from its input geometry all cells that are either
/// completely inside or outside of a specified implicit function. Any type of
/// data can be input to this filter.
///
/// To use this filter you must specify an implicit function. You must also
/// specify whether to extract cells laying inside or outside of the implicit
/// function. (The inside of an implicit function is the negative values
/// region.) An option exists to extract cells that are neither inside or
/// outside (i.e., boundary).
///
/// This differs from Clip in that Clip will subdivide boundary cells into new
/// cells, while this filter will not, producing a more 'crinkly' output.
///
class VTKM_FILTER_COMMON_EXPORT ExtractGeometry
: public vtkm::filter::FilterDataSet<ExtractGeometry>
VTKM_DEPRECATED(
1.8,
"Use vtkm/filter/entity_extraction/ExtractGeometry.h instead of vtkm/filter/ExtractGeometry.h.")
inline void ExtractGeometry_deprecated() {}
inline void ExtractGeometry_deprecated_warning()
{
public:
//currently the ExtractGeometry filter only works on scalar data.
using SupportedTypes = TypeListScalarAll;
ExtractGeometry_deprecated();
}
VTKM_CONT ExtractGeometry();
// Set the volume of interest to extract
void SetImplicitFunction(const vtkm::ImplicitFunctionGeneral& func) { this->Function = func; }
const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; }
VTKM_CONT
bool GetExtractInside() { return this->ExtractInside; }
VTKM_CONT
void SetExtractInside(bool value) { this->ExtractInside = value; }
VTKM_CONT
void ExtractInsideOn() { this->ExtractInside = true; }
VTKM_CONT
void ExtractInsideOff() { this->ExtractInside = false; }
VTKM_CONT
bool GetExtractBoundaryCells() { return this->ExtractBoundaryCells; }
VTKM_CONT
void SetExtractBoundaryCells(bool value) { this->ExtractBoundaryCells = value; }
VTKM_CONT
void ExtractBoundaryCellsOn() { this->ExtractBoundaryCells = true; }
VTKM_CONT
void ExtractBoundaryCellsOff() { this->ExtractBoundaryCells = false; }
VTKM_CONT
bool GetExtractOnlyBoundaryCells() { return this->ExtractOnlyBoundaryCells; }
VTKM_CONT
void SetExtractOnlyBoundaryCells(bool value) { this->ExtractOnlyBoundaryCells = value; }
VTKM_CONT
void ExtractOnlyBoundaryCellsOn() { this->ExtractOnlyBoundaryCells = true; }
VTKM_CONT
void ExtractOnlyBoundaryCellsOff() { this->ExtractOnlyBoundaryCells = false; }
template <typename DerivedPolicy>
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy);
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field);
template <typename DerivedPolicy>
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
return this->MapFieldOntoOutput(result, field);
}
private:
bool ExtractInside;
bool ExtractBoundaryCells;
bool ExtractOnlyBoundaryCells;
vtkm::ImplicitFunctionGeneral Function;
vtkm::worklet::ExtractGeometry Worklet;
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::ExtractGeometry.") ExtractGeometry
: public vtkm::filter::entity_extraction::ExtractGeometry
{
using entity_extraction::ExtractGeometry::ExtractGeometry;
};
#ifndef vtkm_filter_ExtractGeometry_cxx
extern template VTKM_FILTER_COMMON_TEMPLATE_EXPORT vtkm::cont::DataSet ExtractGeometry::DoExecute(
const vtkm::cont::DataSet&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
#endif
}
} // namespace vtkm::filter
#endif // vtk_m_filter_ExtractGeometry_h
#endif //vtk_m_filter_ExtractGeometry_h

@ -1,68 +0,0 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_ExtractStructured_cxx
#include <vtkm/filter/ExtractStructured.h>
#include <vtkm/filter/ExtractStructured.hxx>
#include <vtkm/filter/MapFieldPermutation.h>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
ExtractStructured::ExtractStructured()
: vtkm::filter::FilterDataSet<ExtractStructured>()
, VOI(vtkm::RangeId3(0, -1, 0, -1, 0, -1))
, SampleRate(vtkm::Id3(1, 1, 1))
, IncludeBoundary(false)
, IncludeOffset(false)
, Worklet()
{
}
//-----------------------------------------------------------------------------
bool ExtractStructured::MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field)
{
if (field.IsFieldPoint())
{
return vtkm::filter::MapFieldPermutation(field, this->PointFieldMap, result);
}
else if (field.IsFieldCell())
{
return vtkm::filter::MapFieldPermutation(field, this->CellFieldMap, result);
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
return false;
}
}
//-----------------------------------------------------------------------------
void ExtractStructured::PostExecute(const vtkm::cont::PartitionedDataSet&,
vtkm::cont::PartitionedDataSet&)
{
this->CellFieldMap.ReleaseResources();
this->PointFieldMap.ReleaseResources();
}
//-----------------------------------------------------------------------------
template VTKM_FILTER_COMMON_TEMPLATE_EXPORT vtkm::cont::DataSet ExtractStructured::DoExecute(
const vtkm::cont::DataSet& inData,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault> policy);
}
}

@ -7,126 +7,35 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_ExtractStructured_h
#define vtk_m_filter_ExtractStructured_h
#include <vtkm/filter/vtkm_filter_common_export.h>
#include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/ExtractStructured.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/entity_extraction/ExtractStructured.h>
namespace vtkm
{
namespace filter
{
/// \brief Select piece (e.g., volume of interest) and/or subsample structured points dataset
///
/// Select or subsample a portion of an input structured dataset. The selected
/// portion of interested is referred to as the Volume Of Interest, or VOI.
/// The output of this filter is a structured dataset. The filter treats input
/// data of any topological dimension (i.e., point, line, plane, or volume) and
/// can generate output data of any topological dimension.
///
/// To use this filter set the VOI ivar which are i-j-k min/max indices that
/// specify a rectangular region in the data. (Note that these are 0-offset.)
/// You can also specify a sampling rate to subsample the data.
///
/// Typical applications of this filter are to extract a slice from a volume
/// for image processing, subsampling large volumes to reduce data size, or
/// extracting regions of a volume with interesting data.
///
class VTKM_FILTER_COMMON_EXPORT ExtractStructured
: public vtkm::filter::FilterDataSet<ExtractStructured>
VTKM_DEPRECATED(1.8,
"Use vtkm/filter/entity_extraction/ExtractStructured.h instead of "
"vtkm/filter/ExtractStructured.h.")
inline void ExtractStructured_deprecated() {}
inline void ExtractStructured_deprecated_warning()
{
public:
ExtractStructured();
ExtractStructured_deprecated();
}
// Set the bounding box for the volume of interest
VTKM_CONT
vtkm::RangeId3 GetVOI() const { return this->VOI; }
VTKM_CONT
void SetVOI(vtkm::Id i0, vtkm::Id i1, vtkm::Id j0, vtkm::Id j1, vtkm::Id k0, vtkm::Id k1)
{
this->VOI = vtkm::RangeId3(i0, i1, j0, j1, k0, k1);
}
VTKM_CONT
void SetVOI(vtkm::Id extents[6]) { this->VOI = vtkm::RangeId3(extents); }
VTKM_CONT
void SetVOI(vtkm::Id3 minPoint, vtkm::Id3 maxPoint)
{
this->VOI = vtkm::RangeId3(minPoint, maxPoint);
}
VTKM_CONT
void SetVOI(const vtkm::RangeId3& voi) { this->VOI = voi; }
/// Get the Sampling rate
VTKM_CONT
vtkm::Id3 GetSampleRate() const { return this->SampleRate; }
/// Set the Sampling rate
VTKM_CONT
void SetSampleRate(vtkm::Id i, vtkm::Id j, vtkm::Id k) { this->SampleRate = vtkm::Id3(i, j, k); }
/// Set the Sampling rate
VTKM_CONT
void SetSampleRate(vtkm::Id3 sampleRate) { this->SampleRate = sampleRate; }
/// Get if we should include the outer boundary on a subsample
VTKM_CONT
bool GetIncludeBoundary() { return this->IncludeBoundary; }
/// Set if we should include the outer boundary on a subsample
VTKM_CONT
void SetIncludeBoundary(bool value) { this->IncludeBoundary = value; }
VTKM_CONT
void SetIncludeOffset(bool value) { this->IncludeOffset = value; }
template <typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy);
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field);
template <typename DerivedPolicy>
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
return this->MapFieldOntoOutput(result, field);
}
VTKM_CONT void PostExecute(const vtkm::cont::PartitionedDataSet&,
vtkm::cont::PartitionedDataSet&);
template <typename DerivedPolicy>
VTKM_CONT void PostExecute(const vtkm::cont::PartitionedDataSet& input,
vtkm::cont::PartitionedDataSet& output,
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
this->PostExecute(input, output);
}
private:
vtkm::RangeId3 VOI;
vtkm::Id3 SampleRate = { 1, 1, 1 };
bool IncludeBoundary;
bool IncludeOffset;
vtkm::worklet::ExtractStructured Worklet;
vtkm::cont::ArrayHandle<vtkm::Id> CellFieldMap;
vtkm::cont::ArrayHandle<vtkm::Id> PointFieldMap;
class VTKM_DEPRECATED(1.8,
"Use vtkm::filter::entity_extraction::ExtractStructured.") ExtractStructured
: public vtkm::filter::entity_extraction::ExtractStructured
{
using entity_extraction::ExtractStructured::ExtractStructured;
};
#ifndef vtkm_filter_ExtractStructured_cxx
extern template VTKM_FILTER_COMMON_TEMPLATE_EXPORT vtkm::cont::DataSet ExtractStructured::DoExecute(
const vtkm::cont::DataSet&,
vtkm::filter::PolicyBase<vtkm::filter::PolicyDefault>);
#endif
}
} // namespace vtkm::filter
#endif // vtk_m_filter_ExtractStructured_h
#endif //vtk_m_filter_ExtractStructured_h

@ -1,52 +0,0 @@
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_filter_ExtractStructured_hxx
#define vtk_m_filter_ExtractStructured_hxx
#include <vtkm/filter/ExtractStructured.h>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
template <typename DerivedPolicy>
vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
const vtkm::cont::CoordinateSystem& coordinates = input.GetCoordinateSystem();
auto cellset = this->Worklet.Run(vtkm::filter::ApplyPolicyCellSetStructured(cells, policy, *this),
this->VOI,
this->SampleRate,
this->IncludeBoundary,
this->IncludeOffset);
auto coords = this->Worklet.MapCoordinates(coordinates);
vtkm::cont::CoordinateSystem outputCoordinates(coordinates.GetName(), coords);
vtkm::cont::DataSet output;
output.SetCellSet(vtkm::cont::UnknownCellSet(cellset));
output.AddCoordinateSystem(outputCoordinates);
// Create map arrays for mapping fields. Could potentially save some time to first check to see
// if these arrays would be used.
this->CellFieldMap =
this->Worklet.ProcessCellField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfCells()));
this->PointFieldMap =
this->Worklet.ProcessPointField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfPoints()));
return output;
}
}
}
#endif

@ -7,79 +7,34 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_GhostCellRemove_h
#define vtk_m_filter_GhostCellRemove_h
#include <vtkm/CellClassification.h>
#include <vtkm/filter/FilterDataSetWithField.h>
#include <vtkm/filter/Threshold.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/entity_extraction/GhostCellRemove.h>
namespace vtkm
{
namespace filter
{
struct GhostCellRemovePolicy : vtkm::filter::PolicyBase<GhostCellRemovePolicy>
VTKM_DEPRECATED(
1.8,
"Use vtkm/filter/entity_extraction/GhostCellRemove.h instead of vtkm/filter/GhostCellRemove.h.")
inline void GhostCellRemove_deprecated() {}
inline void GhostCellRemove_deprecated_warning()
{
using FieldTypeList = vtkm::List<vtkm::UInt8>;
GhostCellRemove_deprecated();
}
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::GhostCellRemove.") GhostCellRemove
: public vtkm::filter::entity_extraction::GhostCellRemove
{
using entity_extraction::GhostCellRemove::GhostCellRemove;
};
/// \brief Removes ghost cells
///
class GhostCellRemove : public vtkm::filter::FilterDataSetWithField<GhostCellRemove>
{
public:
//currently the GhostCellRemove filter only works on uint8 data.
using SupportedTypes = vtkm::List<vtkm::UInt8>;
VTKM_CONT
GhostCellRemove();
VTKM_CONT
void RemoveGhostField() { this->RemoveField = true; }
VTKM_CONT
void RemoveAllGhost() { this->RemoveAll = true; }
VTKM_CONT
void RemoveByType(const vtkm::UInt8& vals)
{
this->RemoveAll = false;
this->RemoveVals = vals;
}
VTKM_CONT
bool GetRemoveGhostField() { return this->RemoveField; }
VTKM_CONT
bool GetRemoveAllGhost() const { return this->RemoveAll; }
VTKM_CONT
bool GetRemoveByType() const { return !this->RemoveAll; }
VTKM_CONT
vtkm::UInt8 GetRemoveType() const { return this->RemoveVals; }
template <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy);
//Map a new field onto the resulting dataset after running the filter
//this call is only valid after DoExecute is run
template <typename DerivedPolicy>
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
vtkm::filter::PolicyBase<DerivedPolicy> policy);
private:
bool RemoveAll;
bool RemoveField;
vtkm::UInt8 RemoveVals;
vtkm::worklet::Threshold Worklet;
};
}
} // namespace vtkm::filter
#ifndef vtk_m_filter_GhostCellRemove_hxx
#include <vtkm/filter/GhostCellRemove.hxx>
#endif
#endif // vtk_m_filter_GhostCellRemove_h
#endif //vtk_m_filter_GhostCellRemove_h

@ -7,57 +7,32 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_Mask_h
#define vtk_m_filter_Mask_h
#include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/Mask.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/entity_extraction/Mask.h>
namespace vtkm
{
namespace filter
{
/// \brief Subselect cells using a stride
///
/// Extract only every Nth cell where N is equal to a stride value
class Mask : public vtkm::filter::FilterDataSet<Mask>
VTKM_DEPRECATED(1.8, "Use vtkm/filter/entity_extraction/Mask.h instead of vtkm/filter/Mask.h.")
inline void Mask_deprecated() {}
inline void Mask_deprecated_warning()
{
public:
VTKM_CONT
Mask();
Mask_deprecated();
}
// When CompactPoints is set, instead of copying the points and point fields
// from the input, the filter will create new compact fields without the unused elements
VTKM_CONT
bool GetCompactPoints() const { return this->CompactPoints; }
VTKM_CONT
void SetCompactPoints(bool value) { this->CompactPoints = value; }
// Set the stride of the subsample
VTKM_CONT
vtkm::Id GetStride() const { return this->Stride; }
VTKM_CONT
void SetStride(vtkm::Id& stride) { this->Stride = stride; }
template <typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy);
//Map a new field onto the resulting dataset after running the filter
template <typename DerivedPolicy>
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
vtkm::filter::PolicyBase<DerivedPolicy> policy);
private:
vtkm::Id Stride;
bool CompactPoints;
vtkm::worklet::Mask Worklet;
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::Mask.") Mask
: public vtkm::filter::entity_extraction::Mask
{
using entity_extraction::Mask::Mask;
};
}
} // namespace vtkm::filter
#include <vtkm/filter/Mask.hxx>
#endif // vtk_m_filter_Mask_h
#endif //vtk_m_filter_Mask_h

@ -1,41 +0,0 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_Threshold_cxx
#include <vtkm/filter/Threshold.h>
#include <vtkm/filter/MapFieldPermutation.h>
namespace vtkm
{
namespace filter
{
bool Threshold::MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field)
{
if (field.IsFieldPoint() || field.IsFieldGlobal())
{
//we copy the input handle to the result dataset, reusing the metadata
result.AddField(field);
return true;
}
else if (field.IsFieldCell())
{
return vtkm::filter::MapFieldPermutation(field, this->Worklet.GetValidCellIds(), result);
}
else
{
return false;
}
}
//-----------------------------------------------------------------------------
VTKM_FILTER_COMMON_INSTANTIATE_EXECUTE_METHOD(Threshold);
}
}

@ -7,84 +7,33 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_Threshold_h
#define vtk_m_filter_Threshold_h
#include <vtkm/filter/vtkm_filter_common_export.h>
#include <vtkm/filter/FilterDataSetWithField.h>
#include <vtkm/worklet/Threshold.h>
#include <vtkm/Deprecated.h>
#include <vtkm/filter/entity_extraction/Threshold.h>
namespace vtkm
{
namespace filter
{
/// \brief Extracts cells where scalar value in cell satisfies threshold criterion
///
/// Extracts all cells from any dataset type that
/// satisfy a threshold criterion. A cell satisfies the criterion if the
/// scalar value of every point or cell satisfies the criterion. The
/// criterion takes the form of between two values. The output of this
/// filter is an permutation of the input dataset.
///
/// You can threshold either on point or cell fields
class VTKM_FILTER_COMMON_EXPORT Threshold : public vtkm::filter::FilterDataSetWithField<Threshold>
VTKM_DEPRECATED(1.8,
"Use vtkm/filter/entity_extraction/Threshold.h instead of vtkm/filter/Threshold.h.")
inline void Threshold_deprecated() {}
inline void Threshold_deprecated_warning()
{
public:
using SupportedTypes = vtkm::TypeListScalarAll;
Threshold_deprecated();
}
VTKM_CONT
void SetLowerThreshold(vtkm::Float64 value) { this->LowerValue = value; }
VTKM_CONT
void SetUpperThreshold(vtkm::Float64 value) { this->UpperValue = value; }
VTKM_CONT
vtkm::Float64 GetLowerThreshold() const { return this->LowerValue; }
VTKM_CONT
vtkm::Float64 GetUpperThreshold() const { return this->UpperValue; }
//If using scalars from point data, all scalars for all points in a cell must
//satisfy the threshold criterion if AllScalars is set. Otherwise, just a
//single scalar value satisfying the threshold criterion will extract the cell.
VTKM_CONT
void SetAllInRange(bool value) { this->ReturnAllInRange = value; }
VTKM_CONT
bool GetAllInRange() const { return this->ReturnAllInRange; }
template <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy);
//Map a new field onto the resulting dataset after running the filter
//this call is only valid after DoExecute is called
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field);
template <typename DerivedPolicy>
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
return this->MapFieldOntoOutput(result, field);
}
private:
double LowerValue = 0;
double UpperValue = 0;
bool ReturnAllInRange = false;
vtkm::worklet::Threshold Worklet;
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::Threshold.") Threshold
: public vtkm::filter::entity_extraction::Threshold
{
using entity_extraction::Threshold::Threshold;
};
#ifndef vtkm_filter_Threshold_cxx
VTKM_FILTER_COMMON_EXPORT_EXECUTE_METHOD(Threshold);
#endif
}
} // namespace vtkm::filter
#include <vtkm/filter/Threshold.hxx>
#endif // vtk_m_filter_Threshold_h
#endif //vtk_m_filter_Threshold_h

@ -1,84 +0,0 @@
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_filter_Threshold_hxx
#define vtk_m_filter_Threshold_hxx
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/UnknownCellSet.h>
namespace
{
class ThresholdRange
{
public:
VTKM_CONT
ThresholdRange(const vtkm::Float64& lower, const vtkm::Float64& upper)
: Lower(lower)
, Upper(upper)
{
}
template <typename T>
VTKM_EXEC bool operator()(const T& value) const
{
return value >= static_cast<T>(this->Lower) && value <= static_cast<T>(this->Upper);
}
//Needed to work with ArrayHandleVirtual
template <typename PortalType>
VTKM_EXEC bool operator()(
const vtkm::internal::ArrayPortalValueReference<PortalType>& value) const
{
using T = typename PortalType::ValueType;
return value.Get() >= static_cast<T>(this->Lower) && value.Get() <= static_cast<T>(this->Upper);
}
private:
vtkm::Float64 Lower;
vtkm::Float64 Upper;
};
} // end anon namespace
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
//get the cells and coordinates of the dataset
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
ThresholdRange predicate(this->GetLowerThreshold(), this->GetUpperThreshold());
vtkm::cont::UnknownCellSet cellOut =
this->Worklet.Run(vtkm::filter::ApplyPolicyCellSet(cells, policy, *this),
field,
fieldMeta.GetAssociation(),
predicate,
this->GetAllInRange());
vtkm::cont::DataSet output;
output.SetCellSet(cellOut);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
return output;
}
}
}
#endif

@ -26,7 +26,71 @@ struct SharedStates
vtkm::worklet::RemoveDegenerateCells CellCompactor;
vtkm::worklet::PointMerge PointMerger;
};
}
}
}
// New Filter Design: DoMapField is now a free function in an anonymous namespace. It should be
// considered as a convenience/extension to the lambda passed to the MapFieldsOntoOutput.
// Being a free function discourages the developer to "pass" mutable states from DoExecute phase
// to DoMapField phase via data member. However, there is nothing to prevent developer doing
// stupid thing to circumvent the protection. One example here is that the developer could
// always pass a mutable reference/pointer to the filter instance and thus pass mutable state
// across the DoExecute and DoMapField boundary. We need to explicitly discourage developer
// trying to do such a thing in the manual.
namespace
{
bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
const vtkm::filter::clean_grid::CleanGrid& self,
vtkm::filter::clean_grid::SharedStates& worklets)
{
if (field.IsFieldPoint() && (self.GetCompactPointFields() || self.GetMergePoints()))
{
vtkm::cont::Field compactedField;
if (self.GetCompactPointFields())
{
bool success = vtkm::filter::MapFieldPermutation(
field, worklets.PointCompactor.GetPointScatter().GetOutputToInputMap(), compactedField);
if (!success)
{
return false;
}
}
else
{
compactedField = field;
}
if (self.GetMergePoints())
{
return vtkm::filter::MapFieldMergeAverage(
compactedField, worklets.PointMerger.GetMergeKeys(), result);
}
else
{
result.AddField(compactedField);
return true;
}
}
else if (field.IsFieldCell() && self.GetRemoveDegenerateCells())
{
return vtkm::filter::MapFieldPermutation(
field, worklets.CellCompactor.GetValidCellIds(), result);
}
else
{
result.AddField(field);
return true;
}
}
} // anonymous namespace
namespace vtkm
{
namespace filter
{
namespace clean_grid
{
//-----------------------------------------------------------------------------
vtkm::cont::DataSet CleanGrid::GenerateOutput(const vtkm::cont::DataSet& inData,
vtkm::cont::CellSetExplicit<>& outputCellSet,
@ -116,61 +180,6 @@ vtkm::cont::DataSet CleanGrid::GenerateOutput(const vtkm::cont::DataSet& inData,
return outData;
}
// New Filter Design: DoMapField is now a free function in an anonymous namespace. It should be
// considered as a convenience/extension to the lambda passed to the MapFieldsOntoOutput.
// Being a free function discourages the developer to "pass" mutable states from DoExecute phase
// to DoMapField phase via data member. However, there is nothing to prevent developer doing
// stupid thing to circumvent the protection. One example here is that the developer could
// always pass a mutable reference/pointer to the filter instance and thus pass mutable state
// across the DoExecute and DoMapField boundary. We need to explicitly discourage developer
// trying to do such a thing in the manual.
namespace
{
bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
const CleanGrid& self,
clean_grid::SharedStates& worklets)
{
if (field.IsFieldPoint() && (self.GetCompactPointFields() || self.GetMergePoints()))
{
vtkm::cont::Field compactedField;
if (self.GetCompactPointFields())
{
bool success = vtkm::filter::MapFieldPermutation(
field, worklets.PointCompactor.GetPointScatter().GetOutputToInputMap(), compactedField);
if (!success)
{
return false;
}
}
else
{
compactedField = field;
}
if (self.GetMergePoints())
{
return vtkm::filter::MapFieldMergeAverage(
compactedField, worklets.PointMerger.GetMergeKeys(), result);
}
else
{
result.AddField(compactedField);
return true;
}
}
else if (field.IsFieldCell() && self.GetRemoveDegenerateCells())
{
return vtkm::filter::MapFieldPermutation(
field, worklets.CellCompactor.GetValidCellIds(), result);
}
else
{
result.AddField(field);
return true;
}
}
} // anonymous namespace
vtkm::cont::DataSet CleanGrid::DoExecute(const vtkm::cont::DataSet& inData)
{
// New Filter Design: mutable states that was a data member of the filter is now a local

@ -9,14 +9,24 @@
##============================================================================
set(entity_extraction_headers
ExternalFaces.h
ExtractGeometry.h
ExtractPoints.h
ExtractStructured.h
GhostCellRemove.h
Mask.h
MaskPoints.h
Threshold.h
ThresholdPoints.h
)
set(entity_extraction_sources_device
ExternalFaces.cxx
ExtractGeometry.cxx
ExtractPoints.cxx
ExtractStructured.cxx
GhostCellRemove.cxx
Mask.cxx
MaskPoints.cxx
Threshold.cxx
ThresholdPoints.cxx
)

@ -46,7 +46,8 @@ vtkm::cont::DataSet ExternalFaces::GenerateOutput(const vtkm::cont::DataSet& inp
bool hasCellFields = false;
for (vtkm::Id fieldIdx = 0; fieldIdx < numFields && !hasCellFields; ++fieldIdx)
{
hasCellFields = input.GetField(fieldIdx).IsFieldCell();
const auto& f = input.GetField(fieldIdx);
hasCellFields = f.IsFieldCell();
}
if (!hasCellFields)

@ -36,7 +36,7 @@ class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT ExternalFaces : public vtkm::filter::
{
public:
ExternalFaces();
~ExternalFaces();
~ExternalFaces() override;
// New Design: I am too lazy to make this filter thread-safe. Let's use it as an example of
// thread un-safe filter.

@ -7,18 +7,15 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_ExtractGeometry_hxx
#define vtk_m_filter_ExtractGeometry_hxx
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/UnknownCellSet.h>
#include <vtkm/filter/MapFieldPermutation.h>
#include <vtkm/filter/entity_extraction/ExtractGeometry.h>
#include <vtkm/filter/entity_extraction/worklet/ExtractGeometry.h>
namespace
{
struct CallWorker
{
vtkm::cont::UnknownCellSet& Output;
@ -58,40 +55,68 @@ struct CallWorker
}
};
} // end anon namespace
bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
const vtkm::worklet::ExtractGeometry& worklet)
{
if (field.IsFieldPoint())
{
result.AddField(field);
return true;
}
else if (field.IsFieldCell())
{
vtkm::cont::ArrayHandle<vtkm::Id> permutation = worklet.GetValidCellIds();
return vtkm::filter::MapFieldPermutation(field, permutation, result);
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
return false;
}
}
} // anonymous namespace
namespace vtkm
{
namespace filter
{
namespace entity_extraction
{
//-----------------------------------------------------------------------------
template <typename DerivedPolicy>
vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input)
{
// extract the input cell set and coordinates
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
const vtkm::cont::CoordinateSystem& coords =
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());
vtkm::worklet::ExtractGeometry worklet;
vtkm::cont::UnknownCellSet outCells;
CallWorker worker(outCells,
this->Worklet,
worklet,
coords,
this->Function,
this->ExtractInside,
this->ExtractBoundaryCells,
this->ExtractOnlyBoundaryCells);
vtkm::filter::ApplyPolicyCellSet(cells, policy, *this).CastAndCall(worker);
cells.CastAndCallForTypes<VTKM_DEFAULT_CELL_SET_LIST>(worker);
// create the output dataset
vtkm::cont::DataSet output;
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
output.SetCellSet(outCells);
auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); };
this->MapFieldsOntoOutput(input, output, mapper);
return output;
}
}
}
#endif
} // namespace entity_extraction
} // namespace filter
} // namespace vtkm

@ -0,0 +1,93 @@
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_fulter_entity_extraction_ExtractGeometry_h
#define vtk_m_fulter_entity_extraction_ExtractGeometry_h
#include <vtkm/ImplicitFunction.h>
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/entity_extraction/vtkm_filter_entity_extraction_export.h>
namespace vtkm
{
namespace worklet
{
// Forward declaration for the worklet so we don't need to include the worklet header file
// which would require user code to be compilerd by device compiler.
class ExtractGeometry;
}
namespace filter
{
namespace entity_extraction
{
/// \brief Extract a subset of geometry based on an implicit function
///
/// Extracts from its input geometry all cells that are either
/// completely inside or outside of a specified implicit function. Any type of
/// data can be input to this filter.
///
/// To use this filter you must specify an implicit function. You must also
/// specify whether to extract cells laying inside or outside of the implicit
/// function. (The inside of an implicit function is the negative values
/// region.) An option exists to extract cells that are neither inside or
/// outside (i.e., boundary).
///
/// This differs from Clip in that Clip will subdivide boundary cells into new
/// cells, while this filter will not, producing a more 'crinkly' output.
///
class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT ExtractGeometry : public vtkm::filter::NewFilterField
{
public:
// Set the volume of interest to extract
void SetImplicitFunction(const vtkm::ImplicitFunctionGeneral& func) { this->Function = func; }
const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; }
VTKM_CONT
bool GetExtractInside() const { return this->ExtractInside; }
VTKM_CONT
void SetExtractInside(bool value) { this->ExtractInside = value; }
VTKM_CONT
void ExtractInsideOn() { this->ExtractInside = true; }
VTKM_CONT
void ExtractInsideOff() { this->ExtractInside = false; }
VTKM_CONT
bool GetExtractBoundaryCells() const { return this->ExtractBoundaryCells; }
VTKM_CONT
void SetExtractBoundaryCells(bool value) { this->ExtractBoundaryCells = value; }
VTKM_CONT
void ExtractBoundaryCellsOn() { this->ExtractBoundaryCells = true; }
VTKM_CONT
void ExtractBoundaryCellsOff() { this->ExtractBoundaryCells = false; }
VTKM_CONT
bool GetExtractOnlyBoundaryCells() const { return this->ExtractOnlyBoundaryCells; }
VTKM_CONT
void SetExtractOnlyBoundaryCells(bool value) { this->ExtractOnlyBoundaryCells = value; }
VTKM_CONT
void ExtractOnlyBoundaryCellsOn() { this->ExtractOnlyBoundaryCells = true; }
VTKM_CONT
void ExtractOnlyBoundaryCellsOff() { this->ExtractOnlyBoundaryCells = false; }
private:
VTKM_CONT
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
bool ExtractInside = true;
bool ExtractBoundaryCells = false;
bool ExtractOnlyBoundaryCells = false;
vtkm::ImplicitFunctionGeneral Function;
};
}
}
} // namespace vtkm::filter
#endif // vtk_m_fulter_entity_extraction_ExtractGeometry_h

@ -13,6 +13,29 @@
#include <vtkm/filter/entity_extraction/ExtractPoints.h>
#include <vtkm/filter/entity_extraction/worklet/ExtractPoints.h>
namespace
{
bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field)
{
// point data is copied as is because it was not collapsed
if (field.IsFieldPoint())
{
result.AddField(field);
return true;
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
// cell data does not apply
return false;
}
}
} // anonymous namespace
namespace vtkm
{
namespace filter
@ -40,7 +63,7 @@ vtkm::cont::DataSet ExtractPoints::DoExecute(const vtkm::cont::DataSet& input)
output.SetCellSet(outCellSet);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
auto mapper = [&, this](auto& result, const auto& f) { this->MapFieldOntoOutput(result, f); };
auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f); };
this->MapFieldsOntoOutput(input, output, mapper);
// compact the unused points in the output dataset
@ -57,27 +80,6 @@ vtkm::cont::DataSet ExtractPoints::DoExecute(const vtkm::cont::DataSet& input)
}
}
//-----------------------------------------------------------------------------
VTKM_CONT bool ExtractPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field)
{
// point data is copied as is because it was not collapsed
if (field.IsFieldPoint())
{
result.AddField(field);
return true;
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
// cell data does not apply
return false;
}
}
} // namespace entity_extraction
} // namespace filter
} // namespace vtkm

@ -51,7 +51,7 @@ public:
const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; }
VTKM_CONT
bool GetExtractInside() { return this->ExtractInside; }
bool GetExtractInside() const { return this->ExtractInside; }
VTKM_CONT
void SetExtractInside(bool value) { this->ExtractInside = value; }
VTKM_CONT
@ -63,9 +63,6 @@ private:
VTKM_CONT
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
//Map a new field onto the resulting dataset after running the filter
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field);
bool ExtractInside = true;
vtkm::ImplicitFunctionGeneral Function;

@ -0,0 +1,86 @@
//============================================================================
// 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.
//============================================================================
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/filter/MapFieldPermutation.h>
#include <vtkm/filter/entity_extraction/ExtractStructured.h>
#include <vtkm/filter/entity_extraction/worklet/ExtractStructured.h>
namespace
{
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
const vtkm::cont::ArrayHandle<vtkm::Id>& CellFieldMap,
const vtkm::cont::ArrayHandle<vtkm::Id>& PointFieldMap)
{
if (field.IsFieldPoint())
{
return vtkm::filter::MapFieldPermutation(field, PointFieldMap, result);
}
else if (field.IsFieldCell())
{
return vtkm::filter::MapFieldPermutation(field, CellFieldMap, result);
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
return false;
}
}
} // anonymous namespace
namespace vtkm
{
namespace filter
{
namespace entity_extraction
{
//-----------------------------------------------------------------------------
vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& input)
{
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
const vtkm::cont::CoordinateSystem& coordinates = input.GetCoordinateSystem();
vtkm::worklet::ExtractStructured worklet;
auto cellset = worklet.Run(cells.ResetCellSetList<VTKM_DEFAULT_CELL_SET_LIST_STRUCTURED>(),
this->VOI,
this->SampleRate,
this->IncludeBoundary,
this->IncludeOffset);
auto coords = worklet.MapCoordinates(coordinates);
vtkm::cont::CoordinateSystem outputCoordinates(coordinates.GetName(), coords);
vtkm::cont::DataSet output;
output.SetCellSet(vtkm::cont::UnknownCellSet(cellset));
output.AddCoordinateSystem(outputCoordinates);
// Create map arrays for mapping fields. Could potentially save some time to first check to see
// if these arrays would be used.
auto CellFieldMap =
worklet.ProcessCellField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfCells()));
auto PointFieldMap =
worklet.ProcessPointField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfPoints()));
auto mapper = [&](auto& result, const auto& f) {
DoMapField(result, f, CellFieldMap, PointFieldMap);
};
this->MapFieldsOntoOutput(input, output, mapper);
return output;
}
} // namespace entity_extraction
} // namespace filter
} // namespace vtkm

@ -0,0 +1,98 @@
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_filter_entity_extraction_ExtractStructured_h
#define vtk_m_filter_entity_extraction_ExtractStructured_h
#include <vtkm/RangeId3.h>
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/entity_extraction/vtkm_filter_entity_extraction_export.h>
namespace vtkm
{
namespace filter
{
namespace entity_extraction
{
/// \brief Select piece (e.g., volume of interest) and/or subsample structured points dataset
///
/// Select or subsample a portion of an input structured dataset. The selected
/// portion of interested is referred to as the Volume Of Interest, or VOI.
/// The output of this filter is a structured dataset. The filter treats input
/// data of any topological dimension (i.e., point, line, plane, or volume) and
/// can generate output data of any topological dimension.
///
/// To use this filter set the VOI ivar which are i-j-k min/max indices that
/// specify a rectangular region in the data. (Note that these are 0-offset.)
/// You can also specify a sampling rate to subsample the data.
///
/// Typical applications of this filter are to extract a slice from a volume
/// for image processing, subsampling large volumes to reduce data size, or
/// extracting regions of a volume with interesting data.
///
class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT ExtractStructured : public vtkm::filter::NewFilterField
{
public:
// Set the bounding box for the volume of interest
VTKM_CONT
vtkm::RangeId3 GetVOI() const { return this->VOI; }
VTKM_CONT
void SetVOI(vtkm::Id i0, vtkm::Id i1, vtkm::Id j0, vtkm::Id j1, vtkm::Id k0, vtkm::Id k1)
{
this->VOI = vtkm::RangeId3(i0, i1, j0, j1, k0, k1);
}
VTKM_CONT
void SetVOI(vtkm::Id extents[6]) { this->VOI = vtkm::RangeId3(extents); }
VTKM_CONT
void SetVOI(vtkm::Id3 minPoint, vtkm::Id3 maxPoint)
{
this->VOI = vtkm::RangeId3(minPoint, maxPoint);
}
VTKM_CONT
void SetVOI(const vtkm::RangeId3& voi) { this->VOI = voi; }
/// Get the Sampling rate
VTKM_CONT
vtkm::Id3 GetSampleRate() const { return this->SampleRate; }
/// Set the Sampling rate
VTKM_CONT
void SetSampleRate(vtkm::Id i, vtkm::Id j, vtkm::Id k) { this->SampleRate = vtkm::Id3(i, j, k); }
/// Set the Sampling rate
VTKM_CONT
void SetSampleRate(vtkm::Id3 sampleRate) { this->SampleRate = sampleRate; }
/// Get if we should include the outer boundary on a subsample
VTKM_CONT
bool GetIncludeBoundary() const { return this->IncludeBoundary; }
/// Set if we should include the outer boundary on a subsample
VTKM_CONT
void SetIncludeBoundary(bool value) { this->IncludeBoundary = value; }
VTKM_CONT
void SetIncludeOffset(bool value) { this->IncludeOffset = value; }
private:
VTKM_CONT
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
vtkm::RangeId3 VOI = vtkm::RangeId3(0, -1, 0, -1, 0, -1);
vtkm::Id3 SampleRate = { 1, 1, 1 };
bool IncludeBoundary = false;
bool IncludeOffset = false;
};
} // namespace entity_extraction
} // namespace filter
} // namespace vtkm
#endif // vtk_m_filter_entity_extraction_ExtractStructured_h

@ -8,28 +8,22 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_GhostCellRemove_hxx
#define vtk_m_filter_GhostCellRemove_hxx
#include <vtkm/filter/GhostCellRemove.h>
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/RangeId3.h>
#include <vtkm/cont/UnknownCellSet.h>
#include <vtkm/RangeId3.h>
#include <vtkm/filter/ExtractStructured.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/filter/MapFieldPermutation.h>
#include <vtkm/worklet/CellDeepCopy.h>
#include <vtkm/filter/entity_extraction/ExtractStructured.h>
#include <vtkm/filter/entity_extraction/GhostCellRemove.h>
#include <vtkm/filter/entity_extraction/worklet/Threshold.h>
namespace
{
class RemoveAllGhosts
{
public:
VTKM_CONT
RemoveAllGhosts() {}
RemoveAllGhosts() = default;
VTKM_EXEC bool operator()(const vtkm::UInt8& value) const { return (value == 0); }
};
@ -44,7 +38,7 @@ public:
}
VTKM_CONT
RemoveGhostByType(const vtkm::UInt8& val)
explicit RemoveGhostByType(const vtkm::UInt8& val)
: RemoveType(static_cast<vtkm::UInt8>(~val))
{
}
@ -279,35 +273,53 @@ bool CanDoStructuredStrip(const vtkm::cont::UnknownCellSet& cells,
return canDo;
}
bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
const vtkm::worklet::Threshold& worklet)
{
if (field.IsFieldPoint())
{
//we copy the input handle to the result dataset, reusing the metadata
result.AddField(field);
return true;
}
else if (field.IsFieldCell())
{
return vtkm::filter::MapFieldPermutation(field, worklet.GetValidCellIds(), result);
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
return false;
}
}
} // end anon namespace
namespace vtkm
{
namespace filter
{
namespace entity_extraction
{
//-----------------------------------------------------------------------------
inline VTKM_CONT GhostCellRemove::GhostCellRemove()
: vtkm::filter::FilterDataSetWithField<GhostCellRemove>()
, RemoveAll(false)
, RemoveField(false)
, RemoveVals(0)
VTKM_CONT GhostCellRemove::GhostCellRemove()
{
this->SetActiveField("vtkmGhostCells");
this->SetFieldsToPass("vtkmGhostCells", vtkm::filter::FieldSelection::MODE_EXCLUDE);
}
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(
const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(const vtkm::cont::DataSet& input)
{
//get the cells and coordinates of the dataset
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
vtkm::cont::UnknownCellSet cellOut;
const auto& field = this->GetFieldFromDataSet(input);
vtkm::cont::ArrayHandle<vtkm::UInt8> fieldArray;
vtkm::cont::ArrayCopyShallowIfPossible(field.GetData(), fieldArray);
//Preserve structured output where possible.
if (cells.CanConvert<vtkm::cont::CellSetStructured<1>>() ||
@ -316,9 +328,9 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(
{
vtkm::RangeId3 range;
if (CanDoStructuredStrip(
cells, field, this->Invoke, this->GetRemoveAllGhost(), this->GetRemoveType(), range))
cells, fieldArray, this->Invoke, this->GetRemoveAllGhost(), this->GetRemoveType(), range))
{
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
extract.SetInvoker(this->Invoke);
vtkm::RangeId3 erange(
range.X.Min, range.X.Max + 2, range.Y.Min, range.Y.Max + 2, range.Z.Min, range.Z.Max + 2);
@ -334,19 +346,22 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(
}
}
vtkm::cont::UnknownCellSet cellOut;
vtkm::worklet::Threshold worklet;
if (this->GetRemoveAllGhost())
{
cellOut = this->Worklet.Run(vtkm::filter::ApplyPolicyCellSet(cells, policy, *this),
field,
fieldMeta.GetAssociation(),
RemoveAllGhosts());
cellOut = worklet.Run(cells.ResetCellSetList<VTKM_DEFAULT_CELL_SET_LIST>(),
fieldArray,
field.GetAssociation(),
RemoveAllGhosts());
}
else if (this->GetRemoveByType())
{
cellOut = this->Worklet.Run(vtkm::filter::ApplyPolicyCellSet(cells, policy, *this),
field,
fieldMeta.GetAssociation(),
RemoveGhostByType(this->GetRemoveType()));
cellOut = worklet.Run(cells.ResetCellSetList<VTKM_DEFAULT_CELL_SET_LIST>(),
fieldArray,
field.GetAssociation(),
RemoveGhostByType(this->GetRemoveType()));
}
else
{
@ -357,36 +372,12 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
output.SetCellSet(cellOut);
auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); };
this->MapFieldsOntoOutput(input, output, mapper);
return output;
}
//-----------------------------------------------------------------------------
template <typename DerivedPolicy>
VTKM_CONT bool GhostCellRemove::MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
if (field.IsFieldPoint())
{
//we copy the input handle to the result dataset, reusing the metadata
result.AddField(field);
return true;
}
else if (field.IsFieldCell())
{
return vtkm::filter::MapFieldPermutation(field, this->Worklet.GetValidCellIds(), result);
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
return false;
}
}
}
}
#endif //vtk_m_filter_GhostCellRemove_hxx

@ -0,0 +1,65 @@
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_filter_entity_extraction_GhostCellRemove_h
#define vtk_m_filter_entity_extraction_GhostCellRemove_h
#include <vtkm/CellClassification.h>
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/entity_extraction/vtkm_filter_entity_extraction_export.h>
namespace vtkm
{
namespace filter
{
namespace entity_extraction
{
/// \brief Removes ghost cells
///
class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT GhostCellRemove : public vtkm::filter::NewFilterField
{
public:
VTKM_CONT
GhostCellRemove();
VTKM_CONT
void RemoveGhostField() { this->RemoveField = true; }
VTKM_CONT
void RemoveAllGhost() { this->RemoveAll = true; }
VTKM_CONT
void RemoveByType(const vtkm::UInt8& vals)
{
this->RemoveAll = false;
this->RemoveVals = vals;
}
VTKM_CONT
bool GetRemoveGhostField() const { return this->RemoveField; }
VTKM_CONT
bool GetRemoveAllGhost() const { return this->RemoveAll; }
VTKM_CONT
bool GetRemoveByType() const { return !this->RemoveAll; }
VTKM_CONT
vtkm::UInt8 GetRemoveType() const { return this->RemoveVals; }
private:
VTKM_CONT
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
bool RemoveAll = false;
bool RemoveField = false;
vtkm::UInt8 RemoveVals = 0;
};
} // namespace entity_extraction
} // namespace filter
} // namespace vtkm
#endif // vtk_m_filter_entity_extraction_GhostCellRemove_h

@ -7,14 +7,12 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_Mask_hxx
#define vtk_m_filter_Mask_hxx
#include <vtkm/filter/MapFieldPermutation.h>
#include <vtkm/filter/entity_extraction/Mask.h>
#include <vtkm/filter/entity_extraction/worklet/Mask.h>
namespace
{
struct CallWorklet
{
vtkm::Id Stride;
@ -35,43 +33,9 @@ struct CallWorklet
}
};
} // end anon namespace
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
inline VTKM_CONT Mask::Mask()
: vtkm::filter::FilterDataSet<Mask>()
, Stride(1)
, CompactPoints(false)
{
}
//-----------------------------------------------------------------------------
template <typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet Mask::DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
vtkm::cont::UnknownCellSet cellOut;
CallWorklet workletCaller(this->Stride, cellOut, this->Worklet);
vtkm::filter::ApplyPolicyCellSet(cells, policy, *this).CastAndCall(workletCaller);
// create the output dataset
vtkm::cont::DataSet output;
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
output.SetCellSet(cellOut);
return output;
}
//-----------------------------------------------------------------------------
template <typename DerivedPolicy>
inline VTKM_CONT bool Mask::MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
vtkm::filter::PolicyBase<DerivedPolicy>)
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
const vtkm::worklet::Mask& worklet)
{
if (field.IsFieldPoint() || field.IsFieldGlobal())
{
@ -80,13 +44,41 @@ inline VTKM_CONT bool Mask::MapFieldOntoOutput(vtkm::cont::DataSet& result,
}
else if (field.IsFieldCell())
{
return vtkm::filter::MapFieldPermutation(field, this->Worklet.GetValidCellIds(), result);
return vtkm::filter::MapFieldPermutation(field, worklet.GetValidCellIds(), result);
}
else
{
return false;
}
}
} // end anon namespace
namespace vtkm
{
namespace filter
{
namespace entity_extraction
{
//-----------------------------------------------------------------------------
VTKM_CONT vtkm::cont::DataSet Mask::DoExecute(const vtkm::cont::DataSet& input)
{
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
vtkm::cont::UnknownCellSet cellOut;
vtkm::worklet::Mask worklet;
CallWorklet workletCaller(this->Stride, cellOut, worklet);
cells.CastAndCallForTypes<VTKM_DEFAULT_CELL_SET_LIST>(workletCaller);
// create the output dataset
vtkm::cont::DataSet output;
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
output.SetCellSet(cellOut);
auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); };
this->MapFieldsOntoOutput(input, output, mapper);
return output;
}
}
#endif
} // namespace entity_extraction
} // namespace filter
} // namespace vtkm

@ -0,0 +1,53 @@
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_filter_Mask_h
#define vtk_m_filter_Mask_h
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/entity_extraction/vtkm_filter_entity_extraction_export.h>
namespace vtkm
{
namespace filter
{
namespace entity_extraction
{
/// \brief Subselect cells using a stride
///
/// Extract only every Nth cell where N is equal to a stride value
class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT Mask : public vtkm::filter::NewFilterField
{
public:
// When CompactPoints is set, instead of copying the points and point fields
// from the input, the filter will create new compact fields without the unused elements
VTKM_CONT
bool GetCompactPoints() const { return this->CompactPoints; }
VTKM_CONT
void SetCompactPoints(bool value) { this->CompactPoints = value; }
// Set the stride of the subsample
VTKM_CONT
vtkm::Id GetStride() const { return this->Stride; }
VTKM_CONT
void SetStride(vtkm::Id& stride) { this->Stride = stride; }
private:
VTKM_CONT
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
vtkm::Id Stride = 1;
bool CompactPoints = false;
};
} // namespace entity_extraction
} // namespace filter
} // namespace vtk
#endif // vtk_m_filter_Mask_h

@ -12,49 +12,9 @@
#include <vtkm/filter/entity_extraction/MaskPoints.h>
#include <vtkm/filter/entity_extraction/worklet/MaskPoints.h>
namespace vtkm
namespace
{
namespace filter
{
namespace entity_extraction
{
//-----------------------------------------------------------------------------
VTKM_CONT vtkm::cont::DataSet MaskPoints::DoExecute(const vtkm::cont::DataSet& input)
{
// extract the input cell set
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
// run the worklet on the cell set and input field
vtkm::cont::CellSetSingleType<> outCellSet;
vtkm::worklet::MaskPoints worklet;
outCellSet = worklet.Run(cells, this->Stride);
// create the output dataset
vtkm::cont::DataSet output;
output.SetCellSet(outCellSet);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
auto mapper = [&, this](auto& result, const auto& f) { this->MapFieldOntoOutput(result, f); };
this->MapFieldsOntoOutput(input, output, mapper);
// compact the unused points in the output dataset
if (this->CompactPoints)
{
vtkm::filter::clean_grid::CleanGrid compactor;
compactor.SetCompactPointFields(true);
compactor.SetMergePoints(false);
return compactor.Execute(output);
}
else
{
return output;
}
}
//-----------------------------------------------------------------------------
VTKM_CONT bool MaskPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field)
bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field)
{
// point data is copied as is because it was not collapsed
if (field.IsFieldPoint())
@ -73,6 +33,49 @@ VTKM_CONT bool MaskPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result,
return false;
}
}
} // anonymous namespace
namespace vtkm
{
namespace filter
{
namespace entity_extraction
{
//-----------------------------------------------------------------------------
VTKM_CONT vtkm::cont::DataSet MaskPoints::DoExecute(const vtkm::cont::DataSet& input)
{
// extract the input cell set
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
// run the worklet on the cell set and input field
vtkm::cont::CellSetSingleType<> outCellSet;
vtkm::worklet::MaskPoints worklet;
outCellSet = worklet.Run(cells, this->Stride);
// create the output dataset
vtkm::cont::DataSet output;
output.SetCellSet(outCellSet);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f); };
this->MapFieldsOntoOutput(input, output, mapper);
// compact the unused points in the output dataset
if (this->CompactPoints)
{
vtkm::filter::clean_grid::CleanGrid compactor;
compactor.SetCompactPointFields(true);
compactor.SetMergePoints(false);
return compactor.Execute(output);
}
else
{
return output;
}
}
} // namespace entity_extraction
} // namespace filter
} // namespace vtkm

@ -42,8 +42,6 @@ private:
VTKM_CONT
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field);
vtkm::Id Stride = 1;
bool CompactPoints = true;
};

@ -0,0 +1,112 @@
//============================================================================
// 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.
//============================================================================
#include <vtkm/filter/MapFieldPermutation.h>
#include <vtkm/filter/entity_extraction/Threshold.h>
#include <vtkm/filter/entity_extraction/worklet/Threshold.h>
namespace
{
class ThresholdRange
{
public:
VTKM_CONT
ThresholdRange(const vtkm::Float64& lower, const vtkm::Float64& upper)
: Lower(lower)
, Upper(upper)
{
}
template <typename T>
VTKM_EXEC bool operator()(const T& value) const
{
return value >= static_cast<T>(this->Lower) && value <= static_cast<T>(this->Upper);
}
//Needed to work with ArrayHandleVirtual
template <typename PortalType>
VTKM_EXEC bool operator()(
const vtkm::internal::ArrayPortalValueReference<PortalType>& value) const
{
using T = typename PortalType::ValueType;
return value.Get() >= static_cast<T>(this->Lower) && value.Get() <= static_cast<T>(this->Upper);
}
private:
vtkm::Float64 Lower;
vtkm::Float64 Upper;
};
bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
const vtkm::worklet::Threshold& worklet)
{
if (field.IsFieldPoint() || field.IsFieldGlobal())
{
//we copy the input handle to the result dataset, reusing the metadata
result.AddField(field);
return true;
}
else if (field.IsFieldCell())
{
return vtkm::filter::MapFieldPermutation(field, worklet.GetValidCellIds(), result);
}
else
{
return false;
}
}
} // end anon namespace
namespace vtkm
{
namespace filter
{
namespace entity_extraction
{
//-----------------------------------------------------------------------------
vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input)
{
//get the cells and coordinates of the dataset
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
const auto& field = this->GetFieldFromDataSet(input);
ThresholdRange predicate(this->GetLowerThreshold(), this->GetUpperThreshold());
vtkm::worklet::Threshold worklet;
vtkm::cont::UnknownCellSet cellOut;
auto ResolveArrayType = [&, this](const auto& concrete) {
// Note: there are two overloads of .Run, the first one taking an UncertainCellSet, which is
// the desired entry point in the following call. The other is a function template on the input
// CellSet. Without the call to .ResetCellSetList to turn an UnknownCellSet to an UncertainCellSet,
// the compiler will pick the function template (i.e. wrong overload).
cellOut = worklet.Run(cells.ResetCellSetList<VTKM_DEFAULT_CELL_SET_LIST>(),
concrete,
field.GetAssociation(),
predicate,
this->GetAllInRange());
};
const auto& fieldArray = field.GetData();
fieldArray.CastAndCallForTypes<vtkm::TypeListScalarAll, VTKM_DEFAULT_STORAGE_LIST>(
ResolveArrayType);
vtkm::cont::DataSet output;
output.SetCellSet(cellOut);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); };
this->MapFieldsOntoOutput(input, output, mapper);
return output;
}
} // namespace entity_extraction
} // namespace filter
} // namespace vtkm

@ -0,0 +1,66 @@
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_filter_entity_extraction_Threshold_h
#define vtk_m_filter_entity_extraction_Threshold_h
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/entity_extraction/vtkm_filter_entity_extraction_export.h>
namespace vtkm
{
namespace filter
{
namespace entity_extraction
{
/// \brief Extracts cells where scalar value in cell satisfies threshold criterion
///
/// Extracts all cells from any dataset type that
/// satisfy a threshold criterion. A cell satisfies the criterion if the
/// scalar value of every point or cell satisfies the criterion. The
/// criterion takes the form of between two values. The output of this
/// filter is an permutation of the input dataset.
///
/// You can threshold either on point or cell fields
class VTKM_FILTER_ENTITY_EXTRACTION_EXPORT Threshold : public vtkm::filter::NewFilterField
{
public:
VTKM_CONT
void SetLowerThreshold(vtkm::Float64 value) { this->LowerValue = value; }
VTKM_CONT
void SetUpperThreshold(vtkm::Float64 value) { this->UpperValue = value; }
VTKM_CONT
vtkm::Float64 GetLowerThreshold() const { return this->LowerValue; }
VTKM_CONT
vtkm::Float64 GetUpperThreshold() const { return this->UpperValue; }
//If using scalars from point data, all scalars for all points in a cell must
//satisfy the threshold criterion if AllScalars is set. Otherwise, just a
//single scalar value satisfying the threshold criterion will extract the cell.
VTKM_CONT
void SetAllInRange(bool value) { this->ReturnAllInRange = value; }
VTKM_CONT
bool GetAllInRange() const { return this->ReturnAllInRange; }
private:
VTKM_CONT
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
double LowerValue = 0;
double UpperValue = 0;
bool ReturnAllInRange = false;
};
} // namespace entity_extraction
} // namespace filter
} // namespace vtkm
#endif // vtk_m_filter_entity_extraction_Threshold_h

@ -19,7 +19,7 @@ class ValuesBelow
{
public:
VTKM_CONT
ValuesBelow(const vtkm::Float64& value)
explicit ValuesBelow(const vtkm::Float64& value)
: Value(value)
{
}
@ -39,7 +39,7 @@ class ValuesAbove
{
public:
VTKM_CONT
ValuesAbove(const vtkm::Float64& value)
explicit ValuesAbove(const vtkm::Float64& value)
: Value(value)
{
}
@ -77,12 +77,34 @@ private:
vtkm::Float64 Lower;
vtkm::Float64 Upper;
};
bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field)
{
// point data is copied as is because it was not collapsed
if (field.IsFieldPoint())
{
result.AddField(field);
return true;
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
// cell data does not apply
return false;
}
}
} // anonymous namespace
namespace vtkm
{
namespace filter
{
namespace entity_extraction
{
//-----------------------------------------------------------------------------
@ -156,7 +178,7 @@ VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(const vtkm::cont::DataS
output.SetCellSet(outCellSet);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
auto mapper = [&, this](auto& result, const auto& f) { this->MapFieldOntoOutput(result, f); };
auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f); };
this->MapFieldsOntoOutput(input, output, mapper);
// compact the unused points in the output dataset
@ -173,27 +195,6 @@ VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(const vtkm::cont::DataS
}
}
//-----------------------------------------------------------------------------
VTKM_CONT bool ThresholdPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field)
{
// point data is copied as is because it was not collapsed
if (field.IsFieldPoint())
{
result.AddField(field);
return true;
}
else if (field.IsFieldGlobal())
{
result.AddField(field);
return true;
}
else
{
// cell data does not apply
return false;
}
}
} // namespace entity_extraction
} // namespace filter
} // namespace vtkm

@ -41,18 +41,16 @@ public:
void SetUpperThreshold(vtkm::Float64 value) { this->UpperValue = value; }
VTKM_CONT
void SetThresholdBelow(const vtkm::Float64 value);
void SetThresholdBelow(vtkm::Float64 value);
VTKM_CONT
void SetThresholdAbove(const vtkm::Float64 value);
void SetThresholdAbove(vtkm::Float64 value);
VTKM_CONT
void SetThresholdBetween(const vtkm::Float64 value1, const vtkm::Float64 value2);
void SetThresholdBetween(vtkm::Float64 value1, vtkm::Float64 value2);
private:
VTKM_CONT
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, const vtkm::cont::Field& field);
constexpr static int THRESHOLD_BELOW = 0;
constexpr static int THRESHOLD_ABOVE = 1;
constexpr static int THRESHOLD_BETWEEN = 2;

@ -10,8 +10,13 @@
set(unit_tests
UnitTestExternalFacesFilter.cxx
UnitTestExtractGeometryFilter.cxx
UnitTestExtractPointsFilter.cxx
UnitTestExtractStructuredFilter.cxx
UnitTestGhostCellRemove.cxx
UnitTestMaskFilter.cxx
UnitTestMaskPointsFilter.cxx
UnitTestThresholdFilter.cxx
UnitTestThresholdPointsFilter.cxx
)

@ -11,7 +11,7 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/ExtractGeometry.h>
#include <vtkm/filter/entity_extraction/ExtractGeometry.h>
using vtkm::cont::testing::MakeTestDataSet;
@ -32,7 +32,7 @@ public:
vtkm::Box box(minPoint, maxPoint);
// Setup and run filter to extract by volume of interest
vtkm::filter::ExtractGeometry extractGeometry;
vtkm::filter::entity_extraction::ExtractGeometry extractGeometry;
extractGeometry.SetImplicitFunction(box);
extractGeometry.SetExtractInside(true);
extractGeometry.SetExtractBoundaryCells(false);
@ -59,7 +59,7 @@ public:
vtkm::Box box(minPoint, maxPoint);
// Setup and run filter to extract by volume of interest
vtkm::filter::ExtractGeometry extractGeometry;
vtkm::filter::entity_extraction::ExtractGeometry extractGeometry;
extractGeometry.SetImplicitFunction(box);
extractGeometry.SetExtractInside(false);
extractGeometry.SetExtractBoundaryCells(false);
@ -86,7 +86,7 @@ public:
vtkm::Box box(minPoint, maxPoint);
// Setup and run filter to extract by volume of interest
vtkm::filter::ExtractGeometry extractGeometry;
vtkm::filter::entity_extraction::ExtractGeometry extractGeometry;
extractGeometry.SetImplicitFunction(box);
extractGeometry.SetExtractInside(true);
extractGeometry.SetExtractBoundaryCells(true);
@ -112,7 +112,7 @@ public:
vtkm::Box box(minPoint, maxPoint);
// Setup and run filter to extract by volume of interest
vtkm::filter::ExtractGeometry extractGeometry;
vtkm::filter::entity_extraction::ExtractGeometry extractGeometry;
extractGeometry.SetImplicitFunction(box);
extractGeometry.SetExtractInside(true);
extractGeometry.SetExtractBoundaryCells(true);

@ -11,7 +11,7 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/ExtractStructured.h>
#include <vtkm/filter/entity_extraction/ExtractStructured.h>
using vtkm::cont::testing::MakeTestDataSet;
@ -29,7 +29,7 @@ public:
vtkm::RangeId3 range(1, 4, 1, 4, 0, 1);
vtkm::Id3 sample(1, 1, 1);
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
extract.SetVOI(range);
extract.SetSampleRate(sample);
@ -63,7 +63,7 @@ public:
std::cout << "Testing extract structured uniform" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
// VOI within dataset
extract.SetVOI(1, 4, 1, 4, 1, 4);
@ -99,7 +99,7 @@ public:
std::cout << "Testing extract structured uniform" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
// VOI surrounds dataset
vtkm::Id3 minPoint(-1, -1, -1);
@ -136,7 +136,7 @@ public:
{
std::cout << "Testing extract structured uniform" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
// VOI surrounds dataset
vtkm::RangeId3 range(-1, 3, -1, 3, -1, 3);
@ -173,7 +173,7 @@ public:
{
std::cout << "Testing extract structured uniform" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
// RangeId3 intersects dataset on far boundary
vtkm::RangeId3 range(1, 8, 1, 8, 1, 8);
@ -211,7 +211,7 @@ public:
std::cout << "Testing extract structured uniform" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
// RangeId3 intersects dataset without corner
vtkm::RangeId3 range(2, 8, 1, 4, 1, 4);
@ -249,7 +249,7 @@ public:
std::cout << "Testing extract structured uniform" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
// RangeId3 intersects dataset with plane
vtkm::RangeId3 range(2, 8, 1, 2, 1, 4);
@ -287,7 +287,7 @@ public:
std::cout << "Testing extract structured uniform" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
// RangeId3 within data set with sampling
vtkm::RangeId3 range(0, 5, 0, 5, 1, 4);
@ -325,7 +325,7 @@ public:
std::cout << "Testing extract structured uniform" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
// RangeId3 within data set with sampling
vtkm::RangeId3 range(0, 5, 0, 5, 1, 4);
@ -361,7 +361,7 @@ public:
{
std::cout << "Testing extract structured uniform" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
// RangeId3 within data set with sampling
vtkm::RangeId3 range(0, 5, 0, 5, 1, 4);
@ -401,7 +401,7 @@ public:
std::cout << "Testing extract structured rectilinear" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DRectilinearDataSet0();
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
// RangeId3
vtkm::RangeId3 range(0, 2, 0, 2, 0, 1);
@ -438,7 +438,7 @@ public:
std::cout << "Testing extract structured rectilinear" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DRectilinearDataSet0();
vtkm::filter::ExtractStructured extract;
vtkm::filter::entity_extraction::ExtractStructured extract;
// RangeId3 and subsample
vtkm::RangeId3 range(0, 2, 0, 2, 0, 2);

@ -14,16 +14,16 @@
#include <vtkm/cont/DataSetBuilderUniform.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/GhostCellRemove.h>
#include <vtkm/filter/entity_extraction/GhostCellRemove.h>
namespace
{
static vtkm::cont::ArrayHandle<vtkm::UInt8> StructuredGhostCellArray(vtkm::Id nx,
vtkm::Id ny,
vtkm::Id nz,
int numLayers,
bool addMidGhost = false)
vtkm::cont::ArrayHandle<vtkm::UInt8> StructuredGhostCellArray(vtkm::Id nx,
vtkm::Id ny,
vtkm::Id nz,
int numLayers,
bool addMidGhost = false)
{
vtkm::Id numCells = nx * ny;
if (nz > 0)
@ -80,19 +80,18 @@ static vtkm::cont::ArrayHandle<vtkm::UInt8> StructuredGhostCellArray(vtkm::Id nx
return ghosts;
}
static vtkm::cont::DataSet MakeUniform(vtkm::Id numI,
vtkm::Id numJ,
vtkm::Id numK,
int numLayers,
bool addMidGhost = false)
vtkm::cont::DataSet MakeUniform(vtkm::Id numI,
vtkm::Id numJ,
vtkm::Id numK,
int numLayers,
bool addMidGhost = false)
{
vtkm::cont::DataSetBuilderUniform dsb;
vtkm::cont::DataSet ds;
if (numK == 0)
ds = dsb.Create(vtkm::Id2(numI + 1, numJ + 1));
ds = vtkm::cont::DataSetBuilderUniform::Create(vtkm::Id2(numI + 1, numJ + 1));
else
ds = dsb.Create(vtkm::Id3(numI + 1, numJ + 1, numK + 1));
ds = vtkm::cont::DataSetBuilderUniform::Create(vtkm::Id3(numI + 1, numJ + 1, numK + 1));
auto ghosts = StructuredGhostCellArray(numI, numJ, numK, numLayers, addMidGhost);
ds.AddCellField("vtkmGhostCells", ghosts);
@ -100,13 +99,12 @@ static vtkm::cont::DataSet MakeUniform(vtkm::Id numI,
return ds;
}
static vtkm::cont::DataSet MakeRectilinear(vtkm::Id numI,
vtkm::Id numJ,
vtkm::Id numK,
int numLayers,
bool addMidGhost = false)
vtkm::cont::DataSet MakeRectilinear(vtkm::Id numI,
vtkm::Id numJ,
vtkm::Id numK,
int numLayers,
bool addMidGhost = false)
{
vtkm::cont::DataSetBuilderRectilinear dsb;
vtkm::cont::DataSet ds;
std::size_t nx(static_cast<std::size_t>(numI + 1));
std::size_t ny(static_cast<std::size_t>(numJ + 1));
@ -118,14 +116,14 @@ static vtkm::cont::DataSet MakeRectilinear(vtkm::Id numI,
y[i] = static_cast<float>(i);
if (numK == 0)
ds = dsb.Create(x, y);
ds = vtkm::cont::DataSetBuilderRectilinear::Create(x, y);
else
{
std::size_t nz(static_cast<std::size_t>(numK + 1));
std::vector<float> z(nz);
for (std::size_t i = 0; i < nz; i++)
z[i] = static_cast<float>(i);
ds = dsb.Create(x, y, z);
ds = vtkm::cont::DataSetBuilderRectilinear::Create(x, y, z);
}
auto ghosts = StructuredGhostCellArray(numI, numJ, numK, numLayers, addMidGhost);
@ -166,7 +164,7 @@ static void MakeExplicitCells(const CellSetType& cellSet,
}
}
static vtkm::cont::DataSet MakeExplicit(vtkm::Id numI, vtkm::Id numJ, vtkm::Id numK, int numLayers)
vtkm::cont::DataSet MakeExplicit(vtkm::Id numI, vtkm::Id numJ, vtkm::Id numK, int numLayers)
{
using CoordType = vtkm::Vec3f_32;
@ -187,21 +185,22 @@ static vtkm::cont::DataSet MakeExplicit(vtkm::Id numI, vtkm::Id numJ, vtkm::Id n
vtkm::cont::ArrayHandle<vtkm::IdComponent> numIndices;
vtkm::cont::ArrayHandle<vtkm::UInt8> shapes;
vtkm::cont::DataSet ds;
vtkm::cont::DataSetBuilderExplicit dsb;
if (cellSet.IsType<vtkm::cont::CellSetStructured<2>>())
{
vtkm::Id2 dims(numI, numJ);
MakeExplicitCells(
cellSet.AsCellSet<vtkm::cont::CellSetStructured<2>>(), dims, numIndices, shapes, conn);
ds = dsb.Create(explCoords, vtkm::CellShapeTagQuad(), 4, conn, "coordinates");
ds = vtkm::cont::DataSetBuilderExplicit::Create(
explCoords, vtkm::CellShapeTagQuad(), 4, conn, "coordinates");
}
else if (cellSet.IsType<vtkm::cont::CellSetStructured<3>>())
{
vtkm::Id3 dims(numI, numJ, numK);
MakeExplicitCells(
cellSet.AsCellSet<vtkm::cont::CellSetStructured<3>>(), dims, numIndices, shapes, conn);
ds = dsb.Create(explCoords, vtkm::CellShapeTagHexahedron(), 8, conn, "coordinates");
ds = vtkm::cont::DataSetBuilderExplicit::Create(
explCoords, vtkm::CellShapeTagHexahedron(), 8, conn, "coordinates");
}
auto ghosts = StructuredGhostCellArray(numI, numJ, numK, numLayers);
@ -247,7 +246,7 @@ void TestGhostCellRemove()
std::vector<std::string> removeType = { "all", "byType" };
for (auto& rt : removeType)
{
vtkm::filter::GhostCellRemove ghostCellRemoval;
vtkm::filter::entity_extraction::GhostCellRemove ghostCellRemoval;
ghostCellRemoval.RemoveGhostField();
if (rt == "all")
@ -294,7 +293,7 @@ void TestGhostCellRemove()
else if (dsType == "rectilinear")
ds = MakeRectilinear(nx, ny, nz, layer, true);
vtkm::filter::GhostCellRemove ghostCellRemoval;
vtkm::filter::entity_extraction::GhostCellRemove ghostCellRemoval;
ghostCellRemoval.RemoveGhostField();
auto output = ghostCellRemoval.Execute(ds);
VTKM_TEST_ASSERT(output.GetCellSet().IsType<vtkm::cont::CellSetExplicit<>>(),

@ -11,7 +11,7 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/Mask.h>
#include <vtkm/filter/entity_extraction/Mask.h>
using vtkm::cont::testing::MakeTestDataSet;
@ -27,7 +27,7 @@ public:
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1();
// Setup and run filter to extract by stride
vtkm::filter::Mask mask;
vtkm::filter::entity_extraction::Mask mask;
vtkm::Id stride = 2;
mask.SetStride(stride);
@ -50,7 +50,7 @@ public:
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
// Setup and run filter to extract by stride
vtkm::filter::Mask mask;
vtkm::filter::entity_extraction::Mask mask;
vtkm::Id stride = 9;
mask.SetStride(stride);
@ -71,7 +71,7 @@ public:
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
// Setup and run filter to extract by stride
vtkm::filter::Mask mask;
vtkm::filter::entity_extraction::Mask mask;
vtkm::Id stride = 2;
mask.SetStride(stride);

@ -10,8 +10,8 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/Threshold.h>
#include <vtkm/filter/clean_grid/CleanGrid.h>
#include <vtkm/filter/entity_extraction/Threshold.h>
using vtkm::cont::testing::MakeTestDataSet;
@ -24,7 +24,7 @@ public:
void TestRegular2D(bool returnAllInRange) const
{
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet0();
vtkm::filter::Threshold threshold;
vtkm::filter::entity_extraction::Threshold threshold;
if (returnAllInRange)
{
@ -80,7 +80,7 @@ public:
void TestRegular3D(bool returnAllInRange) const
{
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet0();
vtkm::filter::Threshold threshold;
vtkm::filter::entity_extraction::Threshold threshold;
if (returnAllInRange)
{
@ -141,7 +141,7 @@ public:
std::cout << "Testing threshold on 3D explicit dataset" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet1();
vtkm::filter::Threshold threshold;
vtkm::filter::entity_extraction::Threshold threshold;
threshold.SetLowerThreshold(20);
threshold.SetUpperThreshold(21);
@ -171,7 +171,7 @@ public:
std::cout << "Testing threshold on 3D explicit dataset with empty results" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet1();
vtkm::filter::Threshold threshold;
vtkm::filter::entity_extraction::Threshold threshold;
threshold.SetLowerThreshold(500);
threshold.SetUpperThreshold(500.1);

@ -10,8 +10,12 @@
set(headers
ExternalFaces.h
ExtractGeometry.h
ExtractStructured.h
ExtractPoints.h
Mask.h
MaskPoints.h
Threshold.h
ThresholdPoints.h
)

@ -10,7 +10,6 @@
#ifndef vtkm_m_worklet_ExtractGeometry_h
#define vtkm_m_worklet_ExtractGeometry_h
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/cont/Algorithm.h>
@ -18,7 +17,7 @@
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/cont/UnknownCellSet.h>
#include <vtkm/ImplicitFunction.h>
@ -144,8 +143,8 @@ public:
vtkm::cont::ArrayHandle<bool> passFlags;
ExtractCellsByVOI worklet(extractInside, extractBoundaryCells, extractOnlyBoundaryCells);
DispatcherMapTopology<ExtractCellsByVOI> dispatcher(worklet);
dispatcher.Invoke(cellSet, coordinates, implicitFunction, passFlags);
vtkm::cont::Invoker invoke;
invoke(worklet, cellSet, coordinates, implicitFunction, passFlags);
vtkm::cont::ArrayHandleCounting<vtkm::Id> indices =
vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues());

@ -10,17 +10,16 @@
#ifndef vtkm_m_worklet_ExtractPoints_h
#define vtkm_m_worklet_ExtractPoints_h
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/ImplicitFunction.h>
#include <vtkm/worklet/WorkletMapTopology.h>
namespace vtkm
{
namespace worklet
@ -41,7 +40,7 @@ public:
using ExecutionSignature = _4(_2, _3);
VTKM_CONT
ExtractPointsByVOI(bool extractInside)
explicit ExtractPointsByVOI(bool extractInside)
: passValue(extractInside)
, failValue(!extractInside)
{
@ -93,8 +92,8 @@ public:
vtkm::cont::ArrayHandle<bool> passFlags;
ExtractPointsByVOI worklet(extractInside);
DispatcherMapTopology<ExtractPointsByVOI> dispatcher(worklet);
dispatcher.Invoke(cellSet, coordinates, implicitFunction, passFlags);
vtkm::cont::Invoker invoke;
invoke(worklet, cellSet, coordinates, implicitFunction, passFlags);
vtkm::cont::ArrayHandleCounting<vtkm::Id> indices =
vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), passFlags.GetNumberOfValues());

@ -23,6 +23,7 @@
#include <vtkm/cont/CellSetList.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/cont/UncertainCellSet.h>
#include <vtkm/cont/UnknownArrayHandle.h>
#include <vtkm/worklet/WorkletMapField.h>
@ -73,7 +74,7 @@ struct ExtractCopy : public vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn, FieldOut, WholeArrayIn);
ExtractCopy(const vtkm::Id3& dim)
explicit ExtractCopy(const vtkm::Id3& dim)
: XDim(dim[0])
, XYDim(dim[0] * dim[1])
{
@ -178,7 +179,7 @@ private:
return outCs;
}
default:
return UncertainCellSetStructured();
return {};
}
}
@ -438,7 +439,7 @@ private:
inOrigin[2] + static_cast<ValueType>(this->VOI.Z.Min) * inSpacing[2]);
CoordType outSpacing = inSpacing * static_cast<CoordType>(this->SampleRate);
return CoordsArray(this->OutputDimensions, outOrigin, outSpacing);
return { this->OutputDimensions, outOrigin, outSpacing };
}
RectilinearCoordinatesArrayHandle MapCoordinatesRectilinear(
@ -522,8 +523,8 @@ public:
result.Allocate(this->ValidPoints.GetNumberOfValues());
ExtractCopy worklet(this->InputDimensions);
DispatcherMapField<ExtractCopy> dispatcher(worklet);
dispatcher.Invoke(this->ValidPoints, result, field);
vtkm::cont::Invoker invoke;
invoke(worklet, this->ValidPoints, result, field);
return result;
}
@ -538,8 +539,8 @@ public:
auto inputCellDimensions = this->InputDimensions - vtkm::Id3(1);
ExtractCopy worklet(inputCellDimensions);
DispatcherMapField<ExtractCopy> dispatcher(worklet);
dispatcher.Invoke(this->ValidCells, result, field);
vtkm::cont::Invoker invoke;
invoke(worklet, this->ValidCells, result, field);
return result;
}

@ -10,7 +10,6 @@
#ifndef vtkm_m_worklet_Mask_h
#define vtkm_m_worklet_Mask_h
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/cont/ArrayCopy.h>
@ -18,7 +17,6 @@
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/DataSet.h>
namespace vtkm
{

@ -13,7 +13,6 @@
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/DataSet.h>
namespace vtkm
{

@ -15,10 +15,8 @@
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/Field.h>
#include <vtkm/cont/UncertainCellSet.h>

@ -10,12 +10,11 @@
#ifndef vtkm_m_worklet_ThresholdPoints_h
#define vtkm_m_worklet_ThresholdPoints_h
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/worklet/WorkletMapTopology.h>
namespace vtkm
{
@ -64,8 +63,8 @@ public:
using ThresholdWorklet = ThresholdPointField<UnaryPredicate>;
ThresholdWorklet worklet(predicate);
DispatcherMapTopology<ThresholdWorklet> dispatcher(worklet);
dispatcher.Invoke(cellSet, scalars, passFlags);
vtkm::cont::Invoker invoker;
invoker(worklet, cellSet, scalars, passFlags);
vtkm::cont::ArrayHandle<vtkm::Id> pointIds;
vtkm::cont::ArrayHandleCounting<vtkm::Id> indices =

@ -25,15 +25,12 @@ set(unit_tests
UnitTestContourTreeUniformDistributedFilter.cxx
UnitTestCoordinateSystemTransform.cxx
UnitTestCrossProductFilter.cxx
UnitTestExtractGeometryFilter.cxx
UnitTestExtractStructuredFilter.cxx
UnitTestFieldMetadata.cxx
UnitTestFieldSelection.cxx
UnitTestFieldToColors.cxx
UnitTestGradientExplicit.cxx
UnitTestGradientUniform.cxx
UnitTestGhostCellClassify.cxx
UnitTestGhostCellRemove.cxx
UnitTestImageConnectivityFilter.cxx
UnitTestImageDifferenceFilter.cxx
UnitTestImageMedianFilter.cxx
@ -41,7 +38,6 @@ set(unit_tests
UnitTestLagrangianStructuresFilter.cxx
UnitTestMapFieldMergeAverage.cxx
UnitTestMapFieldPermutation.cxx
UnitTestMaskFilter.cxx
UnitTestMeshQualityFilter.cxx
UnitTestMIRFilter.cxx
UnitTestMultiBlockFilter.cxx
@ -56,7 +52,6 @@ set(unit_tests
UnitTestStreamSurfaceFilter.cxx
UnitTestSurfaceNormalsFilter.cxx
UnitTestTetrahedralizeFilter.cxx
UnitTestThresholdFilter.cxx
UnitTestTriangulateFilter.cxx
UnitTestTubeFilter.cxx
UnitTestVectorMagnitudeFilter.cxx

@ -9,8 +9,8 @@
//============================================================================
#include <vtkm/cont/MergePartitionedDataSet.h>
#include <vtkm/filter/Threshold.h>
#include <vtkm/filter/entity_extraction/ExternalFaces.h>
#include <vtkm/filter/entity_extraction/Threshold.h>
#include <vtkm/source/Amr.h>
#include <vtkm/rendering/testing/RenderTest.h>
@ -30,7 +30,7 @@ void TestAmrArraysExecute(int dim, int numberOfLevels, int cellsPerDimension)
// amrDataSet.PrintSummary(std::cout);
// Remove blanked cells
vtkm::filter::Threshold threshold;
vtkm::filter::entity_extraction::Threshold threshold;
threshold.SetLowerThreshold(0);
threshold.SetUpperThreshold(1);
threshold.SetActiveField("vtkGhostType");

@ -49,6 +49,11 @@
//compliance
#define VTKM_CLANG
#elif defined(__MINGW32__)
//Check for MinGW before GCC, since MinGW will be otherwise categorized
//as VTKM_GCC
#define VTKM_MINGW
#elif defined(__GNUC__)
// Several compilers pretend to be GCC but have minor differences. Try to
// compensate for that, by checking for those compilers first

@ -17,7 +17,7 @@
#include <errno.h>
#include <sys/stat.h>
#ifdef _MSC_VER
#ifdef _WIN32
#include <direct.h>
#endif
@ -42,7 +42,7 @@ std::string Filename(const std::string& filePath)
// std::filesystem::path path(filePath);
// return path.filename();
#ifdef _MSC_VER
#ifdef _WIN32
auto lastSlashPos = filePath.rfind(GetWindowsPathSeperator(filePath));
#else
auto lastSlashPos = filePath.rfind('/');
@ -60,7 +60,7 @@ std::string ParentPath(const std::string& filePath)
// std::filesystem::path path(filePath);
// return path.parent_path();
#ifdef _MSC_VER
#ifdef _WIN32
auto lastSlashPos = filePath.rfind(GetWindowsPathSeperator(filePath));
#else
auto lastSlashPos = filePath.rfind('/');
@ -88,7 +88,7 @@ bool CreateDirectoriesFromFilePath(const std::string& filePath)
return false;
}
#ifdef _MSC_VER
#ifdef _WIN32
auto ret = _mkdir(dir.c_str());
#else
mode_t mode = 0755;
@ -145,7 +145,7 @@ std::string MergePaths(const std::string& filePathPrefix, const std::string& fil
return prefix;
}
#ifdef _MSC_VER
#ifdef _WIN32
prefixPathSeperator = GetWindowsPathSeperator(prefix);
suffixPathSeperator = suffix[0] == '/' || suffix[0] == '\\' ? suffix[0] : prefixPathSeperator;
#endif

@ -27,8 +27,6 @@ set(headers
DispatcherPointNeighborhood.h
DispatcherReduceByKey.h
DotProduct.h
ExtractGeometry.h
ExtractStructured.h
FieldStatistics.h
Gradient.h
ImageDifference.h
@ -38,7 +36,6 @@ set(headers
LagrangianStructures.h
Magnitude.h
Contour.h
Mask.h
MaskIndices.h
MaskNone.h
MaskSelect.h
@ -67,7 +64,6 @@ set(headers
StreamSurface.h
SurfaceNormals.h
Tetrahedralize.h
Threshold.h
TriangleWinding.h
Triangulate.h
Tube.h

@ -32,15 +32,12 @@ set(unit_tests
UnitTestCrossProduct.cxx
UnitTestDescriptiveStatistics.cxx
UnitTestDotProduct.cxx
UnitTestExtractGeometry.cxx
UnitTestExtractStructured.cxx
UnitTestFieldStatistics.cxx
UnitTestGraphConnectivity.cxx
UnitTestInnerJoin.cxx
UnitTestImageConnectivity.cxx
UnitTestKeys.cxx
UnitTestMagnitude.cxx
UnitTestMask.cxx
UnitTestMaskIndices.cxx
UnitTestMaskSelect.cxx
UnitTestNormalize.cxx
@ -64,7 +61,6 @@ set(unit_tests
UnitTestSurfaceNormals.cxx
UnitTestTemporalAdvection.cxx
UnitTestTetrahedralize.cxx
UnitTestThreshold.cxx
UnitTestTriangleWinding.cxx
UnitTestTriangulate.cxx
UnitTestTube.cxx

@ -1,255 +0,0 @@
//============================================================================
// 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.
//============================================================================
#include <vtkm/worklet/ExtractGeometry.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
using vtkm::cont::testing::MakeTestDataSet;
class TestingExtractGeometry
{
public:
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestExplicitById() const
{
std::cout << "Testing extract cell explicit by id:" << std::endl;
using CellSetType = vtkm::cont::CellSetExplicit<>;
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Cells to extract
vtkm::cont::ArrayHandle<vtkm::Id> cellIds = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 2 });
const vtkm::Id nCells = cellIds.GetNumberOfValues();
// Output data set with cell set containing extracted cells and all points
vtkm::worklet::ExtractGeometry extractGeometry;
OutCellSetType outCellSet = extractGeometry.Run(cellSet, cellIds);
auto cellvar =
dataset.GetField("cellvar").GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Float32>>();
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells),
"Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == nCells &&
cellFieldArray.ReadPortal().Get(0) == 110.f,
"Wrong cell field data");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestExplicitByBox() const
{
std::cout << "Testing extract cells with implicit function (box) on explicit:" << std::endl;
using CellSetType = vtkm::cont::CellSetExplicit<>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Implicit function
vtkm::Vec3f minPoint(0.5f, 0.0f, 0.0f);
vtkm::Vec3f maxPoint(2.0f, 2.0f, 2.0f);
bool extractInside = true;
bool extractBoundaryCells = false;
bool extractOnlyBoundaryCells = false;
// Output data set with cell set containing extracted cells and all points
vtkm::worklet::ExtractGeometry extractGeometry;
vtkm::cont::UnknownCellSet outCellSet =
extractGeometry.Run(cellSet,
dataset.GetCoordinateSystem("coordinates"),
vtkm::Box(minPoint, maxPoint),
extractInside,
extractBoundaryCells,
extractOnlyBoundaryCells);
auto cellvar =
dataset.GetField("cellvar").GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Float32>>();
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 2), "Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 2 &&
cellFieldArray.ReadPortal().Get(1) == 120.2f,
"Wrong cell field data");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestUniformById2D() const
{
std::cout << "Testing extract cells structured by id:" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<2>;
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Cells to extract
vtkm::cont::ArrayHandle<vtkm::Id> cellIds =
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 4, 5, 10, 15 });
const vtkm::Id nCells = cellIds.GetNumberOfValues();
// Output data set permutation of with only extracted cells
vtkm::worklet::ExtractGeometry extractGeometry;
OutCellSetType outCellSet = extractGeometry.Run(cellSet, cellIds);
auto cellvar =
dataset.GetField("cellvar").GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Float32>>();
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells),
"Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == nCells &&
cellFieldArray.ReadPortal().Get(1) == 4.f,
"Wrong cell field data");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestUniformById3D() const
{
std::cout << "Testing extract cells structured by id:" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Cells to extract
vtkm::cont::ArrayHandle<vtkm::Id> cellIds =
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 4, 5, 10, 15 });
const vtkm::Id nCells = cellIds.GetNumberOfValues();
// Output data set with cell set containing extracted cells and all points
vtkm::worklet::ExtractGeometry extractGeometry;
OutCellSetType outCellSet = extractGeometry.Run(cellSet, cellIds);
auto cellvar =
dataset.GetField("cellvar").GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Float32>>();
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells),
"Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == nCells &&
cellFieldArray.ReadPortal().Get(2) == 5.f,
"Wrong cell field data");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestUniformByBox() const
{
std::cout << "Testing extract cells with implicit function (box):" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Implicit function
vtkm::Vec3f minPoint(1.0f, 1.0f, 1.0f);
vtkm::Vec3f maxPoint(3.0f, 3.0f, 3.0f);
bool extractInside = true;
bool extractBoundaryCells = false;
bool extractOnlyBoundaryCells = false;
// Output data set with cell set containing extracted points
vtkm::worklet::ExtractGeometry extractGeometry;
vtkm::cont::UnknownCellSet outCellSet =
extractGeometry.Run(cellSet,
dataset.GetCoordinateSystem("coords"),
vtkm::Box(minPoint, maxPoint),
extractInside,
extractBoundaryCells,
extractOnlyBoundaryCells);
auto cellvar =
dataset.GetField("cellvar").GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Float32>>();
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 8 &&
cellFieldArray.ReadPortal().Get(0) == 21.f,
"Wrong cell field data");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestUniformBySphere() const
{
std::cout << "Testing extract cells with implicit function (sphere):" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Implicit function
vtkm::Vec3f center(2.f, 2.f, 2.f);
vtkm::FloatDefault radius(1.8f);
bool extractInside = true;
bool extractBoundaryCells = false;
bool extractOnlyBoundaryCells = false;
// Output data set with cell set containing extracted cells
vtkm::worklet::ExtractGeometry extractGeometry;
vtkm::cont::UnknownCellSet outCellSet =
extractGeometry.Run(cellSet,
dataset.GetCoordinateSystem("coords"),
vtkm::Sphere(center, radius),
extractInside,
extractBoundaryCells,
extractOnlyBoundaryCells);
auto cellvar =
dataset.GetField("cellvar").GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::Float32>>();
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 8 &&
cellFieldArray.ReadPortal().Get(1) == 22.f,
"Wrong cell field data");
}
void operator()() const
{
this->TestUniformById2D();
this->TestUniformById3D();
this->TestUniformBySphere();
this->TestUniformByBox();
this->TestExplicitById();
this->TestExplicitByBox();
}
};
int UnitTestExtractGeometry(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestingExtractGeometry(), argc, argv);
}

@ -1,339 +0,0 @@
//============================================================================
// 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.
//============================================================================
#include <vtkm/worklet/ExtractStructured.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
using vtkm::cont::testing::MakeTestDataSet;
class TestingExtractStructured
{
public:
void TestUniform2D() const
{
std::cout << "Testing extract structured uniform 2D" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<2>;
// Create the input uniform cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make2DUniformDataSet1();
CellSetType cellSet;
dataSet.GetCellSet().AsCellSet(cellSet);
// RangeId3 and subsample
vtkm::RangeId3 range(1, 4, 1, 4, 0, 1);
vtkm::Id3 sample(1, 1, 1);
bool includeBoundary = false;
bool includeOffset = false;
vtkm::worklet::ExtractStructured worklet;
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 9),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 4),
"Wrong result for ExtractStructured worklet");
}
void TestUniform3D() const
{
std::cout << "Testing extract structured uniform 3D" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
// Create the input uniform cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellSet;
dataSet.GetCellSet().AsCellSet(cellSet);
vtkm::worklet::ExtractStructured worklet;
vtkm::worklet::ExtractStructured::UncertainCellSetStructured outCellSet;
// RangeId3 within dataset
vtkm::RangeId3 range0(1, 4, 1, 4, 1, 4);
vtkm::Id3 sample(1, 1, 1);
bool includeBoundary = false;
bool includeOffset = false;
outCellSet = worklet.Run(cellSet, range0, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8),
"Wrong result for ExtractStructured worklet");
// RangeId3 surrounds dataset
vtkm::RangeId3 range1(-1, 8, -1, 8, -1, 8);
outCellSet = worklet.Run(cellSet, range1, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 125),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 64),
"Wrong result for ExtractStructured worklet");
// RangeId3 intersects dataset on near boundary
vtkm::RangeId3 range2(-1, 3, -1, 3, -1, 3);
outCellSet = worklet.Run(cellSet, range2, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8),
"Wrong result for ExtractStructured worklet");
// RangeId3 intersects dataset on far boundary
vtkm::RangeId3 range3(1, 8, 1, 8, 1, 8);
outCellSet = worklet.Run(cellSet, range3, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 64),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 27),
"Wrong result for ExtractStructured worklet");
// RangeId3 intersects dataset without corner
vtkm::RangeId3 range4(2, 8, 1, 4, 1, 4);
outCellSet = worklet.Run(cellSet, range4, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8),
"Wrong result for ExtractStructured worklet");
// RangeId3 intersects dataset with plane
vtkm::RangeId3 range5(2, 8, 1, 2, 1, 4);
outCellSet = worklet.Run(cellSet, range5, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 9),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 4),
"Wrong result for ExtractStructured worklet");
}
void TestUniform3D1() const
{
std::cout << "Testing extract structured uniform with sampling" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
// Create the input uniform cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellSet;
dataSet.GetCellSet().AsCellSet(cellSet);
vtkm::worklet::ExtractStructured worklet;
vtkm::worklet::ExtractStructured::UncertainCellSetStructured outCellSet;
// RangeId3 within data set with sampling
vtkm::RangeId3 range0(0, 5, 0, 5, 1, 4);
vtkm::Id3 sample0(2, 2, 1);
bool includeBoundary0 = false;
bool includeOffset = false;
outCellSet = worklet.Run(cellSet, range0, sample0, includeBoundary0, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 27),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8),
"Wrong result for ExtractStructured worklet");
// RangeId3 and subsample
vtkm::RangeId3 range1(0, 5, 0, 5, 1, 4);
vtkm::Id3 sample1(3, 3, 2);
bool includeBoundary1 = false;
outCellSet = worklet.Run(cellSet, range1, sample1, includeBoundary1, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 8),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 1),
"Wrong result for ExtractStructured worklet");
// RangeId3 and subsample
vtkm::RangeId3 range2(0, 5, 0, 5, 1, 4);
vtkm::Id3 sample2(3, 3, 2);
bool includeBoundary2 = true;
outCellSet = worklet.Run(cellSet, range2, sample2, includeBoundary2, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 18),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 4),
"Wrong result for ExtractStructured worklet");
}
void TestRectilinear2D() const
{
std::cout << "Testing extract structured rectilinear" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<2>;
// Create the input uniform cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make2DRectilinearDataSet0();
CellSetType cellSet;
dataSet.GetCellSet().AsCellSet(cellSet);
// RangeId3 and subsample
vtkm::RangeId3 range(0, 2, 0, 2, 0, 1);
vtkm::Id3 sample(1, 1, 1);
bool includeBoundary = false;
bool includeOffset = false;
// Extract subset
vtkm::worklet::ExtractStructured worklet;
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 4),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 1),
"Wrong result for ExtractStructured worklet");
}
void TestRectilinear3D() const
{
std::cout << "Testing extract structured rectilinear" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
// Create the input uniform cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DRectilinearDataSet0();
CellSetType cellSet;
dataSet.GetCellSet().AsCellSet(cellSet);
// RangeId3 and subsample
vtkm::RangeId3 range(0, 2, 0, 2, 0, 2);
vtkm::Id3 sample(1, 1, 1);
bool includeBoundary = false;
bool includeOffset = false;
// Extract subset
vtkm::worklet::ExtractStructured worklet;
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfPoints(), 8),
"Wrong result for ExtractStructured worklet");
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 1),
"Wrong result for ExtractStructured worklet");
}
void TestOffset3D1() const
{
std::cout << "Testing offset 3D-1" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
CellSetType cellSet;
// RangeID3 and subsample
vtkm::RangeId3 range(5, 15, 0, 10, 0, 10);
vtkm::Id3 sample(1, 1, 1);
vtkm::Id3 test_offset(10, 0, 0);
vtkm::Id3 no_offset(0, 0, 0);
vtkm::Id3 new_dims(5, 10, 10);
bool includeBoundary = false;
bool includeOffset = false;
cellSet.SetPointDimensions(vtkm::make_Vec(10, 10, 10));
vtkm::worklet::ExtractStructured worklet;
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), no_offset));
vtkm::Id3 cellDims =
outCellSet.AsCellSet<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
includeOffset = true;
cellSet.SetGlobalPointIndexStart(test_offset);
outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
cellDims =
outCellSet.AsCellSet<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
CellSetType cs = outCellSet.AsCellSet<CellSetType>();
cellDims = cs.GetPointDimensions();
VTKM_TEST_ASSERT(test_equal(cellDims, new_dims));
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), test_offset));
}
void TestOffset3D2() const
{
std::cout << "Testing Offset 3D-2" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
CellSetType cellSet;
vtkm::RangeId3 range(15, 20, 0, 10, 0, 10);
vtkm::Id3 sample(1, 1, 1);
vtkm::Id3 test_dims(5, 10, 10);
vtkm::Id3 gpis(10, 0, 0);
vtkm::Id3 test_offset(15, 0, 0);
bool includeBoundary = false;
bool includeOffset = true;
cellSet.SetPointDimensions(vtkm::make_Vec(10, 10, 10));
cellSet.SetGlobalPointIndexStart(gpis);
vtkm::worklet::ExtractStructured worklet;
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
CellSetType cs = outCellSet.AsCellSet<CellSetType>();
vtkm::Id3 cellDims = cs.GetPointDimensions();
VTKM_TEST_ASSERT(test_equal(cellDims, test_dims));
VTKM_TEST_ASSERT(test_equal(cs.GetGlobalPointIndexStart(), test_offset));
}
void TestOffset3D3() const
{
std::cout << "Testing Offset 3D-3" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
CellSetType cellSet;
vtkm::RangeId3 range(100, 110, 0, 10, 0, 10);
vtkm::Id3 sample(1, 1, 1);
vtkm::Id3 test_dims(0, 0, 0);
bool includeBoundary = false;
bool includeOffset = true;
cellSet.SetPointDimensions(vtkm::make_Vec(10, 10, 10));
vtkm::worklet::ExtractStructured worklet;
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
CellSetType cs = outCellSet.AsCellSet<CellSetType>();
VTKM_TEST_ASSERT(test_equal(cs.GetPointDimensions(), test_dims));
}
void TestOffset2D() const
{
std::cout << "Testing offset 2D" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<2>;
CellSetType cellSet;
// RangeID3 and subsample
vtkm::RangeId3 range(5, 15, 0, 10, 0, 1);
vtkm::Id3 sample(1, 1, 1);
vtkm::Id2 test_offset(10, 0);
vtkm::Id2 no_offset(0, 0);
vtkm::Id2 new_dims(5, 10);
bool includeBoundary = false;
bool includeOffset = false;
cellSet.SetPointDimensions(vtkm::make_Vec(10, 10));
vtkm::worklet::ExtractStructured worklet;
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), no_offset));
vtkm::Id2 cellDims =
outCellSet.AsCellSet<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
// Test with offset now
includeOffset = true;
cellSet.SetGlobalPointIndexStart(test_offset);
outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
cellDims =
outCellSet.AsCellSet<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
CellSetType cs = outCellSet.AsCellSet<CellSetType>();
cellDims = cs.GetPointDimensions();
VTKM_TEST_ASSERT(test_equal(cellDims, new_dims));
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), test_offset));
}
void operator()() const
{
TestUniform2D();
TestUniform3D();
TestUniform3D1();
TestRectilinear2D();
TestRectilinear3D();
TestOffset3D1();
TestOffset3D2();
TestOffset3D3();
TestOffset2D();
}
};
int UnitTestExtractStructured(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestingExtractStructured(), argc, argv);
}

@ -1,119 +0,0 @@
//============================================================================
// 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.
//============================================================================
#include <vtkm/worklet/Mask.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;
class TestingMask
{
public:
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestUniform2D() const
{
std::cout << "Testing mask cells structured:" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<2>;
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Output data set permutation
vtkm::worklet::Mask maskCells;
OutCellSetType outCellSet = maskCells.Run(cellSet, 2);
vtkm::cont::ArrayHandle<vtkm::Float32> cellvar;
dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar);
vtkm::cont::ArrayHandle<vtkm::Float32> cellFieldArray = maskCells.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for Mask");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 8 &&
cellFieldArray.ReadPortal().Get(7) == 14.f,
"Wrong cell field data");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestUniform3D() const
{
std::cout << "Testing mask cells structured:" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Output data set with cell set permuted
vtkm::worklet::Mask maskCells;
OutCellSetType outCellSet = maskCells.Run(cellSet, 9);
vtkm::cont::ArrayHandle<vtkm::Float32> cellvar;
dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar);
vtkm::cont::ArrayHandle<vtkm::Float32> cellFieldArray = maskCells.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 7), "Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 7 &&
cellFieldArray.ReadPortal().Get(2) == 18.f,
"Wrong cell field data");
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void TestExplicit() const
{
std::cout << "Testing mask cells explicit:" << std::endl;
using CellSetType = vtkm::cont::CellSetExplicit<>;
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
// Input data set created
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
CellSetType cellSet;
dataset.GetCellSet().AsCellSet(cellSet);
// Output data set with cell set permuted
vtkm::worklet::Mask maskCells;
OutCellSetType outCellSet = maskCells.Run(cellSet, 2);
vtkm::cont::ArrayHandle<vtkm::Float32> cellvar;
dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar);
vtkm::cont::ArrayHandle<vtkm::Float32> cellFieldArray = maskCells.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 2), "Wrong result for ExtractCells");
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 2 &&
cellFieldArray.ReadPortal().Get(1) == 120.2f,
"Wrong cell field data");
}
void operator()() const
{
this->TestUniform2D();
this->TestUniform3D();
this->TestExplicit();
}
};
int UnitTestMask(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestingMask(), argc, argv);
}

@ -1,252 +0,0 @@
//============================================================================
// 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.
//============================================================================
#include <vtkm/worklet/Threshold.h>
#include <vtkm/cont/ArrayPortalToIterators.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <vtkm/cont/ArrayPortalToIterators.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
namespace
{
class HasValue
{
public:
VTKM_CONT
HasValue(vtkm::Float32 value)
: Value(value)
{
}
template <typename ScalarType>
VTKM_EXEC bool operator()(ScalarType value) const
{
return static_cast<vtkm::Float32>(value) == this->Value;
}
private:
vtkm::Float32 Value;
};
class ThresholdRange
{
public:
VTKM_CONT
ThresholdRange() {}
ThresholdRange(const vtkm::Float64& lower, const vtkm::Float64& upper)
: Lower(lower)
, Upper(upper)
{
}
void SetLowerValue(const vtkm::Float64& lower) { Lower = lower; }
void SetUpperValue(const vtkm::Float64& upper) { Upper = upper; }
template <typename T>
VTKM_EXEC bool operator()(const T& value) const
{
return value >= static_cast<T>(this->Lower) && value <= static_cast<T>(this->Upper);
}
//Needed to work with ArrayHandleVirtual
template <typename PortalType>
VTKM_EXEC bool operator()(
const vtkm::internal::ArrayPortalValueReference<PortalType>& value) const
{
using T = typename PortalType::ValueType;
return value.Get() >= static_cast<T>(this->Lower) && value.Get() <= static_cast<T>(this->Upper);
}
private:
vtkm::Float64 Lower;
vtkm::Float64 Upper;
};
using vtkm::cont::testing::MakeTestDataSet;
class TestingThreshold
{
public:
void TestUniform2D(bool returnAllInRange) const
{
using CellSetType = vtkm::cont::CellSetStructured<2>;
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet0();
CellSetType cellset;
dataset.GetCellSet().AsCellSet(cellset);
vtkm::cont::ArrayHandle<vtkm::Float32> pointvar;
dataset.GetField("pointvar").GetData().AsArrayHandle(pointvar);
vtkm::worklet::Threshold threshold;
ThresholdRange predicate;
if (returnAllInRange)
{
std::cout << "Testing threshold on 2D uniform dataset returning values 'all in range'"
<< std::endl;
predicate.SetLowerValue(10);
predicate.SetUpperValue(60);
}
else
{
std::cout << "Testing threshold on 2D uniform dataset returning values 'part in range'"
<< std::endl;
predicate.SetLowerValue(60);
predicate.SetUpperValue(61);
}
OutCellSetType outCellSet = threshold.Run(
cellset, pointvar, vtkm::cont::Field::Association::POINTS, predicate, returnAllInRange);
if (returnAllInRange)
{
VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 1, "Wrong number of cells");
vtkm::cont::ArrayHandle<vtkm::Float32> cellvar;
dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar);
vtkm::cont::ArrayHandle<vtkm::Float32> cellFieldArray = threshold.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 1 &&
cellFieldArray.ReadPortal().Get(0) == 100.1f,
"Wrong cell field data");
}
else
{
VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 1, "Wrong number of cells");
vtkm::cont::ArrayHandle<vtkm::Float32> cellvar;
dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar);
vtkm::cont::ArrayHandle<vtkm::Float32> cellFieldArray = threshold.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 1 &&
cellFieldArray.ReadPortal().Get(0) == 200.1f,
"Wrong cell field data");
}
}
void TestUniform3D(bool returnAllInRange) const
{
using CellSetType = vtkm::cont::CellSetStructured<3>;
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet0();
CellSetType cellset;
dataset.GetCellSet().AsCellSet(cellset);
vtkm::cont::ArrayHandle<vtkm::Float32> pointvar;
dataset.GetField("pointvar").GetData().AsArrayHandle(pointvar);
vtkm::worklet::Threshold threshold;
ThresholdRange predicate;
if (returnAllInRange)
{
std::cout << "Testing threshold on 3D uniform dataset returning values 'all in range'"
<< std::endl;
predicate.SetLowerValue(10.1);
predicate.SetUpperValue(180);
}
else
{
std::cout << "Testing threshold on 3D uniform dataset returning values 'part in range'"
<< std::endl;
predicate.SetLowerValue(20);
predicate.SetUpperValue(21);
}
OutCellSetType outCellSet = threshold.Run(
cellset, pointvar, vtkm::cont::Field::Association::POINTS, predicate, returnAllInRange);
if (returnAllInRange)
{
VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 3, "Wrong number of cells");
vtkm::cont::ArrayHandle<vtkm::Float32> cellvar;
dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar);
vtkm::cont::ArrayHandle<vtkm::Float32> cellFieldArray = threshold.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 3 &&
cellFieldArray.ReadPortal().Get(0) == 100.1f &&
cellFieldArray.ReadPortal().Get(1) == 100.2f &&
cellFieldArray.ReadPortal().Get(2) == 100.3f,
"Wrong cell field data");
}
else
{
VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 2, "Wrong number of cells");
vtkm::cont::ArrayHandle<vtkm::Float32> cellvar;
dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar);
vtkm::cont::ArrayHandle<vtkm::Float32> cellFieldArray = threshold.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 2 &&
cellFieldArray.ReadPortal().Get(0) == 100.1f &&
cellFieldArray.ReadPortal().Get(1) == 100.2f,
"Wrong cell field data");
}
}
void TestExplicit3D() const
{
std::cout << "Testing threshold on 3D explicit dataset" << std::endl;
using CellSetType = vtkm::cont::CellSetExplicit<>;
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet0();
CellSetType cellset;
dataset.GetCellSet().AsCellSet(cellset);
vtkm::cont::ArrayHandle<vtkm::Float32> cellvar;
dataset.GetField("cellvar").GetData().AsArrayHandle(cellvar);
vtkm::worklet::Threshold threshold;
OutCellSetType outCellSet =
threshold.Run(cellset, cellvar, vtkm::cont::Field::Association::CELL_SET, HasValue(100.1f));
VTKM_TEST_ASSERT(outCellSet.GetNumberOfCells() == 1, "Wrong number of cells");
vtkm::cont::ArrayHandle<vtkm::Float32> cellFieldArray = threshold.ProcessCellField(cellvar);
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 1 &&
cellFieldArray.ReadPortal().Get(0) == 100.1f,
"Wrong cell field data");
}
void operator()() const
{
this->TestUniform2D(false);
this->TestUniform2D(true);
this->TestUniform3D(false);
this->TestUniform3D(true);
this->TestExplicit3D();
}
};
}
int UnitTestThreshold(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestingThreshold(), argc, argv);
}