Sensor id should be set by the sensor description
This commit is contained in:
parent
64327b20a4
commit
77885b6a82
|
@ -8,8 +8,8 @@
|
|||
#include "Runtime/Engine/Classes/Kismet/KismetMathLibrary.h"
|
||||
#include "StaticMeshResources.h"
|
||||
|
||||
ALidar::ALidar(const FObjectInitializer& ObjectInitializer) :
|
||||
Super(ObjectInitializer)
|
||||
ALidar::ALidar(const FObjectInitializer& ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
|
@ -23,8 +23,9 @@ ALidar::ALidar(const FObjectInitializer& ObjectInitializer) :
|
|||
|
||||
void ALidar::Set(const ULidarDescription &LidarDescription)
|
||||
{
|
||||
Super::Set(LidarDescription);
|
||||
Description = &LidarDescription;
|
||||
LidarMeasurement = FLidarMeasurement(Description->Channels);
|
||||
LidarMeasurement = FLidarMeasurement(GetId(), Description->Channels);
|
||||
CreateLasers();
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,8 @@ class FLidarMeasurement {
|
|||
static_assert(sizeof(float) == sizeof(uint32), "Invalid float size");
|
||||
public:
|
||||
|
||||
explicit FLidarMeasurement(uint32 ChannelCount = 0u)
|
||||
explicit FLidarMeasurement(uint32 SensorId = 0u, uint32 ChannelCount = 0u)
|
||||
: SensorId(SensorId)
|
||||
{
|
||||
Header.AddDefaulted(2u + ChannelCount);
|
||||
Header[1] = ChannelCount;
|
||||
|
@ -42,8 +43,10 @@ public:
|
|||
|
||||
FLidarMeasurement &operator=(FLidarMeasurement &&Other)
|
||||
{
|
||||
SensorId = Other.SensorId;
|
||||
Header = std::move(Other.Header);
|
||||
Points = std::move(Other.Points);
|
||||
Other.SensorId = 0u;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -73,11 +76,13 @@ public:
|
|||
|
||||
FSensorDataView GetView() const
|
||||
{
|
||||
return FSensorDataView(Header, Points);
|
||||
return FSensorDataView(SensorId, Header, Points);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
uint32 SensorId;
|
||||
|
||||
TArray<uint32> Header;
|
||||
|
||||
TArray<float> Points;
|
||||
|
|
|
@ -144,6 +144,7 @@ void ASceneCaptureCamera::Tick(const float DeltaSeconds)
|
|||
TArray<FColor> BitMap;
|
||||
if (ReadPixels(BitMap)) {
|
||||
FSensorDataView DataView(
|
||||
GetId(),
|
||||
FReadOnlyBufferView{reinterpret_cast<const void *>(&ImageHeader), sizeof(ImageHeader)},
|
||||
FReadOnlyBufferView{BitMap});
|
||||
|
||||
|
@ -202,6 +203,7 @@ void ASceneCaptureCamera::Set(const UCameraDescription &CameraDescription)
|
|||
// PostProcessSettings.bOverride_AutoExposureBias = true;
|
||||
// PostProcessSettings.AutoExposureBias = Override.AutoExposureBias;
|
||||
// }
|
||||
Super::Set(CameraDescription);
|
||||
SetImageSize(CameraDescription.ImageSizeX, CameraDescription.ImageSizeY);
|
||||
SetPostProcessEffect(CameraDescription.PostProcessEffect);
|
||||
SetFOVAngle(CameraDescription.FOVAngle);
|
||||
|
|
|
@ -7,15 +7,9 @@
|
|||
#include "Carla.h"
|
||||
#include "Sensor.h"
|
||||
|
||||
static uint32 GetNextSensorId()
|
||||
{
|
||||
static uint32 COUNT = 0u;
|
||||
return ++COUNT;
|
||||
}
|
||||
|
||||
ASensor::ASensor(const FObjectInitializer& ObjectInitializer)
|
||||
: Super(ObjectInitializer),
|
||||
Id(GetNextSensorId()) {}
|
||||
Id(0u) {}
|
||||
|
||||
void ASensor::AttachToActor(AActor *Actor)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "GameFramework/Actor.h"
|
||||
|
||||
#include "Sensor/SensorDataSink.h"
|
||||
#include "Settings/SensorDescription.h"
|
||||
|
||||
#include "Sensor.generated.h"
|
||||
|
||||
|
@ -36,6 +37,11 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
void Set(const USensorDescription &SensorDescription)
|
||||
{
|
||||
Id = SensorDescription.GetId();
|
||||
}
|
||||
|
||||
void WriteSensorData(const FSensorDataView &SensorData)
|
||||
{
|
||||
if (SensorDataSink.IsValid()) {
|
||||
|
|
|
@ -13,11 +13,18 @@ class FSensorDataView {
|
|||
public:
|
||||
|
||||
FSensorDataView(
|
||||
uint32 InSensorId,
|
||||
FReadOnlyBufferView InHeader,
|
||||
FReadOnlyBufferView InData)
|
||||
: Header(InHeader),
|
||||
: SensorId(InSensorId),
|
||||
Header(InHeader),
|
||||
Data(InData) {}
|
||||
|
||||
uint32 GetSensorId() const
|
||||
{
|
||||
return SensorId;
|
||||
}
|
||||
|
||||
FReadOnlyBufferView GetHeader() const
|
||||
{
|
||||
return Header;
|
||||
|
@ -30,6 +37,8 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
uint32 SensorId;
|
||||
|
||||
FReadOnlyBufferView Header;
|
||||
|
||||
FReadOnlyBufferView Data;
|
||||
|
|
|
@ -18,7 +18,7 @@ template <typename T, typename D>
|
|||
static T *SpawnSensor(const D &Description, UWorld &World)
|
||||
{
|
||||
FActorSpawnParameters Params;
|
||||
Params.Name = Description.Name;
|
||||
Params.Name = FName(*Description.Name);
|
||||
return World.SpawnActor<T>(Description.Position, Description.Rotation, Params);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ static void LoadSensorFromConfig(
|
|||
const FIniFile &ConfigFile,
|
||||
USensorDescription &Sensor)
|
||||
{
|
||||
ForEachSectionInName(Sensor.Name.ToString(), [&](const auto &Section){
|
||||
ForEachSectionInName(Sensor.Name, [&](const auto &Section){
|
||||
Sensor.Load(ConfigFile, Section);
|
||||
});
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ template <typename T>
|
|||
static T *MakeSensor(UObject *Parent, const FString &Name, const FString &Type)
|
||||
{
|
||||
auto *Sensor = NewObject<T>(Parent);
|
||||
Sensor->Name = FName(*Name);
|
||||
Sensor->Name = Name;
|
||||
Sensor->Type = Type;
|
||||
return Sensor;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,16 @@
|
|||
|
||||
#include "Util/IniFile.h"
|
||||
|
||||
static uint32 GetNextSensorDescriptionId()
|
||||
{
|
||||
static uint32 COUNT = 0u;
|
||||
return ++COUNT;
|
||||
}
|
||||
|
||||
USensorDescription::USensorDescription(const FObjectInitializer &ObjectInitializer)
|
||||
: Super(ObjectInitializer),
|
||||
Id(GetNextSensorDescriptionId()) {}
|
||||
|
||||
void USensorDescription::AcceptVisitor(ISensorDescriptionVisitor &Visitor) const
|
||||
{
|
||||
unimplemented();
|
||||
|
@ -26,7 +36,8 @@ void USensorDescription::Load(const FIniFile &Config, const FString &Section)
|
|||
|
||||
void USensorDescription::Log() const
|
||||
{
|
||||
UE_LOG(LogCarla, Log, TEXT("[%s/%s]"), TEXT("CARLA/Sensor"), *Name.ToString());
|
||||
UE_LOG(LogCarla, Log, TEXT("[%s/%s]"), TEXT("CARLA/Sensor"), *Name);
|
||||
UE_LOG(LogCarla, Log, TEXT("Id = %d"), Id);
|
||||
UE_LOG(LogCarla, Log, TEXT("Type = %s"), *Type);
|
||||
UE_LOG(LogCarla, Log, TEXT("Position = (%s)"), *Position.ToString());
|
||||
UE_LOG(LogCarla, Log, TEXT("Rotation = (%s)"), *Rotation.ToString());
|
||||
|
|
|
@ -19,6 +19,13 @@ class CARLA_API USensorDescription : public UObject
|
|||
|
||||
public:
|
||||
|
||||
USensorDescription(const FObjectInitializer &ObjectInitializer);
|
||||
|
||||
uint32 GetId() const
|
||||
{
|
||||
return Id;
|
||||
}
|
||||
|
||||
virtual void AcceptVisitor(ISensorDescriptionVisitor &Visitor) const;
|
||||
|
||||
virtual void Load(const FIniFile &Config, const FString &Section);
|
||||
|
@ -32,9 +39,16 @@ public:
|
|||
|
||||
virtual void Log() const;
|
||||
|
||||
private:
|
||||
|
||||
UPROPERTY(Category = "Sensor Description", VisibleAnywhere)
|
||||
uint32 Id;
|
||||
|
||||
public:
|
||||
|
||||
/** Display name of the sensor. */
|
||||
UPROPERTY(Category = "Sensor Description", EditDefaultsOnly)
|
||||
FName Name;
|
||||
FString Name;
|
||||
|
||||
/** Sensor type. */
|
||||
UPROPERTY(Category = "Sensor Description", EditDefaultsOnly)
|
||||
|
|
Loading…
Reference in New Issue