Files
Plugin/Source/SenseGloveCore/Public/SGCore/SGHandPose.h
T

190 lines
6.1 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2022 SenseGlove
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @section DESCRIPTION
*
*
*/
#pragma once
#include "Containers/Array.h"
#include "Containers/UnrealString.h"
#include "Math/Quat.h"
#include "Math/Vector.h"
#include "Templates/UniquePtr.h"
#include "UObject/Object.h"
#include "UObject/ObjectMacros.h"
#include "SGCore/SGBasicHandModel.h"
#include "SGCore/SGQuatArray.h"
#include "SGCore/SGRotatorArray.h"
#include "SGCore/SGVectorArray.h"
#include "SGUtils/SGArrayUtils.h"
#include "SGHandPose.generated.h"
class FSGHandPoseImpl;
UCLASS(BlueprintType)
class SENSEGLOVECORE_API USGHandPose final : public UObject
{
GENERATED_BODY()
public:
static USGHandPose* NewHandPose(
UObject* Outer, const FSGHandPoseImpl& HandPoseImpl);
public:
static USGHandPose* NewHandPose(UObject* Outer);
static USGHandPose* NewHandPose(
UObject* Outer,
bool bRightHanded, const TArray<TArray<FVector>>& JointPositions, const TArray<TArray<FQuat>>& JointRotations,
const TArray<TArray<FVector>>& HandAngles);
static USGHandPose* NewHandPose(
UObject* Outer,
bool bRightHanded,
const TArray<TArray<FVector>>& JointPositions, const TArray<TArray<FRotator>>& JointRotations,
const TArray<TArray<FVector>>& HandAngles);
static USGHandPose* NewHandPose(
UObject* Outer,
bool bRightHanded, const TArray<FSGVectorArray>& JointPositions, const TArray<FSGQuatArray>& JointRotations,
const TArray<FSGVectorArray>& HandAngles);
static USGHandPose* NewHandPose(
UObject* Outer,
bool bRightHanded, const TArray<FSGVectorArray>& JointPositions, const TArray<FSGRotatorArray>& JointRotations,
const TArray<FSGVectorArray>& HandAngles);
public:
static USGHandPose* Deserialize(UObject* Outer, const FString& SerializedString);
static USGHandPose* FromHandAngles(UObject* Outer,
const TArray<TArray<FVector>>& HandAngles, bool bRightHanded,
const USGBasicHandModel* HandDimensions);
static USGHandPose* FromHandAngles(UObject* Outer, const TArray<TArray<FVector>>& HandAngles, bool bRightHanded);
static USGHandPose* DefaultIdle(UObject* Outer, bool bRightHanded, const USGBasicHandModel* HandDimensions);
static USGHandPose* DefaultIdle(UObject* Outer, bool bRightHanded);
static USGHandPose* FlatHand(UObject* Outer, bool bRightHanded, const USGBasicHandModel* HandDimensions);
static USGHandPose* FlatHand(UObject* Outer, bool bRightHanded);
static USGHandPose* ThumbsUp(UObject* Outer, bool bRightHanded, const USGBasicHandModel* HandDimensions);
static USGHandPose* ThumbsUp(UObject* Outer, bool bRightHanded);
static USGHandPose* Fist(UObject* Outer, bool bRightHanded, const USGBasicHandModel* HandDimensions);
static USGHandPose* Fist(UObject* Outer, bool bRightHanded);
private:
struct FImpl;
struct FImplDeleter
{
void operator()(const FImpl* P) const;
};
TUniquePtr<FImpl, FImplDeleter> Pimpl;
FImplDeleter PimplDeleter;
public:
USGHandPose();
USGHandPose(bool bRightHanded,
const TArray<TArray<FVector>>& JointPositions, const TArray<TArray<FQuat>>& JointRotations,
const TArray<TArray<FVector>>& HandAngles);
USGHandPose(bool bRightHanded,
const TArray<TArray<FVector>>& JointPositions, const TArray<TArray<FRotator>>& JointRotations,
const TArray<TArray<FVector>>& HandAngles);
USGHandPose(bool bRightHanded,
const TArray<FSGVectorArray>& JointPositions, const TArray<FSGQuatArray>& JointRotations,
const TArray<FSGVectorArray>& HandAngles);
USGHandPose(bool bRightHanded,
const TArray<FSGVectorArray>& JointPositions, const TArray<FSGRotatorArray>& JointRotations,
const TArray<FSGVectorArray>& HandAngles);
public:
/**
* The cast from underlying type constructor.
*/
explicit USGHandPose(const FSGHandPoseImpl& HandPoseImpl);
public:
/**
* The destructor.
*/
virtual ~USGHandPose() override;
protected:
/**
* Allows to set the underlying object after construction.
*/
void SetHandPoseImpl(const FSGHandPoseImpl& HandPoseImpl);
public:
/**
* The cast to underlying type method.
*/
const FSGHandPoseImpl& ToHandPoseImpl() const;
public:
bool IsRight() const;
TArray<TArray<FVector>> GetJointPositions() const;
TArray<TArray<FQuat>> GetJointRotationsQ() const;
TArray<TArray<FRotator>> GetJointRotations() const;
TArray<TArray<FVector>> GetHandAngles() const;
public:
bool Equals(const USGHandPose* HandPose) const;
float GetNormalizedFlexion(ESGFinger Finger, bool bClamp01 = true) const;
TArray<float> GetNormalizedFlexion(bool bClamp01 = true) const;
public:
FString ToString(bool bShortFormat = false) const;
FString SGSerialize() const;
};