diff --git a/aerodynamic_analysis/src/taw/tawCalculatePolarReport.cpp b/aerodynamic_analysis/src/taw/tawCalculatePolarReport.cpp index c1be325e5ee1bc5bfec573fc00a9bc1c712ce2a6..164658371cdb8205a883bd40b1913a6ae2042108 100644 --- a/aerodynamic_analysis/src/taw/tawCalculatePolarReport.cpp +++ b/aerodynamic_analysis/src/taw/tawCalculatePolarReport.cpp @@ -166,34 +166,6 @@ auto parse_csv_file(const std::string& file_path, const std::string& column_x, return {x_data, y_data}; } -fs::path generate_plot( - const std::map<std::string, std::pair<std::vector<double>, std::vector<double>>>& data, - const std::string& plot_dir, const std::string& html_dir, - const std::string& filename, const std::string& title, - const std::string& xlabel, const std::string& ylabel) { - - if (data.empty()) { - myRuntimeInfo->warn << "No data provided for plotting." << std::endl; - } - - auto plot_path_string = helpers::prepare_plot_path(plot_dir, filename); - - auto f = matplot::figure(true); - f->size(800, 600); - auto ax = f->current_axes(); - ax->hold(true); - - helpers::plot_datasets(ax, data); - helpers::configure_axes(ax, title, xlabel, ylabel); - helpers::configure_legend(ax); - - matplot::save(f, plot_path_string, "svg"); - #ifdef __unix__ - system("pkill gnuplot"); - #endif - return fs::relative(fs::path(plot_path_string), fs::path(html_dir)); -} - void tawCalculatePolar::set_html_body() { const auto& data = myDefaultStrategy->get_default_data(); @@ -301,23 +273,59 @@ void tawCalculatePolar::set_html_body() { lift_curve_data[label] = parse_csv_file(file_path.string(), "AoA", "C_L"); } - auto polar_clean_plot_path = generate_plot( - polar_data, - rtIO_->getPlotDir(), - rtIO_->getHtmlDir(), - "polar_clean.svg", - "Polar Curve (clean configuration)", - "C_D", - "C_L"); - - auto lift_curve_plot_path = generate_plot( - lift_curve_data, - rtIO_->getPlotDir(), - rtIO_->getHtmlDir(), - "lift_curve_clean.svg", - "Lift curve (clean configuration)", - "AoA", - "C_L"); + std::map<std::string, std::pair<std::vector<double>, std::vector<double>>> data = polar_data; + std::string plot_dir = rtIO_->getPlotDir(); + std::string html_dir = rtIO_->getHtmlDir(); + std::string filename = "polar_clean.svg"; + std::string title = "Polar Curve (clean configuration)"; + std::string xlabel = "C_D"; + std::string ylabel = "C_L"; + + if (data.empty()) { + myRuntimeInfo->warn << "No data provided for plotting." << std::endl; + } + + auto plot_path_string = helpers::prepare_plot_path(plot_dir, filename); + + auto f = matplot::figure(true); + f->size(800, 600); + auto ax = f->current_axes(); + ax->hold(true); + + helpers::plot_datasets(ax, data); + helpers::configure_axes(ax, title, xlabel, ylabel); + helpers::configure_legend(ax); + + matplot::save(f, plot_path_string, "svg"); + auto polar_clean_plot_path = fs::relative(fs::path(plot_path_string), fs::path(html_dir)); + ax->clear(); + matplot::cla(); + + data = lift_curve_data; + plot_dir = rtIO_->getPlotDir(); + html_dir = rtIO_->getHtmlDir(); + filename = "lift_curve_clean.svg"; + title = "Lift curve (clean configuration)"; + xlabel = "AoA"; + ylabel = "C_L"; + + if (data.empty()) { + myRuntimeInfo->warn << "No data provided for plotting." << std::endl; + } + + plot_path_string = helpers::prepare_plot_path(plot_dir, filename); + + // f = matplot::figure(true); + f->size(800, 600); + ax = f->current_axes(); + ax->hold(true); + + helpers::plot_datasets(ax, data); + helpers::configure_axes(ax, title, xlabel, ylabel); + helpers::configure_legend(ax); + + matplot::save(f, plot_path_string, "svg"); + auto lift_curve_plot_path = fs::relative(fs::path(plot_path_string), fs::path(html_dir)); report_.htmlReportStream() << std::format("<img src=\"{}\" alt=\"Lift vs. Drag\"/><br>\n", polar_clean_plot_path.string());