2015-02-10 17:36:10 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2015-02-10 17:36:10 +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.
|
|
|
|
//============================================================================
|
2015-05-29 13:51:11 +00:00
|
|
|
#ifndef vtk_m_cont_Field_h
|
|
|
|
#define vtk_m_cont_Field_h
|
2015-02-10 17:36:10 +00:00
|
|
|
|
2016-12-16 22:04:58 +00:00
|
|
|
#include <vtkm/cont/vtkm_cont_export.h>
|
|
|
|
|
2016-05-26 22:02:30 +00:00
|
|
|
#include <vtkm/Range.h>
|
|
|
|
#include <vtkm/Types.h>
|
2015-07-16 19:10:01 +00:00
|
|
|
|
2015-02-10 17:36:10 +00:00
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2021-08-05 22:16:49 +00:00
|
|
|
#include <vtkm/cont/CastAndCall.h>
|
2020-10-21 14:17:35 +00:00
|
|
|
#include <vtkm/cont/UnknownArrayHandle.h>
|
2015-05-29 13:44:57 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2015-02-10 17:36:10 +00:00
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
|
2015-02-10 17:36:10 +00:00
|
|
|
/// A \c Field encapsulates an array on some piece of the mesh, such as
|
2015-08-03 16:06:59 +00:00
|
|
|
/// the points, a cell set, a point logical dimension, or the whole mesh.
|
2015-02-10 17:36:10 +00:00
|
|
|
///
|
2016-12-16 22:04:58 +00:00
|
|
|
class VTKM_CONT_EXPORT Field
|
2015-02-10 17:36:10 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-05-18 20:10:15 +00:00
|
|
|
enum struct Association
|
2015-07-13 19:50:07 +00:00
|
|
|
{
|
Rename field associations
The symbols in `vtkm::cont::Field::Association` have been changed from
`ANY`, `WHOLE_MESH`, `POINTS`, and `CELL_SET` to `Any`, `WholeMesh`,
`Points`, and `Cells`, respectively. The reason for this change is twofold:
* The general standard that VTK-m follows for `enum struct` enumerators
is to use camel case (with the first character capitalized), not all
upper case.
* The use of `CELL_SET` for fields associated with cells is obsolete. A
`DataSet` used to support having more than one `CellSet`, and so a
field association on cells was actually bound to a particular
`CellSet`. However, that is no longer the case. A `DataSet` has exactly
one `CellSet`, so a cell field no longer has to point to a `CellSet`.
Thus the enumeration symbol for `Cells` should match the one for
`Points`.
For backward compatibility, the old enumerations still exist. They are
aliases for the new names, and they are marked as deprecated, so using them
will result in a compiler warning (on some systems).
2022-03-17 15:36:44 +00:00
|
|
|
Any,
|
2022-08-29 10:40:42 +00:00
|
|
|
WholeDataSet,
|
Rename field associations
The symbols in `vtkm::cont::Field::Association` have been changed from
`ANY`, `WHOLE_MESH`, `POINTS`, and `CELL_SET` to `Any`, `WholeMesh`,
`Points`, and `Cells`, respectively. The reason for this change is twofold:
* The general standard that VTK-m follows for `enum struct` enumerators
is to use camel case (with the first character capitalized), not all
upper case.
* The use of `CELL_SET` for fields associated with cells is obsolete. A
`DataSet` used to support having more than one `CellSet`, and so a
field association on cells was actually bound to a particular
`CellSet`. However, that is no longer the case. A `DataSet` has exactly
one `CellSet`, so a cell field no longer has to point to a `CellSet`.
Thus the enumeration symbol for `Cells` should match the one for
`Points`.
For backward compatibility, the old enumerations still exist. They are
aliases for the new names, and they are marked as deprecated, so using them
will result in a compiler warning (on some systems).
2022-03-17 15:36:44 +00:00
|
|
|
Points,
|
|
|
|
Cells,
|
2022-08-24 14:52:29 +00:00
|
|
|
Partitions,
|
2022-08-29 10:40:42 +00:00
|
|
|
Global,
|
2015-07-12 16:05:47 +00:00
|
|
|
};
|
2015-07-13 19:50:07 +00:00
|
|
|
|
2018-11-02 18:18:09 +00:00
|
|
|
VTKM_CONT
|
|
|
|
Field() = default;
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2021-01-05 20:02:31 +00:00
|
|
|
Field(std::string name, Association association, const vtkm::cont::UnknownArrayHandle& data);
|
2015-07-30 14:22:25 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T, typename Storage>
|
2018-11-06 16:40:39 +00:00
|
|
|
VTKM_CONT Field(std::string name,
|
|
|
|
Association association,
|
|
|
|
const vtkm::cont::ArrayHandle<T, Storage>& data)
|
2021-01-05 20:02:31 +00:00
|
|
|
: Field(name, association, vtkm::cont::UnknownArrayHandle{ data })
|
2015-05-11 20:15:58 +00:00
|
|
|
{
|
|
|
|
}
|
2015-06-04 13:06:47 +00:00
|
|
|
|
2018-12-07 20:54:20 +00:00
|
|
|
Field(const vtkm::cont::Field& src);
|
|
|
|
Field(vtkm::cont::Field&& src) noexcept;
|
2018-05-02 14:02:39 +00:00
|
|
|
|
2018-12-07 20:54:20 +00:00
|
|
|
VTKM_CONT virtual ~Field();
|
|
|
|
|
|
|
|
VTKM_CONT Field& operator=(const vtkm::cont::Field& src);
|
|
|
|
VTKM_CONT Field& operator=(vtkm::cont::Field&& src) noexcept;
|
2017-01-18 14:10:11 +00:00
|
|
|
|
2022-08-29 18:01:23 +00:00
|
|
|
VTKM_CONT bool IsCellField() const { return this->FieldAssociation == Association::Cells; }
|
|
|
|
VTKM_CONT bool IsPointField() const { return this->FieldAssociation == Association::Points; }
|
|
|
|
VTKM_CONT bool IsWholeDataSetField() const
|
|
|
|
{
|
|
|
|
return this->FieldAssociation == Association::WholeDataSet;
|
|
|
|
}
|
|
|
|
VTKM_CONT bool IsPartitionsField() const
|
|
|
|
{
|
|
|
|
return this->FieldAssociation == Association::Partitions;
|
|
|
|
}
|
|
|
|
VTKM_CONT bool IsGlobalField() const { return this->FieldAssociation == Association::Global; }
|
|
|
|
|
2021-02-01 16:35:00 +00:00
|
|
|
/// Returns true if the array of the field has a value type that matches something in
|
|
|
|
/// `VTKM_FIELD_TYPE_LIST` and a storage that matches something in `VTKM_FIELD_STORAGE_LIST`.
|
|
|
|
VTKM_CONT bool IsSupportedType() const;
|
|
|
|
|
2021-08-23 14:25:46 +00:00
|
|
|
VTKM_CONT vtkm::Id GetNumberOfValues() const { return this->Data.GetNumberOfValues(); }
|
|
|
|
|
|
|
|
VTKM_CONT const std::string& GetName() const { return this->Name; }
|
|
|
|
VTKM_CONT Association GetAssociation() const { return this->FieldAssociation; }
|
|
|
|
const vtkm::cont::UnknownArrayHandle& GetData() const;
|
|
|
|
vtkm::cont::UnknownArrayHandle& GetData();
|
|
|
|
|
|
|
|
VTKM_CONT const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange() const;
|
|
|
|
|
|
|
|
VTKM_CONT void GetRange(vtkm::Range* range) const;
|
|
|
|
|
2021-02-01 16:35:00 +00:00
|
|
|
/// \brief Get the data as an array with `vtkm::FloatDefault` components.
|
|
|
|
///
|
|
|
|
/// Returns a `vtkm::cont::UnknownArrayHandle` that contains an array that either contains
|
|
|
|
/// values of type `vtkm::FloatDefault` or contains `Vec`s with components of type
|
|
|
|
/// `vtkm::FloatDefault`. If the array has value types that do not match this type, then
|
|
|
|
/// it will be copied into an array that does.
|
|
|
|
///
|
|
|
|
/// Additionally, the returned array will have a storage that is compatible with
|
|
|
|
/// something in `VTKM_FIELD_STORAGE_LIST`. If this condition is not met, then the
|
|
|
|
/// array will be copied.
|
|
|
|
///
|
|
|
|
/// If the array contained in the field already matches the required criteria, the array
|
|
|
|
/// will be returned without copying.
|
|
|
|
///
|
|
|
|
VTKM_CONT vtkm::cont::UnknownArrayHandle GetDataAsDefaultFloat() const;
|
|
|
|
|
|
|
|
/// \brief Get the data as an array of an expected type.
|
|
|
|
///
|
|
|
|
/// Returns a `vtkm::cont::UnknownArrayHandle` that contains an array that (probably) has
|
|
|
|
/// a value type that matches something in `VTKM_FIELD_TYPE_LIST` and a storage that matches
|
|
|
|
/// something in `VTKM_FIELD_STORAGE_LIST`. If the array has a value type and storage that
|
|
|
|
/// match `VTKM_FIELD_TYPE_LIST` and `VTKM_FIELD_STORAGE_LIST` respectively, then the same
|
|
|
|
/// array is returned. If something does not match, then the data are copied to a
|
|
|
|
/// `vtkm::cont::ArrayHandleBasic` with a value type component of `vtkm::FloatDefault`.
|
|
|
|
///
|
|
|
|
/// Note that the returned array is likely to be compatible with `VTKM_FIELD_TYPE_LIST`, but
|
|
|
|
/// not guaranteed. In particular, if this field contains `Vec`s, the returned array will also
|
|
|
|
/// contain `Vec`s of the same size. For example, if the field contains `vtkm::Vec2i_16` values,
|
|
|
|
/// they will (likely) be converted to `vtkm::Vec2f`. Howver, `vtkm::Vec2f` may still not be
|
|
|
|
/// in `VTKM_FIELD_TYPE_LIST`.
|
|
|
|
///
|
|
|
|
VTKM_CONT vtkm::cont::UnknownArrayHandle GetDataWithExpectedTypes() const;
|
|
|
|
|
|
|
|
/// \brief Convert this field to use an array of an expected type.
|
|
|
|
///
|
|
|
|
/// Copies the internal data, as necessary, to an array that (probably) has a value type
|
|
|
|
/// that matches something in `VTKM_FIELD_TYPE_LIST` and a storage that matches something
|
|
|
|
/// in `VTKM_FIELD_STORAGE_LIST`. If the field already has a value type and storage that
|
|
|
|
/// match `VTKM_FIELD_TYPE_LIST` and `VTKM_FIELD_STORAGE_LIST` respectively, then nothing
|
|
|
|
/// in the field is changed. If something does not match, then the data are copied to a
|
|
|
|
/// `vtkm::cont::ArrayHandleBasic` with a value type component of `vtkm::FloatDefault`.
|
|
|
|
///
|
|
|
|
/// Note that the returned array is likely to be compatible with `VTKM_FIELD_TYPE_LIST`, but
|
|
|
|
/// not guaranteed. In particular, if this field contains `Vec`s, the returned array will also
|
|
|
|
/// contain `Vec`s of the same size. For example, if the field contains `vtkm::Vec2i_16` values,
|
|
|
|
/// they will (likely) be converted to `vtkm::Vec2f`. Howver, `vtkm::Vec2f` may still not be
|
|
|
|
/// in `VTKM_FIELD_TYPE_LIST`.
|
|
|
|
///
|
|
|
|
VTKM_CONT void ConvertToExpected();
|
|
|
|
|
2020-10-21 14:17:35 +00:00
|
|
|
VTKM_CONT void SetData(const vtkm::cont::UnknownArrayHandle& newdata);
|
|
|
|
|
2017-12-12 19:10:41 +00:00
|
|
|
template <typename T, typename StorageTag>
|
|
|
|
VTKM_CONT void SetData(const vtkm::cont::ArrayHandle<T, StorageTag>& newdata)
|
2016-01-21 20:51:36 +00:00
|
|
|
{
|
2020-10-21 14:17:35 +00:00
|
|
|
this->SetData(vtkm::cont::UnknownArrayHandle(newdata));
|
2015-02-10 17:36:10 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
virtual void PrintSummary(std::ostream& out) const;
|
2015-05-29 13:44:57 +00:00
|
|
|
|
2018-05-24 14:36:23 +00:00
|
|
|
VTKM_CONT
|
|
|
|
virtual void ReleaseResourcesExecution()
|
|
|
|
{
|
2018-11-06 16:40:39 +00:00
|
|
|
this->Data.ReleaseResourcesExecution();
|
2018-05-24 14:36:23 +00:00
|
|
|
this->Range.ReleaseResourcesExecution();
|
|
|
|
}
|
|
|
|
|
2015-02-10 17:36:10 +00:00
|
|
|
private:
|
2017-05-18 14:29:41 +00:00
|
|
|
std::string Name; ///< name of field
|
2015-05-19 20:21:15 +00:00
|
|
|
|
2022-03-17 17:02:37 +00:00
|
|
|
Association FieldAssociation = Association::Any;
|
2020-10-21 14:17:35 +00:00
|
|
|
vtkm::cont::UnknownArrayHandle Data;
|
2016-05-26 22:02:30 +00:00
|
|
|
mutable vtkm::cont::ArrayHandle<vtkm::Range> Range;
|
2018-11-02 18:18:09 +00:00
|
|
|
mutable bool ModifiedFlag = true;
|
2015-02-10 17:36:10 +00:00
|
|
|
};
|
|
|
|
|
2017-11-07 22:43:36 +00:00
|
|
|
template <typename Functor, typename... Args>
|
2017-12-08 16:40:52 +00:00
|
|
|
void CastAndCall(const vtkm::cont::Field& field, Functor&& f, Args&&... args)
|
2016-08-05 18:47:19 +00:00
|
|
|
{
|
2018-11-06 16:40:39 +00:00
|
|
|
vtkm::cont::CastAndCall(field.GetData(), std::forward<Functor>(f), std::forward<Args>(args)...);
|
2016-08-05 18:47:19 +00:00
|
|
|
}
|
2016-08-03 18:38:25 +00:00
|
|
|
|
2019-08-13 14:10:52 +00:00
|
|
|
|
2017-12-20 22:07:44 +00:00
|
|
|
//@{
|
2018-01-30 00:24:31 +00:00
|
|
|
/// Convenience functions to build fields from C style arrays and std::vector
|
2017-12-20 22:07:44 +00:00
|
|
|
template <typename T>
|
|
|
|
vtkm::cont::Field make_Field(std::string name,
|
2018-05-18 20:10:15 +00:00
|
|
|
Field::Association association,
|
2017-12-20 22:07:44 +00:00
|
|
|
const T* data,
|
|
|
|
vtkm::Id size,
|
2020-07-16 16:32:32 +00:00
|
|
|
vtkm::CopyFlag copy)
|
2017-12-20 22:07:44 +00:00
|
|
|
{
|
|
|
|
return vtkm::cont::Field(name, association, vtkm::cont::make_ArrayHandle(data, size, copy));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
vtkm::cont::Field make_Field(std::string name,
|
2018-05-18 20:10:15 +00:00
|
|
|
Field::Association association,
|
2017-12-20 22:07:44 +00:00
|
|
|
const std::vector<T>& data,
|
2020-07-16 16:32:32 +00:00
|
|
|
vtkm::CopyFlag copy)
|
2017-12-20 22:07:44 +00:00
|
|
|
{
|
|
|
|
return vtkm::cont::Field(name, association, vtkm::cont::make_ArrayHandle(data, copy));
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:32:32 +00:00
|
|
|
template <typename T>
|
|
|
|
vtkm::cont::Field make_FieldMove(std::string name,
|
|
|
|
Field::Association association,
|
|
|
|
std::vector<T>&& data)
|
|
|
|
{
|
2022-11-11 21:34:13 +00:00
|
|
|
return vtkm::cont::Field(name, association, vtkm::cont::make_ArrayHandleMove(std::move(data)));
|
2020-07-16 16:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
vtkm::cont::Field make_Field(std::string name,
|
|
|
|
Field::Association association,
|
|
|
|
std::vector<T>&& data,
|
2020-07-23 23:59:50 +00:00
|
|
|
vtkm::CopyFlag vtkmNotUsed(copy))
|
2020-07-16 16:32:32 +00:00
|
|
|
{
|
|
|
|
return make_FieldMove(name, association, std::move(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
vtkm::cont::Field make_Field(std::string name,
|
|
|
|
Field::Association association,
|
|
|
|
std::initializer_list<T>&& data)
|
|
|
|
{
|
|
|
|
return make_FieldMove(name, association, vtkm::cont::make_ArrayHandle(std::move(data)));
|
|
|
|
}
|
|
|
|
|
2019-08-13 14:10:52 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/// Convenience function to build point fields from vtkm::cont::ArrayHandle
|
|
|
|
template <typename T, typename S>
|
|
|
|
vtkm::cont::Field make_FieldPoint(std::string name, const vtkm::cont::ArrayHandle<T, S>& data)
|
2017-12-20 22:07:44 +00:00
|
|
|
{
|
2022-03-17 17:02:37 +00:00
|
|
|
return vtkm::cont::Field(name, vtkm::cont::Field::Association::Points, data);
|
2019-08-13 14:10:52 +00:00
|
|
|
}
|
|
|
|
|
2021-04-02 17:37:49 +00:00
|
|
|
/// Convenience function to build point fields from vtkm::cont::UnknownArrayHandle
|
2019-08-13 14:10:52 +00:00
|
|
|
inline vtkm::cont::Field make_FieldPoint(std::string name,
|
2020-10-21 14:17:35 +00:00
|
|
|
const vtkm::cont::UnknownArrayHandle& data)
|
2019-08-13 14:10:52 +00:00
|
|
|
{
|
2022-03-17 17:02:37 +00:00
|
|
|
return vtkm::cont::Field(name, vtkm::cont::Field::Association::Points, data);
|
2019-08-13 14:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Convenience function to build cell fields from vtkm::cont::ArrayHandle
|
|
|
|
template <typename T, typename S>
|
2019-08-13 17:08:54 +00:00
|
|
|
vtkm::cont::Field make_FieldCell(std::string name, const vtkm::cont::ArrayHandle<T, S>& data)
|
2019-08-13 14:10:52 +00:00
|
|
|
{
|
2022-03-17 17:02:37 +00:00
|
|
|
return vtkm::cont::Field(name, vtkm::cont::Field::Association::Cells, data);
|
2019-08-13 14:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-02 17:37:49 +00:00
|
|
|
/// Convenience function to build cell fields from vtkm::cont::UnknownArrayHandle
|
2019-08-13 14:10:52 +00:00
|
|
|
inline vtkm::cont::Field make_FieldCell(std::string name,
|
2020-10-21 14:17:35 +00:00
|
|
|
const vtkm::cont::UnknownArrayHandle& data)
|
2019-08-13 14:10:52 +00:00
|
|
|
{
|
2022-03-17 17:02:37 +00:00
|
|
|
return vtkm::cont::Field(name, vtkm::cont::Field::Association::Cells, data);
|
2017-12-20 22:07:44 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
} // namespace cont
|
|
|
|
} // namespace vtkm
|
|
|
|
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace internal
|
|
|
|
{
|
|
|
|
template <>
|
2016-08-03 18:38:25 +00:00
|
|
|
struct DynamicTransformTraits<vtkm::cont::Field>
|
|
|
|
{
|
2017-06-23 18:50:34 +00:00
|
|
|
using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall;
|
2016-08-03 18:38:25 +00:00
|
|
|
};
|
|
|
|
} // namespace internal
|
2015-02-10 17:36:10 +00:00
|
|
|
} // namespace cont
|
|
|
|
} // namespace vtkm
|
|
|
|
|
2018-06-18 17:56:38 +00:00
|
|
|
//=============================================================================
|
|
|
|
// Specializations of serialization related classes
|
2019-09-12 21:19:36 +00:00
|
|
|
/// @cond SERIALIZATION
|
2018-06-18 17:56:38 +00:00
|
|
|
|
2019-02-05 16:02:29 +00:00
|
|
|
namespace mangled_diy_namespace
|
2018-06-18 17:56:38 +00:00
|
|
|
{
|
|
|
|
|
2020-10-21 14:17:35 +00:00
|
|
|
template <>
|
|
|
|
struct VTKM_CONT_EXPORT Serialization<vtkm::cont::Field>
|
|
|
|
{
|
|
|
|
static VTKM_CONT void save(BinaryBuffer& bb, const vtkm::cont::Field& field);
|
|
|
|
static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::Field& field);
|
|
|
|
};
|
|
|
|
|
2018-06-18 17:56:38 +00:00
|
|
|
} // diy
|
2019-09-12 21:19:36 +00:00
|
|
|
/// @endcond SERIALIZATION
|
2018-06-18 17:56:38 +00:00
|
|
|
|
2015-05-29 13:51:11 +00:00
|
|
|
#endif //vtk_m_cont_Field_h
|