add A2 stub
This commit is contained in:
parent
7d2b7b9ba7
commit
38e9a97a85
18
src/a2.cpp
Normal file
18
src/a2.cpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#include "a2.h"
|
||||||
|
|
||||||
|
namespace freling {
|
||||||
|
|
||||||
|
std::vector<BoundingBox> A2(const std::vector<BoundingBox>& regions) {
|
||||||
|
std::vector<BoundingBox> 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
|
17
src/a2.h
Normal file
17
src/a2.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "bounding_box.h"
|
||||||
|
|
||||||
|
namespace freling {
|
||||||
|
|
||||||
|
// The normal signature for this function should be:
|
||||||
|
// std::vector<BoundingBox> 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<BoundingBox> A2(const std::vector<BoundingBox>& regions);
|
||||||
|
|
||||||
|
} // namespace freling
|
|
@ -13,6 +13,7 @@
|
||||||
#include <raygui.h>
|
#include <raygui.h>
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
|
#include "a2.h"
|
||||||
#include "bounding_box.h"
|
#include "bounding_box.h"
|
||||||
#include "frame.h"
|
#include "frame.h"
|
||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
|
@ -95,6 +96,7 @@ int main(int argc, const char* argv[]) {
|
||||||
const std::vector<Color> bbox_colors = {RED, GREEN, BLUE,
|
const std::vector<Color> bbox_colors = {RED, GREEN, BLUE,
|
||||||
YELLOW, ORANGE, PURPLE};
|
YELLOW, ORANGE, PURPLE};
|
||||||
std::vector<freling::BoundingBox> packed_bboxes;
|
std::vector<freling::BoundingBox> packed_bboxes;
|
||||||
|
std::vector<freling::BoundingBox> a2_bboxes;
|
||||||
|
|
||||||
Vector2 win_size = {800, 450};
|
Vector2 win_size = {800, 450};
|
||||||
const int padding = 5;
|
const int padding = 5;
|
||||||
|
@ -109,6 +111,7 @@ int main(int argc, const char* argv[]) {
|
||||||
Image pack_img;
|
Image pack_img;
|
||||||
Texture2D pack_texture;
|
Texture2D pack_texture;
|
||||||
bool packed = false;
|
bool packed = false;
|
||||||
|
bool a2_processed = false;
|
||||||
|
|
||||||
win_size.x = std::max(win_size.x, in_offset.x + in_texture.width + padding);
|
win_size.x = std::max(win_size.x, in_offset.x + in_texture.width + padding);
|
||||||
win_size.y =
|
win_size.y =
|
||||||
|
@ -190,7 +193,7 @@ int main(int argc, const char* argv[]) {
|
||||||
b_size.y},
|
b_size.y},
|
||||||
"Pack Rects")) {
|
"Pack Rects")) {
|
||||||
std::optional<Frame> f_packed =
|
std::optional<Frame> f_packed =
|
||||||
pack(*in_frame, bboxes, packed_bboxes);
|
freling::pack(*in_frame, bboxes, packed_bboxes);
|
||||||
|
|
||||||
if (packed) {
|
if (packed) {
|
||||||
UnloadTexture(pack_texture);
|
UnloadTexture(pack_texture);
|
||||||
|
@ -212,6 +215,13 @@ int main(int argc, const char* argv[]) {
|
||||||
SetWindowSize(win_size.x, win_size.y);
|
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
|
// Input image
|
||||||
//
|
//
|
||||||
|
@ -242,6 +252,15 @@ int main(int argc, const char* argv[]) {
|
||||||
draw(b, pack_offset, color);
|
draw(b, pack_offset, color);
|
||||||
++c;
|
++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();
|
EndDrawing();
|
||||||
|
|
Loading…
Reference in a new issue