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 ACamera;
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 TeleportSpectatorOrFollowActorIfField(const TSharedPtr<FJsonObject>& JsonObject, AActor* Actor, const FTransform& Transform);
67
68 static void AttachActorToSpectatorCamera(AActor* ActorPtr);
69
70 static void ParseAndSetSemanticColors(const TSharedPtr<FJsonObject>& JsonObject);
71
72 static void ParseCommands(const TSharedPtr<FJsonObject>& JsonObject);
73
74 static void ParseVolumeDeletion(const TSharedPtr<FJsonObject>& JsonObject);
75
76 static void ParseDataCapture(const TSharedPtr<FJsonObject>& JsonObject);
77
78 static FTransform ParseTransform(const FString& FieldName, const TSharedPtr<FJsonObject>& Object);
79
80 static FVector4 ParseVector4(const FString& FieldName, const TSharedPtr<FJsonObject>& Object);
81
82 static FDepthCameraParameters ParseDepthCameraParameters(const TSharedPtr<FJsonObject>& ParametersObject);
83
84 static FThermalCameraParameters ParseThermalCameraParameters(const TSharedPtr<FJsonObject>& ParametersObject);
85
86 static FDVSCameraParameters ParseDVSCameraParameters(const TSharedPtr<FJsonObject>& ParametersObject);
87
88 static int GetIntValueOrDefault(const TSharedPtr<FJsonObject>& JsonObject, const FString& FieldName, int Default);
89
96 template<typename T>
97 static T ParseParameters(const TSharedPtr<FJsonObject>& ParametersObject)
98 {
99 T Params;
100
101 if (ParametersObject.IsValid())
102 {
103 FJsonObjectConverter::JsonObjectToUStruct(ParametersObject.ToSharedRef(), T::StaticStruct(), &Params);
104 }
105
106 return Params;
107 }
108
109 static bool IsDataCapture;
110 static TArray<ACamera*> SpawnedCameras;
111};
Definition: Camera.h:52
static TArray< ACamera * > SpawnedCameras
static T ParseParameters(const TSharedPtr< FJsonObject > &ParametersObject)