FeatureMatrixTransformer.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/std/containers/span.h>
  10. #include <Allocators.h>
  11. #include <FeatureMatrix.h>
  12. namespace EMotionFX::MotionMatching
  13. {
  14. //! Transformers can be used to e.g. normalize or scale features in the feature matrix or the query vector.
  15. class FeatureMatrixTransformer
  16. {
  17. public:
  18. AZ_RTTI(FeatureMatrixTransformer, "{B19CDBB8-FA99-4CBD-86C1-640A3CC5988A}");
  19. AZ_CLASS_ALLOCATOR(FeatureMatrixTransformer, MotionMatchAllocator);
  20. virtual ~FeatureMatrixTransformer() = default;
  21. struct Settings
  22. {
  23. float m_featureMin = -1.0f; //!< Minimum value after the transformation.
  24. float m_featureMax = 1.0f; //!< Maximum value after the transformation.
  25. //! Depending on the transformer to be used there might be some outliers from range [m_featureMin, m_featureMax].
  26. //! Clips the values to range [m_featureMin, m_featureMax] in case true or keeps the data untouched in case of false.
  27. bool m_clip = false;
  28. };
  29. //! Prepare the transformer.
  30. //! This might e.g. run some statistical analysis and cache values that will be needed for actually transforming the data.
  31. virtual bool Fit(const FeatureMatrix& featureMatrix, const Settings& settings) = 0;
  32. //! Copy and transform the input data.
  33. //! Note: Use the version that can batch transform the most data.
  34. //! Expect significant performance losses when calling the granular versions on lots of data points.
  35. virtual float Transform(float value, FeatureMatrix::Index column) const = 0;
  36. virtual AZ::Vector2 Transform(const AZ::Vector2& value, FeatureMatrix::Index column) const = 0;
  37. virtual AZ::Vector3 Transform(const AZ::Vector3& value, FeatureMatrix::Index column) const = 0;
  38. virtual void Transform(AZStd::span<float> data) const = 0;
  39. virtual FeatureMatrix Transform(const FeatureMatrix& in) const = 0;
  40. //! Input: Already transformed data, Output: Inverse transformed data (should match data before transform)
  41. virtual float InverseTransform(float value, FeatureMatrix::Index column) const = 0;
  42. virtual AZ::Vector2 InverseTransform(const AZ::Vector2& value, FeatureMatrix::Index column) const = 0;
  43. virtual AZ::Vector3 InverseTransform(const AZ::Vector3& value, FeatureMatrix::Index column) const = 0;
  44. virtual FeatureMatrix InverseTransform(const FeatureMatrix& in) const = 0;
  45. };
  46. } // namespace EMotionFX::MotionMatching