Skip to content

Commit

Permalink
Fixed naming conventions and minor bugs requested in the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
ppueyor committed Sep 22, 2021
1 parent cdcb916 commit bca2944
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 64 deletions.
10 changes: 5 additions & 5 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ namespace airlib
//CinemAirSim
std::vector<std::string> simGetPresetLensSettings(const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
std::string simGetLensSettings(const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
void simSetPresetLensSettings(const std::string& preset_lens_settings = "", const std::string& camera_name = "", const std::string& vehicle_name = "", bool external = false);
void simSetPresetLensSettings(const std::string& preset_lens_settings, const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
std::vector<std::string> simGetPresetFilmbackSettings(const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
void simSetPresetFilmbackSettings(const std::string& preset_filmback_settings = "", const std::string& camera_name = "", const std::string& vehicle_name = "", bool external = false);
void simSetPresetFilmbackSettings(const std::string& preset_filmback_settings, const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
std::string simGetFilmbackSettings(const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
float simSetFilmbackSettings(const float sensor_width, const float sensor_heigth, const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
float simGetFocalLength(const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
void simSetFocalLength(float focal_length, const std::string& camera_name = "", const std::string& vehicle_name = "", bool external = false);
void simSetFocalLength(float focal_length, const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
void simEnableManualFocus(const bool enable, const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
float simGetFocusDistance(const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
void simSetFocusDistance(float focus_distance, const std::string& camera_name = "", const std::string& vehicle_name = "", bool external = false);
void simSetFocusDistance(float focus_distance, const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
float simGetFocusAperture(const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
void simSetFocusAperture(const float focus_aperture, const std::string& camera_name = "", const std::string& vehicle_name = "", bool external = false);
void simSetFocusAperture(const float focus_aperture, const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
void simEnableFocusPlane(const bool enable, const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
std::string simGetCurrentFieldOfView(const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
//end CinemAirSim
Expand Down
14 changes: 0 additions & 14 deletions AirLib/src/api/RpcLibClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,13 @@ __pragma(warning(disable : 4239))
vector<uint8_t> RpcLibClientBase::simGetImage(const std::string& camera_name, ImageCaptureBase::ImageType type, const std::string& vehicle_name, bool external)
{
vector<uint8_t> result = pimpl_->client.call("simGetImage", camera_name, type, vehicle_name, external).as<vector<uint8_t>>();
if (result.size() == 1) {
// rpclib has a bug with serializing empty vectors, so we return a 1 byte vector instead.
result.clear();
}
return result;
}

//CinemAirSim
std::vector<std::string> RpcLibClientBase::simGetPresetLensSettings(const std::string& camera_name, const std::string& vehicle_name, bool external)
{
vector<std::string> result = pimpl_->client.call("simGetPresetLensSettings", camera_name, vehicle_name, external).as<vector<std::string>>();

if (result.size() == 1) {
// rpclib has a bug with serializing empty vectors, so we return a 1 byte vector instead.
result.clear();
}
return result;
}

Expand All @@ -297,11 +288,6 @@ __pragma(warning(disable : 4239))
std::vector<std::string> RpcLibClientBase::simGetPresetFilmbackSettings(const std::string& camera_name, const std::string& vehicle_name, bool external)
{
vector<std::string> result = pimpl_->client.call("simGetPresetFilmbackSettings", camera_name, vehicle_name, external).as<vector<std::string>>();

if (result.size() == 1) {
// rpclib has a bug with serializing empty vectors, so we return a 1 byte vector instead.
result.clear();
}
return result;
}

Expand Down
27 changes: 7 additions & 20 deletions AirLib/src/api/RpcLibServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,44 +155,32 @@ namespace airlib

//CinemAirSim
pimpl_->server.bind("simGetPresetLensSettings", [&](const std::string& camera_name, const std::string& vehicle_name, bool external) -> vector<string> {
auto result = getWorldSimApi()->getPresetLensSettings(CameraDetails(camera_name, vehicle_name, external));
if (result.size() == 0) {
// rpclib has a bug with serializing empty vectors, so we return a 1 byte vector instead.
result.push_back("");
}
return result;
return getWorldSimApi()->getPresetLensSettings(CameraDetails(camera_name, vehicle_name, external));
});

pimpl_->server.bind("simGetLensSettings", [&](const std::string& camera_name, const std::string& vehicle_name, bool external) -> string {
auto result = getWorldSimApi()->getLensSettings(CameraDetails(camera_name, vehicle_name, external));
return result;
return getWorldSimApi()->getLensSettings(CameraDetails(camera_name, vehicle_name, external));
});

pimpl_->server.bind("simSetPresetLensSettings", [&](const std::string preset_lens_settings, const std::string& camera_name, const std::string& vehicle_name, bool external) -> void {
getWorldSimApi()->setPresetLensSettings(preset_lens_settings, CameraDetails(camera_name, vehicle_name, external));
});

pimpl_->server.bind("simGetPresetFilmbackSettings", [&](const std::string& camera_name, const std::string& vehicle_name, bool external) -> vector<string> {
auto result = getWorldSimApi()->getPresetFilmbackSettings(CameraDetails(camera_name, vehicle_name, external));
if (result.size() == 0) {
// rpclib has a bug with serializing empty vectors, so we return a 1 byte vector instead.
result.push_back("");
}
return result;
return getWorldSimApi()->getPresetFilmbackSettings(CameraDetails(camera_name, vehicle_name, external));
});

pimpl_->server.bind("simSetPresetFilmbackSettings", [&](const std::string preset_filmback_settings, const std::string& camera_name, const std::string& vehicle_name, bool external) -> void {
getWorldSimApi()->setPresetFilmbackSettings(preset_filmback_settings, CameraDetails(camera_name, vehicle_name, external));
});

pimpl_->server.bind("simGetFilmbackSettings", [&](const std::string& camera_name, const std::string& vehicle_name, bool external) -> string {
auto result = getWorldSimApi()->getFilmbackSettings(CameraDetails(camera_name, vehicle_name, external));
return result;
return getWorldSimApi()->getFilmbackSettings(CameraDetails(camera_name, vehicle_name, external));
});

pimpl_->server.bind("simSetFilmbackSettings", [&](const float width, const float heigth, const std::string& camera_name, const std::string& vehicle_name, bool external) -> float {
auto result = getWorldSimApi()->setFilmbackSettings(width, heigth, CameraDetails(camera_name, vehicle_name, external));
return result;
return getWorldSimApi()->setFilmbackSettings(width, heigth, CameraDetails(camera_name, vehicle_name, external));
;
});

pimpl_->server.bind("simGetFocalLength", [&](const std::string& camera_name, const std::string& vehicle_name, bool external) -> float {
Expand Down Expand Up @@ -228,8 +216,7 @@ namespace airlib
});

pimpl_->server.bind("simGetCurrentFieldOfView", [&](const std::string& camera_name, const std::string& vehicle_name, bool external) -> string {
auto result = getWorldSimApi()->getCurrentFieldOfView(CameraDetails(camera_name, vehicle_name, external));
return result;
return getWorldSimApi()->getCurrentFieldOfView(CameraDetails(camera_name, vehicle_name, external));
});
//end CinemAirSim

Expand Down
6 changes: 3 additions & 3 deletions PythonClient/airsim/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, ip = "", port = 41451, timeout_value = 3600):
ip = "127.0.0.1"
self.client = msgpackrpc.Client(msgpackrpc.Address(ip, port), timeout = timeout_value, pack_encoding = 'utf-8', unpack_encoding = 'utf-8')

#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - Common vehicle APIs -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
#----------------------------------- Common vehicle APIs ---------------------------------------------
def reset(self):
"""
Reset the vehicle to its original starting state
Expand Down Expand Up @@ -1041,7 +1041,7 @@ def getSettingsString(self):
"""
return self.client.call('getSettingsString')

#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - Multirotor APIs -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
#----------------------------------- Multirotor APIs ---------------------------------------------
class MultirotorClient(VehicleClient, object):
def __init__(self, ip = "", port = 41451, timeout_value = 3600):
super(MultirotorClient, self).__init__(ip, port, timeout_value)
Expand Down Expand Up @@ -1501,7 +1501,7 @@ def getRotorStates(self, vehicle_name = ''):
return RotorStates.from_msgpack(self.client.call('getRotorStates', vehicle_name))
getRotorStates.__annotations__ = {'return': RotorStates}

#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - Car APIs -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
#----------------------------------- Car APIs ---------------------------------------------
class CarClient(VehicleClient, object):
def __init__(self, ip = "", port = 41451, timeout_value = 3600):
super(CarClient, self).__init__(ip, port, timeout_value)
Expand Down
36 changes: 17 additions & 19 deletions Unreal/Plugins/AirSim/Source/PIPCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ void APIPCamera::setupCameraFromSettings(const APIPCamera::CameraSetting& camera
}
setDistortionMaterial(image_type, captures_[image_type], captures_[image_type]->PostProcessSettings);
setNoiseMaterial(image_type, captures_[image_type], captures_[image_type]->PostProcessSettings, noise_setting);
CopyCameraSettingsToSceneCapture(camera_, captures_[image_type]); //CinemAirSim
copyCameraSettingsToSceneCapture(camera_, captures_[image_type]); //CinemAirSim
}
else { //camera component
updateCameraSetting(camera_, capture_setting, ned_transform);
setDistortionMaterial(image_type, camera_, camera_->PostProcessSettings);
setNoiseMaterial(image_type, camera_, camera_->PostProcessSettings, noise_setting);
CopyCameraSettingsToAllSceneCapture(camera_); //CinemAirSim
copyCameraSettingsToAllSceneCapture(camera_); //CinemAirSim
}
}
}
Expand Down Expand Up @@ -607,7 +607,6 @@ std::vector<std::string> APIPCamera::getPresetLensSettings()

ss << "Name: " << name << ";\n\t MinFocalLength: " << preset.LensSettings.MinFocalLength << "; \t MaxFocalLength: " << preset.LensSettings.MaxFocalLength;
ss << "\n\t Min FStop: " << preset.LensSettings.MinFStop << "; \t Max Fstop: " << preset.LensSettings.MaxFStop;
//ss << "\n\t Diaphragm Blade Count: " << preset.LensSettings.DiaphragmBladeCount;
std::string final_string(ss.str());
vector.push_back(final_string);
}
Expand Down Expand Up @@ -641,7 +640,7 @@ void APIPCamera::setPresetLensSettings(std::string preset_string)
{
FString preset(preset_string.c_str());
camera_->SetLensPresetByName(preset);
CopyCameraSettingsToAllSceneCapture(camera_);
copyCameraSettingsToAllSceneCapture(camera_);
}

std::vector<std::string> APIPCamera::getPresetFilmbackSettings()
Expand All @@ -664,7 +663,7 @@ void APIPCamera::setPresetFilmbackSettings(std::string preset_string)
{
FString preset(preset_string.c_str());
camera_->SetFilmbackPresetByName(preset);
CopyCameraSettingsToAllSceneCapture(camera_);
copyCameraSettingsToAllSceneCapture(camera_);
}

std::string APIPCamera::getFilmbackSettings()
Expand All @@ -686,7 +685,7 @@ float APIPCamera::setFilmbackSettings(float sensor_width, float sensor_height)
camera_->Filmback.SensorWidth = sensor_width;
camera_->Filmback.SensorHeight = sensor_height;

CopyCameraSettingsToAllSceneCapture(camera_);
copyCameraSettingsToAllSceneCapture(camera_);

return camera_->Filmback.SensorAspectRatio;
}
Expand All @@ -699,7 +698,7 @@ float APIPCamera::getFocalLength()
void APIPCamera::setFocalLength(float focal_length)
{
camera_->CurrentFocalLength = focal_length;
CopyCameraSettingsToAllSceneCapture(camera_);
copyCameraSettingsToAllSceneCapture(camera_);
}

void APIPCamera::enableManualFocus(bool enable)
Expand All @@ -710,7 +709,7 @@ void APIPCamera::enableManualFocus(bool enable)
else {
camera_->FocusSettings.FocusMethod = ECameraFocusMethod::Disable;
}
CopyCameraSettingsToAllSceneCapture(camera_);
copyCameraSettingsToAllSceneCapture(camera_);
}

float APIPCamera::getFocusDistance()
Expand All @@ -721,7 +720,7 @@ float APIPCamera::getFocusDistance()
void APIPCamera::setFocusDistance(float focus_distance)
{
camera_->FocusSettings.ManualFocusDistance = focus_distance;
CopyCameraSettingsToAllSceneCapture(camera_);
copyCameraSettingsToAllSceneCapture(camera_);
}

float APIPCamera::getFocusAperture()
Expand All @@ -732,7 +731,7 @@ float APIPCamera::getFocusAperture()
void APIPCamera::setFocusAperture(float focus_aperture)
{
camera_->CurrentAperture = focus_aperture;
CopyCameraSettingsToAllSceneCapture(camera_);
copyCameraSettingsToAllSceneCapture(camera_);
}

void APIPCamera::enableFocusPlane(bool enable)
Expand All @@ -747,26 +746,25 @@ std::string APIPCamera::getCurrentFieldOfView()
return ss.str();
}

void APIPCamera::CopyCameraSettingsToAllSceneCapture(UCameraComponent* camera)
void APIPCamera::copyCameraSettingsToAllSceneCapture(UCameraComponent* camera)
{
int image_count = static_cast<int>(Utils::toNumeric(ImageType::Count));
for (int image_type = image_count - 1; image_type >= 0; image_type--) {
if (image_type >= 0) { //scene capture components
CopyCameraSettingsToSceneCapture(camera_, captures_[image_type]);
}
for (image_type >= 0) {
//scene capture components
copyCameraSettingsToSceneCapture(camera_, captures_[image_type]);
}
}

void APIPCamera::CopyCameraSettingsToSceneCapture(UCameraComponent* src, USceneCaptureComponent2D* dst)
void APIPCamera::copyCameraSettingsToSceneCapture(UCameraComponent* src, USceneCaptureComponent2D* dst)
{
if (src && dst) {
dst->SetWorldLocationAndRotation(src->GetComponentLocation(), src->GetComponentRotation());
dst->FOVAngle = src->FieldOfView;

FMinimalViewInfo CameraViewInfo;
src->GetCameraView(/*DeltaTime =*/0.0f, CameraViewInfo);
FMinimalViewInfo camera_view_info;
src->GetCameraView(/*DeltaTime =*/0.0f, camera_view_info);

const FPostProcessSettings& SrcPPSettings = CameraViewInfo.PostProcessSettings;
const FPostProcessSettings& SrcPPSettings = camera_view_info.PostProcessSettings;
FPostProcessSettings& DstPPSettings = dst->PostProcessSettings;

FWeightedBlendables DstWeightedBlendables = DstPPSettings.WeightedBlendables;
Expand Down
6 changes: 3 additions & 3 deletions Unreal/Plugins/AirSim/Source/PIPCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AIRSIM_API APIPCamera : public ACineCameraActor //CinemAirSim
void setPresetFilmbackSettings(std::string preset_string);
std::string getLensSettings();
std::string getFilmbackSettings();
float setFilmbackSettings(float sensor_width, float sensot_height);
float setFilmbackSettings(float sensor_width, float sensor_height);
float getFocalLength();
void setFocalLength(float focal_length);
void enableManualFocus(bool enable);
Expand All @@ -61,8 +61,8 @@ class AIRSIM_API APIPCamera : public ACineCameraActor //CinemAirSim
void enableFocusPlane(bool enable);
std::string getCurrentFieldOfView();

void CopyCameraSettingsToAllSceneCapture(UCameraComponent* camera);
void CopyCameraSettingsToSceneCapture(UCameraComponent* src, USceneCaptureComponent2D* dst);
void copyCameraSettingsToAllSceneCapture(UCameraComponent* camera);
void copyCameraSettingsToSceneCapture(UCameraComponent* src, USceneCaptureComponent2D* dst);
//end CinemAirSim methods

void setCameraTypeEnabled(ImageType type, bool enabled);
Expand Down

0 comments on commit bca2944

Please sign in to comment.