2019-01-14 23:27:19 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
|
|
|
// Copyright 2014 Los Alamos National Security.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//=========================================================================
|
2019-10-07 19:39:02 +00:00
|
|
|
#ifndef vtk_m_filter_MeshQuality_hxx
|
|
|
|
#define vtk_m_filter_MeshQuality_hxx
|
2019-01-14 23:27:19 +00:00
|
|
|
|
2019-09-25 23:46:39 +00:00
|
|
|
#include <vtkm/cont/Algorithm.h>
|
2019-08-08 15:00:04 +00:00
|
|
|
#include <vtkm/cont/ErrorFilterExecution.h>
|
|
|
|
#include <vtkm/cont/Field.h>
|
2019-09-25 23:46:39 +00:00
|
|
|
#include <vtkm/filter/CellMeasures.h>
|
2019-08-08 15:00:04 +00:00
|
|
|
#include <vtkm/filter/CreateResult.h>
|
2019-01-14 23:27:19 +00:00
|
|
|
|
2019-08-07 16:54:47 +00:00
|
|
|
// #define DEBUG_PRINT
|
2019-01-14 23:27:19 +00:00
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace filter
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2019-09-17 00:19:18 +00:00
|
|
|
inline VTKM_CONT MeshQuality::MeshQuality(CellMetric metric)
|
2019-09-27 01:22:53 +00:00
|
|
|
: vtkm::filter::FilterField<MeshQuality>()
|
2019-01-14 23:27:19 +00:00
|
|
|
{
|
|
|
|
this->SetUseCoordinateSystemAsField(true);
|
2019-09-18 03:53:42 +00:00
|
|
|
this->MyMetric = metric;
|
|
|
|
if (this->MyMetric < CellMetric::AREA || this->MyMetric >= CellMetric::NUMBER_OF_CELL_METRICS)
|
2019-09-17 03:48:55 +00:00
|
|
|
{
|
|
|
|
VTKM_ASSERT(true);
|
|
|
|
}
|
2019-09-27 01:28:13 +00:00
|
|
|
this->SetOutputFieldName(MetricNames[(int)this->MyMetric]);
|
2019-01-14 23:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename StorageType, typename DerivedPolicy>
|
|
|
|
inline VTKM_CONT vtkm::cont::DataSet MeshQuality::DoExecute(
|
|
|
|
const vtkm::cont::DataSet& input,
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>& points,
|
|
|
|
const vtkm::filter::FieldMetadata& fieldMeta,
|
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
|
|
|
|
{
|
2021-08-12 18:20:51 +00:00
|
|
|
if (!fieldMeta.IsPointField())
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("Active field for MeshQuality must be point coordinates. "
|
|
|
|
"But the active field is not a point field.");
|
|
|
|
}
|
2019-01-14 23:27:19 +00:00
|
|
|
|
2019-09-25 23:46:39 +00:00
|
|
|
vtkm::worklet::MeshQuality<CellMetric> qualityWorklet;
|
|
|
|
|
|
|
|
if (this->MyMetric == vtkm::filter::CellMetric::RELATIVE_SIZE_SQUARED ||
|
|
|
|
this->MyMetric == vtkm::filter::CellMetric::SHAPE_AND_SIZE)
|
|
|
|
{
|
|
|
|
vtkm::FloatDefault averageArea = 1.;
|
|
|
|
vtkm::worklet::MeshQuality<CellMetric> subWorklet;
|
|
|
|
vtkm::cont::ArrayHandle<T> array;
|
|
|
|
subWorklet.SetMetric(vtkm::filter::CellMetric::AREA);
|
2021-08-12 18:20:51 +00:00
|
|
|
this->Invoke(subWorklet,
|
|
|
|
vtkm::filter::ApplyPolicyCellSet(input.GetCellSet(), policy, *this),
|
|
|
|
points,
|
|
|
|
array);
|
2019-09-25 23:46:39 +00:00
|
|
|
T zero = 0.0;
|
2019-09-25 23:52:59 +00:00
|
|
|
vtkm::FloatDefault totalArea = (vtkm::FloatDefault)vtkm::cont::Algorithm::Reduce(array, zero);
|
2019-09-25 23:46:39 +00:00
|
|
|
|
|
|
|
vtkm::FloatDefault averageVolume = 1.;
|
|
|
|
subWorklet.SetMetric(vtkm::filter::CellMetric::VOLUME);
|
2021-08-12 18:20:51 +00:00
|
|
|
this->Invoke(subWorklet,
|
|
|
|
vtkm::filter::ApplyPolicyCellSet(input.GetCellSet(), policy, *this),
|
|
|
|
points,
|
|
|
|
array);
|
2019-09-25 23:52:59 +00:00
|
|
|
vtkm::FloatDefault totalVolume = (vtkm::FloatDefault)vtkm::cont::Algorithm::Reduce(array, zero);
|
2019-09-25 23:46:39 +00:00
|
|
|
|
|
|
|
vtkm::Id numVals = array.GetNumberOfValues();
|
|
|
|
if (numVals > 0)
|
|
|
|
{
|
2019-09-29 18:34:39 +00:00
|
|
|
averageArea = totalArea / static_cast<vtkm::FloatDefault>(numVals);
|
|
|
|
averageVolume = totalVolume / static_cast<vtkm::FloatDefault>(numVals);
|
2019-09-25 23:46:39 +00:00
|
|
|
}
|
|
|
|
qualityWorklet.SetAverageArea(averageArea);
|
|
|
|
qualityWorklet.SetAverageVolume(averageVolume);
|
|
|
|
}
|
|
|
|
|
2019-01-14 23:27:19 +00:00
|
|
|
//Invoke the MeshQuality worklet
|
|
|
|
vtkm::cont::ArrayHandle<T> outArray;
|
2019-09-18 03:53:42 +00:00
|
|
|
qualityWorklet.SetMetric(this->MyMetric);
|
2021-08-12 18:20:51 +00:00
|
|
|
this->Invoke(qualityWorklet,
|
|
|
|
vtkm::filter::ApplyPolicyCellSet(input.GetCellSet(), policy, *this),
|
|
|
|
points,
|
|
|
|
outArray);
|
2019-01-14 23:27:19 +00:00
|
|
|
|
|
|
|
vtkm::cont::DataSet result;
|
|
|
|
result.CopyStructure(input); //clone of the input dataset
|
|
|
|
|
|
|
|
//Append the metric values of all cells into the output
|
|
|
|
//dataset as a new field
|
2019-09-27 01:28:13 +00:00
|
|
|
result.AddField(vtkm::cont::make_FieldCell(this->GetOutputFieldName(), outArray));
|
2019-01-14 23:27:19 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace filter
|
|
|
|
} // namespace vtkm
|
2019-10-07 19:39:02 +00:00
|
|
|
#endif
|