// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "VectorTypes.h" #include "OrientedBoxTypes.h" #include "Templates/PimplPtr.h" class FProgressCancel; namespace UE { namespace Geometry { using namespace UE::Math; template struct TMinVolumeBox3Internal; /** * Calculate a Minimal-Volume Oriented Box for a set of 3D points. * This internally first computes the Convex Hull of the point set. * The minimal box is then guaranteed to be aligned with one of the faces of the convex hull. * Note that this is increasingly expensive as the Convex Hull face count increases. */ template class TMinVolumeBox3 { public: /** * Calculate the minimal box for the given point set. * @param NumPoints number of points in the set, ie GetPointFunc can be called for any integer in range [0...NumPoints) * @param GetPointFunc function that returns a 3D point for a valid Index * @param bMostAccurateFit if true, use the most expensive method to get the best-possible fit * @param Progress optionally allow early-cancel of the box fit operation * @return true if minimal box was found */ bool Solve(int32 NumPoints, TFunctionRef(int32)> GetPointFunc, bool bMostAccurateFit = false, FProgressCancel* Progress = nullptr); /** * Calculate the minimal box for a Subsampling of MaxPoints points of a point set * @param NumPoints number of points in the set, ie GetPointFunc can be called for any integer in range [0...NumPoints) * @param NumSamplePoints maximum number of points to sample from NumPoints. Currently a random-ish subset is selected. * @param GetPointFunc function that returns a 3D point for a valid Index * @param bMostAccurateFit if true, use the most expensive method to get the best-possible fit * @param Progress optionally allow early-cancel of the box fit operation * @return true if minimal box was found */ bool SolveSubsample(int32 NumPoints, int32 NumSamplePoints, TFunctionRef(int32)> GetPointFunc, bool bMostAccurateFit = false, FProgressCancel* Progress = nullptr); /** @return true if minimal box is available */ bool IsSolutionAvailable() const; /** @return minimal box in BoxOut */ void GetResult(TOrientedBox3& BoxOut); protected: void Initialize(bool bMostAccurateFit); TPimplPtr> Internal; }; typedef TMinVolumeBox3 FMinVolumeBox3f; typedef TMinVolumeBox3 FMinVolumeBox3d; } // end namespace UE::Geometry } // end namespace UE