318 lines
10 KiB
C++
318 lines
10 KiB
C++
/**
|
|
* @file
|
|
*
|
|
* @author Mamadou Babaei <mamadou@senseglove.com>
|
|
*
|
|
* @section LICENSE
|
|
*
|
|
* (The MIT License)
|
|
*
|
|
* Copyright (c) 2020 - 2023 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
|
|
*
|
|
* Glove information taken from the Sense Glove.
|
|
*/
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "Containers/Array.h"
|
|
#include "Containers/UnrealString.h"
|
|
#include "HAL/Platform.h"
|
|
#include "UObject/Object.h"
|
|
#include "UObject/ObjectMacros.h"
|
|
|
|
#include "SGTypes/SGCoreTypes.h"
|
|
#include "SGTypes/SGVectorArray.h"
|
|
|
|
#include "SGSenseGloveInfo.generated.h"
|
|
|
|
class FSGSenseGloveInfoImpl;
|
|
|
|
/**
|
|
* Glove Information taken from a SenseGlove. Contains everything from unique ID, firmware version, etc.
|
|
*/
|
|
UCLASS(BlueprintType)
|
|
class SENSEGLOVECORE_API USGSenseGloveInfo final : public UObject
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
static USGSenseGloveInfo* NewSenseGloveInfo(
|
|
UObject* Outer, const FSGSenseGloveInfoImpl& SenseGloveInfoImpl);
|
|
|
|
public:
|
|
/**
|
|
* The default constructor.
|
|
*/
|
|
static USGSenseGloveInfo* NewSenseGloveInfo(UObject* Outer);
|
|
|
|
/**
|
|
* Create a new Sense Glove device model.
|
|
*/
|
|
static USGSenseGloveInfo* NewSenseGloveInfo(
|
|
UObject* Outer, const FString& DeviceId,
|
|
const FString& HardwareVersion, int32 FirmwareVersion, int32 SubFirmwareVersion,
|
|
bool bRightHanded, int32 NumberOfSensors, const FQuat& ImuCorrection,
|
|
const TArray<FVector>& StartPositions, const TArray<FQuat>& StartRotations,
|
|
const TArray<TArray<FVector>>& GloveLengths, const TArray<bool>& Functions);
|
|
|
|
/**
|
|
* Create a new Sense Glove device model.
|
|
*/
|
|
static USGSenseGloveInfo* NewSenseGloveInfo(
|
|
UObject* Outer, const FString& DeviceId,
|
|
const FString& HardwareVersion, int32 FirmwareVersion, int32 SubFirmwareVersion,
|
|
bool bRightHanded, int32 NumberOfSensors, const FRotator& ImuCorrection,
|
|
const TArray<FVector>& StartPositions, const TArray<FRotator>& StartRotations,
|
|
const TArray<TArray<FVector>>& GloveLengths, const TArray<bool>& Functions);
|
|
|
|
/**
|
|
* Create a new Sense Glove device model.
|
|
*/
|
|
static USGSenseGloveInfo* NewSenseGloveInfo(
|
|
UObject* Outer, const FString& DeviceId,
|
|
const FString& HardwareVersion, int32 FirmwareVersion, int32 SubFirmwareVersion,
|
|
bool bRightHanded, int32 NumberOfSensors, const FQuat& ImuCorrection,
|
|
const TArray<FVector>& StartPositions, const TArray<FQuat>& StartRotations,
|
|
const TArray<FSGVectorArray>& GloveLengths, const TArray<bool>& Functions);
|
|
|
|
/**
|
|
* Create a new Sense Glove device model.
|
|
*/
|
|
static USGSenseGloveInfo* NewSenseGloveInfo(
|
|
UObject* Outer, const FString& DeviceId,
|
|
const FString& HardwareVersion, int32 FirmwareVersion, int32 SubFirmwareVersion,
|
|
bool bRightHanded, int32 NumberOfSensors, const FRotator& ImuCorrection,
|
|
const TArray<FVector>& StartPositions, const TArray<FRotator>& StartRotations,
|
|
const TArray<FSGVectorArray>& GloveLengths, const TArray<bool>& Functions);
|
|
|
|
public:
|
|
/**
|
|
* Create an instance of the SGModel from its string representation.
|
|
*/
|
|
static bool Parse(UObject* Outer, const FString& ConstantsString, USGSenseGloveInfo*& OutGloveInfo,
|
|
bool bUpdateOldModels = true);
|
|
|
|
/**
|
|
* Deserialize a HandProfile back into usable values.
|
|
*/
|
|
static USGSenseGloveInfo* Deserialize(UObject* Outer, const FString& SerializedString);
|
|
|
|
private:
|
|
struct FImpl;
|
|
|
|
struct FImplDeleter
|
|
{
|
|
void operator()(const FImpl* P) const;
|
|
};
|
|
|
|
TUniquePtr<FImpl, FImplDeleter> Pimpl;
|
|
FImplDeleter PimplDeleter;
|
|
|
|
public:
|
|
/**
|
|
* The default constructor.
|
|
*/
|
|
USGSenseGloveInfo();
|
|
|
|
/**
|
|
* Create a new Sense Glove device model.
|
|
*/
|
|
USGSenseGloveInfo(const FString& DeviceId,
|
|
const FString& HardwareVersion, int32 FirmwareVersion, int32 SubFirmwareVersion,
|
|
bool bRightHanded, int32 NumberOfSensors, const FQuat& ImuCorrection,
|
|
const TArray<FVector>& StartPositions, const TArray<FQuat>& StartRotations,
|
|
const TArray<TArray<FVector>>& GloveLengths, const TArray<bool>& Functions);
|
|
|
|
/**
|
|
* Create a new Sense Glove device model.
|
|
*/
|
|
USGSenseGloveInfo(const FString& DeviceId,
|
|
const FString& HardwareVersion, int32 FirmwareVersion, int32 SubFirmwareVersion,
|
|
bool bRightHanded, int32 NumberOfSensors, const FRotator& ImuCorrection,
|
|
const TArray<FVector>& StartPositions, const TArray<FRotator>& StartRotations,
|
|
const TArray<TArray<FVector>>& GloveLengths, const TArray<bool>& Functions);
|
|
|
|
/**
|
|
* Create a new Sense Glove device model.
|
|
*/
|
|
USGSenseGloveInfo(const FString& DeviceId,
|
|
const FString& HardwareVersion, int32 FirmwareVersion, int32 SubFirmwareVersion,
|
|
bool bRightHanded, int32 NumberOfSensors, const FQuat& ImuCorrection,
|
|
const TArray<FVector>& StartPositions, const TArray<FQuat>& StartRotations,
|
|
const TArray<FSGVectorArray>& GloveLengths, const TArray<bool>& Functions);
|
|
|
|
/**
|
|
* Create a new Sense Glove device model.
|
|
*/
|
|
USGSenseGloveInfo(const FString& DeviceId,
|
|
const FString& HardwareVersion, int32 FirmwareVersion, int32 SubFirmwareVersion,
|
|
bool bRightHanded, int32 NumberOfSensors, const FRotator& ImuCorrection,
|
|
const TArray<FVector>& StartPositions, const TArray<FRotator>& StartRotations,
|
|
const TArray<FSGVectorArray>& GloveLengths, const TArray<bool>& Functions);
|
|
|
|
public:
|
|
/**
|
|
* The cast from underlying type constructor.
|
|
*/
|
|
explicit USGSenseGloveInfo(const FSGSenseGloveInfoImpl& SenseGloveInfoImpl);
|
|
|
|
public:
|
|
/**
|
|
* The destructor.
|
|
*/
|
|
virtual ~USGSenseGloveInfo() override;
|
|
|
|
protected:
|
|
/**
|
|
* Allows to set the underlying object after construction.
|
|
*/
|
|
void SetSenseGloveInfoImpl(const FSGSenseGloveInfoImpl& SenseGloveInfoImpl);
|
|
|
|
public:
|
|
/**
|
|
* The cast to underlying type method.
|
|
*/
|
|
const FSGSenseGloveInfoImpl& ToSenseGloveInfoImpl() const;
|
|
|
|
protected:
|
|
/**
|
|
* The non-const cast to underlying type method.
|
|
*/
|
|
FSGSenseGloveInfoImpl& ToSenseGloveInfoImpl();
|
|
|
|
public:
|
|
/**
|
|
* Unique identifier of this device.
|
|
*/
|
|
FString GetDeviceId() const;
|
|
|
|
/**
|
|
* Hardware (sub) version of this Sense Glove Device.
|
|
*/
|
|
FString GetHardwareVersion() const;
|
|
|
|
/**
|
|
* Firmware version running on the device's MicroController.
|
|
*/
|
|
int32 GetFirmwareVersion() const;
|
|
|
|
/**
|
|
* Sub-Firmware version running on the device's MicroController.
|
|
*/
|
|
int32 GetSubFirmwareVersion() const;
|
|
|
|
/**
|
|
* Check if this Sense Glove belongs to a left or right hand.
|
|
*/
|
|
bool IsRight() const;
|
|
|
|
/**
|
|
* The number of Sensors in this SenseGlove.
|
|
*/
|
|
int32 GetNumberOfSensors() const;
|
|
|
|
/**
|
|
* The IMU correction of this Sense Glove.
|
|
*/
|
|
FQuat GetImuCorrectionQ() const;
|
|
|
|
/**
|
|
* The IMU correction of this Sense Glove.
|
|
*/
|
|
FRotator GetImuCorrection() const;
|
|
|
|
/**
|
|
* The starting positions of each Sense Glove finger, relative to the glove origin.
|
|
*/
|
|
TArray<FVector> GetStartPositions() const;
|
|
|
|
/**
|
|
* The starting rotations of each Sense Glove finger, relative to the glove origin.
|
|
*/
|
|
TArray<FQuat> GetStartRotationsQ() const;
|
|
|
|
/**
|
|
* The starting rotations of each Sense Glove finger, relative to the glove origin.
|
|
*/
|
|
TArray<FRotator> GetStartRotations() const;
|
|
|
|
/**
|
|
* The lengths of each Sense Glove finger section, in cm.
|
|
*/
|
|
TArray<TArray<FVector>> GetGloveLengths() const;
|
|
|
|
/**
|
|
* Whether this device has a specific function (T/F).
|
|
*/
|
|
TArray<bool> GetFunctions() const;
|
|
|
|
public:
|
|
/**
|
|
* The starting position of one Sense Glove finger, relative to the glove origin.
|
|
*/
|
|
FVector GetStartPosition(ESGFinger Finger) const;
|
|
|
|
/**
|
|
* The starting rotation of one Sense Glove finger, relative to the glove origin.
|
|
*/
|
|
FQuat GetStartRotationQ(ESGFinger Finger) const;
|
|
|
|
/**
|
|
* The starting rotation of one Sense Glove finger, relative to the glove origin.
|
|
*/
|
|
FRotator GetStartRotation(ESGFinger Finger) const;
|
|
|
|
/**
|
|
* The lengths of one Sense Glove finger's sections, in cm.
|
|
*/
|
|
TArray<FVector> GetGloveLengths(ESGFinger Finger) const;
|
|
|
|
public:
|
|
/**
|
|
* Place incoming sensor data into the right format, according to this glove's model.
|
|
*/
|
|
TArray<TArray<FVector>> ToGloveAngles(const TArray<TArray<float>>& SensorAngles) const;
|
|
|
|
/**
|
|
* Returns true if this SG_Model has the same values as another.
|
|
*/
|
|
bool Equals(const USGSenseGloveInfo* SenseGloveInfo) const;
|
|
|
|
public:
|
|
/**
|
|
* Create a string representation for logging. If shortNotation is false, all values are reported.
|
|
*/
|
|
FString ToString() const;
|
|
|
|
/**
|
|
* Create a string representation for fast logging.
|
|
*/
|
|
FString ToString(bool bShortNotation) const;
|
|
|
|
/**
|
|
* Serialize this HandProfile into a string representation.
|
|
*/
|
|
FString SGSerialize() const;
|
|
};
|