314 lines
11 KiB
C++
314 lines
11 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
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
#include "SGCoreImpl/SGSenseGloveInfoImpl.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "Containers/StringConv.h"
|
|
#include "Runtime/Launch/Resources/Version.h"
|
|
|
|
#include "SGBuildHacks/SGInclude_Core_Quat.h"
|
|
#include "SGBuildHacks/SGInclude_Core_SenseGloveInfo.h"
|
|
#include "SGBuildHacks/SGInclude_Core_Vect3D.h"
|
|
#include "SGCoreImpl/SGCoreEnumCast.h"
|
|
#include "SGCoreImpl/SGQuatImpl.h"
|
|
#include "SGCoreImpl/SGVect3DImpl.h"
|
|
#include "SGUtils/SGArrayUtils.h"
|
|
|
|
struct FSGSenseGloveInfoImpl::FImpl
|
|
{
|
|
/************************
|
|
* Member variables
|
|
************************/
|
|
|
|
FSenseGloveInfoType SenseGloveInfo;
|
|
|
|
/************************
|
|
* Owner object
|
|
************************/
|
|
|
|
FSGSenseGloveInfoImpl* Owner;
|
|
|
|
/************************
|
|
* Constructor / Destructor
|
|
************************/
|
|
|
|
explicit FImpl(FSGSenseGloveInfoImpl* InOwner);
|
|
~FImpl();
|
|
|
|
/************************
|
|
* Default copy constructor & copy assignment operator
|
|
************************/
|
|
|
|
FImpl(const FImpl& Rhs) = default;
|
|
FImpl& operator=(const FImpl& Rhs) = default;
|
|
};
|
|
|
|
bool FSGSenseGloveInfoImpl::Parse(const FString& ConstantsString, FSGSenseGloveInfoImpl& OutGloveInfo,
|
|
const bool bUpdateOldModels)
|
|
{
|
|
std::string Constants(TCHAR_TO_UTF8(*ConstantsString));
|
|
FSenseGloveInfoType GloveInfo;
|
|
|
|
const bool bResults = FSenseGloveInfoType::Parse(MoveTemp(Constants), GloveInfo, bUpdateOldModels);
|
|
OutGloveInfo = FSGSenseGloveInfoImpl(GloveInfo);
|
|
|
|
return bResults;
|
|
}
|
|
|
|
FSGSenseGloveInfoImpl FSGSenseGloveInfoImpl::Deserialize(const FString& SerializedString)
|
|
{
|
|
std::string Serialized(TCHAR_TO_UTF8(*SerializedString));
|
|
const FSGSenseGloveInfoImpl GloveInfo(FSenseGloveInfoType::Deserialize(MoveTemp(Serialized)));
|
|
return GloveInfo;
|
|
}
|
|
|
|
FSGSenseGloveInfoImpl::FSGSenseGloveInfoImpl()
|
|
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
}
|
|
|
|
FSGSenseGloveInfoImpl::FSGSenseGloveInfoImpl(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)
|
|
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
std::string DeviceIdString(TCHAR_TO_UTF8(*DeviceId));
|
|
std::string HardwareVersionString(TCHAR_TO_UTF8(*HardwareVersion));
|
|
FSGQuatImpl::FQuatType ImuCorrectionQuat(FSGQuatImpl(ImuCorrection).ToQuat());
|
|
|
|
std::vector<FSGVect3DImpl::FVect3DType> StartPositionsVector{
|
|
FSGArrayUtils::ToMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(StartPositions)
|
|
};
|
|
|
|
std::vector<FSGQuatImpl::FQuatType> StartRotationsVector{
|
|
FSGArrayUtils::ToStdVector<FQuat, FSGQuatImpl::FQuatType, FSGQuatImpl, &FSGQuatImpl::ToQuat>(StartRotations)
|
|
};
|
|
|
|
std::vector<std::vector<FSGVect3DImpl::FVect3DType>> GloveLengthsVector{
|
|
FSGArrayUtils::ToMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(GloveLengths)
|
|
};
|
|
|
|
std::vector<bool> FunctionsVector{FSGArrayUtils::ToStdVector(Functions)};
|
|
|
|
Pimpl->SenseGloveInfo = FSenseGloveInfoType(MoveTemp(DeviceIdString), MoveTemp(HardwareVersionString),
|
|
FirmwareVersion, SubFirmwareVersion,
|
|
bRightHanded, NumberOfSensors,
|
|
MoveTemp(ImuCorrectionQuat),
|
|
MoveTemp(StartPositionsVector), MoveTemp(StartRotationsVector),
|
|
MoveTemp(GloveLengthsVector), MoveTemp(FunctionsVector));
|
|
}
|
|
|
|
FSGSenseGloveInfoImpl::FSGSenseGloveInfoImpl(const FSenseGloveInfoType& GloveInfo)
|
|
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
Pimpl->SenseGloveInfo = GloveInfo;
|
|
}
|
|
|
|
FSGSenseGloveInfoImpl::FSGSenseGloveInfoImpl(const FSGSenseGloveInfoImpl& Rhs)
|
|
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}, PimplDeleter))
|
|
{
|
|
Pimpl->Owner = this;
|
|
}
|
|
|
|
FSGSenseGloveInfoImpl::FSGSenseGloveInfoImpl(FSGSenseGloveInfoImpl&& Rhs) SG_NOEXCEPT = default;
|
|
|
|
FSGSenseGloveInfoImpl::~FSGSenseGloveInfoImpl() = default;
|
|
|
|
FSGSenseGloveInfoImpl& FSGSenseGloveInfoImpl::operator=(const FSGSenseGloveInfoImpl& Rhs)
|
|
{
|
|
*Pimpl = *Rhs.Pimpl;
|
|
Pimpl->Owner = this;
|
|
return *this;
|
|
}
|
|
|
|
FSGSenseGloveInfoImpl& FSGSenseGloveInfoImpl::operator=(FSGSenseGloveInfoImpl&& Rhs) SG_NOEXCEPT = default;
|
|
|
|
const FSGSenseGloveInfoImpl::FSenseGloveInfoType& FSGSenseGloveInfoImpl::ToSenseGloveInfo() const
|
|
{
|
|
return Pimpl->SenseGloveInfo;
|
|
}
|
|
|
|
FString FSGSenseGloveInfoImpl::GetDeviceId() const
|
|
{
|
|
FString DeviceId(UTF8_TO_TCHAR(Pimpl->SenseGloveInfo.GetDeviceId().c_str()));
|
|
return MoveTemp(DeviceId);
|
|
}
|
|
|
|
FString FSGSenseGloveInfoImpl::GetHardwareVersion() const
|
|
{
|
|
FString HardwareVersion(UTF8_TO_TCHAR(Pimpl->SenseGloveInfo.GetHardwareVersion().c_str()));
|
|
return MoveTemp(HardwareVersion);
|
|
}
|
|
|
|
int32 FSGSenseGloveInfoImpl::GetFirmwareVersion() const
|
|
{
|
|
return Pimpl->SenseGloveInfo.GetFirmwareVersion();
|
|
}
|
|
|
|
int32 FSGSenseGloveInfoImpl::GetSubFirmwareVersion() const
|
|
{
|
|
return Pimpl->SenseGloveInfo.GetSubFirmwareVersion();
|
|
}
|
|
|
|
bool FSGSenseGloveInfoImpl::IsRight() const
|
|
{
|
|
return Pimpl->SenseGloveInfo.IsRight();
|
|
}
|
|
|
|
int32 FSGSenseGloveInfoImpl::GetNumberOfSensors() const
|
|
{
|
|
return Pimpl->SenseGloveInfo.GetNumberOfSensors();
|
|
}
|
|
|
|
FQuat FSGSenseGloveInfoImpl::GetImuCorrection() const
|
|
{
|
|
FQuat ImuCorrection(FSGQuatImpl(Pimpl->SenseGloveInfo.GetImuCorrection()).ToFQuat());
|
|
return MoveTemp(ImuCorrection);
|
|
}
|
|
|
|
TArray<FVector> FSGSenseGloveInfoImpl::GetStartPositions() const
|
|
{
|
|
TArray<FVector> StartPositionsArray{
|
|
FSGArrayUtils::FromMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(
|
|
Pimpl->SenseGloveInfo.GetStartPositions())};
|
|
return MoveTemp(StartPositionsArray);
|
|
}
|
|
|
|
TArray<FQuat> FSGSenseGloveInfoImpl::GetStartRotations() const
|
|
{
|
|
TArray<FQuat> StartRotationsArray{
|
|
FSGArrayUtils::FromStdVector<FSGQuatImpl::FQuatType, FQuat, FSGQuatImpl, &FSGQuatImpl::ToFQuat>(
|
|
Pimpl->SenseGloveInfo.GetStartRotations())};
|
|
return MoveTemp(StartRotationsArray);
|
|
}
|
|
|
|
TArray<TArray<FVector>> FSGSenseGloveInfoImpl::GetGloveLengths() const
|
|
{
|
|
TArray<TArray<FVector>> GloveLengths{
|
|
FSGArrayUtils::FromMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(
|
|
Pimpl->SenseGloveInfo.GetGloveLengths())
|
|
};
|
|
return MoveTemp(GloveLengths);
|
|
}
|
|
|
|
TArray<bool> FSGSenseGloveInfoImpl::GetFunctions() const
|
|
{
|
|
TArray<bool> FunctionsArray{FSGArrayUtils::FromStdVector(Pimpl->SenseGloveInfo.GetFunctions())};
|
|
return MoveTemp(FunctionsArray);
|
|
}
|
|
|
|
FVector FSGSenseGloveInfoImpl::GetStartPosition(const ESGFinger Finger) const
|
|
{
|
|
FVector StartPosition{FSGUnits::MillimetersToCentimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(
|
|
Pimpl->SenseGloveInfo.GetStartPosition(FSGCoreEnumCast::ToEFinger(Finger)))
|
|
};
|
|
return MoveTemp(StartPosition);
|
|
}
|
|
|
|
FQuat FSGSenseGloveInfoImpl::GetStartRotation(const ESGFinger Finger) const
|
|
{
|
|
FQuat StartRotation(FSGQuatImpl(Pimpl->SenseGloveInfo.GetStartRotation(
|
|
FSGCoreEnumCast::ToEFinger(Finger))).ToFQuat());
|
|
return MoveTemp(StartRotation);
|
|
}
|
|
|
|
TArray<FVector> FSGSenseGloveInfoImpl::GetGloveLengths(const ESGFinger Finger) const
|
|
{
|
|
std::vector<FSGVect3DImpl::FVect3DType> GloveLengthsVector{
|
|
Pimpl->SenseGloveInfo.GetGloveLengths(FSGCoreEnumCast::ToEFinger(Finger))
|
|
};
|
|
TArray<FVector> GloveLengthsArray{
|
|
FSGArrayUtils::FromMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(MoveTemp(GloveLengthsVector))
|
|
};
|
|
return MoveTemp(GloveLengthsArray);
|
|
}
|
|
|
|
TArray<TArray<FVector>> FSGSenseGloveInfoImpl::ToGloveAngles(const TArray<TArray<float>>& SensorAngles) const
|
|
{
|
|
/// TODO
|
|
/// Does the nested float TArray requires translation? If so, how to do that without a Movement value?
|
|
std::vector<std::vector<float>> SensorAnglesVector{
|
|
FSGArrayUtils::ToStdVector<float>(SensorAngles)
|
|
};
|
|
TArray<TArray<FVector>> GloveAngles{
|
|
FSGArrayUtils::FromSenseGloveAngles<FSGVect3DImpl::FVect3DType>(
|
|
Pimpl->SenseGloveInfo.ToGloveAngles(MoveTemp((SensorAnglesVector))))
|
|
};
|
|
return MoveTemp(GloveAngles);
|
|
}
|
|
|
|
bool FSGSenseGloveInfoImpl::Equals(const FSGSenseGloveInfoImpl& SGSenseGloveInfo, const bool bGeometryOnly) const
|
|
{
|
|
return Pimpl->SenseGloveInfo.Equals(SGSenseGloveInfo.ToSenseGloveInfo(), bGeometryOnly);
|
|
}
|
|
|
|
FString FSGSenseGloveInfoImpl::ToString(const bool bShortNotation) const
|
|
{
|
|
FString String(UTF8_TO_TCHAR(Pimpl->SenseGloveInfo.ToString(bShortNotation).c_str()));
|
|
return MoveTemp(String);
|
|
}
|
|
|
|
FString FSGSenseGloveInfoImpl::ToString() const
|
|
{
|
|
FString String(UTF8_TO_TCHAR(Pimpl->SenseGloveInfo.ToString().c_str()));
|
|
return MoveTemp(String);
|
|
}
|
|
|
|
FString FSGSenseGloveInfoImpl::Serialize() const
|
|
{
|
|
FString Serialized(UTF8_TO_TCHAR(Pimpl->SenseGloveInfo.Serialize().c_str()));
|
|
return MoveTemp(Serialized);
|
|
}
|
|
|
|
FSGSenseGloveInfoImpl::FImpl::FImpl(FSGSenseGloveInfoImpl* InOwner)
|
|
: Owner(InOwner)
|
|
{
|
|
}
|
|
|
|
FSGSenseGloveInfoImpl::FImpl::~FImpl() = default;
|
|
|
|
void FSGSenseGloveInfoImpl::FImplDeleter::operator()(const FImpl* P) const
|
|
{
|
|
delete P;
|
|
} |