diff --git a/examples/histogram/HistogramMPI.hxx b/examples/histogram/HistogramMPI.hxx index c94a58ae1..013d9a626 100644 --- a/examples/histogram/HistogramMPI.hxx +++ b/examples/histogram/HistogramMPI.hxx @@ -8,7 +8,7 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include +#include #include #include diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index 06345dede..a393fe7c4 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -23,7 +23,25 @@ vtkm_add_instantiations(ClipWithImplicitFunctionInstantiations set(deprecated_headers CellSetConnectivity.h + CleanGrid.h + DotProduct.h + Entropy.h + ExternalFaces.h + ExtractGeometry.h + ExtractPoints.h + ExtractStructured.h + GenerateIds.h + GhostCellRemove.h + Histogram.h ImageConnectivity.h + Mask.h + MaskPoints.h + NDEntropy.h + NDHistogram.h + ParticleDensityCloudInCell.h + ParticleDensityNearestGridPoint.h + Threshold.h + ThresholdPoints.h ) vtkm_declare_headers(${deprecated_headers}) @@ -31,10 +49,6 @@ vtkm_declare_headers(${deprecated_headers}) set(common_headers CellAverage.h CellMeasures.h - CleanGrid.h - ExtractGeometry.h - ExtractPoints.h - ExtractStructured.h FieldMetadata.h FilterCell.h FilterDataSet.h @@ -47,8 +61,6 @@ set(common_headers PolicyBase.h PolicyDefault.h TaskQueue.h - Threshold.h - ThresholdPoints.h Instantiations.h ) @@ -77,28 +89,16 @@ set(extra_headers CoordinateSystemTransform.h CreateResult.h CrossProduct.h - DotProduct.h - Entropy.h - ExternalFaces.h FieldSelection.h FieldToColors.h - GenerateIds.h GhostCellClassify.h - GhostCellRemove.h - Histogram.h + ImageConnectivity.h ImageDifference.h ImageMedian.h Lagrangian.h LagrangianStructures.h - Mask.h - MaskPoints.h MeshQuality.h MIRFilter.h - NDEntropy.h - NDHistogram.h - ParticleDensityBase.h - ParticleDensityCloudInCell.h - ParticleDensityNearestGridPoint.h ParticleAdvection.h Pathline.h PathParticle.h @@ -134,20 +134,14 @@ set(extra_header_template_sources ComputeMoments.hxx CoordinateSystemTransform.hxx CrossProduct.hxx - Entropy.hxx FieldToColors.hxx GhostCellClassify.hxx - Histogram.hxx ImageDifference.hxx ImageMedian.hxx Lagrangian.hxx LagrangianStructures.hxx MeshQuality.hxx MIRFilter.hxx - NDEntropy.hxx - NDHistogram.hxx - ParticleDensityCloudInCell.hxx - ParticleDensityNearestGridPoint.hxx ParticleAdvection.hxx Pathline.hxx PathParticle.hxx @@ -309,6 +303,7 @@ install(TARGETS vtkm_filter EXPORT ${VTKm_EXPORT_NAME}) add_subdirectory(clean_grid) add_subdirectory(connected_components) +add_subdirectory(density_estimate) add_subdirectory(entity_extraction) add_subdirectory(internal) add_subdirectory(particleadvection) diff --git a/vtkm/filter/Entropy.h b/vtkm/filter/Entropy.h index 0724caa28..a2e5163d0 100644 --- a/vtkm/filter/Entropy.h +++ b/vtkm/filter/Entropy.h @@ -7,47 +7,32 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_Entropy_h #define vtk_m_filter_Entropy_h -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Construct the entropy histogram of a given Field -/// -/// Construct a histogram which is used to compute the entropy with a default of 10 bins -/// -class Entropy : public vtkm::filter::FilterField +VTKM_DEPRECATED(1.8, "Use vtkm/filter/density_estimate/Entropy.h instead of vtkm/filter/Entropy.h.") +inline void Entropy_deprecated() {} + +inline void Entropy_deprecated_warning() { -public: - //currently the Entropy filter only works on scalar data. - using SupportedTypes = TypeListScalarAll; + Entropy_deprecated(); +} - //Construct a histogram which is used to compute the entropy with a default of 10 bins - VTKM_CONT - Entropy(); - - VTKM_CONT - void SetNumberOfBins(vtkm::Id count) { this->NumberOfBins = count; } - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMeta, - const vtkm::filter::PolicyBase& policy); - -private: - vtkm::Id NumberOfBins; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::density_estimate::Entropy.") Entropy + : public vtkm::filter::density_estimate::Entropy +{ + using density_estimate::Entropy::Entropy; }; + } } // namespace vtkm::filter - -#include - -#endif // vtk_m_filter_Entropy_h +#endif //vtk_m_filter_Entropy_h diff --git a/vtkm/filter/Entropy.hxx b/vtkm/filter/Entropy.hxx deleted file mode 100644 index 579f91c60..000000000 --- a/vtkm/filter/Entropy.hxx +++ /dev/null @@ -1,50 +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_Entropy_hxx -#define vtk_m_filter_Entropy_hxx - -#include - -namespace vtkm -{ -namespace filter -{ - -//----------------------------------------------------------------------------- -inline VTKM_CONT Entropy::Entropy() - : NumberOfBins(10) -{ - this->SetOutputFieldName("entropy"); -} - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet Entropy::DoExecute( - const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMetadata, - const vtkm::filter::PolicyBase&) -{ - vtkm::worklet::FieldEntropy worklet; - - vtkm::Float64 e = worklet.Run(field, this->NumberOfBins); - - //the entropy vector only contain one element, the entorpy of the input field - vtkm::cont::ArrayHandle entropy; - entropy.Allocate(1); - entropy.WritePortal().Set(0, e); - - return CreateResult(inDataSet, entropy, this->GetOutputFieldName(), fieldMetadata); -} -} -} // namespace vtkm::filter - -#endif diff --git a/vtkm/filter/Histogram.h b/vtkm/filter/Histogram.h index 417865100..6ad4e2bb0 100644 --- a/vtkm/filter/Histogram.h +++ b/vtkm/filter/Histogram.h @@ -7,86 +7,33 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ - #ifndef vtk_m_filter_Histogram_h #define vtk_m_filter_Histogram_h -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Construct the histogram of a given Field -/// -/// Construct a histogram with a default of 10 bins. -/// -class Histogram : public vtkm::filter::FilterField +VTKM_DEPRECATED(1.8, + "Use vtkm/filter/density_estimate/Histogram.h instead of vtkm/filter/Histogram.h.") +inline void Histogram_deprecated() {} + +inline void Histogram_deprecated_warning() { -public: - using SupportedTypes = vtkm::TypeListScalarAll; + Histogram_deprecated(); +} - //Construct a histogram with a default of 10 bins - VTKM_CONT - Histogram(); - - VTKM_CONT - void SetNumberOfBins(vtkm::Id count) { this->NumberOfBins = count; } - - VTKM_CONT - vtkm::Id GetNumberOfBins() const { return this->NumberOfBins; } - - //@{ - /// Get/Set the range to use to generate the histogram. If range is set to - /// empty, the field's global range (computed using `vtkm::cont::FieldRangeGlobalCompute`) - /// will be used. - VTKM_CONT - void SetRange(const vtkm::Range& range) { this->Range = range; } - - VTKM_CONT - const vtkm::Range& GetRange() const { return this->Range; } - //@} - - /// Returns the bin delta of the last computed field. - VTKM_CONT - vtkm::Float64 GetBinDelta() const { return this->BinDelta; } - - /// Returns the range used for most recent execute. If `SetRange` is used to - /// specify and non-empty range, then this will be same as the range after - /// the `Execute` call. - VTKM_CONT - vtkm::Range GetComputedRange() const { return this->ComputedRange; } - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); - - //@{ - /// when operating on vtkm::cont::PartitionedDataSet, we - /// want to do processing across ranks as well. Just adding pre/post handles - /// for the same does the trick. - template - VTKM_CONT void PreExecute(const vtkm::cont::PartitionedDataSet& input, - const vtkm::filter::PolicyBase& policy); - - template - VTKM_CONT void PostExecute(const vtkm::cont::PartitionedDataSet& input, - vtkm::cont::PartitionedDataSet& output, - const vtkm::filter::PolicyBase&); - //@} - -private: - vtkm::Id NumberOfBins; - vtkm::Float64 BinDelta; - vtkm::Range ComputedRange; - vtkm::Range Range; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::density_estimate::Histogram.") Histogram + : public vtkm::filter::density_estimate::Histogram +{ + using density_estimate::Histogram::Histogram; }; + } } // namespace vtkm::filter -#include - -#endif // vtk_m_filter_Histogram_h +#endif //vtk_m_filter_Histogram_h diff --git a/vtkm/filter/NDEntropy.h b/vtkm/filter/NDEntropy.h index 37336e45e..ad0eac2e2 100644 --- a/vtkm/filter/NDEntropy.h +++ b/vtkm/filter/NDEntropy.h @@ -10,41 +10,30 @@ #ifndef vtk_m_filter_NDEntropy_h #define vtk_m_filter_NDEntropy_h -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Calculate the entropy of input N-Dims fields -/// -/// This filter calculate the entropy of input N-Dims fields. -/// -class NDEntropy : public vtkm::filter::FilterDataSet + +VTKM_DEPRECATED(1.8, + "Use vtkm/filter/density_estimate/NDEntropy.h instead of vtkm/filter/NDEntropy.h.") +inline void NDEntropy_deprecated() {} + +inline void NDEntropy_deprecated_warning() { -public: - VTKM_CONT - NDEntropy(); + NDEntropy_deprecated(); +} - VTKM_CONT - void AddFieldAndBin(const std::string& fieldName, vtkm::Id numOfBins); - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inData, - vtkm::filter::PolicyBase policy); - - template - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - vtkm::filter::PolicyBase policy); - -private: - std::vector NumOfBins; - std::vector FieldNames; +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::density_estimate::NDEntropy.") NDEntropy + : public vtkm::filter::density_estimate::NDEntropy +{ + using density_estimate::NDEntropy::NDEntropy; }; + } } // namespace vtkm::filter -#include - #endif //vtk_m_filter_NDEntropy_h diff --git a/vtkm/filter/NDHistogram.h b/vtkm/filter/NDHistogram.h index 2b8cb0e45..68a0b59a2 100644 --- a/vtkm/filter/NDHistogram.h +++ b/vtkm/filter/NDHistogram.h @@ -10,61 +10,31 @@ #ifndef vtk_m_filter_NDHistogram_h #define vtk_m_filter_NDHistogram_h -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Generate a N-Dims histogram from input fields -/// -/// This filter takes a data set and with target fields and bins defined, -/// it would generate a N-Dims histogram from input fields. The result is stored -/// in a field named as "Frequency". This filed contains all the frequencies of -/// the N-Dims histogram in sparse representation. That being said, the result -/// field does not store 0 frequency bins. Meanwhile all input fields now -/// would have the same length and store bin ids instead. -/// E.g. (FieldA[i], FieldB[i], FieldC[i], Frequency[i]) is a bin in the histogram. -/// The first three numbers are binIDs for FieldA, FieldB and FieldC. Frequency[i] stores -/// the frequency for this bin (FieldA[i], FieldB[i], FieldC[i]). -/// -class NDHistogram : public vtkm::filter::FilterDataSet + +VTKM_DEPRECATED( + 1.8, + "Use vtkm/filter/density_estimate/NDHistogram.h instead of vtkm/filter/NDHistogram.h.") +inline void NDHistogram_deprecated() {} + +inline void NDHistogram_deprecated_warning() { -public: - VTKM_CONT - NDHistogram(); + NDHistogram_deprecated(); +} - VTKM_CONT - void AddFieldAndBin(const std::string& fieldName, vtkm::Id numOfBins); - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inData, - vtkm::filter::PolicyBase policy); - - // This index is the field position in FieldNames - // (or the input _fieldName string vector of SetFields() Function) - VTKM_CONT - vtkm::Float64 GetBinDelta(size_t fieldIdx); - - // This index is the field position in FieldNames - // (or the input _fieldName string vector of SetFields() Function) - VTKM_CONT - vtkm::Range GetDataRange(size_t fieldIdx); - - template - VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result, - const vtkm::cont::Field& field, - vtkm::filter::PolicyBase policy); - -private: - std::vector NumOfBins; - std::vector FieldNames; - std::vector BinDeltas; - std::vector DataRanges; //Min Max of the field +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::density_estimate::NDHistogram.") NDHistogram + : public vtkm::filter::density_estimate::NDHistogram +{ + using density_estimate::NDHistogram::NDHistogram; }; + } } // namespace vtkm::filter -#include - #endif //vtk_m_filter_NDHistogram_h diff --git a/vtkm/filter/NewFilter.h b/vtkm/filter/NewFilter.h index 7aca9ee8c..7589accb1 100644 --- a/vtkm/filter/NewFilter.h +++ b/vtkm/filter/NewFilter.h @@ -322,15 +322,14 @@ protected: this->MapFieldsOntoOutput(input, output, defaultMapper); } -private: - VTKM_CONT - virtual vtkm::Id DetermineNumberOfThreads(const vtkm::cont::PartitionedDataSet& input); - - // Note: In C++, subclasses can override private methods of superclass. VTKM_CONT virtual vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inData) = 0; VTKM_CONT virtual vtkm::cont::PartitionedDataSet DoExecutePartitions( const vtkm::cont::PartitionedDataSet& inData); +private: + VTKM_CONT + virtual vtkm::Id DetermineNumberOfThreads(const vtkm::cont::PartitionedDataSet& input); + static void defaultMapper(vtkm::cont::DataSet& output, const vtkm::cont::Field& field) { output.AddField(field); diff --git a/vtkm/filter/ParticleDensityBase.h b/vtkm/filter/ParticleDensityBase.h deleted file mode 100644 index bb53944d8..000000000 --- a/vtkm/filter/ParticleDensityBase.h +++ /dev/null @@ -1,124 +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_particle_density_base_h -#define vtk_m_filter_particle_density_base_h - -#include -#include - -namespace vtkm -{ -namespace filter -{ -// We only need the CoordinateSystem and scalar fields of the input dataset thus a FilterField -template -class ParticleDensityBase : public vtkm::filter::FilterDataSetWithField -{ -public: - // deposit scalar field associated with particles, e.g. mass/charge to mesh cells - using SupportedTypes = vtkm::TypeListFieldScalar; - -protected: - ParticleDensityBase(const vtkm::Id3& dimension, - const vtkm::Vec3f& origin, - const vtkm::Vec3f& spacing) - : Dimension(dimension) - , Origin(origin) - , Spacing(spacing) - , ComputeNumberDensity(false) - , DivideByVolume(true) - { - } - - ParticleDensityBase(const vtkm::Id3& dimension, const vtkm::Bounds& bounds) - : Dimension(dimension) - , Origin({ static_cast(bounds.X.Min), - static_cast(bounds.Y.Min), - static_cast(bounds.Z.Min) }) - , Spacing(vtkm::Vec3f{ static_cast(bounds.X.Length()), - static_cast(bounds.Y.Length()), - static_cast(bounds.Z.Length()) } / - Dimension) - , ComputeNumberDensity(false) - , DivideByVolume(true) - { - } - -public: - template - VTKM_CONT vtkm::cont::DataSet PrepareForExecution(const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy) - { - if (this->ComputeNumberDensity) - { - return static_cast(this)->DoExecute( - input, - vtkm::cont::make_ArrayHandleConstant(vtkm::FloatDefault{ 1 }, input.GetNumberOfPoints()), - vtkm::filter::FieldMetadata{}, // Ignored - policy); - } - else - { - return this->FilterDataSetWithField::PrepareForExecution(input, policy); - } - } - - template - VTKM_CONT bool DoMapField(vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle&, - const vtkm::filter::FieldMetadata&, - vtkm::filter::PolicyBase) - { - return false; - } - - VTKM_CONT void SetComputeNumberDensity(bool yes) { this->ComputeNumberDensity = yes; } - - VTKM_CONT bool GetComputeNumberDensity() const { return this->ComputeNumberDensity; } - - VTKM_CONT void SetDivideByVolume(bool yes) { this->DivideByVolume = yes; } - - VTKM_CONT bool GetDivideByVolume() const { return this->DivideByVolume; } - -protected: - vtkm::Id3 Dimension; // Cell dimension - vtkm::Vec3f Origin; - vtkm::Vec3f Spacing; - bool ComputeNumberDensity; - bool DivideByVolume; - -public: - // conceptually protected but CUDA needs this to be public - class DivideByVolumeWorklet : public vtkm::worklet::WorkletMapField - { - public: - using ControlSignature = void(FieldInOut field); - using ExecutionSignature = void(_1); - - VTKM_EXEC_CONT - explicit DivideByVolumeWorklet(vtkm::Float64 volume) - : Volume(volume) - { - } - - template - VTKM_EXEC void operator()(T& value) const - { - value = static_cast(value / Volume); - } - - private: - vtkm::Float64 Volume; - }; // class DivideByVolumeWorklet -}; -} -} -#endif //vtk_m_filter_particle_density_base_h diff --git a/vtkm/filter/ParticleDensityCloudInCell.h b/vtkm/filter/ParticleDensityCloudInCell.h index c03997cf3..35a93e15a 100644 --- a/vtkm/filter/ParticleDensityCloudInCell.h +++ b/vtkm/filter/ParticleDensityCloudInCell.h @@ -7,51 +7,34 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ +#ifndef vtk_m_filter_ParticleDensityCloudInCell_h +#define vtk_m_filter_ParticleDensityCloudInCell_h -#ifndef vtk_m_filter_particle_density_cic_h -#define vtk_m_filter_particle_density_cic_h - -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Estimate the density of particles using the Cloud-in-Cell method -/// This filter treats the CoordinateSystem of a DataSet as positions of particles. -/// The particles are infinitesimal in size with finite mass (or other scalar attributes -/// such as charge). The filter estimates density by imposing a regular grid as -/// specified in the constructor. It spreads the mass of each particle to its 8 nearest -/// neighboring grid points and summing the contribution of particles for each point -/// in the grid. -/// The mass of particles is established by setting the active field (using SetActiveField). -/// Note that the "mass" can actually be another quantity. For example, you could use -/// electrical charge in place of mass to compute the charge density. -/// Once the sum of the mass is computed for each grid point, the mass is divided by the -/// volume of the cell. Thus, the density will be computed as the units of the mass field -/// per the cubic units of the coordinate system. If you just want a sum of the mass in each -/// cell, turn off the DivideByVolume feature of this filter. -/// In addition, you can also simply count the number of particles in each cell by calling -/// SetComputeNumberDensity(true). -class ParticleDensityCloudInCell : public ParticleDensityBase + +VTKM_DEPRECATED(1.8, + "Use vtkm/filter/density_estimate/ParticleDensityCloudInCell.h instead of " + "vtkm/filter/ParticleDensityCloudInCell.h.") +inline void ParticleDensityCloudInCell_deprecated() {} + +inline void ParticleDensityCloudInCell_deprecated_warning() { -public: - using Superclass = ParticleDensityBase; + ParticleDensityCloudInCell_deprecated(); +} - ParticleDensityCloudInCell(const vtkm::Id3& dimension, - const vtkm::Vec3f& origin, - const vtkm::Vec3f& spacing); - - ParticleDensityCloudInCell(const Id3& dimension, const vtkm::Bounds& bounds); - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::density_estimate::ParticleDensityCloudInCell.") + ParticleDensityCloudInCell : public vtkm::filter::density_estimate::ParticleDensityCloudInCell +{ + using density_estimate::ParticleDensityCloudInCell::ParticleDensityCloudInCell; }; -} // filter -} // vtkm -#include -#endif // vtk_m_filter_particle_density_cic_h +} +} // namespace vtkm::filter + +#endif //vtk_m_filter_ParticleDensityCloudInCell_h diff --git a/vtkm/filter/ParticleDensityNearestGridPoint.h b/vtkm/filter/ParticleDensityNearestGridPoint.h index 8841968c6..4edbd5dba 100644 --- a/vtkm/filter/ParticleDensityNearestGridPoint.h +++ b/vtkm/filter/ParticleDensityNearestGridPoint.h @@ -7,51 +7,35 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ +#ifndef vtk_m_filter_ParticleDensityNearestGridPoint_h +#define vtk_m_filter_ParticleDensityNearestGridPoint_h -#ifndef vtk_m_filter_particle_density_ngp_h -#define vtk_m_filter_particle_density_ngp_h - -#include +#include +#include namespace vtkm { namespace filter { -/// \brief Estimate the density of particles using the Nearest Grid Point method -/// This filter treats the CoordinateSystem of a DataSet as positions of particles. -/// The particles are infinitesimal in size with finite mass (or other scalar attributes -/// such as charge). The filter estimates density by imposing a regular grid as -/// specified in the constructor and summing the mass of particles within each cell -/// in the grid. -/// The mass of particles is established by setting the active field (using SetActiveField). -/// Note that the "mass" can actually be another quantity. For example, you could use -/// electrical charge in place of mass to compute the charge density. -/// Once the sum of the mass is computed for each grid cell, the mass is divided by the -/// volume of the cell. Thus, the density will be computed as the units of the mass field -/// per the cubic units of the coordinate system. If you just want a sum of the mass in each -/// cell, turn off the DivideByVolume feature of this filter. -/// In addition, you can also simply count the number of particles in each cell by calling -/// SetComputeNumberDensity(true). -class ParticleDensityNearestGridPoint : public ParticleDensityBase + +VTKM_DEPRECATED(1.8, + "Use vtkm/filter/density_estimate/ParticleDensityNearestGridPoint.h instead of " + "vtkm/filter/ParticleDensityNearestGridPoint.h.") +inline void ParticleDensityNearestGridPoint_deprecated() {} + +inline void ParticleDensityNearestGridPoint_deprecated_warning() { -public: - using Superclass = ParticleDensityBase; + ParticleDensityNearestGridPoint_deprecated(); +} - ParticleDensityNearestGridPoint(const vtkm::Id3& dimension, - const vtkm::Vec3f& origin, - const vtkm::Vec3f& spacing); - - ParticleDensityNearestGridPoint(const vtkm::Id3& dimension, const vtkm::Bounds& bounds); - - template - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase policy); +class VTKM_DEPRECATED(1.8, "Use vtkm::filter::density_estimate::ParticleDensityNearestGridPoint.") + ParticleDensityNearestGridPoint + : public vtkm::filter::density_estimate::ParticleDensityNearestGridPoint +{ + using density_estimate::ParticleDensityNearestGridPoint::ParticleDensityNearestGridPoint; }; -} -} -#include +} +} // namespace vtkm::filter -#endif //vtk_m_filter_particle_density_ngp_h +#endif //vtk_m_filter_ParticleDensityNearestGridPoint_h diff --git a/vtkm/filter/density_estimate/CMakeLists.txt b/vtkm/filter/density_estimate/CMakeLists.txt new file mode 100644 index 000000000..05209da58 --- /dev/null +++ b/vtkm/filter/density_estimate/CMakeLists.txt @@ -0,0 +1,50 @@ +##============================================================================ +## 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. +##============================================================================ +set(density_estimate_headers + Entropy.h + Histogram.h + NDEntropy.h + NDHistogram.h + ParticleDensityBase.h + ParticleDensityCloudInCell.h + ParticleDensityNearestGridPoint.h + ) + +set(density_estimate_sources_device + Entropy.cxx + Histogram.cxx + NDEntropy.cxx + NDHistogram.cxx + ParticleDensityBase.cxx + ParticleDensityCloudInCell.cxx + ParticleDensityNearestGridPoint.cxx + ) + +vtkm_library( + NAME vtkm_filter_density_estimate + HEADERS ${density_estimate_headers} + DEVICE_SOURCES ${density_estimate_sources_device} + USE_VTKM_JOB_POOL +) + +set_property(TARGET + vtkm_filter_density_estimate + PROPERTY UNITY_BUILD_MODE GROUP + ) + +target_link_libraries(vtkm_filter_density_estimate PRIVATE vtkm_worklet PUBLIC vtkm_filter_core) +target_link_libraries(vtkm_filter PUBLIC INTERFACE vtkm_filter_density_estimate) + +add_subdirectory(worklet) + +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +if (VTKm_ENABLE_TESTING) + add_subdirectory(testing) +endif () diff --git a/vtkm/filter/density_estimate/Entropy.cxx b/vtkm/filter/density_estimate/Entropy.cxx new file mode 100644 index 000000000..c87a3ece0 --- /dev/null +++ b/vtkm/filter/density_estimate/Entropy.cxx @@ -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. +//============================================================================ +#include +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace density_estimate +{ +//----------------------------------------------------------------------------- +VTKM_CONT Entropy::Entropy() + +{ + this->SetOutputFieldName("entropy"); +} + +//----------------------------------------------------------------------------- +VTKM_CONT vtkm::cont::DataSet Entropy::DoExecute(const vtkm::cont::DataSet& inDataSet) +{ + vtkm::worklet::FieldEntropy worklet; + + vtkm::Float64 e = 0; + auto resolveType = [&](const auto& concrete) { e = worklet.Run(concrete, this->NumberOfBins); }; + const auto& fieldArray = this->GetFieldFromDataSet(inDataSet).GetData(); + fieldArray + .CastAndCallForTypesWithFloatFallback( + resolveType); + + //the entropy vector only contain one element, the entropy of the input field + vtkm::cont::ArrayHandle entropy; + entropy.Allocate(1); + entropy.WritePortal().Set(0, e); + + vtkm::cont::DataSet output; + output.AddField( + { this->GetOutputFieldName(), vtkm::cont::Field::Association::WHOLE_MESH, entropy }); + + // The output is a "summary" of the input, no need to map fields + return output; +} +} // namespace density_estimate +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/density_estimate/Entropy.h b/vtkm/filter/density_estimate/Entropy.h new file mode 100644 index 000000000..e820ab50a --- /dev/null +++ b/vtkm/filter/density_estimate/Entropy.h @@ -0,0 +1,51 @@ +//============================================================================ +// 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_density_estimate_Entropy_h +#define vtk_m_filter_density_estimate_Entropy_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace density_estimate +{ +/// \brief Construct the entropy histogram of a given Field +/// +/// Construct a histogram which is used to compute the entropy with a default of 10 bins +/// +class VTKM_FILTER_DENSITY_ESTIMATE_EXPORT Entropy : public vtkm::filter::NewFilterField +{ +public: + //currently the Entropy filter only works on scalar data. + using SupportedTypes = TypeListScalarAll; + + //Construct a histogram which is used to compute the entropy with a default of 10 bins + VTKM_CONT + Entropy(); + + VTKM_CONT + void SetNumberOfBins(vtkm::Id count) { this->NumberOfBins = count; } + VTKM_CONT + vtkm::Id GetNumberOfBins() const { return this->NumberOfBins; } + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + vtkm::Id NumberOfBins = 10; +}; +} // namespace density_estimate +} // namespace filter +} // namespace vtkm + +#endif // vtk_m_filter_density_estimate_Entropy_h diff --git a/vtkm/filter/Histogram.hxx b/vtkm/filter/density_estimate/Histogram.cxx similarity index 77% rename from vtkm/filter/Histogram.hxx rename to vtkm/filter/density_estimate/Histogram.cxx index 20bf1f76d..b00679612 100644 --- a/vtkm/filter/Histogram.hxx +++ b/vtkm/filter/density_estimate/Histogram.cxx @@ -8,13 +8,10 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_filter_Histogram_hxx -#define vtk_m_filter_Histogram_hxx - -#include +#include +#include #include -#include #include #include #include @@ -27,6 +24,8 @@ namespace vtkm { namespace filter { +namespace density_estimate +{ namespace detail { class DistributedHistogram @@ -165,53 +164,61 @@ private: } // namespace detail //----------------------------------------------------------------------------- -inline VTKM_CONT Histogram::Histogram() - : NumberOfBins(10) - , BinDelta(0) - , ComputedRange() - , Range() +VTKM_CONT Histogram::Histogram() { this->SetOutputFieldName("histogram"); } -//----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet Histogram::DoExecute( - const vtkm::cont::DataSet&, - const vtkm::cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata&, - vtkm::filter::PolicyBase) +VTKM_CONT vtkm::cont::DataSet Histogram::DoExecute(const vtkm::cont::DataSet& input) { vtkm::cont::ArrayHandle binArray; - T delta; - vtkm::worklet::FieldHistogram worklet; - if (this->ComputedRange.IsNonEmpty()) - { - worklet.Run(field, - this->NumberOfBins, - static_cast(this->ComputedRange.Min), - static_cast(this->ComputedRange.Max), - delta, - binArray); - } - else - { - worklet.Run(field, this->NumberOfBins, this->ComputedRange, delta, binArray); - } + auto resolveType = [&](const auto& concrete) { + using T = typename std::decay_t::ValueType; + T delta; + + vtkm::worklet::FieldHistogram worklet; + if (this->ComputedRange.IsNonEmpty()) + { + worklet.Run(concrete, + this->NumberOfBins, + static_cast(this->ComputedRange.Min), + static_cast(this->ComputedRange.Max), + delta, + binArray); + } + else + { + worklet.Run(concrete, this->NumberOfBins, this->ComputedRange, delta, binArray); + } + + this->BinDelta = static_cast(delta); + }; + + const auto& fieldArray = this->GetFieldFromDataSet(input).GetData(); + fieldArray + .CastAndCallForTypesWithFloatFallback( + resolveType); - this->BinDelta = static_cast(delta); vtkm::cont::DataSet output; - vtkm::cont::Field rfield( - this->GetOutputFieldName(), vtkm::cont::Field::Association::WHOLE_MESH, binArray); - output.AddField(rfield); + output.AddField( + { this->GetOutputFieldName(), vtkm::cont::Field::Association::WHOLE_MESH, binArray }); + + // The output is a "summary" of the input, no need to map fields return output; } +VTKM_CONT vtkm::cont::PartitionedDataSet Histogram::DoExecutePartitions( + const vtkm::cont::PartitionedDataSet& input) +{ + this->PreExecute(input); + auto result = this->NewFilter::DoExecutePartitions(input); + this->PostExecute(input, result); + return result; +} + //----------------------------------------------------------------------------- -template -inline VTKM_CONT void Histogram::PreExecute(const vtkm::cont::PartitionedDataSet& input, - const vtkm::filter::PolicyBase&) +VTKM_CONT void Histogram::PreExecute(const vtkm::cont::PartitionedDataSet& input) { if (this->Range.IsNonEmpty()) { @@ -230,10 +237,8 @@ inline VTKM_CONT void Histogram::PreExecute(const vtkm::cont::PartitionedDataSet } //----------------------------------------------------------------------------- -template -inline VTKM_CONT void Histogram::PostExecute(const vtkm::cont::PartitionedDataSet&, - vtkm::cont::PartitionedDataSet& result, - const vtkm::filter::PolicyBase&) +VTKM_CONT void Histogram::PostExecute(const vtkm::cont::PartitionedDataSet&, + vtkm::cont::PartitionedDataSet& result) { // iterate and compute histogram for each local block. detail::DistributedHistogram helper(result.GetNumberOfPartitions()); @@ -250,7 +255,6 @@ inline VTKM_CONT void Histogram::PostExecute(const vtkm::cont::PartitionedDataSe result = vtkm::cont::PartitionedDataSet(output); } -} -} // namespace vtkm::filter - -#endif +} // namespace density_estimate +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/density_estimate/Histogram.h b/vtkm/filter/density_estimate/Histogram.h new file mode 100644 index 000000000..1600a80a6 --- /dev/null +++ b/vtkm/filter/density_estimate/Histogram.h @@ -0,0 +1,84 @@ +//============================================================================ +// 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_density_estimate_Histogram_h +#define vtk_m_filter_density_estimate_Histogram_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace density_estimate +{ +/// \brief Construct the histogram of a given Field +/// +/// Construct a histogram with a default of 10 bins. +/// +class VTKM_FILTER_DENSITY_ESTIMATE_EXPORT Histogram : public vtkm::filter::NewFilterField +{ +public: + //Construct a histogram with a default of 10 bins + VTKM_CONT + Histogram(); + + VTKM_CONT + void SetNumberOfBins(vtkm::Id count) { this->NumberOfBins = count; } + + VTKM_CONT + vtkm::Id GetNumberOfBins() const { return this->NumberOfBins; } + + //@{ + /// Get/Set the range to use to generate the histogram. If range is set to + /// empty, the field's global range (computed using `vtkm::cont::FieldRangeGlobalCompute`) + /// will be used. + VTKM_CONT + void SetRange(const vtkm::Range& range) { this->Range = range; } + + VTKM_CONT + const vtkm::Range& GetRange() const { return this->Range; } + //@} + + /// Returns the bin delta of the last computed field. + VTKM_CONT + vtkm::Float64 GetBinDelta() const { return this->BinDelta; } + + /// Returns the range used for most recent execute. If `SetRange` is used to + /// specify and non-empty range, then this will be same as the range after + /// the `Execute` call. + VTKM_CONT + vtkm::Range GetComputedRange() const { return this->ComputedRange; } + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + VTKM_CONT vtkm::cont::PartitionedDataSet DoExecutePartitions( + const vtkm::cont::PartitionedDataSet& inData) override; + + //@{ + /// when operating on vtkm::cont::PartitionedDataSet, we + /// want to do processing across ranks as well. Just adding pre/post handles + /// for the same does the trick. + VTKM_CONT void PreExecute(const vtkm::cont::PartitionedDataSet& input); + VTKM_CONT void PostExecute(const vtkm::cont::PartitionedDataSet& input, + vtkm::cont::PartitionedDataSet& output); + //@} + + vtkm::Id NumberOfBins = 10; + vtkm::Float64 BinDelta = 0; + vtkm::Range ComputedRange; + vtkm::Range Range; +}; +} // namespace density_estimate +} // namespace filter +} // namespace vtkm + +#endif // vtk_m_filter_density_estimate_Histogram_h diff --git a/vtkm/filter/NDEntropy.hxx b/vtkm/filter/density_estimate/NDEntropy.cxx similarity index 61% rename from vtkm/filter/NDEntropy.hxx rename to vtkm/filter/density_estimate/NDEntropy.cxx index 7c920b0e3..ebb5f53cd 100644 --- a/vtkm/filter/NDEntropy.hxx +++ b/vtkm/filter/density_estimate/NDEntropy.cxx @@ -7,29 +7,22 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_filter_NDEntropy_hxx -#define vtk_m_filter_NDEntropy_hxx - -#include -#include +#include +#include namespace vtkm { namespace filter { - -inline VTKM_CONT NDEntropy::NDEntropy() {} - +namespace density_estimate +{ void NDEntropy::AddFieldAndBin(const std::string& fieldName, vtkm::Id numOfBins) { this->FieldNames.push_back(fieldName); this->NumOfBins.push_back(numOfBins); } -template -inline VTKM_CONT vtkm::cont::DataSet NDEntropy::DoExecute( - const vtkm::cont::DataSet& inData, - vtkm::filter::PolicyBase vtkmNotUsed(policy)) +VTKM_CONT vtkm::cont::DataSet NDEntropy::DoExecute(const vtkm::cont::DataSet& inData) { vtkm::worklet::NDimsEntropy ndEntropy; ndEntropy.SetNumOfDataPoints(inData.GetField(0).GetNumberOfValues()); @@ -48,20 +41,11 @@ inline VTKM_CONT vtkm::cont::DataSet NDEntropy::DoExecute( entropyHandle.Allocate(1); entropyHandle.WritePortal().Set(0, entropy); - vtkm::cont::DataSet outputData; - outputData.AddField(vtkm::cont::make_FieldPoint("Entropy", entropyHandle)); + outputData.AddField({ "Entropy", vtkm::cont::Field::Association::WHOLE_MESH, entropyHandle }); + // The output is a "summary" of the input, no need to map fields return outputData; } - -//----------------------------------------------------------------------------- -template -inline VTKM_CONT bool NDEntropy::MapFieldOntoOutput(vtkm::cont::DataSet&, - const vtkm::cont::Field&, - vtkm::filter::PolicyBase) -{ - return false; -} -} -} -#endif +} // namespace density_estimate +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/density_estimate/NDEntropy.h b/vtkm/filter/density_estimate/NDEntropy.h new file mode 100644 index 000000000..6cfcd5f13 --- /dev/null +++ b/vtkm/filter/density_estimate/NDEntropy.h @@ -0,0 +1,42 @@ +//============================================================================ +// 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_density_estimate_NDEntropy_h +#define vtk_m_filter_density_estimate_NDEntropy_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace density_estimate +{ +/// \brief Calculate the entropy of input N-Dims fields +/// +/// This filter calculate the entropy of input N-Dims fields. +/// +class VTKM_FILTER_DENSITY_ESTIMATE_EXPORT NDEntropy : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT + void AddFieldAndBin(const std::string& fieldName, vtkm::Id numOfBins); + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + std::vector NumOfBins; + std::vector FieldNames; +}; +} +} +} // namespace vtkm::filter + +#endif //vtk_m_filter_density_estimate_NDEntropy_h diff --git a/vtkm/filter/NDHistogram.hxx b/vtkm/filter/density_estimate/NDHistogram.cxx similarity index 58% rename from vtkm/filter/NDHistogram.hxx rename to vtkm/filter/density_estimate/NDHistogram.cxx index f054f359f..65a35d5a5 100644 --- a/vtkm/filter/NDHistogram.hxx +++ b/vtkm/filter/density_estimate/NDHistogram.cxx @@ -7,20 +7,17 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_filter_NDHistogram_hxx -#define vtk_m_filter_NDHistogram_hxx - #include -#include -#include + +#include +#include namespace vtkm { namespace filter { - -inline VTKM_CONT NDHistogram::NDHistogram() {} - +namespace density_estimate +{ void NDHistogram::AddFieldAndBin(const std::string& fieldName, vtkm::Id numOfBins) { this->FieldNames.push_back(fieldName); @@ -37,9 +34,7 @@ vtkm::Range NDHistogram::GetDataRange(size_t fieldIdx) return DataRanges[fieldIdx]; } -template -inline VTKM_CONT vtkm::cont::DataSet NDHistogram::DoExecute(const vtkm::cont::DataSet& inData, - vtkm::filter::PolicyBase policy) +VTKM_CONT vtkm::cont::DataSet NDHistogram::DoExecute(const vtkm::cont::DataSet& inData) { vtkm::worklet::NDimsHistogram ndHistogram; @@ -53,10 +48,7 @@ inline VTKM_CONT vtkm::cont::DataSet NDHistogram::DoExecute(const vtkm::cont::Da vtkm::Range rangeField; vtkm::Float64 deltaField; ndHistogram.AddField( - vtkm::filter::ApplyPolicyFieldNotActive(inData.GetField(this->FieldNames[i]), policy), - this->NumOfBins[i], - rangeField, - deltaField); + inData.GetField(this->FieldNames[i]).GetData(), this->NumOfBins[i], rangeField, deltaField); DataRanges.push_back(rangeField); BinDeltas.push_back(deltaField); } @@ -68,21 +60,14 @@ inline VTKM_CONT vtkm::cont::DataSet NDHistogram::DoExecute(const vtkm::cont::Da vtkm::cont::DataSet outputData; for (size_t i = 0; i < binIds.size(); i++) { - outputData.AddField(vtkm::cont::make_FieldPoint(this->FieldNames[i], binIds[i])); + outputData.AddField( + { this->FieldNames[i], vtkm::cont::Field::Association::WHOLE_MESH, binIds[i] }); } - outputData.AddField(vtkm::cont::make_FieldPoint("Frequency", freqs)); - + outputData.AddField({ "Frequency", vtkm::cont::Field::Association::WHOLE_MESH, freqs }); + // The output is a "summary" of the input, no need to map fields return outputData; } -//----------------------------------------------------------------------------- -template -inline VTKM_CONT bool NDHistogram::MapFieldOntoOutput(vtkm::cont::DataSet&, - const vtkm::cont::Field&, - vtkm::filter::PolicyBase) -{ - return false; -} -} -} -#endif +} // namespace density_estimate +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/density_estimate/NDHistogram.h b/vtkm/filter/density_estimate/NDHistogram.h new file mode 100644 index 000000000..2a4cbeff5 --- /dev/null +++ b/vtkm/filter/density_estimate/NDHistogram.h @@ -0,0 +1,62 @@ +//============================================================================ +// 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_density_estimate_NDHistogram_h +#define vtk_m_filter_density_estimate_NDHistogram_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace density_estimate +{ +/// \brief Generate a N-Dims histogram from input fields +/// +/// This filter takes a data set and with target fields and bins defined, +/// it would generate a N-Dims histogram from input fields. The result is stored +/// in a field named as "Frequency". This filed contains all the frequencies of +/// the N-Dims histogram in sparse representation. That being said, the result +/// field does not store 0 frequency bins. Meanwhile all input fields now +/// would have the same length and store bin ids instead. +/// E.g. (FieldA[i], FieldB[i], FieldC[i], Frequency[i]) is a bin in the histogram. +/// The first three numbers are binIDs for FieldA, FieldB and FieldC. Frequency[i] stores +/// the frequency for this bin (FieldA[i], FieldB[i], FieldC[i]). +/// +class VTKM_FILTER_DENSITY_ESTIMATE_EXPORT NDHistogram : public vtkm::filter::NewFilterField +{ +public: + VTKM_CONT + void AddFieldAndBin(const std::string& fieldName, vtkm::Id numOfBins); + + // This index is the field position in FieldNames + // (or the input _fieldName string vector of SetFields() Function) + VTKM_CONT + vtkm::Float64 GetBinDelta(size_t fieldIdx); + + // This index is the field position in FieldNames + // (or the input _fieldName string vector of SetFields() Function) + VTKM_CONT + vtkm::Range GetDataRange(size_t fieldIdx); + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; + + std::vector NumOfBins; + std::vector FieldNames; + std::vector BinDeltas; + std::vector DataRanges; //Min Max of the field +}; +} // namespace density_estimate +} // namespace filter +} // namespace vtm + +#endif //vtk_m_filter_density_estimate_NDHistogram_h diff --git a/vtkm/filter/density_estimate/ParticleDensityBase.cxx b/vtkm/filter/density_estimate/ParticleDensityBase.cxx new file mode 100644 index 000000000..b91c538a6 --- /dev/null +++ b/vtkm/filter/density_estimate/ParticleDensityBase.cxx @@ -0,0 +1,54 @@ +//============================================================================ +// 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 +#include + +namespace +{ +class DivideByVolumeWorklet : public vtkm::worklet::WorkletMapField +{ +public: + using ControlSignature = void(FieldInOut field); + using ExecutionSignature = void(_1); + + VTKM_EXEC_CONT + explicit DivideByVolumeWorklet(vtkm::Float64 volume) + : Volume(volume) + { + } + + template + VTKM_EXEC void operator()(T& value) const + { + value = static_cast(value / Volume); + } + +private: + vtkm::Float64 Volume; +}; // class DivideByVolumeWorklet +} + +namespace vtkm +{ +namespace filter +{ +namespace density_estimate +{ + +VTKM_CONT void ParticleDensityBase::DoDivideByVolume( + const vtkm::cont::UnknownArrayHandle& density) const +{ + auto volume = this->Spacing[0] * this->Spacing[1] * this->Spacing[2]; + this->Invoke(DivideByVolumeWorklet{ volume }, density); +} +} // namespace density_estimate +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/density_estimate/ParticleDensityBase.h b/vtkm/filter/density_estimate/ParticleDensityBase.h new file mode 100644 index 000000000..90c1ae512 --- /dev/null +++ b/vtkm/filter/density_estimate/ParticleDensityBase.h @@ -0,0 +1,75 @@ +//============================================================================ +// 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_density_estimate_ParticleDensityBase_h +#define vtk_m_filter_density_estimate_ParticleDensityBase_h + +#include +#include + +namespace vtkm +{ +namespace filter +{ +namespace density_estimate +{ +class VTKM_FILTER_DENSITY_ESTIMATE_EXPORT ParticleDensityBase : public vtkm::filter::NewFilterField +{ +protected: + ParticleDensityBase(const vtkm::Id3& dimension, + const vtkm::Vec3f& origin, + const vtkm::Vec3f& spacing) + : Dimension(dimension) + , Origin(origin) + , Spacing(spacing) + , ComputeNumberDensity(false) + , DivideByVolume(true) + { + } + + ParticleDensityBase(const vtkm::Id3& dimension, const vtkm::Bounds& bounds) + : Dimension(dimension) + , Origin({ static_cast(bounds.X.Min), + static_cast(bounds.Y.Min), + static_cast(bounds.Z.Min) }) + , Spacing(vtkm::Vec3f{ static_cast(bounds.X.Length()), + static_cast(bounds.Y.Length()), + static_cast(bounds.Z.Length()) } / + Dimension) + , ComputeNumberDensity(false) + , DivideByVolume(true) + { + } + +public: + VTKM_CONT void SetComputeNumberDensity(bool yes) { this->ComputeNumberDensity = yes; } + + VTKM_CONT bool GetComputeNumberDensity() const { return this->ComputeNumberDensity; } + + VTKM_CONT void SetDivideByVolume(bool yes) { this->DivideByVolume = yes; } + + VTKM_CONT bool GetDivideByVolume() const { return this->DivideByVolume; } + +protected: + // Note: we are using the paradoxical "const ArrayHandle&" parameter whose content can actually + // be change by the function. + VTKM_CONT void DoDivideByVolume(const vtkm::cont::UnknownArrayHandle& array) const; + + vtkm::Id3 Dimension; // Cell dimension + vtkm::Vec3f Origin; + vtkm::Vec3f Spacing; + bool ComputeNumberDensity; + bool DivideByVolume; +}; +} // namespace density_estimate +} // namespace filter +} // namespace vtkm + +#endif //vtk_m_filter_density_estimate_ParticleDensityBase_h diff --git a/vtkm/filter/ParticleDensityCloudInCell.hxx b/vtkm/filter/density_estimate/ParticleDensityCloudInCell.cxx similarity index 58% rename from vtkm/filter/ParticleDensityCloudInCell.hxx rename to vtkm/filter/density_estimate/ParticleDensityCloudInCell.cxx index 1070a5347..4a0efd94b 100644 --- a/vtkm/filter/ParticleDensityCloudInCell.hxx +++ b/vtkm/filter/density_estimate/ParticleDensityCloudInCell.cxx @@ -8,13 +8,9 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_filter_particle_density_cic_hxx -#define vtk_m_filter_particle_density_cic_hxx - -#include #include #include -#include +#include #include namespace vtkm @@ -74,25 +70,22 @@ namespace vtkm { namespace filter { -inline VTKM_CONT ParticleDensityCloudInCell::ParticleDensityCloudInCell(const vtkm::Id3& dimension, - const vtkm::Vec3f& origin, - const vtkm::Vec3f& spacing) +namespace density_estimate +{ +VTKM_CONT ParticleDensityCloudInCell::ParticleDensityCloudInCell(const vtkm::Id3& dimension, + const vtkm::Vec3f& origin, + const vtkm::Vec3f& spacing) : Superclass(dimension, origin, spacing) { } -inline VTKM_CONT ParticleDensityCloudInCell::ParticleDensityCloudInCell(const Id3& dimension, - const vtkm::Bounds& bounds) +VTKM_CONT ParticleDensityCloudInCell::ParticleDensityCloudInCell(const Id3& dimension, + const vtkm::Bounds& bounds) : Superclass(dimension, bounds) { } -template -inline VTKM_CONT vtkm::cont::DataSet ParticleDensityCloudInCell::DoExecute( - const cont::DataSet& dataSet, - const cont::ArrayHandle& field, - const vtkm::filter::FieldMetadata&, - PolicyBase) +VTKM_CONT vtkm::cont::DataSet ParticleDensityCloudInCell::DoExecute(const cont::DataSet& input) { // Unlike ParticleDensityNGP, particle deposit mass on the grid points, thus it is natural to // return the density as PointField; @@ -104,30 +97,56 @@ inline VTKM_CONT vtkm::cont::DataSet ParticleDensityCloudInCell::DoExecute( locator.SetCoordinates(uniform.GetCoordinateSystem()); locator.Update(); - auto coords = dataSet.GetCoordinateSystem().GetDataAsMultiplexer(); + auto coords = input.GetCoordinateSystem().GetDataAsMultiplexer(); - vtkm::cont::ArrayHandle density; - vtkm::cont::ArrayCopy(vtkm::cont::ArrayHandleConstant(0, uniform.GetNumberOfPoints()), - density); + auto resolveType = [&, this](const auto& concrete) { + // use std::decay to remove const ref from the decltype of concrete. + using T = typename std::decay_t::ValueType; - this->Invoke(vtkm::worklet::CICWorklet{}, - coords, - field, - locator, - uniform.GetCellSet().template AsCellSet>(), - density); + // We create an ArrayHandle and pass it to the Worklet as AtomicArrayInOut. + // However, the ArrayHandle needs to be allocated and initialized first. + vtkm::cont::ArrayHandle density; + density.AllocateAndFill(uniform.GetNumberOfPoints(), 0); - if (DivideByVolume) - { - auto volume = this->Spacing[0] * this->Spacing[1] * this->Spacing[2]; - this->Invoke(DivideByVolumeWorklet{ volume }, density); - } + this->Invoke(vtkm::worklet::CICWorklet{}, + coords, + concrete, + locator, + uniform.GetCellSet().template AsCellSet>(), + density); - uniform.AddField(vtkm::cont::make_FieldPoint("density", density)); + if (DivideByVolume) + { + this->DoDivideByVolume(density); + } + uniform.AddField(vtkm::cont::make_FieldPoint("density", density)); + }; + + // Note: This is the so called Immediately-Invoked Function Expression (IIFE). Here we define + // a lambda expression and immediately call it at the end. This allows us to not declare an + // UnknownArrayHandle first and then assign it in the if-else statement. If I really want to + // show-off, I can even inline the `fieldArray` variable and turn it into a long expression. + auto fieldArray = [&, this]() -> vtkm::cont::UnknownArrayHandle { + if (this->ComputeNumberDensity) + { + return vtkm::cont::make_ArrayHandleConstant(vtkm::FloatDefault{ 1 }, + input.GetNumberOfPoints()); + } + else + { + return this->GetFieldFromDataSet(input).GetData(); + } + }(); + fieldArray.CastAndCallForTypes< + vtkm::TypeListFieldScalar, + vtkm::ListAppend>>( + resolveType); + + // Deposition of the input field to the output field is already mapping. No need to map other + // fields. return uniform; } - -} -} -#endif // vtk_m_filter_particle_density_cic_hxx +} // namespace density_estimate +} // namespace filter +} // namespace vtkm diff --git a/vtkm/filter/density_estimate/ParticleDensityCloudInCell.h b/vtkm/filter/density_estimate/ParticleDensityCloudInCell.h new file mode 100644 index 000000000..9d3f99932 --- /dev/null +++ b/vtkm/filter/density_estimate/ParticleDensityCloudInCell.h @@ -0,0 +1,56 @@ +//============================================================================ +// 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_density_estimate_ParticleDensityCIC_h +#define vtk_m_filter_density_estimate_ParticleDensityCIC_h + +#include + +namespace vtkm +{ +namespace filter +{ +namespace density_estimate +{ +/// \brief Estimate the density of particles using the Cloud-in-Cell method +/// This filter treats the CoordinateSystem of a DataSet as positions of particles. +/// The particles are infinitesimal in size with finite mass (or other scalar attributes +/// such as charge). The filter estimates density by imposing a regular grid as +/// specified in the constructor. It spreads the mass of each particle to its 8 nearest +/// neighboring grid points and summing the contribution of particles for each point +/// in the grid. +/// The mass of particles is established by setting the active field (using SetActiveField). +/// Note that the "mass" can actually be another quantity. For example, you could use +/// electrical charge in place of mass to compute the charge density. +/// Once the sum of the mass is computed for each grid point, the mass is divided by the +/// volume of the cell. Thus, the density will be computed as the units of the mass field +/// per the cubic units of the coordinate system. If you just want a sum of the mass in each +/// cell, turn off the DivideByVolume feature of this filter. +/// In addition, you can also simply count the number of particles in each cell by calling +/// SetComputeNumberDensity(true). +class VTKM_FILTER_DENSITY_ESTIMATE_EXPORT ParticleDensityCloudInCell : public ParticleDensityBase +{ +public: + using Superclass = ParticleDensityBase; + + ParticleDensityCloudInCell(const vtkm::Id3& dimension, + const vtkm::Vec3f& origin, + const vtkm::Vec3f& spacing); + + ParticleDensityCloudInCell(const Id3& dimension, const vtkm::Bounds& bounds); + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; +}; +} // namespace density_estimate +} // namespace filter +} // namespace vtkm + +#endif // vtk_m_filter_density_estimate_ParticleDensityCIC_h diff --git a/vtkm/filter/ParticleDensityNearestGridPoint.hxx b/vtkm/filter/density_estimate/ParticleDensityNearestGridPoint.cxx similarity index 56% rename from vtkm/filter/ParticleDensityNearestGridPoint.hxx rename to vtkm/filter/density_estimate/ParticleDensityNearestGridPoint.cxx index c1c866fdb..17804f90a 100644 --- a/vtkm/filter/ParticleDensityNearestGridPoint.hxx +++ b/vtkm/filter/density_estimate/ParticleDensityNearestGridPoint.cxx @@ -8,14 +8,9 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_filter_particle_density_ngp_hxx -#define vtk_m_filter_particle_density_ngp_hxx - -#include -#include #include #include -#include +#include #include namespace vtkm @@ -57,7 +52,9 @@ namespace vtkm { namespace filter { -inline VTKM_CONT ParticleDensityNearestGridPoint::ParticleDensityNearestGridPoint( +namespace density_estimate +{ +VTKM_CONT ParticleDensityNearestGridPoint::ParticleDensityNearestGridPoint( const vtkm::Id3& dimension, const vtkm::Vec3f& origin, const vtkm::Vec3f& spacing) @@ -65,20 +62,15 @@ inline VTKM_CONT ParticleDensityNearestGridPoint::ParticleDensityNearestGridPoin { } -inline VTKM_CONT ParticleDensityNearestGridPoint::ParticleDensityNearestGridPoint( +VTKM_CONT ParticleDensityNearestGridPoint::ParticleDensityNearestGridPoint( const Id3& dimension, const vtkm::Bounds& bounds) : Superclass(dimension, bounds) { } -template -inline VTKM_CONT vtkm::cont::DataSet ParticleDensityNearestGridPoint::DoExecute( - const vtkm::cont::DataSet& dataSet, - const vtkm::cont::ArrayHandle& - field, // particles' scala field to be deposited to the mesh, e.g. mass or charge - const vtkm::filter::FieldMetadata&, - vtkm::filter::PolicyBase) +VTKM_CONT vtkm::cont::DataSet ParticleDensityNearestGridPoint::DoExecute( + const vtkm::cont::DataSet& input) { // TODO: it really doesn't need to be a UniformGrid, any CellSet with CellLocator will work. // Make it another input rather an output generated. @@ -96,27 +88,51 @@ inline VTKM_CONT vtkm::cont::DataSet ParticleDensityNearestGridPoint::DoExecute( locator.SetCoordinates(uniform.GetCoordinateSystem()); locator.Update(); - auto coords = dataSet.GetCoordinateSystem().GetDataAsMultiplexer(); + auto coords = input.GetCoordinateSystem().GetDataAsMultiplexer(); - // We create an ArrayHandle and pass it to the Worklet as AtomicArrayInOut. - // However the ArrayHandle needs to be allocated and initialized first. The - // easiest way to do it is to copy from an ArrayHandleConstant - vtkm::cont::ArrayHandle density; - vtkm::cont::ArrayCopy(vtkm::cont::ArrayHandleConstant(0, uniform.GetNumberOfCells()), density); + auto resolveType = [&, this](const auto& concrete) { + // use std::decay to remove const ref from the decltype of concrete. + using T = typename std::decay_t::ValueType; - this->Invoke(vtkm::worklet::NGPWorklet{}, coords, field, locator, density); + // We create an ArrayHandle and pass it to the Worklet as AtomicArrayInOut. + // However, the ArrayHandle needs to be allocated and initialized first. + vtkm::cont::ArrayHandle density; + density.AllocateAndFill(uniform.GetNumberOfPoints(), 0); - if (DivideByVolume) - { - auto volume = this->Spacing[0] * this->Spacing[1] * this->Spacing[2]; - this->Invoke(DivideByVolumeWorklet{ volume }, density); - } + this->Invoke(vtkm::worklet::NGPWorklet{}, coords, concrete, locator, density); - uniform.AddField(vtkm::cont::make_FieldCell("density", density)); + if (DivideByVolume) + { + this->DoDivideByVolume(density); + } + uniform.AddField(vtkm::cont::make_FieldCell("density", density)); + }; + + // Note: This is the so called Immediately-Invoked Function Expression (IIFE). Here we define + // a lambda expression and immediately call it at the end. This allows us to not declare an + // UnknownArrayHandle first and then assign it in the if-else statement. If I really want to + // show-off, I can even inline the `fieldArray` variable and turn it into a long expression. + auto fieldArray = [&, this]() -> vtkm::cont::UnknownArrayHandle { + if (this->ComputeNumberDensity) + { + return vtkm::cont::make_ArrayHandleConstant(vtkm::FloatDefault{ 1 }, + input.GetNumberOfPoints()); + } + else + { + return this->GetFieldFromDataSet(input).GetData(); + } + }(); + fieldArray.CastAndCallForTypes< + vtkm::TypeListFieldScalar, + vtkm::ListAppend>>( + resolveType); + + // Deposition of the input field to the output field is already mapping. No need to map other + // fields. return uniform; } - } } -#endif //vtk_m_filter_particle_density_ngp_hxx +} diff --git a/vtkm/filter/density_estimate/ParticleDensityNearestGridPoint.h b/vtkm/filter/density_estimate/ParticleDensityNearestGridPoint.h new file mode 100644 index 000000000..f95947f2e --- /dev/null +++ b/vtkm/filter/density_estimate/ParticleDensityNearestGridPoint.h @@ -0,0 +1,55 @@ +//============================================================================ +// 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_density_estimate_ParticleDensityNGP_h +#define vtk_m_filter_density_estimate_ParticleDensityNGP_h + +#include + +namespace vtkm +{ +namespace filter +{ +namespace density_estimate +{ +/// \brief Estimate the density of particles using the Nearest Grid Point method +/// This filter treats the CoordinateSystem of a DataSet as positions of particles. +/// The particles are infinitesimal in size with finite mass (or other scalar attributes +/// such as charge). The filter estimates density by imposing a regular grid as +/// specified in the constructor and summing the mass of particles within each cell +/// in the grid. +/// The mass of particles is established by setting the active field (using SetActiveField). +/// Note that the "mass" can actually be another quantity. For example, you could use +/// electrical charge in place of mass to compute the charge density. +/// Once the sum of the mass is computed for each grid cell, the mass is divided by the +/// volume of the cell. Thus, the density will be computed as the units of the mass field +/// per the cubic units of the coordinate system. If you just want a sum of the mass in each +/// cell, turn off the DivideByVolume feature of this filter. +/// In addition, you can also simply count the number of particles in each cell by calling +/// SetComputeNumberDensity(true). +class VTKM_FILTER_DENSITY_ESTIMATE_EXPORT ParticleDensityNearestGridPoint + : public ParticleDensityBase +{ +public: + using Superclass = ParticleDensityBase; + + ParticleDensityNearestGridPoint(const vtkm::Id3& dimension, + const vtkm::Vec3f& origin, + const vtkm::Vec3f& spacing); + + ParticleDensityNearestGridPoint(const vtkm::Id3& dimension, const vtkm::Bounds& bounds); + +private: + VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override; +}; +} // namespace density_estimate +} // namespace filter +} // namespace vtkm +#endif //vtk_m_filter_density_estimate_ParticleDensityNGP_h diff --git a/vtkm/filter/density_estimate/testing/CMakeLists.txt b/vtkm/filter/density_estimate/testing/CMakeLists.txt new file mode 100644 index 000000000..0df78a255 --- /dev/null +++ b/vtkm/filter/density_estimate/testing/CMakeLists.txt @@ -0,0 +1,28 @@ +##============================================================================ +## 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. +##============================================================================ + +set(unit_tests + UnitTestEntropyFilter.cxx + UnitTestHistogramFilter.cxx + UnitTestNDEntropyFilter.cxx + UnitTestNDHistogramFilter.cxx + UnitTestPartitionedDataSetHistogramFilter.cxx + UnitTestParticleDensity.cxx) + +set(libraries + vtkm_filter_density_estimate + vtkm_source) + +vtkm_unit_tests( + SOURCES ${unit_tests} + LIBRARIES ${libraries} + ALL_BACKENDS # use ArrayCopy + USE_VTKM_JOB_POOL +) diff --git a/vtkm/filter/testing/UnitTestEntropyFilter.cxx b/vtkm/filter/density_estimate/testing/UnitTestEntropyFilter.cxx similarity index 95% rename from vtkm/filter/testing/UnitTestEntropyFilter.cxx rename to vtkm/filter/density_estimate/testing/UnitTestEntropyFilter.cxx index f77bc520e..7e3f06f15 100644 --- a/vtkm/filter/testing/UnitTestEntropyFilter.cxx +++ b/vtkm/filter/density_estimate/testing/UnitTestEntropyFilter.cxx @@ -8,7 +8,7 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include +#include #include #include @@ -24,7 +24,7 @@ void TestEntropy() vtkm::source::Tangle tangle(dims); vtkm::cont::DataSet dataSet = tangle.Execute(); - vtkm::filter::Entropy entropyFilter; + vtkm::filter::density_estimate::Entropy entropyFilter; ///// calculate entropy of "tangle" field of the data set ///// entropyFilter.SetNumberOfBins(50); //set number of bins diff --git a/vtkm/filter/testing/UnitTestHistogramFilter.cxx b/vtkm/filter/density_estimate/testing/UnitTestHistogramFilter.cxx similarity index 99% rename from vtkm/filter/testing/UnitTestHistogramFilter.cxx rename to vtkm/filter/density_estimate/testing/UnitTestHistogramFilter.cxx index 5074a9554..5b6c8b6eb 100644 --- a/vtkm/filter/testing/UnitTestHistogramFilter.cxx +++ b/vtkm/filter/density_estimate/testing/UnitTestHistogramFilter.cxx @@ -8,7 +8,7 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include +#include #include #include @@ -295,7 +295,7 @@ void TestHistogram() // Data attached is the poisson distribution vtkm::cont::DataSet ds = MakeTestDataSet(); - vtkm::filter::Histogram histogram; + vtkm::filter::density_estimate::Histogram histogram; // Run data histogram.SetNumberOfBins(10); diff --git a/vtkm/filter/testing/UnitTestNDEntropyFilter.cxx b/vtkm/filter/density_estimate/testing/UnitTestNDEntropyFilter.cxx similarity index 99% rename from vtkm/filter/testing/UnitTestNDEntropyFilter.cxx rename to vtkm/filter/density_estimate/testing/UnitTestNDEntropyFilter.cxx index 0fe67abe0..1fe9c0a25 100644 --- a/vtkm/filter/testing/UnitTestNDEntropyFilter.cxx +++ b/vtkm/filter/density_estimate/testing/UnitTestNDEntropyFilter.cxx @@ -8,7 +8,7 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include +#include #include #include @@ -177,7 +177,7 @@ void RunTest() { vtkm::cont::DataSet ds = MakeTestDataSet(); - vtkm::filter::NDEntropy ndEntropyFilter; + vtkm::filter::density_estimate::NDEntropy ndEntropyFilter; ndEntropyFilter.AddFieldAndBin("fieldA", 10); ndEntropyFilter.AddFieldAndBin("fieldB", 10); diff --git a/vtkm/filter/testing/UnitTestNDHistogramFilter.cxx b/vtkm/filter/density_estimate/testing/UnitTestNDHistogramFilter.cxx similarity index 97% rename from vtkm/filter/testing/UnitTestNDHistogramFilter.cxx rename to vtkm/filter/density_estimate/testing/UnitTestNDHistogramFilter.cxx index e368377a3..09e61fcd6 100644 --- a/vtkm/filter/testing/UnitTestNDHistogramFilter.cxx +++ b/vtkm/filter/density_estimate/testing/UnitTestNDHistogramFilter.cxx @@ -8,10 +8,8 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include - -#include #include +#include namespace { @@ -60,7 +58,7 @@ void RunTest() { vtkm::cont::DataSet ds = MakeTestDataSet(); - vtkm::filter::NDHistogram ndHistFilter; + vtkm::filter::density_estimate::NDHistogram ndHistFilter; ndHistFilter.AddFieldAndBin("fieldA", 4); ndHistFilter.AddFieldAndBin("fieldB", 4); diff --git a/vtkm/filter/testing/UnitTestParticleDensity.cxx b/vtkm/filter/density_estimate/testing/UnitTestParticleDensity.cxx similarity index 92% rename from vtkm/filter/testing/UnitTestParticleDensity.cxx rename to vtkm/filter/density_estimate/testing/UnitTestParticleDensity.cxx index 1cf7bb039..8ea2975f4 100644 --- a/vtkm/filter/testing/UnitTestParticleDensity.cxx +++ b/vtkm/filter/density_estimate/testing/UnitTestParticleDensity.cxx @@ -11,8 +11,8 @@ #include #include #include -#include -#include +#include +#include #include void TestNGP() @@ -41,7 +41,7 @@ void TestNGP() dataSet.AddCellField("mass", mass); auto cellDims = vtkm::Id3{ 3, 3, 3 }; - vtkm::filter::ParticleDensityNearestGridPoint filter{ + vtkm::filter::density_estimate::ParticleDensityNearestGridPoint filter{ cellDims, { 0.f, 0.f, 0.f }, vtkm::Vec3f{ 1.f / 3.f, 1.f / 3.f, 1.f / 3.f } }; filter.SetActiveField("mass"); @@ -91,9 +91,9 @@ void TestCIC() dataSet.AddCellField("mass", mass); auto cellDims = vtkm::Id3{ 3, 3, 3 }; - vtkm::filter::ParticleDensityCloudInCell filter{ cellDims, - { 0.f, 0.f, 0.f }, - vtkm::Vec3f{ 1.f / 3.f, 1.f / 3.f, 1.f / 3.f } }; + vtkm::filter::density_estimate::ParticleDensityCloudInCell filter{ + cellDims, { 0.f, 0.f, 0.f }, vtkm::Vec3f{ 1.f / 3.f, 1.f / 3.f, 1.f / 3.f } + }; filter.SetActiveField("mass"); auto density = filter.Execute(dataSet); diff --git a/vtkm/filter/testing/UnitTestPartitionedDataSetHistogramFilter.cxx b/vtkm/filter/density_estimate/testing/UnitTestPartitionedDataSetHistogramFilter.cxx similarity index 97% rename from vtkm/filter/testing/UnitTestPartitionedDataSetHistogramFilter.cxx rename to vtkm/filter/density_estimate/testing/UnitTestPartitionedDataSetHistogramFilter.cxx index 4423e3281..20a58c810 100644 --- a/vtkm/filter/testing/UnitTestPartitionedDataSetHistogramFilter.cxx +++ b/vtkm/filter/density_estimate/testing/UnitTestPartitionedDataSetHistogramFilter.cxx @@ -7,7 +7,7 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include +#include #include #include @@ -102,7 +102,7 @@ static void TestPartitionedDataSetHistogram() AddField(partition2, 100.0, 500.0, 1024, "double"); mb.AppendPartition(partition2); - vtkm::filter::Histogram histogram; + vtkm::filter::density_estimate::Histogram histogram; histogram.SetActiveField("double"); auto result = histogram.Execute(mb); VTKM_TEST_ASSERT(result.GetNumberOfPartitions() == 1, "Expecting 1 partition."); diff --git a/vtkm/filter/density_estimate/worklet/CMakeLists.txt b/vtkm/filter/density_estimate/worklet/CMakeLists.txt new file mode 100644 index 000000000..d3b3bd1c7 --- /dev/null +++ b/vtkm/filter/density_estimate/worklet/CMakeLists.txt @@ -0,0 +1,17 @@ +##============================================================================ +## 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. +##============================================================================ + +set(headers + FieldEntropy.h + FieldHistogram.h + NDimsEntropy.h + NDimsHistogram.h) + +vtkm_declare_headers(${headers}) diff --git a/vtkm/worklet/FieldEntropy.h b/vtkm/filter/density_estimate/worklet/FieldEntropy.h similarity index 97% rename from vtkm/worklet/FieldEntropy.h rename to vtkm/filter/density_estimate/worklet/FieldEntropy.h index 2b8523e48..d9688fbdb 100644 --- a/vtkm/worklet/FieldEntropy.h +++ b/vtkm/filter/density_estimate/worklet/FieldEntropy.h @@ -15,8 +15,8 @@ #include #include #include +#include #include -#include #include #include diff --git a/vtkm/worklet/FieldHistogram.h b/vtkm/filter/density_estimate/worklet/FieldHistogram.h similarity index 100% rename from vtkm/worklet/FieldHistogram.h rename to vtkm/filter/density_estimate/worklet/FieldHistogram.h diff --git a/vtkm/worklet/NDimsEntropy.h b/vtkm/filter/density_estimate/worklet/NDimsEntropy.h similarity index 97% rename from vtkm/worklet/NDimsEntropy.h rename to vtkm/filter/density_estimate/worklet/NDimsEntropy.h index e64aef44a..b3d75b3e9 100644 --- a/vtkm/worklet/NDimsEntropy.h +++ b/vtkm/filter/density_estimate/worklet/NDimsEntropy.h @@ -15,8 +15,8 @@ #include #include #include +#include #include -#include #include #include diff --git a/vtkm/worklet/NDimsHistogram.h b/vtkm/filter/density_estimate/worklet/NDimsHistogram.h similarity index 100% rename from vtkm/worklet/NDimsHistogram.h rename to vtkm/filter/density_estimate/worklet/NDimsHistogram.h diff --git a/vtkm/filter/testing/CMakeLists.txt b/vtkm/filter/testing/CMakeLists.txt index 4ec3e73a0..6bc2716be 100644 --- a/vtkm/filter/testing/CMakeLists.txt +++ b/vtkm/filter/testing/CMakeLists.txt @@ -24,14 +24,12 @@ set(unit_tests UnitTestContourTreeUniformDistributedFilter.cxx UnitTestCoordinateSystemTransform.cxx UnitTestCrossProductFilter.cxx - UnitTestEntropyFilter.cxx UnitTestFieldMetadata.cxx UnitTestFieldSelection.cxx UnitTestFieldToColors.cxx UnitTestGradientExplicit.cxx UnitTestGradientUniform.cxx UnitTestGhostCellClassify.cxx - UnitTestHistogramFilter.cxx UnitTestImageDifferenceFilter.cxx UnitTestImageMedianFilter.cxx UnitTestLagrangianFilter.cxx @@ -41,11 +39,7 @@ set(unit_tests UnitTestMeshQualityFilter.cxx UnitTestMIRFilter.cxx UnitTestMultiBlockFilter.cxx - UnitTestNDEntropyFilter.cxx - UnitTestNDHistogramFilter.cxx - UnitTestParticleDensity.cxx UnitTestPartitionedDataSetFilters.cxx - UnitTestPartitionedDataSetHistogramFilter.cxx UnitTestPointAverageFilter.cxx UnitTestPointAverageCellSetExtrude.cxx UnitTestPointElevationFilter.cxx diff --git a/vtkm/worklet/CMakeLists.txt b/vtkm/worklet/CMakeLists.txt index e138ac121..97ccb698b 100644 --- a/vtkm/worklet/CMakeLists.txt +++ b/vtkm/worklet/CMakeLists.txt @@ -27,8 +27,6 @@ set(headers DispatcherPointNeighborhood.h DispatcherReduceByKey.h DotProduct.h - FieldEntropy.h - FieldHistogram.h FieldStatistics.h Gradient.h ImageDifference.h @@ -43,9 +41,7 @@ set(headers MaskSelect.h MeshQuality.h MIR.h - NDimsEntropy.h NDimsHistMarginalization.h - NDimsHistogram.h Normalize.h OrientCellNormals.h OrientNormals.h diff --git a/vtkm/worklet/testing/CMakeLists.txt b/vtkm/worklet/testing/CMakeLists.txt index 59559495c..ddf412678 100644 --- a/vtkm/worklet/testing/CMakeLists.txt +++ b/vtkm/worklet/testing/CMakeLists.txt @@ -30,15 +30,12 @@ set(unit_tests UnitTestCrossProduct.cxx UnitTestDescriptiveStatistics.cxx UnitTestDotProduct.cxx - UnitTestFieldHistogram.cxx UnitTestFieldStatistics.cxx UnitTestKeys.cxx UnitTestMagnitude.cxx UnitTestMaskIndices.cxx UnitTestMaskSelect.cxx UnitTestNormalize.cxx - UnitTestNDimsEntropy.cxx - UnitTestNDimsHistogram.cxx UnitTestNDimsHistMarginalization.cxx UnitTestOrientNormals.cxx UnitTestParticleAdvection.cxx diff --git a/vtkm/worklet/testing/UnitTestFieldHistogram.cxx b/vtkm/worklet/testing/UnitTestFieldHistogram.cxx deleted file mode 100644 index 734cea8dc..000000000 --- a/vtkm/worklet/testing/UnitTestFieldHistogram.cxx +++ /dev/null @@ -1,323 +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 - -#include -#include - -// -// Make a simple 2D, 1000 point dataset populated with stat distributions -// -vtkm::cont::DataSet MakeTestDataSet() -{ - vtkm::cont::DataSet dataSet; - - const int dimension = 2; - const int xVerts = 20; - const int yVerts = 50; - const int nVerts = xVerts * yVerts; - - const int xCells = xVerts - 1; - const int yCells = yVerts - 1; - const int nCells = xCells * yCells; - - // Poisson distribution [0:49] mean = 10 - vtkm::Float32 poisson[nVerts] = { - 8, 10, 9, 8, 14, 11, 12, 9, 19, 7, 8, 11, 7, 10, 11, 11, 11, 6, 8, 8, 7, 15, 9, 7, - 8, 10, 9, 10, 10, 12, 7, 6, 14, 10, 14, 10, 7, 11, 13, 9, 13, 11, 10, 10, 12, 12, 7, 12, - 10, 11, 12, 8, 13, 9, 5, 12, 11, 9, 5, 9, 12, 9, 6, 10, 11, 9, 9, 11, 9, 7, 7, 18, - 16, 13, 12, 8, 10, 11, 9, 8, 17, 3, 15, 15, 9, 10, 10, 8, 10, 9, 7, 9, 8, 10, 13, 9, - 7, 11, 7, 10, 13, 10, 11, 9, 10, 7, 10, 6, 12, 6, 9, 7, 6, 12, 12, 9, 12, 12, 11, 6, - 1, 12, 8, 13, 14, 8, 8, 10, 7, 7, 6, 7, 5, 11, 6, 11, 13, 8, 13, 5, 9, 12, 7, 11, - 10, 15, 11, 9, 7, 12, 15, 7, 8, 7, 12, 8, 21, 16, 13, 11, 10, 14, 12, 11, 12, 14, 7, 11, - 7, 12, 16, 8, 10, 8, 9, 7, 8, 7, 13, 13, 11, 15, 7, 7, 6, 11, 7, 12, 12, 13, 14, 11, - 13, 11, 11, 9, 15, 8, 6, 11, 12, 10, 11, 7, 6, 14, 11, 10, 12, 5, 8, 9, 11, 15, 11, 10, - 17, 14, 9, 10, 10, 12, 11, 13, 13, 12, 11, 7, 8, 10, 7, 11, 10, 5, 8, 10, 13, 13, 12, 6, - 10, 7, 13, 8, 11, 7, 10, 7, 8, 7, 14, 16, 9, 11, 8, 11, 9, 15, 11, 10, 10, 12, 7, 7, - 11, 7, 5, 17, 9, 11, 11, 11, 10, 17, 10, 15, 7, 11, 12, 16, 9, 8, 11, 14, 9, 22, 8, 8, - 8, 13, 12, 12, 1, 14, 15, 6, 15, 8, 11, 16, 14, 8, 6, 9, 8, 9, 9, 10, 8, 6, 13, 8, - 6, 12, 11, 12, 13, 8, 6, 6, 5, 6, 10, 9, 11, 12, 14, 12, 10, 11, 10, 10, 8, 13, 8, 11, - 7, 13, 13, 12, 12, 13, 15, 4, 9, 16, 7, 9, 8, 10, 6, 9, 11, 12, 6, 7, 14, 6, 4, 15, - 5, 18, 9, 9, 11, 12, 9, 5, 6, 7, 15, 6, 11, 14, 8, 12, 6, 9, 5, 9, 14, 9, 12, 6, - 9, 14, 11, 12, 12, 13, 15, 9, 8, 7, 13, 12, 7, 13, 6, 9, 10, 10, 10, 9, 11, 5, 9, 13, - 16, 9, 10, 8, 9, 6, 13, 12, 8, 12, 9, 12, 17, 8, 11, 10, 8, 7, 11, 7, 13, 13, 10, 14, - 11, 9, 6, 6, 14, 16, 5, 9, 13, 11, 12, 7, 4, 6, 9, 11, 11, 10, 12, 9, 7, 13, 8, 8, - 12, 5, 10, 7, 11, 11, 10, 10, 14, 6, 8, 8, 3, 12, 16, 11, 11, 7, 6, 12, 11, 5, 9, 12, - 9, 13, 7, 8, 9, 9, 12, 7, 9, 8, 12, 11, 6, 10, 6, 7, 6, 11, 10, 8, 9, 8, 4, 19, - 12, 6, 10, 9, 6, 12, 9, 14, 7, 8, 11, 7, 7, 12, 13, 9, 13, 12, 8, 6, 10, 17, 19, 10, - 10, 13, 5, 11, 8, 10, 8, 16, 12, 6, 6, 7, 10, 9, 12, 8, 5, 10, 7, 18, 9, 12, 10, 4, - 9, 9, 15, 15, 6, 7, 7, 11, 12, 4, 8, 18, 5, 12, 12, 11, 10, 14, 9, 9, 10, 8, 10, 8, - 10, 9, 9, 4, 10, 12, 5, 13, 6, 9, 7, 5, 12, 8, 11, 10, 9, 17, 9, 9, 8, 11, 18, 11, - 10, 9, 4, 13, 10, 15, 5, 10, 9, 7, 7, 8, 10, 6, 6, 19, 10, 16, 7, 7, 9, 10, 10, 13, - 10, 10, 14, 13, 12, 8, 7, 13, 12, 11, 13, 12, 9, 8, 6, 8, 10, 3, 8, 8, 12, 12, 13, 13, - 10, 5, 10, 7, 13, 7, 9, 5, 13, 7, 10, 8, 13, 11, 17, 9, 6, 14, 10, 10, 13, 9, 15, 8, - 15, 9, 12, 11, 12, 8, 3, 9, 8, 10, 12, 8, 14, 13, 12, 11, 12, 9, 18, 10, 13, 7, 4, 4, - 11, 8, 3, 7, 9, 10, 12, 7, 11, 21, 9, 7, 8, 9, 10, 10, 11, 9, 15, 13, 21, 12, 8, 11, - 9, 10, 11, 9, 17, 8, 9, 8, 14, 6, 13, 9, 8, 11, 12, 12, 12, 11, 6, 13, 7, 9, 11, 15, - 17, 17, 11, 10, 7, 8, 11, 8, 6, 9, 13, 7, 9, 6, 5, 10, 7, 16, 16, 9, 7, 6, 14, 8, - 13, 16, 7, 7, 10, 11, 6, 10, 9, 9, 8, 14, 11, 9, 11, 9, 10, 11, 9, 8, 14, 11, 7, 12, - 11, 8, 9, 9, 10, 11, 11, 10, 9, 6, 6, 11, 16, 10, 7, 6, 6, 13, 18, 8, 12, 11, 14, 13, - 8, 8, 10, 17, 17, 6, 6, 10, 18, 5, 8, 11, 6, 6, 14, 10, 9, 6, 11, 6, 13, 12, 10, 6, - 9, 9, 9, 13, 7, 17, 10, 14, 10, 9, 10, 10, 11, 10, 11, 15, 13, 6, 12, 19, 10, 12, 12, 15, - 13, 10, 10, 13, 11, 13, 13, 17, 6, 5, 6, 7, 6, 9, 13, 11, 8, 12, 9, 6, 10, 16, 11, 12, - 5, 12, 14, 13, 13, 16, 11, 6, 12, 12, 15, 8, 7, 11, 8, 5, 10, 8, 9, 11, 9, 12, 10, 5, - 12, 11, 9, 6, 14, 12, 10, 11, 9, 6, 7, 12, 8, 12, 8, 15, 9, 8, 7, 9, 3, 6, 14, 7, - 8, 11, 9, 10, 12, 9, 10, 9, 8, 6, 12, 11, 6, 8, 9, 8, 15, 11, 7, 18, 12, 11, 10, 13, - 11, 11, 10, 7, 9, 8, 8, 11, 11, 13, 6, 12, 13, 16, 11, 11, 5, 12, 14, 15, 9, 14, 15, 6, - 8, 7, 6, 8, 9, 19, 7, 12, 11, 8, 14, 12, 10, 9, 3, 7 - }; - - // Normal distribution [0:49] mean = 25 standard deviation = 5.0 - vtkm::Float32 normal[nVerts] = { - 24, 19, 28, 19, 25, 28, 25, 22, 27, 26, 35, 26, 30, 28, 24, 23, 21, 31, 20, 11, 21, 22, 14, 25, - 20, 24, 24, 21, 24, 29, 26, 21, 32, 29, 23, 28, 31, 25, 23, 30, 18, 24, 22, 25, 33, 24, 22, 23, - 21, 17, 20, 28, 30, 18, 20, 32, 25, 24, 32, 15, 27, 24, 27, 19, 30, 27, 17, 24, 29, 23, 22, 19, - 24, 19, 28, 24, 25, 24, 25, 30, 24, 31, 30, 27, 25, 25, 25, 15, 29, 23, 29, 29, 21, 25, 35, 24, - 28, 10, 31, 23, 22, 22, 22, 33, 29, 27, 18, 27, 27, 24, 20, 20, 21, 29, 23, 31, 23, 23, 22, 23, - 30, 27, 28, 31, 16, 29, 25, 19, 33, 28, 25, 24, 15, 27, 37, 29, 15, 19, 14, 19, 24, 23, 30, 29, - 35, 22, 19, 26, 26, 14, 24, 30, 32, 23, 30, 29, 26, 27, 25, 23, 17, 26, 32, 29, 20, 17, 21, 23, - 22, 20, 36, 12, 26, 23, 15, 29, 24, 22, 26, 33, 24, 23, 20, 26, 22, 17, 26, 26, 34, 22, 26, 17, - 23, 18, 29, 27, 21, 29, 28, 29, 24, 25, 28, 19, 18, 21, 23, 23, 27, 25, 24, 25, 24, 25, 21, 25, - 21, 27, 23, 20, 29, 15, 28, 30, 24, 27, 17, 23, 16, 21, 25, 17, 27, 28, 21, 13, 19, 27, 16, 30, - 31, 25, 30, 17, 17, 25, 26, 22, 21, 17, 24, 17, 25, 22, 27, 14, 27, 24, 27, 25, 26, 31, 21, 23, - 30, 30, 22, 19, 23, 22, 23, 25, 24, 25, 24, 28, 26, 30, 18, 25, 30, 37, 27, 34, 28, 34, 25, 10, - 25, 22, 35, 30, 24, 32, 24, 34, 19, 29, 26, 16, 27, 17, 26, 23, 27, 25, 26, 21, 31, 21, 28, 15, - 32, 24, 23, 23, 18, 15, 22, 25, 16, 25, 31, 26, 25, 28, 24, 26, 23, 25, 33, 20, 27, 28, 24, 29, - 32, 20, 24, 20, 19, 32, 24, 6, 24, 21, 26, 18, 15, 30, 19, 26, 22, 30, 35, 23, 22, 30, 20, 22, - 18, 30, 28, 25, 16, 25, 27, 30, 18, 24, 30, 28, 20, 19, 20, 28, 21, 24, 15, 33, 20, 18, 20, 36, - 30, 26, 25, 18, 28, 27, 31, 31, 15, 26, 16, 22, 27, 14, 17, 27, 27, 22, 32, 30, 22, 34, 22, 25, - 20, 22, 26, 29, 28, 33, 18, 23, 20, 20, 27, 24, 28, 21, 25, 27, 25, 19, 19, 25, 19, 32, 29, 27, - 23, 21, 28, 33, 23, 23, 28, 26, 31, 19, 21, 29, 21, 27, 23, 32, 24, 26, 21, 28, 28, 24, 17, 31, - 27, 21, 19, 32, 28, 23, 30, 23, 29, 15, 26, 26, 15, 20, 25, 26, 27, 31, 21, 23, 23, 33, 28, 19, - 23, 22, 22, 25, 27, 17, 23, 17, 25, 28, 26, 30, 32, 31, 19, 25, 25, 19, 23, 29, 27, 23, 34, 22, - 13, 21, 32, 10, 20, 33, 21, 17, 29, 31, 14, 24, 23, 19, 19, 22, 17, 26, 37, 26, 22, 26, 38, 29, - 29, 27, 30, 20, 31, 14, 32, 32, 24, 23, 23, 18, 21, 31, 24, 20, 28, 15, 21, 25, 25, 20, 30, 25, - 22, 21, 21, 25, 24, 25, 18, 23, 28, 30, 20, 27, 27, 19, 10, 32, 24, 20, 29, 26, 25, 20, 25, 29, - 28, 24, 32, 26, 22, 19, 23, 27, 27, 29, 20, 25, 21, 30, 28, 31, 24, 19, 23, 19, 19, 18, 30, 18, - 16, 24, 20, 20, 30, 25, 29, 25, 31, 21, 28, 31, 24, 26, 27, 21, 24, 23, 26, 18, 32, 26, 28, 26, - 24, 26, 29, 30, 22, 20, 24, 28, 25, 29, 20, 21, 22, 15, 30, 27, 33, 26, 22, 32, 30, 31, 20, 19, - 24, 26, 27, 31, 17, 17, 33, 27, 16, 27, 27, 22, 27, 19, 24, 21, 17, 24, 28, 23, 26, 24, 19, 26, - 20, 24, 22, 19, 22, 21, 21, 28, 29, 39, 19, 16, 25, 29, 31, 22, 22, 29, 26, 22, 22, 22, 26, 23, - 23, 23, 30, 25, 25, 25, 27, 29, 18, 33, 21, 12, 22, 29, 12, 20, 35, 22, 34, 28, 18, 29, 21, 20, - 24, 33, 24, 26, 23, 34, 31, 25, 31, 22, 35, 21, 20, 29, 27, 22, 30, 22, 27, 23, 22, 32, 16, 19, - 27, 22, 24, 27, 21, 33, 25, 25, 19, 28, 20, 27, 21, 25, 28, 20, 27, 22, 21, 20, 26, 30, 33, 23, - 20, 24, 17, 23, 28, 35, 14, 23, 22, 28, 28, 26, 25, 18, 20, 28, 28, 22, 13, 24, 22, 20, 30, 26, - 26, 18, 22, 20, 23, 24, 20, 27, 34, 28, 18, 24, 34, 33, 25, 33, 37, 21, 20, 31, 19, 23, 29, 22, - 21, 24, 19, 27, 19, 32, 25, 23, 33, 26, 33, 27, 29, 30, 19, 22, 30, 19, 18, 24, 25, 17, 31, 19, - 31, 26, 22, 23, 28, 28, 25, 24, 19, 19, 27, 28, 23, 21, 29, 26, 31, 22, 22, 25, 16, 29, 21, 22, - 23, 25, 22, 21, 22, 19, 27, 26, 28, 30, 22, 21, 24, 22, 23, 26, 28, 22, 18, 25, 23, 27, 31, 19, - 15, 29, 20, 19, 27, 25, 21, 29, 22, 24, 25, 17, 36, 29, 22, 22, 24, 28, 27, 22, 26, 31, 29, 31, - 18, 25, 23, 16, 37, 27, 21, 31, 25, 24, 20, 23, 28, 33, 24, 21, 26, 20, 18, 31, 20, 24, 23, 19, - 27, 17, 23, 23, 20, 26, 28, 23, 26, 31, 25, 31, 19, 32, 26, 18, 19, 29, 20, 21, 15, 25, 27, 29, - 22, 22, 22, 26, 23, 22, 23, 29, 28, 20, 21, 22, 20, 22, 27, 25, 23, 32, 23, 20, 31, 20, 27, 26, - 34, 20, 22, 36, 21, 29, 25, 20, 21, 22, 29, 29, 25, 22, 24, 22 - }; - - //Chi squared distribution [0:49] degrees of freedom = 5.0 - vtkm::Float32 chiSquare[nVerts] = { - 3, 1, 4, 6, 5, 4, 8, 7, 2, 9, 2, 0, 0, 4, 3, 2, 5, 2, 3, 6, 3, 8, 3, 4, - 3, 3, 2, 7, 2, 10, 9, 6, 1, 1, 4, 7, 3, 3, 1, 4, 4, 3, 9, 4, 4, 7, 3, 2, - 4, 7, 3, 3, 2, 10, 1, 6, 2, 2, 3, 8, 3, 3, 6, 9, 4, 1, 4, 3, 16, 7, 0, 1, - 8, 7, 13, 3, 5, 0, 3, 8, 10, 3, 5, 5, 1, 5, 2, 1, 3, 2, 5, 3, 4, 3, 3, 3, - 3, 1, 13, 2, 3, 1, 2, 7, 3, 4, 1, 2, 5, 4, 4, 4, 2, 6, 3, 2, 7, 8, 1, 3, - 4, 1, 2, 0, 1, 6, 1, 8, 8, 1, 1, 4, 2, 1, 4, 3, 5, 4, 6, 4, 2, 3, 8, 8, - 3, 3, 3, 4, 5, 8, 8, 16, 7, 12, 4, 3, 14, 8, 3, 12, 5, 0, 5, 3, 5, 2, 9, 2, - 9, 4, 1, 0, 0, 4, 4, 6, 3, 4, 11, 2, 4, 7, 4, 2, 1, 9, 4, 3, 2, 5, 1, 5, - 3, 8, 2, 8, 1, 8, 0, 4, 1, 3, 2, 1, 2, 3, 2, 1, 8, 5, 4, 1, 9, 9, 1, 3, - 5, 0, 1, 6, 10, 8, 3, 12, 3, 4, 4, 7, 1, 3, 6, 4, 4, 6, 1, 4, 7, 5, 6, 11, - 6, 5, 2, 7, 2, 5, 3, 5, 6, 3, 6, 2, 1, 10, 8, 3, 7, 0, 2, 6, 9, 3, 11, 3, - 2, 5, 1, 4, 6, 10, 9, 1, 4, 3, 7, 12, 3, 10, 0, 2, 11, 2, 1, 0, 4, 1, 2, 16, - 5, 17, 7, 8, 2, 10, 10, 3, 1, 3, 2, 2, 4, 8, 4, 3, 2, 4, 4, 6, 8, 6, 2, 3, - 2, 4, 2, 4, 7, 10, 5, 3, 5, 2, 4, 6, 9, 3, 1, 1, 1, 1, 4, 2, 2, 7, 4, 9, - 2, 3, 5, 6, 2, 5, 1, 6, 5, 7, 8, 3, 7, 2, 2, 8, 6, 2, 10, 2, 1, 4, 5, 1, - 1, 1, 5, 6, 1, 1, 4, 5, 4, 2, 4, 3, 2, 7, 19, 4, 7, 2, 7, 5, 2, 5, 3, 8, - 4, 6, 7, 2, 0, 0, 2, 12, 6, 2, 2, 3, 5, 9, 4, 9, 2, 2, 7, 8, 3, 3, 10, 6, - 3, 2, 1, 6, 2, 4, 6, 3, 5, 8, 2, 3, 6, 14, 0, 3, 6, 5, 2, 7, 0, 3, 8, 5, - 3, 2, 2, 5, 1, 3, 12, 11, 16, 2, 1, 3, 7, 3, 1, 6, 4, 3, 12, 5, 1, 3, 1, 4, - 9, 1, 3, 3, 4, 4, 6, 7, 7, 5, 2, 4, 2, 3, 2, 2, 6, 4, 2, 2, 3, 5, 1, 4, - 9, 1, 0, 7, 6, 4, 3, 3, 7, 3, 3, 6, 2, 7, 9, 3, 1, 16, 5, 4, 3, 6, 3, 2, - 5, 2, 2, 4, 3, 1, 3, 3, 6, 3, 5, 9, 1, 10, 1, 7, 2, 2, 6, 7, 3, 5, 3, 7, - 2, 2, 2, 2, 6, 4, 3, 2, 5, 5, 3, 15, 4, 2, 7, 7, 4, 3, 3, 5, 1, 2, 9, 0, - 5, 7, 12, 2, 4, 8, 5, 7, 8, 3, 2, 2, 18, 1, 7, 2, 2, 1, 3, 3, 3, 7, 1, 9, - 8, 4, 3, 7, 6, 4, 5, 2, 0, 5, 1, 5, 10, 4, 2, 8, 2, 2, 0, 5, 6, 4, 5, 0, - 1, 5, 11, 3, 3, 4, 4, 2, 3, 5, 1, 6, 5, 7, 2, 2, 5, 7, 4, 8, 4, 1, 1, 7, - 2, 3, 9, 6, 13, 1, 5, 4, 6, 2, 4, 11, 2, 5, 5, 1, 4, 1, 4, 7, 1, 5, 8, 3, - 1, 10, 9, 13, 1, 7, 2, 9, 4, 3, 3, 10, 12, 2, 0, 4, 6, 5, 5, 1, 4, 7, 2, 12, - 7, 6, 5, 0, 6, 4, 4, 12, 1, 3, 10, 1, 9, 2, 2, 2, 1, 5, 5, 6, 9, 6, 4, 1, - 11, 6, 9, 3, 2, 7, 1, 7, 4, 3, 0, 3, 1, 12, 17, 2, 1, 6, 4, 4, 2, 1, 5, 5, - 3, 2, 2, 4, 6, 5, 4, 6, 11, 3, 12, 6, 3, 6, 3, 0, 6, 3, 7, 4, 8, 5, 14, 5, - 1, 9, 4, 6, 5, 3, 9, 3, 1, 1, 0, 3, 7, 3, 5, 1, 6, 2, 2, 6, 2, 12, 1, 0, - 6, 3, 3, 5, 4, 7, 2, 2, 15, 7, 3, 10, 4, 2, 6, 3, 4, 8, 3, 1, 5, 5, 5, 4, - 3, 7, 3, 4, 5, 5, 2, 4, 2, 5, 1, 12, 5, 6, 3, 2, 8, 5, 2, 3, 11, 11, 6, 5, - 0, 3, 3, 9, 4, 2, 11, 1, 5, 3, 5, 6, 3, 6, 4, 2, 4, 10, 11, 3, 3, 4, 1, 1, - 1, 3, 5, 5, 1, 1, 4, 1, 5, 1, 6, 8, 6, 4, 6, 7, 6, 3, 5, 3, 6, 6, 6, 4, - 0, 6, 3, 1, 2, 4, 2, 6, 1, 1, 1, 2, 2, 4, 7, 2, 6, 2, 5, 7, 6, 4, 6, 3, - 1, 4, 5, 1, 4, 6, 2, 3, 0, 6, 11, 2, 9, 2, 6, 4, 5, 6, 2, 19, 2, 10, 4, 2, - 3, 3, 11, 7, 3, 3, 1, 5, 3, 6, 4, 3, 0, 6, 6, 6, 4, 2, 5, 2, 2, 2, 6, 10, - 4, 9, 3, 7, 7, 0, 6, 8, 5, 2, 3, 2, 3, 3, 3, 1, 6, 1, 8, 2, 5, 3, 6, 11, - 5, 7, 2, 6, 7, 3, 4, 1, 0, 5, 8, 3, 2, 9, 3, 1, 2, 3, 3, 9, 5, 6, 5, 1, - 4, 5, 6, 7, 6, 1, 5, 1, 6, 6, 2, 6, 7, 2, 4, 6 - }; - - // Uniform distribution [0:49] - vtkm::Float32 uniform[nVerts] = { - 0, 6, 37, 22, 26, 10, 2, 33, 33, 46, 19, 25, 41, 1, 2, 26, 33, 0, 19, 3, 20, 34, 29, 46, - 42, 26, 4, 32, 20, 35, 45, 38, 13, 2, 36, 16, 31, 37, 49, 18, 12, 49, 36, 37, 32, 3, 31, 44, - 13, 21, 38, 23, 11, 13, 17, 8, 24, 44, 45, 3, 45, 25, 25, 15, 49, 24, 13, 4, 47, 3, 25, 19, - 13, 45, 26, 23, 47, 2, 38, 38, 41, 6, 0, 34, 43, 31, 36, 36, 49, 44, 11, 15, 17, 25, 29, 42, - 20, 42, 13, 20, 26, 23, 14, 8, 7, 28, 40, 1, 26, 24, 47, 37, 27, 44, 31, 42, 7, 10, 35, 6, - 4, 13, 0, 20, 1, 35, 46, 11, 9, 15, 44, 32, 7, 34, 19, 19, 24, 7, 29, 42, 29, 47, 27, 7, - 49, 20, 7, 28, 12, 24, 23, 48, 6, 9, 15, 31, 6, 32, 31, 40, 12, 23, 19, 10, 1, 45, 21, 7, - 47, 20, 6, 44, 4, 8, 3, 18, 12, 6, 39, 22, 17, 22, 40, 46, 32, 10, 33, 45, 12, 43, 23, 25, - 30, 40, 37, 23, 47, 31, 21, 41, 34, 35, 49, 47, 42, 14, 26, 25, 5, 20, 28, 43, 22, 36, 43, 35, - 40, 35, 37, 0, 44, 26, 23, 3, 35, 24, 33, 34, 9, 45, 43, 44, 27, 6, 22, 49, 10, 22, 15, 25, - 44, 21, 23, 40, 18, 10, 49, 7, 31, 30, 0, 0, 38, 36, 15, 20, 34, 34, 10, 41, 35, 41, 4, 4, - 38, 31, 10, 10, 4, 19, 47, 47, 19, 13, 34, 14, 38, 39, 21, 14, 9, 0, 9, 49, 12, 40, 6, 19, - 30, 8, 41, 7, 49, 12, 11, 5, 10, 31, 34, 39, 34, 37, 33, 31, 2, 29, 11, 15, 34, 5, 38, 26, - 27, 29, 16, 35, 7, 8, 24, 43, 40, 27, 36, 15, 6, 26, 15, 29, 25, 21, 12, 18, 19, 22, 23, 19, - 13, 3, 18, 12, 33, 33, 25, 36, 36, 47, 23, 47, 16, 23, 25, 33, 20, 30, 49, 7, 33, 17, 27, 26, - 41, 0, 13, 32, 27, 45, 13, 48, 12, 42, 34, 22, 40, 1, 8, 35, 35, 21, 29, 37, 49, 34, 13, 37, - 8, 0, 24, 3, 8, 45, 39, 37, 21, 0, 29, 25, 3, 27, 19, 10, 19, 31, 32, 35, 26, 14, 40, 18, - 34, 15, 0, 5, 26, 38, 11, 2, 3, 8, 36, 14, 2, 23, 22, 25, 22, 7, 14, 41, 34, 28, 34, 16, - 2, 49, 27, 0, 42, 1, 18, 24, 28, 36, 33, 26, 1, 6, 48, 9, 17, 30, 30, 6, 27, 47, 17, 41, - 48, 12, 12, 21, 40, 44, 12, 38, 34, 22, 13, 33, 5, 10, 5, 27, 0, 8, 29, 21, 4, 34, 18, 41, - 6, 48, 1, 4, 24, 38, 46, 12, 17, 38, 24, 37, 33, 34, 37, 1, 11, 11, 28, 32, 30, 18, 11, 11, - 32, 8, 37, 7, 2, 33, 6, 47, 24, 31, 45, 0, 29, 36, 24, 2, 22, 25, 38, 3, 22, 48, 23, 16, - 22, 37, 10, 8, 18, 46, 48, 12, 3, 6, 26, 8, 25, 5, 42, 18, 21, 16, 35, 28, 43, 37, 41, 34, - 19, 46, 30, 18, 26, 22, 20, 12, 4, 21, 23, 14, 5, 10, 40, 26, 33, 43, 12, 35, 13, 19, 4, 22, - 11, 39, 24, 0, 13, 33, 21, 9, 48, 6, 39, 47, 8, 30, 3, 17, 14, 25, 41, 41, 36, 16, 40, 31, - 2, 2, 7, 38, 3, 25, 46, 11, 10, 4, 34, 35, 24, 13, 35, 18, 10, 11, 21, 23, 43, 48, 22, 1, - 26, 1, 37, 29, 41, 16, 11, 26, 21, 20, 49, 48, 42, 43, 15, 7, 49, 31, 23, 46, 34, 40, 27, 28, - 7, 47, 41, 7, 2, 17, 5, 4, 25, 1, 28, 42, 25, 33, 36, 34, 1, 9, 33, 17, 3, 7, 46, 11, - 19, 29, 8, 1, 34, 38, 35, 3, 29, 46, 46, 21, 25, 41, 45, 30, 36, 25, 24, 8, 48, 28, 13, 26, - 34, 33, 4, 27, 30, 33, 24, 28, 29, 22, 7, 25, 36, 1, 2, 26, 16, 1, 12, 5, 19, 27, 29, 30, - 46, 38, 25, 24, 32, 34, 20, 24, 23, 35, 26, 13, 30, 14, 35, 26, 46, 11, 20, 29, 39, 46, 34, 41, - 26, 11, 7, 44, 12, 32, 0, 46, 13, 42, 13, 47, 25, 6, 20, 35, 21, 5, 38, 4, 22, 17, 14, 37, - 16, 16, 2, 28, 24, 10, 5, 48, 43, 24, 18, 40, 8, 7, 2, 7, 23, 19, 44, 21, 20, 32, 15, 3, - 40, 44, 45, 45, 38, 8, 28, 1, 40, 26, 43, 13, 43, 29, 19, 40, 26, 46, 21, 28, 37, 44, 16, 9, - 37, 35, 43, 3, 35, 43, 17, 4, 8, 20, 4, 33, 28, 40, 43, 38, 31, 44, 43, 24, 5, 18, 19, 34, - 6, 3, 7, 23, 35, 11, 19, 48, 31, 34, 45, 18, 42, 39, 21, 3, 24, 24, 22, 24, 37, 46, 15, 7, - 5, 4, 48, 20, 11, 48, 41, 9, 6, 9, 16, 28, 22, 29, 21, 18, 19, 30, 21, 7, 33, 49, 34, 20, - 42, 40, 39, 18, 0, 23, 31, 32, 32, 39, 18, 17, 19, 16, 34, 7, 14, 33, 42, 15, 7, 30, 0, 46, - 19, 25, 17, 13, 14, 41, 6, 31, 2, 22, 18, 7, 37, 33, 0, 39, 28, 14, 20, 16, 25, 35, 42, 11, - 23, 18, 2, 3, 10, 28, 41, 21, 41, 14, 9, 17, 46, 29, 18, 23, 31, 47, 20, 2, 22, 29, 37, 43, - 6, 5, 33, 41, 29, 32, 49, 0, 46, 9, 48, 26, 13, 35, 29, 41, 41, 32, 36, 32, 17, 26, 33, 16, - 43, 22, 45, 13, 47, 5, 20, 41, 48, 16, 26, 26, 40, 46, 33, 12 - }; - - vtkm::cont::ArrayHandleUniformPointCoordinates coordinates(vtkm::Id3(xVerts, yVerts, 1)); - dataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", coordinates)); - - // Set point scalars - dataSet.AddField(vtkm::cont::make_Field( - "p_poisson", vtkm::cont::Field::Association::POINTS, poisson, nVerts, vtkm::CopyFlag::On)); - dataSet.AddField(vtkm::cont::make_Field( - "p_normal", vtkm::cont::Field::Association::POINTS, normal, nVerts, vtkm::CopyFlag::On)); - dataSet.AddField(vtkm::cont::make_Field( - "p_chiSquare", vtkm::cont::Field::Association::POINTS, chiSquare, nVerts, vtkm::CopyFlag::On)); - dataSet.AddField(vtkm::cont::make_Field( - "p_uniform", vtkm::cont::Field::Association::POINTS, uniform, nVerts, vtkm::CopyFlag::On)); - - // Set cell scalars - dataSet.AddField(vtkm::cont::make_Field( - "c_poisson", vtkm::cont::Field::Association::CELL_SET, poisson, nCells, vtkm::CopyFlag::On)); - dataSet.AddField(vtkm::cont::make_Field( - "c_normal", vtkm::cont::Field::Association::CELL_SET, normal, nCells, vtkm::CopyFlag::On)); - dataSet.AddField(vtkm::cont::make_Field("c_chiSquare", - vtkm::cont::Field::Association::CELL_SET, - chiSquare, - nCells, - vtkm::CopyFlag::On)); - dataSet.AddField(vtkm::cont::make_Field( - "c_uniform", vtkm::cont::Field::Association::CELL_SET, poisson, nCells, vtkm::CopyFlag::On)); - - vtkm::cont::CellSetStructured cellSet; - - //Set regular structure - cellSet.SetPointDimensions(vtkm::make_Vec(xVerts, yVerts)); - dataSet.SetCellSet(cellSet); - - return dataSet; -} - -// -// Print the histogram result and tally -// -void PrintHistogram(vtkm::cont::ArrayHandle bins, - vtkm::Id numberOfBins, - const vtkm::Range& range, - vtkm::Float32 delta) -{ - vtkm::cont::ArrayHandle::ReadPortalType binPortal = bins.ReadPortal(); - - vtkm::Id sum = 0; - for (vtkm::Id i = 0; i < numberOfBins; i++) - { - vtkm::Float64 lo = range.Min + (static_cast(i) * delta); - vtkm::Float64 hi = lo + delta; - sum += binPortal.Get(i); - std::cout << " BIN[" << i << "] Range[" << lo << ", " << hi << "] = " << binPortal.Get(i) - << std::endl; - } - VTKM_TEST_ASSERT(test_equal(sum, 1000), "Histogram not full"); -} - -// -// Create a dataset with known point data and cell data (statistical distributions) -// Extract arrays of point and cell fields -// Create output structure to hold histogram bins -// Run FieldHistogram filter -// -void TestFieldHistogram() -{ - // Create the output bin array - vtkm::Id numberOfBins = 10; - vtkm::Range range; - vtkm::Float32 delta; - vtkm::cont::ArrayHandle bins; - bins.Allocate(numberOfBins); - - // Data attached is the poisson distribution - vtkm::cont::DataSet ds = MakeTestDataSet(); - - // Get point data - vtkm::cont::ArrayHandle p_poisson; - ds.GetField("p_poisson").GetData().AsArrayHandle(p_poisson); - vtkm::cont::ArrayHandle p_normal; - ds.GetField("p_normal").GetData().AsArrayHandle(p_normal); - vtkm::cont::ArrayHandle p_chiSquare; - ds.GetField("p_chiSquare").GetData().AsArrayHandle(p_chiSquare); - vtkm::cont::ArrayHandle p_uniform; - ds.GetField("p_uniform").GetData().AsArrayHandle(p_uniform); - - vtkm::worklet::FieldHistogram histogram; - // Run data - histogram.Run(p_poisson, numberOfBins, range, delta, bins); - std::cout << "Poisson distributed POINT data:" << std::endl; - PrintHistogram(bins, numberOfBins, range, delta); - - histogram.Run(p_normal, numberOfBins, range, delta, bins); - std::cout << "Normal distributed POINT data:" << std::endl; - PrintHistogram(bins, numberOfBins, range, delta); - - histogram.Run(p_chiSquare, numberOfBins, range, delta, bins); - std::cout << "Chi Square distributed POINT data:" << std::endl; - PrintHistogram(bins, numberOfBins, range, delta); - - histogram.Run(p_uniform, numberOfBins, range, delta, bins); - std::cout << "Uniform distributed POINT data:" << std::endl; - PrintHistogram(bins, numberOfBins, range, delta); -} // TestFieldHistogram - -int UnitTestFieldHistogram(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestFieldHistogram, argc, argv); -} diff --git a/vtkm/worklet/testing/UnitTestNDimsEntropy.cxx b/vtkm/worklet/testing/UnitTestNDimsEntropy.cxx deleted file mode 100644 index 4c5577bf9..000000000 --- a/vtkm/worklet/testing/UnitTestNDimsEntropy.cxx +++ /dev/null @@ -1,205 +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 - -#include -#include - -namespace -{ -// Make testing dataset with three fields(variables), each one has 1000 values -vtkm::cont::DataSet MakeTestDataSet() -{ - vtkm::cont::DataSet dataSet; - - const int xVerts = 20; - const int yVerts = 50; - const int nVerts = xVerts * yVerts; - - vtkm::Float32 fieldA[nVerts] = { - 8, 10, 9, 8, 14, 11, 12, 9, 19, 7, 8, 11, 7, 10, 11, 11, 11, 6, 8, 8, 7, 15, 9, 7, - 8, 10, 9, 10, 10, 12, 7, 6, 14, 10, 14, 10, 7, 11, 13, 9, 13, 11, 10, 10, 12, 12, 7, 12, - 10, 11, 12, 8, 13, 9, 5, 12, 11, 9, 5, 9, 12, 9, 6, 10, 11, 9, 9, 11, 9, 7, 7, 18, - 16, 13, 12, 8, 10, 11, 9, 8, 17, 3, 15, 15, 9, 10, 10, 8, 10, 9, 7, 9, 8, 10, 13, 9, - 7, 11, 7, 10, 13, 10, 11, 9, 10, 7, 10, 6, 12, 6, 9, 7, 6, 12, 12, 9, 12, 12, 11, 6, - 1, 12, 8, 13, 14, 8, 8, 10, 7, 7, 6, 7, 5, 11, 6, 11, 13, 8, 13, 5, 9, 12, 7, 11, - 10, 15, 11, 9, 7, 12, 15, 7, 8, 7, 12, 8, 21, 16, 13, 11, 10, 14, 12, 11, 12, 14, 7, 11, - 7, 12, 16, 8, 10, 8, 9, 7, 8, 7, 13, 13, 11, 15, 7, 7, 6, 11, 7, 12, 12, 13, 14, 11, - 13, 11, 11, 9, 15, 8, 6, 11, 12, 10, 11, 7, 6, 14, 11, 10, 12, 5, 8, 9, 11, 15, 11, 10, - 17, 14, 9, 10, 10, 12, 11, 13, 13, 12, 11, 7, 8, 10, 7, 11, 10, 5, 8, 10, 13, 13, 12, 6, - 10, 7, 13, 8, 11, 7, 10, 7, 8, 7, 14, 16, 9, 11, 8, 11, 9, 15, 11, 10, 10, 12, 7, 7, - 11, 7, 5, 17, 9, 11, 11, 11, 10, 17, 10, 15, 7, 11, 12, 16, 9, 8, 11, 14, 9, 22, 8, 8, - 8, 13, 12, 12, 1, 14, 15, 6, 15, 8, 11, 16, 14, 8, 6, 9, 8, 9, 9, 10, 8, 6, 13, 8, - 6, 12, 11, 12, 13, 8, 6, 6, 5, 6, 10, 9, 11, 12, 14, 12, 10, 11, 10, 10, 8, 13, 8, 11, - 7, 13, 13, 12, 12, 13, 15, 4, 9, 16, 7, 9, 8, 10, 6, 9, 11, 12, 6, 7, 14, 6, 4, 15, - 5, 18, 9, 9, 11, 12, 9, 5, 6, 7, 15, 6, 11, 14, 8, 12, 6, 9, 5, 9, 14, 9, 12, 6, - 9, 14, 11, 12, 12, 13, 15, 9, 8, 7, 13, 12, 7, 13, 6, 9, 10, 10, 10, 9, 11, 5, 9, 13, - 16, 9, 10, 8, 9, 6, 13, 12, 8, 12, 9, 12, 17, 8, 11, 10, 8, 7, 11, 7, 13, 13, 10, 14, - 11, 9, 6, 6, 14, 16, 5, 9, 13, 11, 12, 7, 4, 6, 9, 11, 11, 10, 12, 9, 7, 13, 8, 8, - 12, 5, 10, 7, 11, 11, 10, 10, 14, 6, 8, 8, 3, 12, 16, 11, 11, 7, 6, 12, 11, 5, 9, 12, - 9, 13, 7, 8, 9, 9, 12, 7, 9, 8, 12, 11, 6, 10, 6, 7, 6, 11, 10, 8, 9, 8, 4, 19, - 12, 6, 10, 9, 6, 12, 9, 14, 7, 8, 11, 7, 7, 12, 13, 9, 13, 12, 8, 6, 10, 17, 19, 10, - 10, 13, 5, 11, 8, 10, 8, 16, 12, 6, 6, 7, 10, 9, 12, 8, 5, 10, 7, 18, 9, 12, 10, 4, - 9, 9, 15, 15, 6, 7, 7, 11, 12, 4, 8, 18, 5, 12, 12, 11, 10, 14, 9, 9, 10, 8, 10, 8, - 10, 9, 9, 4, 10, 12, 5, 13, 6, 9, 7, 5, 12, 8, 11, 10, 9, 17, 9, 9, 8, 11, 18, 11, - 10, 9, 4, 13, 10, 15, 5, 10, 9, 7, 7, 8, 10, 6, 6, 19, 10, 16, 7, 7, 9, 10, 10, 13, - 10, 10, 14, 13, 12, 8, 7, 13, 12, 11, 13, 12, 9, 8, 6, 8, 10, 3, 8, 8, 12, 12, 13, 13, - 10, 5, 10, 7, 13, 7, 9, 5, 13, 7, 10, 8, 13, 11, 17, 9, 6, 14, 10, 10, 13, 9, 15, 8, - 15, 9, 12, 11, 12, 8, 3, 9, 8, 10, 12, 8, 14, 13, 12, 11, 12, 9, 18, 10, 13, 7, 4, 4, - 11, 8, 3, 7, 9, 10, 12, 7, 11, 21, 9, 7, 8, 9, 10, 10, 11, 9, 15, 13, 21, 12, 8, 11, - 9, 10, 11, 9, 17, 8, 9, 8, 14, 6, 13, 9, 8, 11, 12, 12, 12, 11, 6, 13, 7, 9, 11, 15, - 17, 17, 11, 10, 7, 8, 11, 8, 6, 9, 13, 7, 9, 6, 5, 10, 7, 16, 16, 9, 7, 6, 14, 8, - 13, 16, 7, 7, 10, 11, 6, 10, 9, 9, 8, 14, 11, 9, 11, 9, 10, 11, 9, 8, 14, 11, 7, 12, - 11, 8, 9, 9, 10, 11, 11, 10, 9, 6, 6, 11, 16, 10, 7, 6, 6, 13, 18, 8, 12, 11, 14, 13, - 8, 8, 10, 17, 17, 6, 6, 10, 18, 5, 8, 11, 6, 6, 14, 10, 9, 6, 11, 6, 13, 12, 10, 6, - 9, 9, 9, 13, 7, 17, 10, 14, 10, 9, 10, 10, 11, 10, 11, 15, 13, 6, 12, 19, 10, 12, 12, 15, - 13, 10, 10, 13, 11, 13, 13, 17, 6, 5, 6, 7, 6, 9, 13, 11, 8, 12, 9, 6, 10, 16, 11, 12, - 5, 12, 14, 13, 13, 16, 11, 6, 12, 12, 15, 8, 7, 11, 8, 5, 10, 8, 9, 11, 9, 12, 10, 5, - 12, 11, 9, 6, 14, 12, 10, 11, 9, 6, 7, 12, 8, 12, 8, 15, 9, 8, 7, 9, 3, 6, 14, 7, - 8, 11, 9, 10, 12, 9, 10, 9, 8, 6, 12, 11, 6, 8, 9, 8, 15, 11, 7, 18, 12, 11, 10, 13, - 11, 11, 10, 7, 9, 8, 8, 11, 11, 13, 6, 12, 13, 16, 11, 11, 5, 12, 14, 15, 9, 14, 15, 6, - 8, 7, 6, 8, 9, 19, 7, 12, 11, 8, 14, 12, 10, 9, 3, 7 - }; - - vtkm::Float32 fieldB[nVerts] = { - 24, 19, 28, 19, 25, 28, 25, 22, 27, 26, 35, 26, 30, 28, 24, 23, 21, 31, 20, 11, 21, 22, 14, 25, - 20, 24, 24, 21, 24, 29, 26, 21, 32, 29, 23, 28, 31, 25, 23, 30, 18, 24, 22, 25, 33, 24, 22, 23, - 21, 17, 20, 28, 30, 18, 20, 32, 25, 24, 32, 15, 27, 24, 27, 19, 30, 27, 17, 24, 29, 23, 22, 19, - 24, 19, 28, 24, 25, 24, 25, 30, 24, 31, 30, 27, 25, 25, 25, 15, 29, 23, 29, 29, 21, 25, 35, 24, - 28, 10, 31, 23, 22, 22, 22, 33, 29, 27, 18, 27, 27, 24, 20, 20, 21, 29, 23, 31, 23, 23, 22, 23, - 30, 27, 28, 31, 16, 29, 25, 19, 33, 28, 25, 24, 15, 27, 37, 29, 15, 19, 14, 19, 24, 23, 30, 29, - 35, 22, 19, 26, 26, 14, 24, 30, 32, 23, 30, 29, 26, 27, 25, 23, 17, 26, 32, 29, 20, 17, 21, 23, - 22, 20, 36, 12, 26, 23, 15, 29, 24, 22, 26, 33, 24, 23, 20, 26, 22, 17, 26, 26, 34, 22, 26, 17, - 23, 18, 29, 27, 21, 29, 28, 29, 24, 25, 28, 19, 18, 21, 23, 23, 27, 25, 24, 25, 24, 25, 21, 25, - 21, 27, 23, 20, 29, 15, 28, 30, 24, 27, 17, 23, 16, 21, 25, 17, 27, 28, 21, 13, 19, 27, 16, 30, - 31, 25, 30, 17, 17, 25, 26, 22, 21, 17, 24, 17, 25, 22, 27, 14, 27, 24, 27, 25, 26, 31, 21, 23, - 30, 30, 22, 19, 23, 22, 23, 25, 24, 25, 24, 28, 26, 30, 18, 25, 30, 37, 27, 34, 28, 34, 25, 10, - 25, 22, 35, 30, 24, 32, 24, 34, 19, 29, 26, 16, 27, 17, 26, 23, 27, 25, 26, 21, 31, 21, 28, 15, - 32, 24, 23, 23, 18, 15, 22, 25, 16, 25, 31, 26, 25, 28, 24, 26, 23, 25, 33, 20, 27, 28, 24, 29, - 32, 20, 24, 20, 19, 32, 24, 6, 24, 21, 26, 18, 15, 30, 19, 26, 22, 30, 35, 23, 22, 30, 20, 22, - 18, 30, 28, 25, 16, 25, 27, 30, 18, 24, 30, 28, 20, 19, 20, 28, 21, 24, 15, 33, 20, 18, 20, 36, - 30, 26, 25, 18, 28, 27, 31, 31, 15, 26, 16, 22, 27, 14, 17, 27, 27, 22, 32, 30, 22, 34, 22, 25, - 20, 22, 26, 29, 28, 33, 18, 23, 20, 20, 27, 24, 28, 21, 25, 27, 25, 19, 19, 25, 19, 32, 29, 27, - 23, 21, 28, 33, 23, 23, 28, 26, 31, 19, 21, 29, 21, 27, 23, 32, 24, 26, 21, 28, 28, 24, 17, 31, - 27, 21, 19, 32, 28, 23, 30, 23, 29, 15, 26, 26, 15, 20, 25, 26, 27, 31, 21, 23, 23, 33, 28, 19, - 23, 22, 22, 25, 27, 17, 23, 17, 25, 28, 26, 30, 32, 31, 19, 25, 25, 19, 23, 29, 27, 23, 34, 22, - 13, 21, 32, 10, 20, 33, 21, 17, 29, 31, 14, 24, 23, 19, 19, 22, 17, 26, 37, 26, 22, 26, 38, 29, - 29, 27, 30, 20, 31, 14, 32, 32, 24, 23, 23, 18, 21, 31, 24, 20, 28, 15, 21, 25, 25, 20, 30, 25, - 22, 21, 21, 25, 24, 25, 18, 23, 28, 30, 20, 27, 27, 19, 10, 32, 24, 20, 29, 26, 25, 20, 25, 29, - 28, 24, 32, 26, 22, 19, 23, 27, 27, 29, 20, 25, 21, 30, 28, 31, 24, 19, 23, 19, 19, 18, 30, 18, - 16, 24, 20, 20, 30, 25, 29, 25, 31, 21, 28, 31, 24, 26, 27, 21, 24, 23, 26, 18, 32, 26, 28, 26, - 24, 26, 29, 30, 22, 20, 24, 28, 25, 29, 20, 21, 22, 15, 30, 27, 33, 26, 22, 32, 30, 31, 20, 19, - 24, 26, 27, 31, 17, 17, 33, 27, 16, 27, 27, 22, 27, 19, 24, 21, 17, 24, 28, 23, 26, 24, 19, 26, - 20, 24, 22, 19, 22, 21, 21, 28, 29, 39, 19, 16, 25, 29, 31, 22, 22, 29, 26, 22, 22, 22, 26, 23, - 23, 23, 30, 25, 25, 25, 27, 29, 18, 33, 21, 12, 22, 29, 12, 20, 35, 22, 34, 28, 18, 29, 21, 20, - 24, 33, 24, 26, 23, 34, 31, 25, 31, 22, 35, 21, 20, 29, 27, 22, 30, 22, 27, 23, 22, 32, 16, 19, - 27, 22, 24, 27, 21, 33, 25, 25, 19, 28, 20, 27, 21, 25, 28, 20, 27, 22, 21, 20, 26, 30, 33, 23, - 20, 24, 17, 23, 28, 35, 14, 23, 22, 28, 28, 26, 25, 18, 20, 28, 28, 22, 13, 24, 22, 20, 30, 26, - 26, 18, 22, 20, 23, 24, 20, 27, 34, 28, 18, 24, 34, 33, 25, 33, 37, 21, 20, 31, 19, 23, 29, 22, - 21, 24, 19, 27, 19, 32, 25, 23, 33, 26, 33, 27, 29, 30, 19, 22, 30, 19, 18, 24, 25, 17, 31, 19, - 31, 26, 22, 23, 28, 28, 25, 24, 19, 19, 27, 28, 23, 21, 29, 26, 31, 22, 22, 25, 16, 29, 21, 22, - 23, 25, 22, 21, 22, 19, 27, 26, 28, 30, 22, 21, 24, 22, 23, 26, 28, 22, 18, 25, 23, 27, 31, 19, - 15, 29, 20, 19, 27, 25, 21, 29, 22, 24, 25, 17, 36, 29, 22, 22, 24, 28, 27, 22, 26, 31, 29, 31, - 18, 25, 23, 16, 37, 27, 21, 31, 25, 24, 20, 23, 28, 33, 24, 21, 26, 20, 18, 31, 20, 24, 23, 19, - 27, 17, 23, 23, 20, 26, 28, 23, 26, 31, 25, 31, 19, 32, 26, 18, 19, 29, 20, 21, 15, 25, 27, 29, - 22, 22, 22, 26, 23, 22, 23, 29, 28, 20, 21, 22, 20, 22, 27, 25, 23, 32, 23, 20, 31, 20, 27, 26, - 34, 20, 22, 36, 21, 29, 25, 20, 21, 22, 29, 29, 25, 22, 24, 22 - }; - - vtkm::Float32 fieldC[nVerts] = { - 3, 1, 4, 6, 5, 4, 8, 7, 2, 9, 2, 0, 0, 4, 3, 2, 5, 2, 3, 6, 3, 8, 3, 4, - 3, 3, 2, 7, 2, 10, 9, 6, 1, 1, 4, 7, 3, 3, 1, 4, 4, 3, 9, 4, 4, 7, 3, 2, - 4, 7, 3, 3, 2, 10, 1, 6, 2, 2, 3, 8, 3, 3, 6, 9, 4, 1, 4, 3, 16, 7, 0, 1, - 8, 7, 13, 3, 5, 0, 3, 8, 10, 3, 5, 5, 1, 5, 2, 1, 3, 2, 5, 3, 4, 3, 3, 3, - 3, 1, 13, 2, 3, 1, 2, 7, 3, 4, 1, 2, 5, 4, 4, 4, 2, 6, 3, 2, 7, 8, 1, 3, - 4, 1, 2, 0, 1, 6, 1, 8, 8, 1, 1, 4, 2, 1, 4, 3, 5, 4, 6, 4, 2, 3, 8, 8, - 3, 3, 3, 4, 5, 8, 8, 16, 7, 12, 4, 3, 14, 8, 3, 12, 5, 0, 5, 3, 5, 2, 9, 2, - 9, 4, 1, 0, 0, 4, 4, 6, 3, 4, 11, 2, 4, 7, 4, 2, 1, 9, 4, 3, 2, 5, 1, 5, - 3, 8, 2, 8, 1, 8, 0, 4, 1, 3, 2, 1, 2, 3, 2, 1, 8, 5, 4, 1, 9, 9, 1, 3, - 5, 0, 1, 6, 10, 8, 3, 12, 3, 4, 4, 7, 1, 3, 6, 4, 4, 6, 1, 4, 7, 5, 6, 11, - 6, 5, 2, 7, 2, 5, 3, 5, 6, 3, 6, 2, 1, 10, 8, 3, 7, 0, 2, 6, 9, 3, 11, 3, - 2, 5, 1, 4, 6, 10, 9, 1, 4, 3, 7, 12, 3, 10, 0, 2, 11, 2, 1, 0, 4, 1, 2, 16, - 5, 17, 7, 8, 2, 10, 10, 3, 1, 3, 2, 2, 4, 8, 4, 3, 2, 4, 4, 6, 8, 6, 2, 3, - 2, 4, 2, 4, 7, 10, 5, 3, 5, 2, 4, 6, 9, 3, 1, 1, 1, 1, 4, 2, 2, 7, 4, 9, - 2, 3, 5, 6, 2, 5, 1, 6, 5, 7, 8, 3, 7, 2, 2, 8, 6, 2, 10, 2, 1, 4, 5, 1, - 1, 1, 5, 6, 1, 1, 4, 5, 4, 2, 4, 3, 2, 7, 19, 4, 7, 2, 7, 5, 2, 5, 3, 8, - 4, 6, 7, 2, 0, 0, 2, 12, 6, 2, 2, 3, 5, 9, 4, 9, 2, 2, 7, 8, 3, 3, 10, 6, - 3, 2, 1, 6, 2, 4, 6, 3, 5, 8, 2, 3, 6, 14, 0, 3, 6, 5, 2, 7, 0, 3, 8, 5, - 3, 2, 2, 5, 1, 3, 12, 11, 16, 2, 1, 3, 7, 3, 1, 6, 4, 3, 12, 5, 1, 3, 1, 4, - 9, 1, 3, 3, 4, 4, 6, 7, 7, 5, 2, 4, 2, 3, 2, 2, 6, 4, 2, 2, 3, 5, 1, 4, - 9, 1, 0, 7, 6, 4, 3, 3, 7, 3, 3, 6, 2, 7, 9, 3, 1, 16, 5, 4, 3, 6, 3, 2, - 5, 2, 2, 4, 3, 1, 3, 3, 6, 3, 5, 9, 1, 10, 1, 7, 2, 2, 6, 7, 3, 5, 3, 7, - 2, 2, 2, 2, 6, 4, 3, 2, 5, 5, 3, 15, 4, 2, 7, 7, 4, 3, 3, 5, 1, 2, 9, 0, - 5, 7, 12, 2, 4, 8, 5, 7, 8, 3, 2, 2, 18, 1, 7, 2, 2, 1, 3, 3, 3, 7, 1, 9, - 8, 4, 3, 7, 6, 4, 5, 2, 0, 5, 1, 5, 10, 4, 2, 8, 2, 2, 0, 5, 6, 4, 5, 0, - 1, 5, 11, 3, 3, 4, 4, 2, 3, 5, 1, 6, 5, 7, 2, 2, 5, 7, 4, 8, 4, 1, 1, 7, - 2, 3, 9, 6, 13, 1, 5, 4, 6, 2, 4, 11, 2, 5, 5, 1, 4, 1, 4, 7, 1, 5, 8, 3, - 1, 10, 9, 13, 1, 7, 2, 9, 4, 3, 3, 10, 12, 2, 0, 4, 6, 5, 5, 1, 4, 7, 2, 12, - 7, 6, 5, 0, 6, 4, 4, 12, 1, 3, 10, 1, 9, 2, 2, 2, 1, 5, 5, 6, 9, 6, 4, 1, - 11, 6, 9, 3, 2, 7, 1, 7, 4, 3, 0, 3, 1, 12, 17, 2, 1, 6, 4, 4, 2, 1, 5, 5, - 3, 2, 2, 4, 6, 5, 4, 6, 11, 3, 12, 6, 3, 6, 3, 0, 6, 3, 7, 4, 8, 5, 14, 5, - 1, 9, 4, 6, 5, 3, 9, 3, 1, 1, 0, 3, 7, 3, 5, 1, 6, 2, 2, 6, 2, 12, 1, 0, - 6, 3, 3, 5, 4, 7, 2, 2, 15, 7, 3, 10, 4, 2, 6, 3, 4, 8, 3, 1, 5, 5, 5, 4, - 3, 7, 3, 4, 5, 5, 2, 4, 2, 5, 1, 12, 5, 6, 3, 2, 8, 5, 2, 3, 11, 11, 6, 5, - 0, 3, 3, 9, 4, 2, 11, 1, 5, 3, 5, 6, 3, 6, 4, 2, 4, 10, 11, 3, 3, 4, 1, 1, - 1, 3, 5, 5, 1, 1, 4, 1, 5, 1, 6, 8, 6, 4, 6, 7, 6, 3, 5, 3, 6, 6, 6, 4, - 0, 6, 3, 1, 2, 4, 2, 6, 1, 1, 1, 2, 2, 4, 7, 2, 6, 2, 5, 7, 6, 4, 6, 3, - 1, 4, 5, 1, 4, 6, 2, 3, 0, 6, 11, 2, 9, 2, 6, 4, 5, 6, 2, 19, 2, 10, 4, 2, - 3, 3, 11, 7, 3, 3, 1, 5, 3, 6, 4, 3, 0, 6, 6, 6, 4, 2, 5, 2, 2, 2, 6, 10, - 4, 9, 3, 7, 7, 0, 6, 8, 5, 2, 3, 2, 3, 3, 3, 1, 6, 1, 8, 2, 5, 3, 6, 11, - 5, 7, 2, 6, 7, 3, 4, 1, 0, 5, 8, 3, 2, 9, 3, 1, 2, 3, 3, 9, 5, 6, 5, 1, - 4, 5, 6, 7, 6, 1, 5, 1, 6, 6, 2, 6, 7, 2, 4, 6 - }; - - vtkm::cont::ArrayHandleUniformPointCoordinates coordinates(vtkm::Id3(xVerts, yVerts, 1)); - dataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", coordinates)); - - // Set point scalars - dataSet.AddField(vtkm::cont::make_Field( - "fieldA", vtkm::cont::Field::Association::POINTS, fieldA, nVerts, vtkm::CopyFlag::On)); - dataSet.AddField(vtkm::cont::make_Field( - "fieldB", vtkm::cont::Field::Association::POINTS, fieldB, nVerts, vtkm::CopyFlag::On)); - dataSet.AddField(vtkm::cont::make_Field( - "fieldC", vtkm::cont::Field::Association::POINTS, fieldC, nVerts, vtkm::CopyFlag::On)); - - return dataSet; -} - -// -// Create a dataset with known point data -// Extract the three field -// Run NDimsEntropy to calculate the entropy -// -void TestNDimsEntropy() -{ - // Data attached is the poisson distribution - vtkm::cont::DataSet ds = MakeTestDataSet(); - - vtkm::worklet::NDimsEntropy ndEntropy; - ndEntropy.SetNumOfDataPoints(ds.GetField(0).GetNumberOfValues()); - - // Add field one by one - ndEntropy.AddField(ds.GetField("fieldA").GetData(), 10); - ndEntropy.AddField(ds.GetField("fieldB").GetData(), 10); - ndEntropy.AddField(ds.GetField("fieldC").GetData(), 10); - - // Run worklet to calculate multi-variate entropy - vtkm::Float64 entropy = ndEntropy.Run(); - - VTKM_TEST_ASSERT(fabs(entropy - 7.457857) < 0.001, - "N-Dimentional entropy calculation is incorrect"); -} // TestNDimsEntropy -} - -int UnitTestNDimsEntropy(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestNDimsEntropy, argc, argv); -} diff --git a/vtkm/worklet/testing/UnitTestNDimsHistMarginalization.cxx b/vtkm/worklet/testing/UnitTestNDimsHistMarginalization.cxx index deb870b22..699e7ca86 100644 --- a/vtkm/worklet/testing/UnitTestNDimsHistMarginalization.cxx +++ b/vtkm/worklet/testing/UnitTestNDimsHistMarginalization.cxx @@ -8,8 +8,8 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ +#include #include -#include #include #include diff --git a/vtkm/worklet/testing/UnitTestNDimsHistogram.cxx b/vtkm/worklet/testing/UnitTestNDimsHistogram.cxx deleted file mode 100644 index 02d8493f7..000000000 --- a/vtkm/worklet/testing/UnitTestNDimsHistogram.cxx +++ /dev/null @@ -1,121 +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 - -#include -#include - -namespace -{ -// Make testing dataset with three fields(variables), each one has 100 values -vtkm::cont::DataSet MakeTestDataSet() -{ - vtkm::cont::DataSet dataSet; - - const int nVerts = 100; - - vtkm::Float32 fieldA[nVerts] = { 8, 10, 9, 8, 14, 11, 12, 9, 19, 7, 8, 11, 7, 10, 11, - 11, 11, 6, 8, 8, 7, 15, 9, 7, 8, 10, 9, 10, 10, 12, - 7, 6, 14, 10, 14, 10, 7, 11, 13, 9, 13, 11, 10, 10, 12, - 12, 7, 12, 10, 11, 12, 8, 13, 9, 5, 12, 11, 9, 5, 9, - 12, 9, 6, 10, 11, 9, 9, 11, 9, 7, 7, 18, 16, 13, 12, - 8, 10, 11, 9, 8, 17, 3, 15, 15, 9, 10, 10, 8, 10, 9, - 7, 9, 8, 10, 13, 9, 7, 11, 7, 10 }; - - vtkm::Float32 fieldB[nVerts] = { 24, 19, 28, 19, 25, 28, 25, 22, 27, 26, 35, 26, 30, 28, 24, - 23, 21, 31, 20, 11, 21, 22, 14, 25, 20, 24, 24, 21, 24, 29, - 26, 21, 32, 29, 23, 28, 31, 25, 23, 30, 18, 24, 22, 25, 33, - 24, 22, 23, 21, 17, 20, 28, 30, 18, 20, 32, 25, 24, 32, 15, - 27, 24, 27, 19, 30, 27, 17, 24, 29, 23, 22, 19, 24, 19, 28, - 24, 25, 24, 25, 30, 24, 31, 30, 27, 25, 25, 25, 15, 29, 23, - 29, 29, 21, 25, 35, 24, 28, 10, 31, 23 }; - - vtkm::Float32 fieldC[nVerts] = { - 3, 1, 4, 6, 5, 4, 8, 7, 2, 9, 2, 0, 0, 4, 3, 2, 5, 2, 3, 6, 3, 8, 3, 4, 3, - 3, 2, 7, 2, 10, 9, 6, 1, 1, 4, 7, 3, 3, 1, 4, 4, 3, 9, 4, 4, 7, 3, 2, 4, 7, - 3, 3, 2, 10, 1, 6, 2, 2, 3, 8, 3, 3, 6, 9, 4, 1, 4, 3, 16, 7, 0, 1, 8, 7, 13, - 3, 5, 0, 3, 8, 10, 3, 5, 5, 1, 5, 2, 1, 3, 2, 5, 3, 4, 3, 3, 3, 3, 1, 13, 2 - }; - - // Set point scalars - dataSet.AddField(vtkm::cont::make_Field( - "fieldA", vtkm::cont::Field::Association::POINTS, fieldA, nVerts, vtkm::CopyFlag::On)); - dataSet.AddField(vtkm::cont::make_Field( - "fieldB", vtkm::cont::Field::Association::POINTS, fieldB, nVerts, vtkm::CopyFlag::On)); - dataSet.AddField(vtkm::cont::make_Field( - "fieldC", vtkm::cont::Field::Association::POINTS, fieldC, nVerts, vtkm::CopyFlag::On)); - - return dataSet; -} - -void TestNDimsHistogram() -{ - // Create a dataset - vtkm::cont::DataSet ds = MakeTestDataSet(); - - vtkm::worklet::NDimsHistogram ndHistogram; - - // Set the number of data points - ndHistogram.SetNumOfDataPoints(ds.GetField(0).GetNumberOfValues()); - - // Add field one by one - vtkm::Range rangeFieldA; - vtkm::Float64 deltaFieldA; - ndHistogram.AddField(ds.GetField("fieldA").GetData(), 4, rangeFieldA, deltaFieldA); - - vtkm::Range rangeFieldB; - vtkm::Float64 deltaFieldB; - ndHistogram.AddField(ds.GetField("fieldB").GetData(), 4, rangeFieldB, deltaFieldB); - - vtkm::Range rangeFieldC; - vtkm::Float64 deltaFieldC; - ndHistogram.AddField(ds.GetField("fieldC").GetData(), 4, rangeFieldC, deltaFieldC); - - // the return binIds and freqs is sparse distribution representation - // (we do not keep the 0 frequency entities) - // e.g. we have three variable(data arrays) in this example - // binIds[0, 1, 2][j] is a combination of bin ID of three variable, - // freqs[j] is the frequency of this bin IDs combination - std::vector> binIds; - vtkm::cont::ArrayHandle freqs; - ndHistogram.Run(binIds, freqs); - - // Ground truth ND histogram - vtkm::Id gtNonSparseBins = 33; - vtkm::Id gtIdx0[33] = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3 }; - vtkm::Id gtIdx1[33] = { 1, 1, 2, 3, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, - 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 1, 1, 2, 2, 2, 3 }; - vtkm::Id gtIdx2[33] = { 0, 1, 1, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 3, - 0, 0, 1, 0, 1, 2, 3, 0, 1, 2, 0, 2, 0, 1, 2, 1 }; - vtkm::Id gtFreq[33] = { 1, 1, 1, 3, 2, 1, 1, 6, 6, 3, 17, 8, 2, 6, 2, 1, 2, - 1, 1, 4, 11, 4, 1, 1, 3, 3, 1, 1, 1, 1, 1, 2, 1 }; - - // Check result - vtkm::Id nonSparseBins = binIds[0].WritePortal().GetNumberOfValues(); - VTKM_TEST_ASSERT(nonSparseBins == gtNonSparseBins, "Incorrect ND-histogram results"); - - for (int i = 0; i < nonSparseBins; i++) - { - vtkm::Id idx0 = binIds[0].WritePortal().Get(i); - vtkm::Id idx1 = binIds[1].WritePortal().Get(i); - vtkm::Id idx2 = binIds[2].WritePortal().Get(i); - vtkm::Id f = freqs.WritePortal().Get(i); - VTKM_TEST_ASSERT(idx0 == gtIdx0[i] && idx1 == gtIdx1[i] && idx2 == gtIdx2[i] && f == gtFreq[i], - "Incorrect ND-histogram results"); - } -} // TestNDHistogram -} - -int UnitTestNDimsHistogram(int argc, char* argv[]) -{ - return vtkm::cont::testing::Testing::Run(TestNDimsHistogram, argc, argv); -}