Files
Plugin/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGloveInfoImpl.cpp
T

396 lines
14 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
*
*
*/
#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()
:
#if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 )
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */
{
}
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)
:
#if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 )
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */
{
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)
:
#if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 )
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */
{
Pimpl->SenseGloveInfo = GloveInfo;
}
FSGSenseGloveInfoImpl::FSGSenseGloveInfoImpl(const FSGSenseGloveInfoImpl& Rhs)
:
#if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 )
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}))
#endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */
{
Pimpl->Owner = this;
}
FSGSenseGloveInfoImpl::FSGSenseGloveInfoImpl(FSGSenseGloveInfoImpl&& Rhs) noexcept = default;
FSGSenseGloveInfoImpl::~FSGSenseGloveInfoImpl() = default;
FSGSenseGloveInfoImpl& FSGSenseGloveInfoImpl::operator=(const FSGSenseGloveInfoImpl& Rhs)
{
*Pimpl = *Rhs.Pimpl;
Pimpl->Owner = this;
return *this;
}
FSGSenseGloveInfoImpl& FSGSenseGloveInfoImpl::operator=(FSGSenseGloveInfoImpl&& Rhs) 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);
}
void FSGSenseGloveInfoImpl::SetDeviceId(const FString& DeviceId)
{
return Pimpl->SenseGloveInfo.SetDeviceId(TCHAR_TO_UTF8(*DeviceId));
}
FString FSGSenseGloveInfoImpl::GetHardwareVersion() const
{
FString HardwareVersion(UTF8_TO_TCHAR(Pimpl->SenseGloveInfo.GetHardwareVersion().c_str()));
return MoveTemp(HardwareVersion);
}
void FSGSenseGloveInfoImpl::SetHardwareVersion(const FString& HardwareVersion)
{
Pimpl->SenseGloveInfo.SetHardwareVersion(TCHAR_TO_UTF8(*HardwareVersion));
}
int32 FSGSenseGloveInfoImpl::GetFirmwareVersion() const
{
return Pimpl->SenseGloveInfo.GetFirmwareVersion();
}
void FSGSenseGloveInfoImpl::SetFirmwareVersion(const int32 FirmwareVersion)
{
Pimpl->SenseGloveInfo.SetFirmwareVersion(FirmwareVersion);
}
int32 FSGSenseGloveInfoImpl::GetSubFirmwareVersion() const
{
return Pimpl->SenseGloveInfo.GetSubFirmwareVersion();
}
void FSGSenseGloveInfoImpl::SetSubFirmwareVersion(const int32 SubFirmwareVersion)
{
Pimpl->SenseGloveInfo.SetSubFirmwareVersion(SubFirmwareVersion);
}
bool FSGSenseGloveInfoImpl::IsRight() const
{
return Pimpl->SenseGloveInfo.IsRight();
}
void FSGSenseGloveInfoImpl::SetIsRight(const bool bRightHanded)
{
Pimpl->SenseGloveInfo.SetIsRight(bRightHanded);
}
int32 FSGSenseGloveInfoImpl::GetNumberOfSensors() const
{
return Pimpl->SenseGloveInfo.GetNumberOfSensors();
}
void FSGSenseGloveInfoImpl::SetNumberOfSensors(const int32 NumberOfSensors)
{
Pimpl->SenseGloveInfo.SetNumberOfSensors(NumberOfSensors);
}
FQuat FSGSenseGloveInfoImpl::GetImuCorrection() const
{
FQuat ImuCorrection(FSGQuatImpl(Pimpl->SenseGloveInfo.GetImuCorrection()).ToFQuat());
return MoveTemp(ImuCorrection);
}
void FSGSenseGloveInfoImpl::SetImuCorrection(const FQuat& ImuCorrection)
{
Pimpl->SenseGloveInfo.SetImuCorrection(FSGQuatImpl(ImuCorrection).ToQuat());
}
TArray<FVector> FSGSenseGloveInfoImpl::GetStartPositions() const
{
TArray<FVector> StartPositionsArray{
FSGArrayUtils::FromMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(
Pimpl->SenseGloveInfo.GetStartPositions())};
return MoveTemp(StartPositionsArray);
}
void FSGSenseGloveInfoImpl::SetStartPositions(const TArray<FVector>& StartPositions)
{
std::vector<FSGVect3DImpl::FVect3DType> StartPositionsVector{
FSGArrayUtils::ToMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(StartPositions)
};
Pimpl->SenseGloveInfo.SetStartPositions(MoveTemp(StartPositionsVector));
}
TArray<FQuat> FSGSenseGloveInfoImpl::GetStartRotations() const
{
TArray<FQuat> StartRotationsArray{
FSGArrayUtils::FromStdVector<FSGQuatImpl::FQuatType, FQuat, FSGQuatImpl, &FSGQuatImpl::ToFQuat>(
Pimpl->SenseGloveInfo.GetStartRotations())};
return MoveTemp(StartRotationsArray);
}
void FSGSenseGloveInfoImpl::SetStartRotations(const TArray<FQuat>& StartRotations)
{
std::vector<FSGQuatImpl::FQuatType> StartRotationsVector{
FSGArrayUtils::ToStdVector<FQuat, FSGQuatImpl::FQuatType, FSGQuatImpl, &FSGQuatImpl::ToQuat>(
StartRotations)
};
Pimpl->SenseGloveInfo.SetStartRotations(MoveTemp(StartRotationsVector));
}
TArray<TArray<FVector>> FSGSenseGloveInfoImpl::GetGloveLengths() const
{
TArray<TArray<FVector>> GloveLengths{
FSGArrayUtils::FromMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(
Pimpl->SenseGloveInfo.GetGloveLengths())
};
return MoveTemp(GloveLengths);
}
void FSGSenseGloveInfoImpl::SetGloveLengths(const TArray<TArray<FVector>>& GloveLengths) const
{
std::vector<std::vector<FSGVect3DImpl::FVect3DType>> GloveLengthsVector{
FSGArrayUtils::ToMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(GloveLengths)
};
Pimpl->SenseGloveInfo.SetGloveLengths(MoveTemp(GloveLengthsVector));
}
TArray<bool> FSGSenseGloveInfoImpl::GetFunctions() const
{
TArray<bool> FunctionsArray{FSGArrayUtils::FromStdVector(Pimpl->SenseGloveInfo.GetFunctions())};
return MoveTemp(FunctionsArray);
}
void FSGSenseGloveInfoImpl::SetFunctions(const TArray<bool>& Functions) const
{
std::vector<bool> FunctionsVector{FSGArrayUtils::ToStdVector(Functions)};
Pimpl->SenseGloveInfo.SetFunctions(MoveTemp(FunctionsVector));
}
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
{
std::vector<std::vector<float>> SensorAnglesVector{FSGArrayUtils::ToStdVector<float>(SensorAngles)};
TArray<TArray<FVector>> GloveAngles{
FSGArrayUtils::FromStdVector<FSGVect3DImpl::FVect3DType, FVector, FSGVect3DImpl, &FSGVect3DImpl::ToFVector>(
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;
}