From 15ea8caeb007e6497b019576c18168e2350e591a Mon Sep 17 00:00:00 2001 From: Armin Burgmeier Date: Fri, 16 Feb 2018 16:07:03 +0100 Subject: [PATCH 1/2] Introduce projection mode for capture settings This allows to switch to orthographic projection mode. --- AirLib/include/common/AirSimSettings.hpp | 13 +++++++++++++ Unreal/Plugins/AirSim/Source/PIPCamera.cpp | 8 ++++++++ docs/settings.md | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/AirLib/include/common/AirSimSettings.hpp b/AirLib/include/common/AirSimSettings.hpp index 19def177cd..85e6dff298 100644 --- a/AirLib/include/common/AirSimSettings.hpp +++ b/AirLib/include/common/AirSimSettings.hpp @@ -86,6 +86,9 @@ struct AirSimSettings { float auto_exposure_histogram_log_max = Utils::nan(); // 4; float motion_blur_amount = Utils::nan(); float target_gamma = Utils::nan(); //1.0f; //This would be reset to kSceneTargetGamma for scene as default + int projection_mode = 0; // ECameraProjectionMode::Perspective + float ortho_width = Utils::nan(); + }; struct NoiseSetting { @@ -449,6 +452,16 @@ struct AirSimSettings { capture_setting.image_type = settings.getInt("ImageType", 0); capture_setting.target_gamma = settings.getFloat("TargetGamma", capture_setting.image_type == 0 ? CaptureSetting::kSceneTargetGamma : Utils::nan()); + + std::string projection_mode = Utils::toLower(settings.getString("ProjectionMode", "")); + if (projection_mode == "" || projection_mode == "perspective") + capture_setting.projection_mode = 0; // Perspective + else if (projection_mode == "orthographic") + capture_setting.projection_mode = 1; // Orthographic + else + throw std::invalid_argument(std::string("CaptureSettings projection_mode has invalid value in settings ") + projection_mode); + + capture_setting.ortho_width = settings.getFloat("OrthoWidth", capture_setting.ortho_width); } void loadSubWindowsSettings(const Settings& settings) diff --git a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp index db21e37f52..64ca7a6737 100644 --- a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp +++ b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp @@ -140,8 +140,12 @@ void APIPCamera::updateCaptureComponentSetting(USceneCaptureComponent2D* capture if (!std::isnan(setting.target_gamma)) render_target->TargetGamma = setting.target_gamma; + capture->ProjectionType = static_cast(setting.projection_mode); + if (!std::isnan(setting.fov_degrees)) capture->FOVAngle = setting.fov_degrees; + if (!std::isnan(setting.ortho_width)) + capture->OrthoWidth = setting.ortho_width * 100.0f; updateCameraPostProcessingSetting(capture->PostProcessSettings, setting); } @@ -151,8 +155,12 @@ void APIPCamera::updateCameraSetting(UCameraComponent* camera, const CaptureSett //if (!std::isnan(setting.target_gamma)) // camera-> = setting.target_gamma; + camera->SetProjectionMode(static_cast(setting.projection_mode)); + if (!std::isnan(setting.fov_degrees)) camera->SetFieldOfView(setting.fov_degrees); + if (!std::isnan(setting.ortho_width)) + camera->SetOrthoWidth(setting.ortho_width * 100.0f); updateCameraPostProcessingSetting(camera->PostProcessSettings, setting); } diff --git a/docs/settings.md b/docs/settings.md index 35147d24e9..f68771aa72 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -56,7 +56,9 @@ Below are complete list of settings available along with their default values. I "AutoExposureMaxBrightness": 0.64, "AutoExposureMinBrightness": 0.03, "MotionBlurAmount": 0, - "TargetGamma": 1.0 + "TargetGamma": 1.0, + "ProjectionMode": "perspective", + "OrthoWidth": 5.12 } ], "NoiseSettings": [ From 2f7d78154238457c121e262417abac798ef6c9fa Mon Sep 17 00:00:00 2001 From: Armin Burgmeier Date: Mon, 19 Feb 2018 11:11:22 +0100 Subject: [PATCH 2/2] Use NedTransform to transform airsim units to world units --- Unreal/Plugins/AirSim/Source/NedTransform.cpp | 5 +++++ Unreal/Plugins/AirSim/Source/NedTransform.h | 1 + Unreal/Plugins/AirSim/Source/PIPCamera.cpp | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Unreal/Plugins/AirSim/Source/NedTransform.cpp b/Unreal/Plugins/AirSim/Source/NedTransform.cpp index 9a9ee2f099..113b7e8b4a 100644 --- a/Unreal/Plugins/AirSim/Source/NedTransform.cpp +++ b/Unreal/Plugins/AirSim/Source/NedTransform.cpp @@ -29,6 +29,11 @@ float NedTransform::toNedMeters(float length) return length / world_to_meters_; } +float NedTransform::toNeuUU(float length) +{ + return length * world_to_meters_; +} + NedTransform::Vector3r NedTransform::toNedMeters(const FVector& position, bool use_offset) { return NedTransform::toVector3r(position - (use_offset ? offset_ : FVector::ZeroVector), 1 / world_to_meters_, true); diff --git a/Unreal/Plugins/AirSim/Source/NedTransform.h b/Unreal/Plugins/AirSim/Source/NedTransform.h index d5047c86d1..d10aa6f80e 100644 --- a/Unreal/Plugins/AirSim/Source/NedTransform.h +++ b/Unreal/Plugins/AirSim/Source/NedTransform.h @@ -20,6 +20,7 @@ class NedTransform static FQuat toFQuat(const Quaternionr& q, bool convert_from_ned); static Quaternionr toQuaternionr(const FQuat& q, bool convert_to_ned); static float toNedMeters(float length); + static float toNeuUU(float length); //TODO: make below private static FVector toFVector(const Vector3r& vec, float scale, bool convert_from_ned); diff --git a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp index 64ca7a6737..a0d261f65d 100644 --- a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp +++ b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp @@ -7,6 +7,7 @@ #include "Materials/MaterialInstanceDynamic.h" #include "AirBlueprintLib.h" #include "ImageUtils.h" +#include "NedTransform.h" APIPCamera::APIPCamera() @@ -145,7 +146,7 @@ void APIPCamera::updateCaptureComponentSetting(USceneCaptureComponent2D* capture if (!std::isnan(setting.fov_degrees)) capture->FOVAngle = setting.fov_degrees; if (!std::isnan(setting.ortho_width)) - capture->OrthoWidth = setting.ortho_width * 100.0f; + capture->OrthoWidth = NedTransform::toNeuUU(setting.ortho_width); updateCameraPostProcessingSetting(capture->PostProcessSettings, setting); } @@ -160,7 +161,7 @@ void APIPCamera::updateCameraSetting(UCameraComponent* camera, const CaptureSett if (!std::isnan(setting.fov_degrees)) camera->SetFieldOfView(setting.fov_degrees); if (!std::isnan(setting.ortho_width)) - camera->SetOrthoWidth(setting.ortho_width * 100.0f); + camera->SetOrthoWidth(NedTransform::toNeuUU(setting.ortho_width)); updateCameraPostProcessingSetting(camera->PostProcessSettings, setting); }