Agrarsense
SimulatorJsonParser.h
Go to the documentation of this file.
1// Copyright (c) 2023 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 "EngineMinimal.h"
10#include "Kismet/BlueprintFunctionLibrary.h"
11#include "GameFramework/Actor.h"
12
13#include "Json.h"
14#include "JsonUtilities.h"
15#include "JsonObjectConverter.h"
16
17#include "SimulatorJsonParser.generated.h"
18
19class APIDDrone;
20class AVehicle;
21class ASensor;
22
27struct FDroneParameters;
28
33UCLASS()
34class AGRARSENSE_API USimulatorJsonParser : public UBlueprintFunctionLibrary
35{
36
37 GENERATED_BODY()
38
39public:
40
45 UFUNCTION(BlueprintCallable, Category = "ROS JSON Utilities")
46 static void ParseAndOperateJSONFile(const FString& Path);
47
48private:
49
50 static void ParseVehicle(const TSharedPtr<FJsonObject>& JsonObject);
51
52 static void ParsePropOrFoliage(const TSharedPtr<FJsonObject>& JsonObject, const FString& ObjectType);
53
54 static void SpawnSensorToVehicle(AVehicle* Vehicle, const TSharedPtr<FJsonObject>& SensorObject);
55
56 static void SpawnSensorWorld(const TSharedPtr<FJsonObject>& SensorObject);
57
58 static void SpawnWalker(const TSharedPtr<FJsonObject>& JsonObject);
59
60 static void ParseWalkerSpawnPoints(const TSharedPtr<FJsonObject>& ParametersObject, FWalkerParameters& WalkerParams);
61
62 static void ChangeWeather(const TSharedPtr<FJsonObject>& JsonObject);
63
64 static void ParseAndSetDroneParameters(APIDDrone* DronePtr, const TSharedPtr<FJsonObject>& JsonObject);
65
66 static void ParseAndSetWheeledVehicleParameters(AVehicle* VehiclePtr, const TSharedPtr<FJsonObject>& JsonObject);
67
68 static void HandleSpectatorMovement(const TSharedPtr<FJsonObject>& JsonObject, AActor* Actor, const FTransform& Transform);
69
70 static void AttachActorToSpectatorCamera(AActor* ActorPtr);
71
72 static void ParseAndSetSemanticColors(const TSharedPtr<FJsonObject>& JsonObject);
73
74 static void ParseCommands(const TSharedPtr<FJsonObject>& JsonObject);
75
76 static void ParseVolumeDeletion(const TSharedPtr<FJsonObject>& JsonObject);
77
78 static void ParseDataCapture(const TSharedPtr<FJsonObject>& JsonObject);
79
80 static FTransform ParseTransform(const FString& FieldName, const TSharedPtr<FJsonObject>& Object);
81
82 static FVector4 ParseVector4(const FString& FieldName, const TSharedPtr<FJsonObject>& Object);
83
84 static FThermalCameraParameters ParseThermalCameraParameters(const TSharedPtr<FJsonObject>& ParametersObject);
85
86 static int32 GetIntValueOrDefault(const TSharedPtr<FJsonObject>& JsonObject, const FString& FieldName, int32 DefaultValue);
87
88 /*
89 * Adjusts the Z value of the given transform so that its position represents
90 * the specified height above the ground, instead of an absolute world Z value.
91 * It performs a downward line trace to find the ground level and updates the transform accordingly.
92 */
93 static void ComputeAndSetZFromGround(FTransform& Position);
94
101 template<typename T>
102 static T ParseParameters(const TSharedPtr<FJsonObject>& ParametersObject)
103 {
104 T Params;
105
106 if (ParametersObject.IsValid())
107 {
108 FJsonObjectConverter::JsonObjectToUStruct(ParametersObject.ToSharedRef(), T::StaticStruct(), &Params);
109 }
110
111 return Params;
112 }
113
114 static bool IsDataCapture;
115
116 static TArray<ASensor*> SpawnedSensorsForDataCapture;
117};
Definition: Sensor.h:45
static T ParseParameters(const TSharedPtr< FJsonObject > &ParametersObject)
static TArray< ASensor * > SpawnedSensorsForDataCapture