diff --git a/Source/ROSIntegrationVision/Private/VisionComponent.cpp b/Source/ROSIntegrationVision/Private/VisionComponent.cpp index 0a1597c..3ec2259 100644 --- a/Source/ROSIntegrationVision/Private/VisionComponent.cpp +++ b/Source/ROSIntegrationVision/Private/VisionComponent.cpp @@ -626,9 +626,9 @@ bool UVisionComponent::ColorObject(AActor *Actor, const FString &name) if (UStaticMesh *StaticMesh = StaticMeshComponent->GetStaticMesh()) { uint32 PaintingMeshLODIndex = 0; - uint32 NumLODLevel = StaticMesh->RenderData->LODResources.Num(); + uint32 NumLODLevel = StaticMesh->GetRenderData()->LODResources.Num(); //check(NumLODLevel == 1); - FStaticMeshLODResources &LODModel = StaticMesh->RenderData->LODResources[PaintingMeshLODIndex]; + FStaticMeshLODResources &LODModel = StaticMesh->GetRenderData()->LODResources[PaintingMeshLODIndex]; FStaticMeshComponentLODInfo *InstanceMeshLODInfo = NULL; // PaintingMeshLODIndex + 1 is the minimum requirement, enlarge if not satisfied @@ -743,18 +743,25 @@ void UVisionComponent::ProcessObject() } } -// TODO maybe shift towards "server" who publishs async + +//Decode float16 → float32 first +//Then scale by 0.01 void UVisionComponent::convertDepth(const uint16_t *in, __m128 *out) const { - const size_t size = (Width * Height) / 4; - for (size_t i = 0; i < size; ++i, in += 4, ++out) - { - // Divide by 100 here in order to convert UU (cm) into ROS units (m) - *out = _mm_cvtph_ps( - _mm_div_epi16( - _mm_set_epi16(0, 0, 0, 0, *(in + 3), *(in + 2), *(in + 1), *(in + 0)), - _mm_set_epi16(100, 100, 100, 100, 100, 100, 100, 100) - ) - );// / 100; - } + const size_t size = (Width * Height) / 4; + const __m128 scale = _mm_set1_ps(0.01f); + + for (size_t i = 0; i < size; ++i, in += 4, ++out) + { + float f[4]; + for (int j = 0; j < 4; ++j) + { + FFloat16 half; + half.Encoded = in[j]; + f[j] = half.GetFloat(); + } + + __m128 depth = _mm_loadu_ps(f); + *out = _mm_mul_ps(depth, scale); + } }