From c87ac58a8dea3f9c734fbce6b32ce3472e7f954b Mon Sep 17 00:00:00 2001 From: Tristan Walter <twalter@orn.mpg.de> Date: Thu, 5 Nov 2020 14:17:18 +0100 Subject: [PATCH] * shorthorizontalline makes more sense now --- .../src/commons/common/gui/IMGUIBase.cpp | 2 +- Application/src/commons/common/misc/PVBlob.h | 17 ++++++++--------- .../src/commons/common/misc/PixelTree.cpp | 10 +++++----- Application/src/commons/common/misc/PixelTree.h | 10 +++++----- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Application/src/commons/common/gui/IMGUIBase.cpp b/Application/src/commons/common/gui/IMGUIBase.cpp index 3d9e8a2..7c286db 100644 --- a/Application/src/commons/common/gui/IMGUIBase.cpp +++ b/Application/src/commons/common/gui/IMGUIBase.cpp @@ -433,7 +433,7 @@ void clear_cache() { const float base_scale = 32; float dpi_scale = max(float(fw) / float(width), float(fh) / float(height)); - im_font_scale = max(1, dpi_scale) * 0.75; + im_font_scale = max(1, dpi_scale) * 0.75f; _dpi_scale = dpi_scale; ImFontConfig config; diff --git a/Application/src/commons/common/misc/PVBlob.h b/Application/src/commons/common/misc/PVBlob.h index 1cd2d1b..58c7fc2 100644 --- a/Application/src/commons/common/misc/PVBlob.h +++ b/Application/src/commons/common/misc/PVBlob.h @@ -99,23 +99,22 @@ namespace pv { static std::shared_ptr<std::vector<cmn::HorizontalLine>> uncompress(uint16_t start_y, const std::vector<ShortHorizontalLine>& compressed); public: - ShortHorizontalLine() {} + constexpr ShortHorizontalLine() : _x0(0), _x1(0) {} - ShortHorizontalLine(uint16_t x0, uint16_t x1, bool eol = false) { + constexpr ShortHorizontalLine(uint16_t x0, uint16_t x1, bool eol = false) + : _x0(x0), _x1((x1 & 0x7FFF) | uint16_t(eol << 15)) + { assert(x1 < 32768); // MAGIC NUMBERZ (uint16_t - 1 bit) - - _x0 = x0; - _x1 = (x1 << 1) + eol; } - uint16_t x0() const { return _x0; } - uint16_t x1() const { return (_x1 & 0xFFFE) >> 1; } + constexpr uint16_t x0() const { return _x0; } + constexpr uint16_t x1() const { return _x1 & 0x7FFF; } //! returns true if this is the last element on the current y coordinate // if true, the following lines are on current_y + 1. // @note stored in the last bit of _x1 - bool eol() const { return _x1 & 0x1; } - void eol(bool v) { _x1 = v ? (_x1 | 0x1) : (_x1 & 0xFFFE); } + constexpr bool eol() const { return (_x1 & 0x8000) != 0; } + constexpr void eol(bool v) { _x1 = (_x1 & 0x7FFF) | uint16_t(v << 15); } }; struct CompressedBlob { diff --git a/Application/src/commons/common/misc/PixelTree.cpp b/Application/src/commons/common/misc/PixelTree.cpp index d514ba3..b128d6a 100644 --- a/Application/src/commons/common/misc/PixelTree.cpp +++ b/Application/src/commons/common/misc/PixelTree.cpp @@ -709,8 +709,8 @@ inline blobs_t _threshold_blob(pv::BlobPtr blob,const std::vector<uchar>& differ #endif decltype(non_full_nodes.begin()) it; - int64_t out_idx = Node::leaf_index(int64_t(out.x * 10), int32_t(out.y * 10)); - int64_t in_idx = Node::leaf_index(int64_t(in.x * 10), int32_t(in.y * 10)); + uint64_t out_idx = Node::leaf_index(int64_t(out.x * 10), int32_t(out.y * 10)); + uint64_t in_idx = Node::leaf_index(int64_t(in.x * 10), int32_t(in.y * 10)); Subnode *in_node = nullptr, *out_node = nullptr; @@ -799,7 +799,7 @@ Node::Node(float x, float y, const std::array<int, 9>& neighbors) : x(x), y(y), std::vector<std::shared_ptr<std::vector<Vec2>>> Tree::generate_edges() { #undef IS_SET -#define IS_SET(NAME) (node->neighbors[ indexes[NAME] ])//node->neighbors.find( (Direction)NAME ) != node->neighbors.end()) +#define IS_SET(NAME) (node->neighbors[ (size_t)indexes[NAME] ]) //! we now have the pixel positions of all pixels with at least one border. now we have to find the half-pixel edges around these pixels and connect them. constexpr int max_val = (int)TOPL + 1; @@ -808,7 +808,7 @@ Node::Node(float x, float y, const std::array<int, 9>& neighbors) : x(x), y(y), }; //Debug(""); - static constexpr auto linear_search = [](int64_t idx, auto &nodes) -> pixel::Node* { + static constexpr auto linear_search = [](uint64_t idx, auto &nodes) -> pixel::Node* { for(auto &node : nodes) { if(node->index == idx) { return node.get(); @@ -876,7 +876,7 @@ Node::Node(float x, float y, const std::array<int, 9>& neighbors) : x(x), y(y), int opposite = (int)border + 2; if(opposite >= max_val) opposite -= max_val; - auto v = offset + vectors[left]; + auto v = offset + vectors[(size_t)left]; //Debug("\t%s is set. add %f,%f (%s with sides %s -> %s %f,%f)", NAME(left), v.x, v.y, NAME(left), NAME(border), NAME(opposite), vectors[left].x, vectors[left].y); auto ptr = linear_search(LEAF_INDEX(v), _nodes); if(ptr) diff --git a/Application/src/commons/common/misc/PixelTree.h b/Application/src/commons/common/misc/PixelTree.h index 7e2a5bf..86f9795 100644 --- a/Application/src/commons/common/misc/PixelTree.h +++ b/Application/src/commons/common/misc/PixelTree.h @@ -60,13 +60,13 @@ namespace pixel { std::array<Subnode*, 2> edges; //std::vector<std::shared_ptr<Subnode>> edges; bool walked; - int64_t index; + uint64_t index; Subnode() : walked(false), index(0) { edges[0] = edges[1] = nullptr; } - Subnode(int64_t index, const Vec2& position, Subnode* first) : position(position), walked(false), index(index) { + Subnode(uint64_t index, const Vec2& position, Subnode* first) : position(position), walked(false), index(index) { edges[0] = first; edges[1] = nullptr; } @@ -80,7 +80,7 @@ namespace pixel { class Node { public: float x,y; - int64_t index; + uint64_t index; #ifdef TREE_WITH_PIXELS Vec2 gradient; // pixel value gradient @@ -100,8 +100,8 @@ namespace pixel { return x == other.x && y == other.y; } - constexpr static int64_t leaf_index(int64_t x, int32_t y) { - return int64_t( ( (int64_t(x) << 32) & 0xFFFFFFFF00000000 ) | int64_t(y) ); + constexpr static uint64_t leaf_index(int64_t x, int32_t y) { + return uint64_t( ( (uint64_t(x) << 32) & 0xFFFFFFFF00000000 ) | (uint64_t(y) & 0x00000000FFFFFFFF) ); } }; -- GitLab