Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions Source/ROSIntegrationVision/Private/VisionComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}