Skip to content

Commit

Permalink
Small cleanups, mark some methods as const
Browse files Browse the repository at this point in the history
  • Loading branch information
rajat2004 committed Feb 27, 2021
1 parent 1537a7d commit a1acd18
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
4 changes: 1 addition & 3 deletions AirLib/include/common/AirSimSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct AirSimSettings {
{
}

RecordingSetting(bool record_on_move_val, float record_interval_val, std::string folder_val, bool enabled_val)
RecordingSetting(bool record_on_move_val, float record_interval_val, const std::string& folder_val, bool enabled_val)
: record_on_move(record_on_move_val), record_interval(record_interval_val), folder(folder_val),
enabled(enabled_val)
{
Expand Down Expand Up @@ -124,7 +124,6 @@ struct AirSimSettings {
// ShowFlag.VisualizeHDR 1.
//to replicate camera settings_json to SceneCapture2D
//TODO: should we use UAirBlueprintLib::GetDisplayGamma()?
typedef msr::airlib::Utils Utils;
static constexpr float kSceneTargetGamma = 1.4f;

int image_type = 0;
Expand Down Expand Up @@ -621,7 +620,6 @@ struct AirSimSettings {
// Map contains a default vehicle if vehicles haven't been specified
std::string default_vehicle_name = vehicles.begin()->first;


for (size_t child_index = 0; child_index < req_cameras_settings.size(); ++child_index) {
Settings req_camera_settings;

Expand Down
16 changes: 8 additions & 8 deletions Unreal/Plugins/AirSim/Source/Recording/RecordingFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
#include "common/common_utils/FileSystem.hpp"


void RecordingFile::appendRecord(const std::vector<msr::airlib::ImageCaptureBase::ImageResponse>& responses, msr::airlib::VehicleSimApiBase* vehicle_sim_api)
void RecordingFile::appendRecord(const std::vector<msr::airlib::ImageCaptureBase::ImageResponse>& responses,
msr::airlib::VehicleSimApiBase* vehicle_sim_api) const
{
bool save_success = false;
std::stringstream image_file_names;
std::ostringstream image_file_names;

for (auto i = 0; i < responses.size(); ++i) {
const auto& response = responses.at(i);

//build image file name
std::stringstream image_file_name;
std::ostringstream image_file_name;
image_file_name << "img_"
<< vehicle_sim_api->getVehicleName() << "_"
<< response.camera_name << "_" <<
Expand Down Expand Up @@ -69,7 +70,6 @@ void RecordingFile::appendRecord(const std::vector<msr::airlib::ImageCaptureBase
writeString(vehicle_sim_api->getRecordFileLine(false).append(image_file_names.str()).append("\n"));

//UAirBlueprintLib::LogMessage(TEXT("Screenshot saved to:"), filePath, LogDebugLevel::Success);
images_saved_++;
}
}

Expand All @@ -92,7 +92,7 @@ void RecordingFile::createFile(const std::string& file_path, const std::string&
}
}

bool RecordingFile::isFileOpen()
bool RecordingFile::isFileOpen() const
{
return log_file_handle_ != nullptr;
}
Expand All @@ -105,11 +105,11 @@ void RecordingFile::closeFile()
log_file_handle_ = nullptr;
}

void RecordingFile::writeString(const std::string& str)
void RecordingFile::writeString(const std::string& str) const
{
try {
if (log_file_handle_) {
FString line_f = FString(str.c_str());
FString line_f(str.c_str());
log_file_handle_->Write((const uint8*)TCHAR_TO_ANSI(*line_f), line_f.Len());
}
else
Expand Down Expand Up @@ -167,7 +167,7 @@ void RecordingFile::stopRecording(bool ignore_if_stopped)
UAirBlueprintLib::LogMessage(TEXT("Data saved to: "), FString(image_path_.c_str()), LogDebugLevel::Success);
}

bool RecordingFile::isRecording()
bool RecordingFile::isRecording() const
{
return is_recording_;
}
11 changes: 5 additions & 6 deletions Unreal/Plugins/AirSim/Source/Recording/RecordingFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ class RecordingFile {
public:
~RecordingFile();

void appendRecord(const std::vector<msr::airlib::ImageCaptureBase::ImageResponse>& responses, msr::airlib::VehicleSimApiBase* vehicle_sim_api);
void appendRecord(const std::vector<msr::airlib::ImageCaptureBase::ImageResponse>& responses, msr::airlib::VehicleSimApiBase* vehicle_sim_api) const;
void appendColumnHeader(const std::string& header_columns);
void startRecording(msr::airlib::VehicleSimApiBase* vehicle_sim_api, const std::string& folder="");
void stopRecording(bool ignore_if_stopped);
bool isRecording();
bool isRecording() const;

private:
void createFile(const std::string& file_path, const std::string& header_columns);
void closeFile();
void writeString(const std::string& line);
bool isFileOpen();
void writeString(const std::string& line) const;
bool isFileOpen() const;

private:
std::string record_filename = "airsim_rec";
unsigned int images_saved_ = 0;
std::string record_filename = "airsim_rec";
std::string image_path_;
bool is_recording_ = false;
IFileHandle* log_file_handle_ = nullptr;
Expand Down

0 comments on commit a1acd18

Please sign in to comment.