From 38e9a97a8583756f533019b3eaf5d568b86dd2e4 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Wed, 16 Feb 2022 13:59:14 +0100 Subject: [PATCH] add A2 stub --- src/a2.cpp | 18 ++++++++++++++++++ src/a2.h | 17 +++++++++++++++++ src/main_gui.cpp | 21 ++++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/a2.cpp create mode 100644 src/a2.h diff --git a/src/a2.cpp b/src/a2.cpp new file mode 100644 index 0000000..fe50fdb --- /dev/null +++ b/src/a2.cpp @@ -0,0 +1,18 @@ +#include "a2.h" + +namespace freling { + +std::vector A2(const std::vector& regions) { + std::vector updated_boxes(regions.size()); + for (int i = 0, size = regions.size(); i < size; ++i) { + auto& box = updated_boxes[i]; + const auto& region = regions[i]; + box.x = region.x + 2; + box.y = region.y + 2; + box.width = region.width - 4; + box.height = region.height - 4; + } + return updated_boxes; +} + +} // namespace freling diff --git a/src/a2.h b/src/a2.h new file mode 100644 index 0000000..7bc6b9b --- /dev/null +++ b/src/a2.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +#include "bounding_box.h" + +namespace freling { + +// The normal signature for this function should be: +// std::vector A2(const Frame& regions); +// However, since we are mocking this algorithm we just need to fulfill this +// constraint: "We assume for the sake of simplicity, that no bounding boxe +// in B′ overlaps more than one region in F Regions". +// To do so, we need to have the original delimitation of regions. +std::vector A2(const std::vector& regions); + +} // namespace freling diff --git a/src/main_gui.cpp b/src/main_gui.cpp index e218a30..101b141 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -13,6 +13,7 @@ #include #pragma clang diagnostic pop +#include "a2.h" #include "bounding_box.h" #include "frame.h" #include "pack.h" @@ -95,6 +96,7 @@ int main(int argc, const char* argv[]) { const std::vector bbox_colors = {RED, GREEN, BLUE, YELLOW, ORANGE, PURPLE}; std::vector packed_bboxes; + std::vector a2_bboxes; Vector2 win_size = {800, 450}; const int padding = 5; @@ -109,6 +111,7 @@ int main(int argc, const char* argv[]) { Image pack_img; Texture2D pack_texture; bool packed = false; + bool a2_processed = false; win_size.x = std::max(win_size.x, in_offset.x + in_texture.width + padding); win_size.y = @@ -190,7 +193,7 @@ int main(int argc, const char* argv[]) { b_size.y}, "Pack Rects")) { std::optional f_packed = - pack(*in_frame, bboxes, packed_bboxes); + freling::pack(*in_frame, bboxes, packed_bboxes); if (packed) { UnloadTexture(pack_texture); @@ -212,6 +215,13 @@ int main(int argc, const char* argv[]) { SetWindowSize(win_size.x, win_size.y); } + if (GuiButton((Rectangle){padding + (padding + b_size.x) * 2, padding, + b_size.x, b_size.y}, + "A2")) { + a2_bboxes = freling::A2(packed_bboxes); + a2_processed = true; + } + // // Input image // @@ -242,6 +252,15 @@ int main(int argc, const char* argv[]) { draw(b, pack_offset, color); ++c; }; + + if (a2_processed) { + int c = 0; + for (const auto& b : a2_bboxes) { + const auto& color = bbox_colors[c % bbox_colors.size()]; + draw(b, pack_offset, color); + ++c; + }; + } } EndDrawing();