vtk-m/vtkm/filter/ExternalFaces.hxx

143 lines
4.5 KiB
C++
Raw Normal View History

2016-01-19 14:59:31 +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 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// 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.
//============================================================================
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace filter
{
2016-01-19 14:59:31 +00:00
//-----------------------------------------------------------------------------
2017-05-18 14:29:41 +00:00
inline VTKM_CONT ExternalFaces::ExternalFaces()
: vtkm::filter::FilterDataSet<ExternalFaces>()
, CompactPoints(false)
, Worklet()
2016-01-19 14:59:31 +00:00
{
}
2017-05-18 14:29:41 +00:00
namespace
{
template <typename BasePolicy>
struct CellSetExplicitPolicy : public BasePolicy
{
using AllCellSetList = vtkm::cont::CellSetListTagExplicitDefault;
};
2016-01-19 14:59:31 +00:00
template <typename DerivedPolicy>
2017-05-18 14:29:41 +00:00
inline vtkm::filter::PolicyBase<CellSetExplicitPolicy<DerivedPolicy>> GetCellSetExplicitPolicy(
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
return vtkm::filter::PolicyBase<CellSetExplicitPolicy<DerivedPolicy>>();
2016-01-19 14:59:31 +00:00
}
} // anonymous namespace
2016-01-19 14:59:31 +00:00
//-----------------------------------------------------------------------------
2017-05-18 14:29:41 +00:00
template <typename DerivedPolicy, typename DeviceAdapter>
inline VTKM_CONT vtkm::filter::ResultDataSet ExternalFaces::DoExecute(
const vtkm::cont::DataSet& input,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
2017-05-18 14:29:41 +00:00
const DeviceAdapter&)
2016-01-19 14:59:31 +00:00
{
//1. extract the cell set
2017-05-18 14:29:41 +00:00
const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(this->GetActiveCellSetIndex());
2016-01-19 14:59:31 +00:00
//2. using the policy convert the dynamic cell set, and run the
2016-01-19 14:59:31 +00:00
// external faces worklet
vtkm::cont::CellSetExplicit<> outCellSet(cells.GetName());
if (cells.IsSameType(vtkm::cont::CellSetStructured<3>()))
this->Worklet.Run(cells.Cast<vtkm::cont::CellSetStructured<3>>(),
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()),
outCellSet,
DeviceAdapter());
else
this->Worklet.Run(
vtkm::filter::ApplyPolicyUnstructured(cells, policy), outCellSet, DeviceAdapter());
2016-01-19 14:59:31 +00:00
//3. create the output dataset
vtkm::cont::DataSet output;
output.AddCellSet(outCellSet);
2017-05-18 14:29:41 +00:00
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
2016-01-19 14:59:31 +00:00
if (this->CompactPoints)
{
this->Compactor.SetCompactPointFields(true);
2017-05-18 14:29:41 +00:00
return this->Compactor.DoExecute(output, GetCellSetExplicitPolicy(policy), DeviceAdapter());
}
else
{
return vtkm::filter::ResultDataSet(output);
}
// Check the fields of the dataset to see what kinds of fields are present so
// we can free the mapping arrays that won't be needed.
const vtkm::Id numFields = input.GetNumberOfFields();
bool hasCellFields = false;
for (vtkm::Id fieldIdx = 0; fieldIdx < numFields && !hasCellFields; ++fieldIdx)
{
auto f = input.GetField(fieldIdx);
if (f.GetAssociation() == vtkm::cont::Field::ASSOC_CELL_SET)
{
hasCellFields = true;
}
}
if (!hasCellFields)
{
this->Worklet.ReleaseCellMapArrays();
}
2016-01-19 14:59:31 +00:00
}
//-----------------------------------------------------------------------------
2017-05-18 14:29:41 +00:00
template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
inline VTKM_CONT bool ExternalFaces::DoMapField(
vtkm::filter::ResultDataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
2017-05-18 14:29:41 +00:00
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& device)
2016-01-19 14:59:31 +00:00
{
if (fieldMeta.IsPointField())
{
if (this->CompactPoints)
{
return this->Compactor.DoMapField(result, input, fieldMeta, policy, DeviceAdapter());
}
else
{
result.GetDataSet().AddField(fieldMeta.AsField(input));
return true;
}
}
else if (fieldMeta.IsCellField())
{
vtkm::cont::ArrayHandle<T> fieldArray;
fieldArray = this->Worklet.ProcessCellField(input, device);
result.GetDataSet().AddField(fieldMeta.AsField(fieldArray));
return true;
}
return false;
2016-01-19 14:59:31 +00:00
}
}
}