2018-04-02 21:58:21 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2018-04-02 21:58:21 +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.
|
|
|
|
//============================================================================
|
2019-08-08 15:00:04 +00:00
|
|
|
#ifndef vtk_m_filter_CreateResult_h
|
|
|
|
#define vtk_m_filter_CreateResult_h
|
2018-04-02 21:58:21 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/cont/ErrorBadValue.h>
|
|
|
|
#include <vtkm/cont/Field.h>
|
|
|
|
|
2019-08-12 19:46:55 +00:00
|
|
|
#include <vtkm/filter/FieldMetadata.h>
|
|
|
|
|
2022-01-27 00:11:11 +00:00
|
|
|
// Once all the filters move to the NewFilter base classes, this header should
|
|
|
|
// be deprecated.
|
|
|
|
|
2018-04-02 21:58:21 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace filter
|
|
|
|
{
|
|
|
|
//@{
|
|
|
|
/// These are utility functions defined to use in filters when creating an
|
|
|
|
/// output dataset to return from `DoExecute` methods. The various overloads
|
2018-04-20 16:26:18 +00:00
|
|
|
/// provides different ways of creating the output dataset (copying the input
|
2019-08-12 19:46:55 +00:00
|
|
|
/// without any of the fields) and adding additional field(s).
|
2018-04-02 21:58:21 +00:00
|
|
|
|
|
|
|
/// Use this if you have built a \c Field object. An output
|
|
|
|
/// \c DataSet will be created by adding the field to the input.
|
|
|
|
inline VTKM_CONT vtkm::cont::DataSet CreateResult(const vtkm::cont::DataSet& inDataSet,
|
|
|
|
const vtkm::cont::Field& field)
|
|
|
|
{
|
2018-04-20 16:26:18 +00:00
|
|
|
vtkm::cont::DataSet clone;
|
|
|
|
clone.CopyStructure(inDataSet);
|
2018-04-02 21:58:21 +00:00
|
|
|
clone.AddField(field);
|
2019-08-12 19:46:55 +00:00
|
|
|
VTKM_ASSERT(!field.GetName().empty());
|
2018-04-02 21:58:21 +00:00
|
|
|
VTKM_ASSERT(clone.HasField(field.GetName(), field.GetAssociation()));
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Use this function if you have an ArrayHandle that holds the data for
|
2019-08-12 19:46:55 +00:00
|
|
|
/// the field. You also need to specify a name for the field.
|
2018-04-02 21:58:21 +00:00
|
|
|
template <typename T, typename Storage>
|
|
|
|
inline VTKM_CONT vtkm::cont::DataSet CreateResult(
|
|
|
|
const vtkm::cont::DataSet& inDataSet,
|
|
|
|
const vtkm::cont::ArrayHandle<T, Storage>& fieldArray,
|
|
|
|
const std::string& fieldName,
|
2019-08-12 19:46:55 +00:00
|
|
|
const vtkm::filter::FieldMetadata& metaData)
|
2018-04-02 21:58:21 +00:00
|
|
|
{
|
2019-08-12 19:46:55 +00:00
|
|
|
VTKM_ASSERT(!fieldName.empty());
|
2018-04-02 21:58:21 +00:00
|
|
|
|
2018-04-20 16:26:18 +00:00
|
|
|
vtkm::cont::DataSet clone;
|
|
|
|
clone.CopyStructure(inDataSet);
|
2019-08-12 19:46:55 +00:00
|
|
|
clone.AddField(metaData.AsField(fieldName, fieldArray));
|
2018-04-02 21:58:21 +00:00
|
|
|
|
|
|
|
// Sanity check.
|
2019-08-12 19:46:55 +00:00
|
|
|
VTKM_ASSERT(clone.HasField(fieldName, metaData.GetAssociation()));
|
2018-04-02 21:58:21 +00:00
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
2021-04-02 17:37:49 +00:00
|
|
|
/// Use this function if you have a UnknownArrayHandle that holds the data
|
2019-08-12 19:46:55 +00:00
|
|
|
/// for the field.
|
2018-05-18 20:10:15 +00:00
|
|
|
inline VTKM_CONT vtkm::cont::DataSet CreateResult(const vtkm::cont::DataSet& inDataSet,
|
2021-04-02 17:37:49 +00:00
|
|
|
const vtkm::cont::UnknownArrayHandle& fieldArray,
|
2018-05-18 20:10:15 +00:00
|
|
|
const std::string& fieldName,
|
2019-08-12 19:46:55 +00:00
|
|
|
const vtkm::filter::FieldMetadata& metaData)
|
|
|
|
{
|
|
|
|
VTKM_ASSERT(!fieldName.empty());
|
|
|
|
|
|
|
|
vtkm::cont::DataSet clone;
|
|
|
|
clone.CopyStructure(inDataSet);
|
|
|
|
clone.AddField(metaData.AsField(fieldName, fieldArray));
|
|
|
|
|
|
|
|
// Sanity check.
|
|
|
|
VTKM_ASSERT(clone.HasField(fieldName, metaData.GetAssociation()));
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Use this function if you want to explicit construct a Cell field and have a ArrayHandle
|
|
|
|
/// that holds the data for the field.
|
2019-08-13 17:08:54 +00:00
|
|
|
template <typename T, typename Storage>
|
2019-08-12 19:46:55 +00:00
|
|
|
inline VTKM_CONT vtkm::cont::DataSet CreateResultFieldCell(
|
|
|
|
const vtkm::cont::DataSet& inDataSet,
|
|
|
|
const vtkm::cont::ArrayHandle<T, Storage>& fieldArray,
|
2019-08-13 17:08:54 +00:00
|
|
|
const std::string& fieldName)
|
2019-08-12 19:46:55 +00:00
|
|
|
{
|
|
|
|
VTKM_ASSERT(!fieldName.empty());
|
|
|
|
|
|
|
|
vtkm::cont::DataSet clone;
|
|
|
|
clone.CopyStructure(inDataSet);
|
2019-08-13 17:08:54 +00:00
|
|
|
clone.AddField(vtkm::cont::make_FieldCell(fieldName, fieldArray));
|
2019-08-12 19:46:55 +00:00
|
|
|
|
|
|
|
// Sanity check.
|
2019-08-13 14:10:52 +00:00
|
|
|
VTKM_ASSERT(clone.HasCellField(fieldName));
|
2019-08-12 19:46:55 +00:00
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
2021-04-02 17:37:49 +00:00
|
|
|
/// Use this function if you want to explicit construct a Cell field and have a UnknownArrayHandle
|
2019-08-12 19:46:55 +00:00
|
|
|
/// that holds the data for the field.
|
|
|
|
inline VTKM_CONT vtkm::cont::DataSet CreateResultFieldCell(
|
|
|
|
const vtkm::cont::DataSet& inDataSet,
|
2021-04-02 17:37:49 +00:00
|
|
|
const vtkm::cont::UnknownArrayHandle& fieldArray,
|
2019-08-13 17:08:54 +00:00
|
|
|
const std::string& fieldName)
|
2019-08-12 19:46:55 +00:00
|
|
|
{
|
|
|
|
VTKM_ASSERT(!fieldName.empty());
|
|
|
|
|
|
|
|
vtkm::cont::DataSet clone;
|
|
|
|
clone.CopyStructure(inDataSet);
|
2019-08-13 17:08:54 +00:00
|
|
|
clone.AddField(vtkm::cont::make_FieldCell(fieldName, fieldArray));
|
2019-08-12 19:46:55 +00:00
|
|
|
|
|
|
|
// Sanity check.
|
2019-08-13 14:10:52 +00:00
|
|
|
VTKM_ASSERT(clone.HasCellField(fieldName));
|
2019-08-12 19:46:55 +00:00
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Use this function if you want to explicit construct a Point field and have a ArrayHandle
|
|
|
|
/// that holds the data for the field.
|
|
|
|
template <typename T, typename Storage>
|
|
|
|
inline VTKM_CONT vtkm::cont::DataSet CreateResultFieldPoint(
|
|
|
|
const vtkm::cont::DataSet& inDataSet,
|
|
|
|
const vtkm::cont::ArrayHandle<T, Storage>& fieldArray,
|
|
|
|
const std::string& fieldName)
|
|
|
|
{
|
|
|
|
VTKM_ASSERT(!fieldName.empty());
|
|
|
|
|
|
|
|
vtkm::cont::DataSet clone;
|
|
|
|
clone.CopyStructure(inDataSet);
|
2019-08-13 14:10:52 +00:00
|
|
|
clone.AddField(vtkm::cont::make_FieldPoint(fieldName, fieldArray));
|
2019-08-12 19:46:55 +00:00
|
|
|
|
|
|
|
// Sanity check.
|
2019-08-13 14:10:52 +00:00
|
|
|
VTKM_ASSERT(clone.HasPointField(fieldName));
|
2019-08-12 19:46:55 +00:00
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
2021-04-02 17:37:49 +00:00
|
|
|
/// Use this function if you want to explicit construct a Point field and have a UnknownArrayHandle
|
2019-08-12 19:46:55 +00:00
|
|
|
/// that holds the data for the field.
|
|
|
|
inline VTKM_CONT vtkm::cont::DataSet CreateResultFieldPoint(
|
|
|
|
const vtkm::cont::DataSet& inDataSet,
|
2021-04-02 17:37:49 +00:00
|
|
|
const vtkm::cont::UnknownArrayHandle& fieldArray,
|
2019-08-12 19:46:55 +00:00
|
|
|
const std::string& fieldName)
|
2018-04-02 21:58:21 +00:00
|
|
|
{
|
2019-08-12 19:46:55 +00:00
|
|
|
VTKM_ASSERT(!fieldName.empty());
|
2018-04-02 21:58:21 +00:00
|
|
|
|
2018-04-20 16:26:18 +00:00
|
|
|
vtkm::cont::DataSet clone;
|
|
|
|
clone.CopyStructure(inDataSet);
|
2019-08-13 14:10:52 +00:00
|
|
|
clone.AddField(vtkm::cont::make_FieldPoint(fieldName, fieldArray));
|
2018-04-02 21:58:21 +00:00
|
|
|
|
|
|
|
// Sanity check.
|
2019-08-13 14:10:52 +00:00
|
|
|
VTKM_ASSERT(clone.HasPointField(fieldName));
|
2018-04-02 21:58:21 +00:00
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
//@}
|
|
|
|
} // namespace vtkm::filter
|
|
|
|
} // namespace vtkm
|
|
|
|
|
|
|
|
#endif
|