Agrarsense
TreeHeightsFromImageComponent.h
Go to the documentation of this file.
1// Copyright (c) 2024 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "CoreMinimal.h"
9#include "Components/ActorComponent.h"
10#include "Math/Color.h"
11#include "Engine/Texture2D.h"
12#include "TreeHeightsFromImageComponent.generated.h"
13
14UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
15class AGRARSENSE_API UTreeHeightsFromImageComponent : public UActorComponent
16{
17 GENERATED_BODY()
18
19public:
20
21 UTreeHeightsFromImageComponent();
22
23protected:
24
25 virtual void BeginPlay() override;
26
27 void CacheTexture();
28
29 float EuclideanDistance(const FColor& Color1, const FColor& Color2);
30
31 FColor FindClosestColor(const FColor& TargetColor, const TMap<int32, FColor>& ColorMap);
32
33 UFUNCTION(BlueprintCallable)
34 int32 GetColorFromPixel(FVector point);
35
36 const TMap<int32, FColor> colorHeight = {
37 {0, FColor(48, 18, 59)},
38 {1, FColor(59, 48, 129)},
39 {2, FColor(67, 77, 183)},
40 {3, FColor(70, 104, 222)},
41 {4, FColor(70, 130, 247)},
42 {5, FColor(61, 156, 252)},
43 {6, FColor(44, 182, 239)},
44 {7, FColor(30, 205, 216)},
45 {8, FColor(26, 223, 190)},
46 {9, FColor(42, 237, 163)},
47 {10, FColor(73, 247, 130)},
48 {11, FColor(111, 253, 97)},
49 {12, FColor(147, 253, 71)},
50 {13, FColor(177, 248, 56)},
51 {14, FColor(203, 236, 53)},
52 {15, FColor(226, 219, 56)},
53 {16, FColor(243, 199, 57)},
54 {17, FColor(252, 176, 53)},
55 {18, FColor(253, 148, 43)},
56 {19, FColor(249, 118, 30)},
57 {20, FColor(239, 89, 17)},
58 {21, FColor(224, 65, 9)},
59 {22, FColor(205, 45, 5)},
60 {23, FColor(181, 28, 2)},
61 {24, FColor(153, 14, 1)},
62 {25, FColor(122, 4, 3)}
63 };
64
65 const TMap<int32, FColor> colorHeightRovaniemi = {
66 {0, FColor(48, 18, 59)},
67 {1, FColor(61, 52, 137)},
68 {2, FColor(68, 85, 196)},
69 {3, FColor(71, 115, 235)},
70 {4, FColor(67, 144, 254)},
71 {5, FColor(51, 173, 247)},
72 {6, FColor(31, 201, 221)},
73 {7, FColor(24, 223, 191)},
74 {8, FColor(42, 239, 161)},
75 {9, FColor(81, 250, 123)},
76 {10, FColor(126, 255, 85)},
77 {11, FColor(164, 252, 60)},
78 {12, FColor(194, 242, 52)},
79 {13, FColor(222, 224, 55)},
80 {14, FColor(242, 201, 58)},
81 {15, FColor(253, 175, 53)},
82 {16, FColor(254, 143, 41)},
83 {17, FColor(246, 109, 25)},
84 {18, FColor(233, 77, 13)},
85 {19, FColor(214, 53, 6)},
86 {20, FColor(189, 32, 2)},
87 {21, FColor(157, 16, 1)},
88 {22, FColor(122, 4, 3)}
89 };
90
91 UPROPERTY()
92 int32 Width;
93 UPROPERTY()
94 int32 Height;
95
96public:
97
98 UPROPERTY(EditAnywhere, Category = "Generate")
99 bool GenerateTrigger;
100
101#if WITH_EDITOR
102 virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
103#endif
104
105 UPROPERTY(EditAnywhere)
106 UTexture2D* treeMapImage;
107
108 UPROPERTY()
109 TArray<uint8> Pixels;
110
111};