10 PrimaryActorTick.bCanEverTick =
false;
21 FTexture2DMipMap& Mip =
treeMapImage->GetPlatformData()->Mips[0];
22 void* Data = Mip.BulkData.Lock(LOCK_READ_ONLY);
29 if (Width <= 0 || Height <= 0)
32 UE_LOG(LogTemp, Warning, TEXT(
"Image width: %i, Height: %i"), Width, Height);
34 uint8* Pixels =
static_cast<uint8*
>(Data);
35 for (int32 y = 0; y < Height; y++)
37 for (int32 x = 0; x < Width; x++)
39 int32 Index = (y * Width + x) * 4;
40 uint8 R = Pixels[Index];
41 uint8 G = Pixels[Index + 1];
42 uint8 B = Pixels[Index + 2];
43 uint8 A = Pixels[Index + 3];
45 FColor pixelColor = FColor(B, G, R);
47 if (x == 446 && y == 353)
49 UE_LOG(LogTemp, Warning, TEXT(
"Coordinates RGB = %i, %i, %i"), B, G, R);
51 UE_LOG(LogTemp, Warning, TEXT(
"Closest color: R=%d, G=%d, B=%d"), ClosestColor.R, ClosestColor.G, ClosestColor.B);
55 if (Pair.Value == ClosestColor)
56 UE_LOG(LogTemp, Warning, TEXT(
"This should be a %im size tree"), Pair.Key);
61 if (x == Width / 2 && y == Height / 2)
63 UE_LOG(LogTemp, Warning, TEXT(
"Coordinates middlepoint Width: %i, Height: %i"), x, y);
70 Mip.BulkData.Unlock();
84 return FMath::Sqrt(FMath::Square(R2 - R1) + FMath::Square(G2 - G1) + FMath::Square(B2 - B1));
89 float MinDistance = FLT_MAX;
92 for (
const auto& Pair : ColorMap)
95 if (Distance < MinDistance)
97 MinDistance = Distance;
98 ClosestColor = Pair.Value;
const TMap< int, FColor > colorHeight
virtual void BeginPlay() override
FColor FindClosestColor(const FColor &TargetColor, const TMap< int32, FColor > &ColorMap)
float EuclideanDistance(const FColor &Color1, const FColor &Color2)
UTexture2D * treeMapImage