CARLA
RayCastSemanticLidar.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 
8 
9 #pragma once
10 
11 #include "Carla/Sensor/Sensor.h"
12 
16 
20 
21 #include "RayCastSemanticLidar.generated.h"
22 
23 /// A ray-cast based Lidar sensor.
24 UCLASS()
25 class CARLA_API ARayCastSemanticLidar : public ASensor
26 {
27  GENERATED_BODY()
28 
29 protected:
30 
33 
34 public:
35  static FActorDefinition GetSensorDefinition();
36 
37  ARayCastSemanticLidar(const FObjectInitializer &ObjectInitializer);
38 
39  virtual void Set(const FActorDescription &Description) override;
40  virtual void Set(const FLidarDescription &LidarDescription);
41 
42 protected:
43  virtual void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaTime) override;
44 
45  /// Creates a Laser for each channel.
46  void CreateLasers();
47 
48  /// Updates LidarMeasurement with the points read in DeltaTime.
49  void SimulateLidar(const float DeltaTime);
50 
51  /// Shoot a laser ray-trace, return whether the laser hit something.
52  bool ShootLaser(const float VerticalAngle, float HorizontalAngle, FHitResult &HitResult, FCollisionQueryParams& TraceParams) const;
53 
54  /// Method that allow to preprocess if the rays will be traced.
55  virtual void PreprocessRays(uint32_t Channels, uint32_t MaxPointsPerChannel);
56 
57  /// Compute all raw detection information
58  void ComputeRawDetection(const FHitResult &HitInfo, const FTransform &SensorTransf, FSemanticDetection &Detection) const;
59 
60  /// Saving the hits the raycast returns per channel
61  void WritePointAsync(uint32_t Channel, FHitResult &Detection);
62 
63  /// Clear the recorded data structure
64  void ResetRecordedHits(uint32_t Channels, uint32_t MaxPointsPerChannel);
65 
66  /// This method uses all the saved FHitResults, compute the
67  /// RawDetections and then send it to the LidarData structure.
68  virtual void ComputeAndSaveDetections(const FTransform &SensorTransform);
69 
70  UPROPERTY(EditAnywhere)
71  FLidarDescription Description;
72 
73  TArray<float> LaserAngles;
74 
75  std::vector<std::vector<FHitResult>> RecordedHits;
76  std::vector<std::vector<bool>> RayPreprocessCondition;
77  std::vector<uint32_t> PointsPerChannel;
78 
79 private:
80  FSemanticLidarData SemanticLidarData;
81 
82 };
Helper class to store and serialize the data generated by a RawLidar.
A definition of a Carla Actor with all the variation and attributes.
A ray-cast based Lidar sensor.
A description of a Carla Actor with all its variation.