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;
21
26struct FDroneParameters;
27
32UCLASS()
33class AGRARSENSE_API USimulatorJsonParser : public UBlueprintFunctionLibrary
34{
35
36 GENERATED_BODY()
37
38public:
39
44 UFUNCTION(BlueprintCallable, Category = "ROS JSON Utilities")
45 static void ParseAndOperateJSONFile(const FString& Path);
46
47private:
48
49 static void ParseVehicle(const TSharedPtr<FJsonObject>& JsonObject);
50
51 static void ParsePropOrFoliage(const TSharedPtr<FJsonObject>& JsonObject, const FString& ObjectType);
52
53 static void SpawnSensorToVehicle(AVehicle* Vehicle, const TSharedPtr<FJsonObject>& SensorObject);
54
55 static void SpawnSensorWorld(const TSharedPtr<FJsonObject>& SensorObject);
56
57 static void SpawnWalker(const TSharedPtr<FJsonObject>& JsonObject);
58
59 static void ParseWalkerSpawnPoints(const TSharedPtr<FJsonObject>& ParametersObject, FWalkerParameters& WalkerParams);
60
61 static void ChangeWeather(const TSharedPtr<FJsonObject>& JsonObject);
62
63 static void ParseAndSetDroneParameters(APIDDrone* DronePtr, const TSharedPtr<FJsonObject>& JsonObject);
64
65 static void TeleportSpectatorOrFollowActorIfField(const TSharedPtr<FJsonObject>& JsonObject, AActor* Actor, const FTransform& Transform);
66
67 static void AttachActorToSpectatorCamera(AActor* ActorPtr);
68
69 static void ParseAndSetSemanticColors(const TSharedPtr<FJsonObject>& JsonObject);
70
71 static void ParseCommands(const TSharedPtr<FJsonObject>& JsonObject);
72
73 static void ParseVolumeDeletion(const TSharedPtr<FJsonObject>& JsonObject);
74
75 static FTransform ParseTransform(const FString& FieldName, const TSharedPtr<FJsonObject>& Object);
76
77 static FVector4 ParseVector4(const FString& FieldName, const TSharedPtr<FJsonObject>& Object);
78
79 static FDepthCameraParameters ParseDepthCameraParameters(const TSharedPtr<FJsonObject>& ParametersObject);
80
81 static FThermalCameraParameters ParseThermalCameraParameters(const TSharedPtr<FJsonObject>& ParametersObject);
82
83 static FDVSCameraParameters ParseDVSCameraParameters(const TSharedPtr<FJsonObject>& ParametersObject);
84
85 static int GetIntValueOrDefault(const TSharedPtr<FJsonObject>& JsonObject, const FString& FieldName, int Default);
86
93 template<typename T>
94 static T ParseParameters(const TSharedPtr<FJsonObject>& ParametersObject)
95 {
96 T Params;
97
98 if (ParametersObject.IsValid())
99 {
100 FJsonObjectConverter::JsonObjectToUStruct(ParametersObject.ToSharedRef(), T::StaticStruct(), &Params);
101 }
102
103 return Params;
104 }
105
106};
static T ParseParameters(const TSharedPtr< FJsonObject > &ParametersObject)