Save road map metadata when saving map image as png

This commit is contained in:
nsubiron 2017-05-30 11:54:52 +01:00
parent ab65bca04a
commit b30ebdb001
3 changed files with 33 additions and 7 deletions

View File

@ -281,9 +281,7 @@ void ACityMapGenerator::GenerateRoadMap()
#endif // WITH_EDITOR
if (bSaveRoadMapToDisk) {
const FString MapName = World->GetMapName() + TEXT(".png");
const FString FilePath = FPaths::Combine(FPaths::GameSavedDir(), MapName);
RoadMap->SaveAsPNG(FilePath);
RoadMap->SaveAsPNG(FPaths::GameSavedDir(), World->GetMapName());
}
#if WITH_EDITOR

View File

@ -3,6 +3,7 @@
#include "Carla.h"
#include "RoadMap.h"
#include "FileHelper.h"
#include "HighResScreenshot.h"
#if WITH_EDITOR
@ -11,6 +12,8 @@
#include <type_traits>
#define LOCTEXT_NAMESPACE "CarlaRoadMap"
/// ============================================================================
/// -- Static local methods ----------------------------------------------------
/// ============================================================================
@ -239,7 +242,7 @@ FRoadMapIntersectionResult URoadMap::Intersect(
return Result;
}
bool URoadMap::SaveAsPNG(const FString &Path) const
bool URoadMap::SaveAsPNG(const FString &Folder, const FString &MapName) const
{
if (!IsValid()) {
UE_LOG(LogCarla, Error, TEXT("Cannot save invalid road map to disk"));
@ -251,11 +254,34 @@ bool URoadMap::SaveAsPNG(const FString &Path) const
BitMap.Emplace(FRoadMapPixelData(Value).EncodeAsColor());
}
FIntPoint DestSize(Width, Height);
const FString ImagePath = FPaths::Combine(Folder, MapName + TEXT(".png"));
const FString MetadataPath = FPaths::Combine(Folder, MapName + TEXT(".txt"));
const FIntPoint DestSize(Width, Height);
FString ResultPath;
FHighResScreenshotConfig &HighResScreenshotConfig = GetHighResScreenshotConfig();
HighResScreenshotConfig.SetHDRCapture(false);
HighResScreenshotConfig.SaveImage(Path, BitMap, DestSize, &ResultPath);
HighResScreenshotConfig.SaveImage(ImagePath, BitMap, DestSize, &ResultPath);
// Save metadata.
FFormatNamedArguments Args;
Args.Add("MapName", FText::FromString(MapName));
Args.Add("Width", GetWidth());
Args.Add("Height", GetHeight());
Args.Add("CmPerPixel", 1.0f / PixelsPerCentimeter);
Args.Add("Transform", FText::FromString(WorldToMap.ToString()));
Args.Add("Offset", FText::FromString(MapOffset.ToString()));
const auto Contents = FText::Format(
LOCTEXT("RoadMapMetadata",
"Map name = {MapName}\n"
"Size = {Width}x{Height} pixels\n"
"Density = {CmPerPixel} cm/pixel\n"
"World-To-Map Transform (T|R|S) = ({Transform})\n"
"Map Offset = ({Offset})\n"),
Args);
if (!FFileHelper::SaveStringToFile(Contents.ToString(), *MetadataPath)) {
UE_LOG(LogCarla, Error, TEXT("Failed to save map metadata"));
}
UE_LOG(LogCarla, Log, TEXT("Saved road map to \"%s\""), *ResultPath);
return true;
@ -305,3 +331,5 @@ void URoadMap::DrawDebugPixelsToLevel(UWorld *World, const bool bJustFlushDoNotD
}
#endif // WITH_EDITOR
#undef LOCTEXT_NAMESPACE

View File

@ -139,7 +139,7 @@ public:
float ChecksPerCentimeter) const;
/// Save the current map as PNG with the pixel data encoded as color.
bool SaveAsPNG(const FString &Path) const;
bool SaveAsPNG(const FString &Folder, const FString &MapName) const;
#if WITH_EDITOR