RoveSoSimulator
Loading...
Searching...
No Matches
LidarScannerLibrary.h
1// Copyright Mars Rover 2025
2
3#pragma once
4
5#include "Async/ParallelFor.h"
6#include "CoreMinimal.h"
7#include "Kismet/BlueprintFunctionLibrary.h"
8#include "Engine/World.h"
9#include "LidarScannerLibrary.generated.h"
10
11
12class AGeoReferencingSystem;
13
14USTRUCT(BlueprintType)
16{
17 GENERATED_BODY()
18
19 UPROPERTY(BlueprintReadOnly, Category = "Lidar Point")
20 double Easting;
21
22 UPROPERTY(BlueprintReadOnly, Category = "Lidar Point")
23 double Northing;
24
25 UPROPERTY(BlueprintReadOnly, Category = "Lidar Point")
26 double Altitude;
27
28 UPROPERTY(BlueprintReadOnly, Category = "Lidar Point")
29 uint8 Classification;
30};
31
32/**
33 * @brief Blueprintable library to simulate Lidar Scanning for Autonomy
34 */
35UCLASS()
36class ROVESOSIMULATOR_API ULidarScannerLibrary : public UBlueprintFunctionLibrary
37{
38 GENERATED_BODY()
39
40public:
41 /**
42 * Performs a grid-based ray trace over a specified area to generate a point cloud.
43 * @param WorldContextObject The world context.
44 * @param ScanBoundsMin The minimum corner of the 2D scan area (X, Y).
45 * @param ScanBoundsMax The maximum corner of the 2D scan area (X, Y).
46 * @param TraceZ_Start The Z-height to start traces from.
47 * @param TraceZ_End The Z-height to end traces at.
48 * @param Density The desired number of points per square meter.
49 * @return An array of FVectors representing the hit locations.
50 */
51 UFUNCTION(BlueprintCallable, Category = "Lidar Tools")
52 static TArray<FVector> ScanForLidarPoints(
53 //static TArray<FLidarPoint> ScanAndGeoreferencePoints(
54 UObject* WorldContextObject,
55 FVector2D ScanBoundsMin,
56 FVector2D ScanBoundsMax,
57 float TraceZ_Start,
58 float TraceZ_End,
59 float Density
60 );
61
62 /**
63 * Performs a grid-based ray trace over a specified area to generate a georeferenced point cloud.
64 * @param WorldContextObject The world context.
65 * @param ScanBoundsMin The minimum corner of the 2D scan area (X, Y).
66 * @param ScanBoundsMax The maximum corner of the 2D scan area (X, Y).
67 * @param TraceZ_Start The Z-height to start traces from.
68 * @param TraceZ_End The Z-height to end traces at.
69 * @param Density The desired number of points per square meter.
70 * @return An array of FLidarPoint structs containing georeferenced coordinates and classification.
71 */
72 UFUNCTION(BlueprintCallable, Category = "Lidar Tools")
73 static TArray<FLidarPoint> ScanAndGeoreferencePoints(
74 UObject* WorldContextObject,
75 FVector2D ScanBoundsMin,
76 FVector2D ScanBoundsMax,
77 float TraceZ_Start,
78 float TraceZ_End,
79 float Density
80 );
81
82 /**
83 * Exports an array of LidarPoint data to a simple CSV text file.
84 * @param LidarPoints The array of points to export.
85 * @param FilePath The full path where the file will be saved (e.g., "C:/LidarScans/MyScan.csv").
86 * @return True if the file was written successfully, false otherwise.
87 */
88 UFUNCTION(BlueprintCallable, Category = "Lidar Tools")
89 static bool ExportLidarDataToCSV(const TArray<FLidarPoint>& LidarPoints, const FString& FilePath);
90
91 /**
92 * Scans a large area in manageable chunks and exports each chunk's data to separate CSV files.
93 * @param WorldContextObject The world context.
94 * @param ScanBoundsMin The minimum corner of the overall 2D scan area (X, Y).
95 * @param ScanBoundsMax The maximum corner of the overall 2D scan area (X, Y).
96 * @param TraceZ_Start The Z-height to start traces from.
97 * @param TraceZ_End The Z-height to end traces at.
98 * @param Density The desired number of points per square meter.
99 * @param ChunkSizeMeters The size of each chunk in meters (e.g., 200 for 200x200m chunks).
100 * @param OutputDirectory The directory where all chunk files will be saved.
101 */
102 UFUNCTION(BlueprintCallable, Category = "Lidar Tools")
103 static void ScanWorldInChunks(
104 UObject* WorldContextObject,
105 FVector2D ScanBoundsMin,
106 FVector2D ScanBoundsMax,
107 float TraceZ_Start,
108 float TraceZ_End,
109 float Density,
110 float ChunkSizeMeters, // User-defined size for each chunk (e.g., 200 meters)
111 const FString& OutputDirectory // The FOLDER where all chunk files will be saved
112 );
113
114private:
115 // This is our "Worker" function. It's not exposed to Blueprints,
116 // as it's only called by our manager function.
117 static bool ScanAndExportChunkToCSV(
118 const UWorld* World,
119 /*class AGeoReferencingSystem* GeoSystem,*/
120 const AGeoReferencingSystem* GeoSystem,
121 FVector2D ChunkBoundsMin,
122 FVector2D ChunkBoundsMax,
123 float TraceZ_Start,
124 float TraceZ_End,
125 float Density,
126 const FString& FilePath // The full path for this specific chunk's output file
127 );
128
129};
Definition LidarScannerLibrary.h:16