44 #include <ilqgames/gui/control_sliders.h> 45 #include <ilqgames/gui/cost_inspector.h> 46 #include <ilqgames/utils/operating_point.h> 47 #include <ilqgames/utils/player_cost_cache.h> 48 #include <ilqgames/utils/solver_log.h> 49 #include <ilqgames/utils/types.h> 51 #include <glog/logging.h> 52 #include <imgui/imgui.h> 58 void CostInspector::Render()
const {
63 player_costs_[selected_problem_][sliders_->LogIndex(selected_problem_)];
66 if (costs1.Log().NumIterates() == 0)
return;
69 ImGui::Begin(
"Cost Inspector");
72 if (ImGui::BeginCombo(
"Problem",
73 std::to_string(selected_problem_ + 1).c_str())) {
74 for (
size_t problem_idx = 0; problem_idx < sliders_->NumProblems();
76 const bool is_selected = (selected_problem_ == problem_idx);
77 if (ImGui::Selectable(std::to_string(problem_idx + 1).c_str(),
79 selected_problem_ = problem_idx;
80 if (is_selected) ImGui::SetItemDefaultFocus();
88 player_costs_[selected_problem_][sliders_->LogIndex(selected_problem_)];
90 if (ImGui::BeginCombo(
"Player",
91 std::to_string(selected_player_ + 1).c_str())) {
92 for (PlayerIndex ii = 0; ii < costs2.NumPlayers(); ii++) {
93 const bool is_selected = (selected_player_ == ii);
94 if (ImGui::Selectable(std::to_string(ii + 1).c_str(), is_selected))
95 selected_player_ = ii;
96 if (is_selected) ImGui::SetItemDefaultFocus();
104 player_costs_[selected_problem_][sliders_->LogIndex(selected_problem_)];
106 if (ImGui::BeginCombo(
"Cost", selected_cost_name_.c_str())) {
107 for (
const auto& entry : costs3.EvaluatedCosts(selected_player_)) {
108 const std::string& cost_name = entry.first;
109 const bool is_selected = (selected_cost_name_ == cost_name);
110 if (ImGui::Selectable(cost_name.c_str(), is_selected))
111 selected_cost_name_ = cost_name;
112 if (is_selected) ImGui::SetItemDefaultFocus();
120 player_costs_[selected_problem_][sliders_->LogIndex(selected_problem_)];
121 if (ImGui::BeginChild(
"Cost over time", ImVec2(0, 0),
false)) {
122 const std::string label =
"Player " + std::to_string(selected_player_ + 1) +
123 ": " + selected_cost_name_;
124 if (costs4.PlayerHasCost(selected_player_, selected_cost_name_)) {
125 const std::vector<float>& values =
126 costs4.EvaluatedCost(sliders_->SolverIterate(selected_problem_),
127 selected_player_, selected_cost_name_);
128 ImGui::PlotLines(label.c_str(), values.data(), values.size(), 0,
129 label.c_str(), FLT_MAX, FLT_MAX,
130 ImGui::GetWindowContentRegionMax());
133 const float time = sliders_->InterpolationTime(selected_problem_);
135 ImColor(ImVec4(234.0 / 255.0, 110.0 / 255.0, 110.0 / 255.0, 0.5));
136 constexpr
float kLineThickness = 2.0;
138 const ImVec2 window_top_left = ImGui::GetWindowPos();
139 const float line_y_lower = window_top_left.y + ImGui::GetWindowHeight();
140 const float line_y_upper = window_top_left.y;
141 const float line_x = window_top_left.x + ImGui::GetWindowWidth() * time /
142 costs4.Log().FinalTime();
144 ImDrawList* draw_list = ImGui::GetWindowDrawList();
145 draw_list->AddLine(ImVec2(line_x, line_y_lower),
146 ImVec2(line_x, line_y_upper), color, kLineThickness);