//============================================================================ // 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_NDEntropy_hxx #define vtk_m_filter_NDEntropy_hxx #include #include namespace vtkm { namespace filter { inline VTKM_CONT NDEntropy::NDEntropy() { } 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::worklet::NDimsEntropy ndEntropy; ndEntropy.SetNumOfDataPoints(inData.GetField(0).GetNumberOfValues()); // Add field one by one // (By using AddFieldAndBin(), the length of FieldNames and NumOfBins must be the same) for (size_t i = 0; i < FieldNames.size(); i++) { ndEntropy.AddField(inData.GetField(FieldNames[i]).GetData(), NumOfBins[i]); } // Run worklet to calculate multi-variate entropy vtkm::cont::ArrayHandle entropyHandle; vtkm::Float64 entropy = ndEntropy.Run(); entropyHandle.Allocate(1); entropyHandle.WritePortal().Set(0, entropy); vtkm::cont::DataSet outputData; outputData.AddField(vtkm::cont::make_FieldPoint("Entropy", entropyHandle)); return outputData; } //----------------------------------------------------------------------------- template inline VTKM_CONT bool NDEntropy::MapFieldOntoOutput(vtkm::cont::DataSet&, const vtkm::cont::Field&, vtkm::filter::PolicyBase) { return false; } } } #endif