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/PointAverage.h>
#include <vtkm/filter/PolicyBase.h> #include <vtkm/filter/PolicyBase.h>
#include <vtkm/filter/Tetrahedralize.h> #include <vtkm/filter/Tetrahedralize.h>
#include <vtkm/filter/Threshold.h>
#include <vtkm/filter/Triangulate.h> #include <vtkm/filter/Triangulate.h>
#include <vtkm/filter/VectorMagnitude.h> #include <vtkm/filter/VectorMagnitude.h>
#include <vtkm/filter/VertexClustering.h> #include <vtkm/filter/VertexClustering.h>
#include <vtkm/filter/WarpScalar.h> #include <vtkm/filter/WarpScalar.h>
#include <vtkm/filter/WarpVector.h> #include <vtkm/filter/WarpVector.h>
#include <vtkm/filter/entity_extraction/ExternalFaces.h> #include <vtkm/filter/entity_extraction/ExternalFaces.h>
#include <vtkm/filter/entity_extraction/Threshold.h>
#include <vtkm/filter/entity_extraction/ThresholdPoints.h> #include <vtkm/filter/entity_extraction/ThresholdPoints.h>
#include <vtkm/io/VTKDataSetReader.h> #include <vtkm/io/VTKDataSetReader.h>
@ -193,7 +193,7 @@ void BenchThreshold(::benchmark::State& state)
vtkm::Float64 quarter = range.Length() / 4.; vtkm::Float64 quarter = range.Length() / 4.;
vtkm::Float64 mid = range.Center(); vtkm::Float64 mid = range.Center();
vtkm::filter::Threshold filter; vtkm::filter::entity_extraction::Threshold filter;
filter.SetActiveField(PointScalarsName, vtkm::cont::Field::Association::POINTS); filter.SetActiveField(PointScalarsName, vtkm::cont::Field::Association::POINTS);
filter.SetLowerThreshold(mid - quarter); filter.SetLowerThreshold(mid - quarter);
filter.SetUpperThreshold(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) void Testing::SetEnv(const std::string& var, const std::string& value)
{ {
static std::vector<std::pair<std::string, std::string>> envVars{}; static std::vector<std::pair<std::string, std::string>> envVars{};
#ifdef _MSC_VER #ifdef _WIN32
auto iter = envVars.emplace(envVars.end(), var, value); auto iter = envVars.emplace(envVars.end(), var, value);
_putenv_s(iter->first.c_str(), iter->second.c_str()); _putenv_s(iter->first.c_str(), iter->second.c_str());
#else #else
@ -76,7 +76,7 @@ void Testing::SetEnv(const std::string& var, const std::string& value)
void Testing::UnsetEnv(const std::string& var) void Testing::UnsetEnv(const std::string& var)
{ {
#ifdef _MSC_VER #ifdef _WIN32
SetEnv(var, ""); SetEnv(var, "");
#else #else
unsetenv(var.c_str()); unsetenv(var.c_str());

@ -22,12 +22,24 @@ vtkm_add_instantiations(ClipWithImplicitFunctionInstantiations
) )
set(deprecated_headers set(deprecated_headers
CleanGrid.h
DotProduct.h
Entropy.h Entropy.h
ExternalFaces.h
ExtractGeometry.h
ExtractPoints.h
ExtractStructured.h
GenerateIds.h
GhostCellRemove.h
Histogram.h Histogram.h
Mask.h
MaskPoints.h
NDEntropy.h NDEntropy.h
NDHistogram.h NDHistogram.h
ParticleDensityCloudInCell.h ParticleDensityCloudInCell.h
ParticleDensityNearestGridPoint.h ParticleDensityNearestGridPoint.h
Threshold.h
ThresholdPoints.h
) )
vtkm_declare_headers(${deprecated_headers}) vtkm_declare_headers(${deprecated_headers})
@ -35,10 +47,6 @@ vtkm_declare_headers(${deprecated_headers})
set(common_headers set(common_headers
CellAverage.h CellAverage.h
CellMeasures.h CellMeasures.h
CleanGrid.h
ExtractGeometry.h
ExtractPoints.h
ExtractStructured.h
FieldMetadata.h FieldMetadata.h
FilterCell.h FilterCell.h
FilterDataSet.h FilterDataSet.h
@ -51,16 +59,12 @@ set(common_headers
PolicyBase.h PolicyBase.h
PolicyDefault.h PolicyDefault.h
TaskQueue.h TaskQueue.h
Threshold.h
ThresholdPoints.h
Instantiations.h Instantiations.h
) )
set(common_header_template_sources set(common_header_template_sources
CellAverage.hxx CellAverage.hxx
CellMeasures.hxx CellMeasures.hxx
ExtractGeometry.hxx
ExtractStructured.hxx
FilterDataSet.hxx FilterDataSet.hxx
FilterDataSetWithField.hxx FilterDataSetWithField.hxx
FilterField.hxx FilterField.hxx
@ -68,15 +72,11 @@ set(common_header_template_sources
FilterParticleAdvection.hxx FilterParticleAdvection.hxx
FilterTemporalParticleAdvection.hxx FilterTemporalParticleAdvection.hxx
PointAverage.hxx PointAverage.hxx
Threshold.hxx
) )
set(common_sources_device set(common_sources_device
CellAverage.cxx CellAverage.cxx
ExtractGeometry.cxx
ExtractStructured.cxx
PointAverage.cxx PointAverage.cxx
Threshold.cxx
) )
set(extra_headers set(extra_headers
@ -88,20 +88,14 @@ set(extra_headers
CoordinateSystemTransform.h CoordinateSystemTransform.h
CreateResult.h CreateResult.h
CrossProduct.h CrossProduct.h
DotProduct.h
ExternalFaces.h
FieldSelection.h FieldSelection.h
FieldToColors.h FieldToColors.h
GenerateIds.h
GhostCellClassify.h GhostCellClassify.h
GhostCellRemove.h
ImageConnectivity.h ImageConnectivity.h
ImageDifference.h ImageDifference.h
ImageMedian.h ImageMedian.h
Lagrangian.h Lagrangian.h
LagrangianStructures.h LagrangianStructures.h
Mask.h
MaskPoints.h
MeshQuality.h MeshQuality.h
MIRFilter.h MIRFilter.h
ParticleAdvection.h ParticleAdvection.h
@ -142,13 +136,11 @@ set(extra_header_template_sources
CrossProduct.hxx CrossProduct.hxx
FieldToColors.hxx FieldToColors.hxx
GhostCellClassify.hxx GhostCellClassify.hxx
GhostCellRemove.hxx
ImageConnectivity.hxx ImageConnectivity.hxx
ImageDifference.hxx ImageDifference.hxx
ImageMedian.hxx ImageMedian.hxx
Lagrangian.hxx Lagrangian.hxx
LagrangianStructures.hxx LagrangianStructures.hxx
Mask.hxx
MeshQuality.hxx MeshQuality.hxx
MIRFilter.hxx MIRFilter.hxx
ParticleAdvection.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 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information. // PURPOSE. See the above copyright notice for more information.
//============================================================================ //============================================================================
#ifndef vtk_m_filter_ExtractGeometry_h #ifndef vtk_m_filter_ExtractGeometry_h
#define vtk_m_filter_ExtractGeometry_h #define vtk_m_filter_ExtractGeometry_h
#include <vtkm/filter/vtkm_filter_common_export.h> #include <vtkm/Deprecated.h>
#include <vtkm/filter/entity_extraction/ExtractGeometry.h>
#include <vtkm/ImplicitFunction.h>
#include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/ExtractGeometry.h>
namespace vtkm namespace vtkm
{ {
namespace filter namespace filter
{ {
/// \brief Extract a subset of geometry based on an implicit function VTKM_DEPRECATED(
/// 1.8,
/// Extracts from its input geometry all cells that are either "Use vtkm/filter/entity_extraction/ExtractGeometry.h instead of vtkm/filter/ExtractGeometry.h.")
/// completely inside or outside of a specified implicit function. Any type of inline void ExtractGeometry_deprecated() {}
/// data can be input to this filter.
/// inline void ExtractGeometry_deprecated_warning()
/// 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>
{ {
public: ExtractGeometry_deprecated();
//currently the ExtractGeometry filter only works on scalar data. }
using SupportedTypes = TypeListScalarAll;
VTKM_CONT ExtractGeometry(); class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::ExtractGeometry.") ExtractGeometry
: public vtkm::filter::entity_extraction::ExtractGeometry
// Set the volume of interest to extract {
void SetImplicitFunction(const vtkm::ImplicitFunctionGeneral& func) { this->Function = func; } using entity_extraction::ExtractGeometry::ExtractGeometry;
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;
}; };
#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 } // 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 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information. // PURPOSE. See the above copyright notice for more information.
//============================================================================ //============================================================================
#ifndef vtk_m_filter_ExtractStructured_h #ifndef vtk_m_filter_ExtractStructured_h
#define vtk_m_filter_ExtractStructured_h #define vtk_m_filter_ExtractStructured_h
#include <vtkm/filter/vtkm_filter_common_export.h> #include <vtkm/Deprecated.h>
#include <vtkm/filter/entity_extraction/ExtractStructured.h>
#include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/ExtractStructured.h>
namespace vtkm namespace vtkm
{ {
namespace filter namespace filter
{ {
/// \brief Select piece (e.g., volume of interest) and/or subsample structured points dataset
/// VTKM_DEPRECATED(1.8,
/// Select or subsample a portion of an input structured dataset. The selected "Use vtkm/filter/entity_extraction/ExtractStructured.h instead of "
/// portion of interested is referred to as the Volume Of Interest, or VOI. "vtkm/filter/ExtractStructured.h.")
/// The output of this filter is a structured dataset. The filter treats input inline void ExtractStructured_deprecated() {}
/// data of any topological dimension (i.e., point, line, plane, or volume) and
/// can generate output data of any topological dimension. inline void ExtractStructured_deprecated_warning()
///
/// 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>
{ {
public: ExtractStructured_deprecated();
ExtractStructured(); }
// Set the bounding box for the volume of interest class VTKM_DEPRECATED(1.8,
VTKM_CONT "Use vtkm::filter::entity_extraction::ExtractStructured.") ExtractStructured
vtkm::RangeId3 GetVOI() const { return this->VOI; } : public vtkm::filter::entity_extraction::ExtractStructured
{
VTKM_CONT using entity_extraction::ExtractStructured::ExtractStructured;
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;
}; };
#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 } // 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 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information. // PURPOSE. See the above copyright notice for more information.
//============================================================================ //============================================================================
#ifndef vtk_m_filter_GhostCellRemove_h #ifndef vtk_m_filter_GhostCellRemove_h
#define vtk_m_filter_GhostCellRemove_h #define vtk_m_filter_GhostCellRemove_h
#include <vtkm/CellClassification.h> #include <vtkm/Deprecated.h>
#include <vtkm/filter/FilterDataSetWithField.h> #include <vtkm/filter/entity_extraction/GhostCellRemove.h>
#include <vtkm/filter/Threshold.h>
namespace vtkm namespace vtkm
{ {
namespace filter 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 } // namespace vtkm::filter
#ifndef vtk_m_filter_GhostCellRemove_hxx #endif //vtk_m_filter_GhostCellRemove_h
#include <vtkm/filter/GhostCellRemove.hxx>
#endif
#endif // vtk_m_filter_GhostCellRemove_h

@ -7,57 +7,32 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information. // PURPOSE. See the above copyright notice for more information.
//============================================================================ //============================================================================
#ifndef vtk_m_filter_Mask_h #ifndef vtk_m_filter_Mask_h
#define vtk_m_filter_Mask_h #define vtk_m_filter_Mask_h
#include <vtkm/filter/FilterDataSet.h> #include <vtkm/Deprecated.h>
#include <vtkm/worklet/Mask.h> #include <vtkm/filter/entity_extraction/Mask.h>
namespace vtkm namespace vtkm
{ {
namespace filter namespace filter
{ {
/// \brief Subselect cells using a stride
/// VTKM_DEPRECATED(1.8, "Use vtkm/filter/entity_extraction/Mask.h instead of vtkm/filter/Mask.h.")
/// Extract only every Nth cell where N is equal to a stride value inline void Mask_deprecated() {}
class Mask : public vtkm::filter::FilterDataSet<Mask>
inline void Mask_deprecated_warning()
{ {
public: Mask_deprecated();
VTKM_CONT }
Mask();
// When CompactPoints is set, instead of copying the points and point fields class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::Mask.") Mask
// from the input, the filter will create new compact fields without the unused elements : public vtkm::filter::entity_extraction::Mask
VTKM_CONT {
bool GetCompactPoints() const { return this->CompactPoints; } using entity_extraction::Mask::Mask;
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;
}; };
} }
} // namespace vtkm::filter } // 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 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information. // PURPOSE. See the above copyright notice for more information.
//============================================================================ //============================================================================
#ifndef vtk_m_filter_Threshold_h #ifndef vtk_m_filter_Threshold_h
#define vtk_m_filter_Threshold_h #define vtk_m_filter_Threshold_h
#include <vtkm/filter/vtkm_filter_common_export.h> #include <vtkm/Deprecated.h>
#include <vtkm/filter/entity_extraction/Threshold.h>
#include <vtkm/filter/FilterDataSetWithField.h>
#include <vtkm/worklet/Threshold.h>
namespace vtkm namespace vtkm
{ {
namespace filter namespace filter
{ {
/// \brief Extracts cells where scalar value in cell satisfies threshold criterion VTKM_DEPRECATED(1.8,
/// "Use vtkm/filter/entity_extraction/Threshold.h instead of vtkm/filter/Threshold.h.")
/// Extracts all cells from any dataset type that inline void Threshold_deprecated() {}
/// satisfy a threshold criterion. A cell satisfies the criterion if the
/// scalar value of every point or cell satisfies the criterion. The inline void Threshold_deprecated_warning()
/// 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>
{ {
public: Threshold_deprecated();
using SupportedTypes = vtkm::TypeListScalarAll; }
VTKM_CONT class VTKM_DEPRECATED(1.8, "Use vtkm::filter::entity_extraction::Threshold.") Threshold
void SetLowerThreshold(vtkm::Float64 value) { this->LowerValue = value; } : public vtkm::filter::entity_extraction::Threshold
VTKM_CONT {
void SetUpperThreshold(vtkm::Float64 value) { this->UpperValue = value; } using entity_extraction::Threshold::Threshold;
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;
}; };
#ifndef vtkm_filter_Threshold_cxx
VTKM_FILTER_COMMON_EXPORT_EXECUTE_METHOD(Threshold);
#endif
} }
} // namespace vtkm::filter } // 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::RemoveDegenerateCells CellCompactor;
vtkm::worklet::PointMerge PointMerger; 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::DataSet CleanGrid::GenerateOutput(const vtkm::cont::DataSet& inData,
vtkm::cont::CellSetExplicit<>& outputCellSet, vtkm::cont::CellSetExplicit<>& outputCellSet,
@ -116,61 +180,6 @@ vtkm::cont::DataSet CleanGrid::GenerateOutput(const vtkm::cont::DataSet& inData,
return outData; 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) 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 // 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 set(entity_extraction_headers
ExternalFaces.h ExternalFaces.h
ExtractGeometry.h
ExtractPoints.h ExtractPoints.h
ExtractStructured.h
GhostCellRemove.h
Mask.h
MaskPoints.h MaskPoints.h
Threshold.h
ThresholdPoints.h ThresholdPoints.h
) )
set(entity_extraction_sources_device set(entity_extraction_sources_device
ExternalFaces.cxx ExternalFaces.cxx
ExtractGeometry.cxx
ExtractPoints.cxx ExtractPoints.cxx
ExtractStructured.cxx
GhostCellRemove.cxx
Mask.cxx
MaskPoints.cxx MaskPoints.cxx
Threshold.cxx
ThresholdPoints.cxx ThresholdPoints.cxx
) )

@ -46,7 +46,8 @@ vtkm::cont::DataSet ExternalFaces::GenerateOutput(const vtkm::cont::DataSet& inp
bool hasCellFields = false; bool hasCellFields = false;
for (vtkm::Id fieldIdx = 0; fieldIdx < numFields && !hasCellFields; ++fieldIdx) 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) if (!hasCellFields)

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

@ -7,18 +7,15 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information. // 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/CoordinateSystem.h>
#include <vtkm/cont/UnknownCellSet.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 namespace
{ {
struct CallWorker struct CallWorker
{ {
vtkm::cont::UnknownCellSet& Output; 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 vtkm
{ {
namespace filter namespace filter
{ {
namespace entity_extraction
{
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename DerivedPolicy> vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input)
vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{ {
// extract the input cell set and coordinates // extract the input cell set and coordinates
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); const vtkm::cont::UnknownCellSet& cells = input.GetCellSet();
const vtkm::cont::CoordinateSystem& coords = const vtkm::cont::CoordinateSystem& coords =
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()); input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());
vtkm::worklet::ExtractGeometry worklet;
vtkm::cont::UnknownCellSet outCells; vtkm::cont::UnknownCellSet outCells;
CallWorker worker(outCells, CallWorker worker(outCells,
this->Worklet, worklet,
coords, coords,
this->Function, this->Function,
this->ExtractInside, this->ExtractInside,
this->ExtractBoundaryCells, this->ExtractBoundaryCells,
this->ExtractOnlyBoundaryCells); this->ExtractOnlyBoundaryCells);
vtkm::filter::ApplyPolicyCellSet(cells, policy, *this).CastAndCall(worker); cells.CastAndCallForTypes<VTKM_DEFAULT_CELL_SET_LIST>(worker);
// create the output dataset // create the output dataset
vtkm::cont::DataSet output; vtkm::cont::DataSet output;
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
output.SetCellSet(outCells); output.SetCellSet(outCells);
auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); };
this->MapFieldsOntoOutput(input, output, mapper);
return output; 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/ExtractPoints.h>
#include <vtkm/filter/entity_extraction/worklet/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 vtkm
{ {
namespace filter namespace filter
@ -40,7 +63,7 @@ vtkm::cont::DataSet ExtractPoints::DoExecute(const vtkm::cont::DataSet& input)
output.SetCellSet(outCellSet); output.SetCellSet(outCellSet);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); 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); this->MapFieldsOntoOutput(input, output, mapper);
// compact the unused points in the output dataset // 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 entity_extraction
} // namespace filter } // namespace filter
} // namespace vtkm } // namespace vtkm

@ -51,7 +51,7 @@ public:
const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; } const vtkm::ImplicitFunctionGeneral& GetImplicitFunction() const { return this->Function; }
VTKM_CONT VTKM_CONT
bool GetExtractInside() { return this->ExtractInside; } bool GetExtractInside() const { return this->ExtractInside; }
VTKM_CONT VTKM_CONT
void SetExtractInside(bool value) { this->ExtractInside = value; } void SetExtractInside(bool value) { this->ExtractInside = value; }
VTKM_CONT VTKM_CONT
@ -63,9 +63,6 @@ private:
VTKM_CONT VTKM_CONT
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; 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; bool ExtractInside = true;
vtkm::ImplicitFunctionGeneral Function; 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. // PURPOSE. See the above copyright notice for more information.
//============================================================================ //============================================================================
#ifndef vtk_m_filter_GhostCellRemove_hxx #include <vtkm/RangeId3.h>
#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/cont/UnknownCellSet.h> #include <vtkm/cont/UnknownCellSet.h>
#include <vtkm/RangeId3.h> #include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/filter/ExtractStructured.h>
#include <vtkm/filter/MapFieldPermutation.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 namespace
{ {
class RemoveAllGhosts class RemoveAllGhosts
{ {
public: public:
VTKM_CONT VTKM_CONT
RemoveAllGhosts() {} RemoveAllGhosts() = default;
VTKM_EXEC bool operator()(const vtkm::UInt8& value) const { return (value == 0); } VTKM_EXEC bool operator()(const vtkm::UInt8& value) const { return (value == 0); }
}; };
@ -44,7 +38,7 @@ public:
} }
VTKM_CONT VTKM_CONT
RemoveGhostByType(const vtkm::UInt8& val) explicit RemoveGhostByType(const vtkm::UInt8& val)
: RemoveType(static_cast<vtkm::UInt8>(~val)) : RemoveType(static_cast<vtkm::UInt8>(~val))
{ {
} }
@ -279,35 +273,53 @@ bool CanDoStructuredStrip(const vtkm::cont::UnknownCellSet& cells,
return canDo; 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 } // end anon namespace
namespace vtkm namespace vtkm
{ {
namespace filter namespace filter
{ {
namespace entity_extraction
{
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline VTKM_CONT GhostCellRemove::GhostCellRemove() VTKM_CONT GhostCellRemove::GhostCellRemove()
: vtkm::filter::FilterDataSetWithField<GhostCellRemove>()
, RemoveAll(false)
, RemoveField(false)
, RemoveVals(0)
{ {
this->SetActiveField("vtkmGhostCells"); this->SetActiveField("vtkmGhostCells");
this->SetFieldsToPass("vtkmGhostCells", vtkm::filter::FieldSelection::MODE_EXCLUDE); this->SetFieldsToPass("vtkmGhostCells", vtkm::filter::FieldSelection::MODE_EXCLUDE);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy> VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(const vtkm::cont::DataSet& input)
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)
{ {
//get the cells and coordinates of the dataset
const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); 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. //Preserve structured output where possible.
if (cells.CanConvert<vtkm::cont::CellSetStructured<1>>() || if (cells.CanConvert<vtkm::cont::CellSetStructured<1>>() ||
@ -316,9 +328,9 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(
{ {
vtkm::RangeId3 range; vtkm::RangeId3 range;
if (CanDoStructuredStrip( 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); extract.SetInvoker(this->Invoke);
vtkm::RangeId3 erange( vtkm::RangeId3 erange(
range.X.Min, range.X.Max + 2, range.Y.Min, range.Y.Max + 2, range.Z.Min, range.Z.Max + 2); 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()) if (this->GetRemoveAllGhost())
{ {
cellOut = this->Worklet.Run(vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), cellOut = worklet.Run(cells.ResetCellSetList<VTKM_DEFAULT_CELL_SET_LIST>(),
field, fieldArray,
fieldMeta.GetAssociation(), field.GetAssociation(),
RemoveAllGhosts()); RemoveAllGhosts());
} }
else if (this->GetRemoveByType()) else if (this->GetRemoveByType())
{ {
cellOut = this->Worklet.Run(vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), cellOut = worklet.Run(cells.ResetCellSetList<VTKM_DEFAULT_CELL_SET_LIST>(),
field, fieldArray,
fieldMeta.GetAssociation(), field.GetAssociation(),
RemoveGhostByType(this->GetRemoveType())); RemoveGhostByType(this->GetRemoveType()));
} }
else else
{ {
@ -357,36 +372,12 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
output.SetCellSet(cellOut); output.SetCellSet(cellOut);
auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); };
this->MapFieldsOntoOutput(input, output, mapper);
return output; 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 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information. // 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/MapFieldPermutation.h>
#include <vtkm/filter/entity_extraction/Mask.h>
#include <vtkm/filter/entity_extraction/worklet/Mask.h>
namespace namespace
{ {
struct CallWorklet struct CallWorklet
{ {
vtkm::Id Stride; vtkm::Id Stride;
@ -35,43 +33,9 @@ struct CallWorklet
} }
}; };
} // end anon namespace VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::Field& field,
namespace vtkm const vtkm::worklet::Mask& worklet)
{
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>)
{ {
if (field.IsFieldPoint() || field.IsFieldGlobal()) if (field.IsFieldPoint() || field.IsFieldGlobal())
{ {
@ -80,13 +44,41 @@ inline VTKM_CONT bool Mask::MapFieldOntoOutput(vtkm::cont::DataSet& result,
} }
else if (field.IsFieldCell()) else if (field.IsFieldCell())
{ {
return vtkm::filter::MapFieldPermutation(field, this->Worklet.GetValidCellIds(), result); return vtkm::filter::MapFieldPermutation(field, worklet.GetValidCellIds(), result);
} }
else else
{ {
return false; 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;
} }
} } // namespace entity_extraction
#endif } // 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/MaskPoints.h>
#include <vtkm/filter/entity_extraction/worklet/MaskPoints.h> #include <vtkm/filter/entity_extraction/worklet/MaskPoints.h>
namespace vtkm namespace
{ {
namespace filter bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field)
{
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)
{ {
// point data is copied as is because it was not collapsed // point data is copied as is because it was not collapsed
if (field.IsFieldPoint()) if (field.IsFieldPoint())
@ -73,6 +33,49 @@ VTKM_CONT bool MaskPoints::MapFieldOntoOutput(vtkm::cont::DataSet& result,
return false; 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 entity_extraction
} // namespace filter } // namespace filter
} // namespace vtkm } // namespace vtkm

@ -42,8 +42,6 @@ private:
VTKM_CONT VTKM_CONT
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; 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; vtkm::Id Stride = 1;
bool CompactPoints = true; 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: public:
VTKM_CONT VTKM_CONT
ValuesBelow(const vtkm::Float64& value) explicit ValuesBelow(const vtkm::Float64& value)
: Value(value) : Value(value)
{ {
} }
@ -39,7 +39,7 @@ class ValuesAbove
{ {
public: public:
VTKM_CONT VTKM_CONT
ValuesAbove(const vtkm::Float64& value) explicit ValuesAbove(const vtkm::Float64& value)
: Value(value) : Value(value)
{ {
} }
@ -77,12 +77,34 @@ private:
vtkm::Float64 Lower; vtkm::Float64 Lower;
vtkm::Float64 Upper; 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 vtkm
{ {
namespace filter namespace filter
{ {
namespace entity_extraction namespace entity_extraction
{ {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -156,7 +178,7 @@ VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(const vtkm::cont::DataS
output.SetCellSet(outCellSet); output.SetCellSet(outCellSet);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); 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); this->MapFieldsOntoOutput(input, output, mapper);
// compact the unused points in the output dataset // 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 entity_extraction
} // namespace filter } // namespace filter
} // namespace vtkm } // namespace vtkm

@ -41,18 +41,16 @@ public:
void SetUpperThreshold(vtkm::Float64 value) { this->UpperValue = value; } void SetUpperThreshold(vtkm::Float64 value) { this->UpperValue = value; }
VTKM_CONT VTKM_CONT
void SetThresholdBelow(const vtkm::Float64 value); void SetThresholdBelow(vtkm::Float64 value);
VTKM_CONT VTKM_CONT
void SetThresholdAbove(const vtkm::Float64 value); void SetThresholdAbove(vtkm::Float64 value);
VTKM_CONT VTKM_CONT
void SetThresholdBetween(const vtkm::Float64 value1, const vtkm::Float64 value2); void SetThresholdBetween(vtkm::Float64 value1, vtkm::Float64 value2);
private: private:
VTKM_CONT VTKM_CONT
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; 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_BELOW = 0;
constexpr static int THRESHOLD_ABOVE = 1; constexpr static int THRESHOLD_ABOVE = 1;
constexpr static int THRESHOLD_BETWEEN = 2; constexpr static int THRESHOLD_BETWEEN = 2;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -49,6 +49,11 @@
//compliance //compliance
#define VTKM_CLANG #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__) #elif defined(__GNUC__)
// Several compilers pretend to be GCC but have minor differences. Try to // Several compilers pretend to be GCC but have minor differences. Try to
// compensate for that, by checking for those compilers first // compensate for that, by checking for those compilers first

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

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

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