367 lines
10 KiB
C++
367 lines
10 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
|
|
*
|
|
* A data class containing the minimum required data for a hand's forward
|
|
* kinematics.
|
|
* Used in both kinematics and calibration.
|
|
*/
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "Containers/Array.h"
|
|
#include "Containers/UnrealString.h"
|
|
#include "HAL/Platform.h"
|
|
#include "Math/Quat.h"
|
|
#include "Math/Vector.h"
|
|
#include "Templates/UniquePtr.h"
|
|
#include "UObject/Object.h"
|
|
#include "UObject/ObjectMacros.h"
|
|
|
|
#include "SGCore/SGFloatArray.h"
|
|
#include "SGTypes/SGCoreTypes.h"
|
|
#include "SGUtils/SGArrayUtils.h"
|
|
|
|
#include "SGBasicHandModel.generated.h"
|
|
|
|
class FSGBasicHandModelImpl;
|
|
|
|
/**
|
|
* Represents data of a user's hand required for forward kinematics.
|
|
*/
|
|
UCLASS(BlueprintType)
|
|
class SENSEGLOVECORE_API USGBasicHandModel final : public UObject
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
static USGBasicHandModel* NewBasicHandModel(
|
|
UObject* Outer, const FSGBasicHandModelImpl& BasicHandModelImpl);
|
|
|
|
public:
|
|
/**
|
|
* The basic class constructor.
|
|
*/
|
|
static USGBasicHandModel* NewBasicHandModel(UObject* Outer);
|
|
|
|
/**
|
|
* Create a new BasicHandModel with no starting rotations.
|
|
*/
|
|
static USGBasicHandModel* NewBasicHandModel(
|
|
UObject* Outer,
|
|
bool bRightHanded, const TArray<TArray<float>>& Lengths, const TArray<FVector>& StartPositions);
|
|
|
|
/**
|
|
* Create a new BasicHandModel with no starting rotations.
|
|
*/
|
|
static USGBasicHandModel* NewBasicHandModel(
|
|
UObject* Outer,
|
|
bool bRightHanded, const TArray<FSGFloatArray>& Lengths, const TArray<FVector>& StartPositions);
|
|
|
|
/**
|
|
* Create a new BasicHandModel.
|
|
*/
|
|
static USGBasicHandModel* NewBasicHandModel(
|
|
UObject* Outer,
|
|
bool bRightHanded, const TArray<TArray<float>>& Lengths,
|
|
const TArray<FVector>& StartPositions, const TArray<FQuat>& StartRotations);
|
|
|
|
/**
|
|
* Create a new BasicHandModel.
|
|
*/
|
|
static USGBasicHandModel* NewBasicHandModel(
|
|
UObject* Outer,
|
|
bool bRightHanded, const TArray<TArray<float>>& Lengths,
|
|
const TArray<FVector>& StartPositions, const TArray<FRotator>& StartRotations);
|
|
|
|
/**
|
|
* Create a new BasicHandModel.
|
|
*/
|
|
static USGBasicHandModel* NewBasicHandModel(
|
|
UObject* Outer,
|
|
bool bRightHanded, const TArray<FSGFloatArray>& Lengths,
|
|
const TArray<FVector>& StartPositions, const TArray<FQuat>& StartRotations);
|
|
|
|
/**
|
|
* Create a new BasicHandModel.
|
|
*/
|
|
static USGBasicHandModel* NewBasicHandModel(
|
|
UObject* Outer,
|
|
bool bRightHanded, const TArray<FSGFloatArray>& Lengths,
|
|
const TArray<FVector>& StartPositions, const TArray<FRotator>& StartRotations);
|
|
|
|
public:
|
|
/**
|
|
* Retrieve a default left or right hand model.
|
|
*/
|
|
static USGBasicHandModel* Default(UObject* Outer, bool bRightHanded);
|
|
|
|
/**
|
|
* Convert a serialized HandModel back into its class representation.
|
|
*/
|
|
static USGBasicHandModel* Deserialize(UObject* Outer, const FString& SerializedString);
|
|
|
|
public:
|
|
/**
|
|
* Default finger lengths (based on right hand).
|
|
*
|
|
* @remarks Any missing fingers are replaced with their respective value.
|
|
*/
|
|
static TArray<TArray<float>> GetBaseFingerLengths();
|
|
|
|
/**
|
|
* Default joint positions (based on right hand).
|
|
*
|
|
* @remarks Any missing positions are replaced with their respective value.
|
|
*/
|
|
static TArray<FVector> GetBaseJointPositions();
|
|
|
|
/**
|
|
* Default joint angles (based on right hand).
|
|
*
|
|
* @remarks Any missing angles are replaced with their respective value.
|
|
*/
|
|
static TArray<FVector> GetBaseJointAngles();
|
|
|
|
private:
|
|
struct FImpl;
|
|
|
|
struct FImplDeleter
|
|
{
|
|
void operator()(const FImpl* P) const;
|
|
};
|
|
|
|
TUniquePtr<FImpl, FImplDeleter> Pimpl;
|
|
FImplDeleter PimplDeleter;
|
|
|
|
public:
|
|
/**
|
|
* The basic class constructor.
|
|
*/
|
|
USGBasicHandModel();
|
|
|
|
/**
|
|
* Create a new BasicHandModel with no starting rotations.
|
|
*/
|
|
USGBasicHandModel(bool bRightHanded, const TArray<TArray<float>>& Lengths,
|
|
const TArray<FVector>& StartPositions);
|
|
|
|
/**
|
|
* Create a new BasicHandModel with no starting rotations.
|
|
*/
|
|
USGBasicHandModel(bool bRightHanded, const TArray<FSGFloatArray>& Lengths,
|
|
const TArray<FVector>& StartPositions);
|
|
|
|
/**
|
|
* Create a new BasicHandModel.
|
|
*/
|
|
USGBasicHandModel(bool bRightHanded, const TArray<TArray<float>>& Lengths,
|
|
const TArray<FVector>& StartPositions, const TArray<FQuat>& StartRotations);
|
|
|
|
/**
|
|
* Create a new BasicHandModel.
|
|
*/
|
|
USGBasicHandModel(bool bRightHanded, const TArray<TArray<float>>& Lengths,
|
|
const TArray<FVector>& StartPositions, const TArray<FRotator>& StartRotations);
|
|
|
|
/**
|
|
* Create a new BasicHandModel.
|
|
*/
|
|
USGBasicHandModel(bool bRightHanded, const TArray<FSGFloatArray>& Lengths,
|
|
const TArray<FVector>& StartPositions, const TArray<FQuat>& StartRotations);
|
|
|
|
/**
|
|
* Create a new BasicHandModel.
|
|
*/
|
|
USGBasicHandModel(bool bRightHanded, const TArray<FSGFloatArray>& Lengths,
|
|
const TArray<FVector>& StartPositions, const TArray<FRotator>& StartRotations);
|
|
|
|
public:
|
|
/**
|
|
* The cast from underlying type constructor.
|
|
*/
|
|
explicit USGBasicHandModel(const FSGBasicHandModelImpl& BasicHandModelImpl);
|
|
|
|
public:
|
|
/**
|
|
* The destructor.
|
|
*/
|
|
virtual ~USGBasicHandModel() override;
|
|
|
|
protected:
|
|
/**
|
|
* Allows to set the underlying object after construction.
|
|
*/
|
|
void SetBasicHandModelImpl(const FSGBasicHandModelImpl& BasicHandModelImpl);
|
|
|
|
public:
|
|
/**
|
|
* The cast to underlying type method.
|
|
*/
|
|
const FSGBasicHandModelImpl& ToBasicHandModelImpl() const;
|
|
|
|
protected:
|
|
/**
|
|
* The non-const cast to underlying type method.
|
|
*/
|
|
FSGBasicHandModelImpl& ToBasicHandModelImpl();
|
|
|
|
public:
|
|
/**
|
|
* Whether or not this BasicHandModel was created for a left- or right hand. Used for validation.
|
|
*/
|
|
bool IsRight() const;
|
|
|
|
/**
|
|
* The length of individual finger phalangers in mm, sorted per finger. Generally 5x3.
|
|
*/
|
|
TArray<TArray<float>> GetFingerLengths() const;
|
|
|
|
/**
|
|
* Retrieve the finger lengths of a specific finger in cm.
|
|
*/
|
|
TArray<float> GetFingerLengths(ESGFinger Finger) const;
|
|
|
|
/**
|
|
* Set the finger lengths of a specific finger in cm.
|
|
*/
|
|
void SetFingerLengths(ESGFinger Finger, const TArray<float>& Lengths);
|
|
|
|
/**
|
|
* Set the finger lengths of a specific finger in cm.
|
|
*/
|
|
void SetFingerLengths(uint8 Finger, const TArray<float>& Lengths);
|
|
|
|
/**
|
|
* Get the finger ratios of all fingers.
|
|
*/
|
|
TArray<TArray<float>> GetFingerRatios() const;
|
|
|
|
/**
|
|
* Get the finger ratios of a specific finger.
|
|
*/
|
|
TArray<float> GetFingerRatios(ESGFinger Finger) const;
|
|
|
|
/**
|
|
* Starting joint positions relative to the device Origin.
|
|
*/
|
|
TArray<FVector> GetStartJointPositions() const;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
void SetStartJointPosition(ESGFinger Finger, const FVector& Position);
|
|
|
|
/**
|
|
*
|
|
*/
|
|
void SetStartJointPosition(uint8 Finger, const FVector& Position);
|
|
|
|
/**
|
|
* Starting joint rotations relative to the device Origin.
|
|
*/
|
|
TArray<FQuat> GetStartJointRotationsQ() const;
|
|
|
|
/**
|
|
* Starting joint rotations relative to the device Origin.
|
|
*/
|
|
TArray<FRotator> GetStartJointRotations() const;
|
|
|
|
/**
|
|
* Retrieve the start position of a specific finger.
|
|
*/
|
|
FVector GetJointPosition(ESGFinger Finger) const;
|
|
|
|
/**
|
|
* Set the start position of a specific finger.
|
|
*/
|
|
void SetJointPosition(const FVector& NewPosition, ESGFinger Finger);
|
|
|
|
/**
|
|
* Retrieve the start rotation of a specific finger.
|
|
*/
|
|
FQuat GetJointRotationQ(ESGFinger Finger) const;
|
|
|
|
/**
|
|
* Retrieve the start rotation of a specific finger.
|
|
*/
|
|
FRotator GetJointRotation(ESGFinger Finger) const;
|
|
|
|
/**
|
|
* Set the start rotation of a specific finger.
|
|
*/
|
|
void SetJointRotation(const FQuat& NewRotation, ESGFinger Finger);
|
|
|
|
/**
|
|
* Set the start rotation of a specific finger.
|
|
*/
|
|
void SetJointRotation(const FRotator& NewRotation, ESGFinger Finger);
|
|
|
|
/**
|
|
* Get the total lengths of fingers, in cm.
|
|
*/
|
|
TArray<float> GetTotalLengths() const;
|
|
|
|
/**
|
|
* Get the total length of a specific finger, in mm.
|
|
*/
|
|
float GetTotalLength(ESGFinger Finger) const;
|
|
|
|
public:
|
|
/**
|
|
* Retrieve the lengths of a specific finger, as BasicHandModel representation (L, 0, 0).
|
|
*
|
|
* @remarks Used for forwards kinematics.
|
|
*/
|
|
TArray<FVector> Get3DLengths(ESGFinger Finger) const;
|
|
|
|
public:
|
|
/**
|
|
* Check if this BasicHandModel has the same values as another BasicHandModel.
|
|
*/
|
|
bool Equals(const USGBasicHandModel* BasicHandModel) const;
|
|
|
|
public:
|
|
/**
|
|
* Convert this handModel into a string notation, readable for humans. Does not include starting positions / rotations.
|
|
*/
|
|
FString ToString() const;
|
|
|
|
/**
|
|
* Convert this handModel into a string notation, readable for humans. Optionally includes starting positions / rotations.
|
|
*/
|
|
FString ToString(bool bLengthsOnly) const;
|
|
|
|
/**
|
|
* Serialize this HandModel into a string representation.
|
|
*/
|
|
FString SGSerialize() const;
|
|
}; |