vtk-m/vtkm/filter/Entropy.hxx

51 lines
1.6 KiB
C++
Raw Normal View History

2017-05-23 16:06:31 +00:00
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +00:00
//
2017-05-23 16:06:31 +00:00
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_Entropy_hxx
#define vtk_m_filter_Entropy_hxx
2017-05-23 16:06:31 +00:00
#include <vtkm/worklet/FieldEntropy.h>
namespace vtkm
{
namespace filter
{
2017-05-23 16:06:31 +00:00
//-----------------------------------------------------------------------------
inline VTKM_CONT Entropy::Entropy()
: NumberOfBins(10)
2017-05-23 16:06:31 +00:00
{
this->SetOutputFieldName("entropy");
}
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet Entropy::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMetadata,
const vtkm::filter::PolicyBase<DerivedPolicy>&)
2017-05-23 16:06:31 +00:00
{
vtkm::worklet::FieldEntropy worklet;
vtkm::Float64 e = worklet.Run(field, this->NumberOfBins);
2017-05-23 16:06:31 +00:00
//the entropy vector only contain one element, the entorpy of the input field
2017-05-23 17:59:19 +00:00
vtkm::cont::ArrayHandle<vtkm::Float64> entropy;
entropy.Allocate(1);
entropy.WritePortal().Set(0, e);
2017-05-23 16:06:31 +00:00
return CreateResult(inDataSet, entropy, this->GetOutputFieldName(), fieldMetadata);
2017-05-23 16:06:31 +00:00
}
}
} // namespace vtkm::filter
#endif