From 0f6b3e018d6d7d42cbcbd10ce191fd76405a68d2 Mon Sep 17 00:00:00 2001
From: Tristan Walter <twalter@orn.mpg.de>
Date: Thu, 5 Nov 2020 15:04:10 +0100
Subject: [PATCH] * fixing path handling (to_string does not exist) * some more
 warnings removed * preventing frame < 0

---
 .../src/commons/common/gui/IMGUIBase.cpp      | 12 ++++-----
 Application/src/commons/common/misc/vec2.cpp  | 12 ++++++---
 Application/src/grabber/grabber.cpp           |  4 +--
 Application/src/grabber/main.cpp              | 10 ++++----
 Application/src/grabber/pvconvert.cpp         |  2 +-
 Application/src/tracker/gui/gui.cpp           | 25 +++++++------------
 6 files changed, 31 insertions(+), 34 deletions(-)

diff --git a/Application/src/commons/common/gui/IMGUIBase.cpp b/Application/src/commons/common/gui/IMGUIBase.cpp
index 7c286db..ac869f5 100644
--- a/Application/src/commons/common/gui/IMGUIBase.cpp
+++ b/Application/src/commons/common/gui/IMGUIBase.cpp
@@ -1048,17 +1048,17 @@ void IMGUIBase::draw_element(const DrawOrder& order) {
             
             // Non Anti-aliased Stroke
             auto &points = ptr->points();
-            int points_count = (int)points.size();
-            int count = points_count - 1;
+            auto points_count = points.size();
             
             if(points_count <= 1)
                 break;
             
+            auto count = points_count - 1;
             float thickness = ptr->thickness();
             const ImVec2 uv = list->_Data->TexUvWhitePixel;
             
-            const int idx_count = count*6;
-            const int vtx_count = count*4;      // FIXME-OPT: Not sharing edges
+            const auto idx_count = count*6;
+            const auto vtx_count = count*4;      // FIXME-OPT: Not sharing edges
             list->PrimReserve(idx_count, vtx_count);
             assert(idx_count > 0 && vtx_count > 0);
             
@@ -1067,9 +1067,9 @@ void IMGUIBase::draw_element(const DrawOrder& order) {
             //transform.combine(o->global_transform());
             //auto transform = o->global_transform();
 
-            for (int i1 = 0; i1 < count; i1++)
+            for (size_t i1 = 0; i1 < count; i1++)
             {
-                const int i2 = (i1+1) == points_count ? 0 : i1+1;
+                const size_t i2 = (i1+1) == points_count ? 0 : i1+1;
                 auto p1 = order.transform.transformPoint(points[i1].position());
                 auto p2 = order.transform.transformPoint(points[i2].position());
                 
diff --git a/Application/src/commons/common/misc/vec2.cpp b/Application/src/commons/common/misc/vec2.cpp
index 3b5bd77..9425baa 100644
--- a/Application/src/commons/common/misc/vec2.cpp
+++ b/Application/src/commons/common/misc/vec2.cpp
@@ -17,10 +17,14 @@ namespace cmn {
         if(y + height >= bounds.y + bounds.height)
             height = bounds.y + bounds.height - y;
         
-        if(width < 0)
-            width = x = 0;
-        if(height < 0)
-            height = y = 0;
+        if(width < 0) {
+            width = 0;
+            x = std::clamp(x, bounds.x, bounds.x + bounds.width);
+        }
+        if(height < 0) {
+            height = 0;
+            y = std::clamp(y, bounds.y, bounds.y + bounds.height);
+        }
     }
     
     Float2_t Bounds::distance(const Vec2& p) const {
diff --git a/Application/src/grabber/grabber.cpp b/Application/src/grabber/grabber.cpp
index d5686f4..180ced6 100644
--- a/Application/src/grabber/grabber.cpp
+++ b/Application/src/grabber/grabber.cpp
@@ -210,7 +210,7 @@ void ImageThreads::processing() {
 
 file::Path FrameGrabber::make_filename() {
     auto path = pv::DataLocation::parse("output", SETTING(filename).value<file::Path>());
-    if(path.extension().to_string() == "pv")
+    if(path.extension() == "pv")
         return path.remove_extension();
     
     return path;
@@ -741,7 +741,7 @@ FrameGrabber::~FrameGrabber() {
 }
 
 file::Path FrameGrabber::average_name() const {
-    auto path = pv::DataLocation::parse("output", "average_" + SETTING(filename).value<file::Path>().filename().to_string() + ".png");
+    auto path = pv::DataLocation::parse("output", "average_" + (std::string)SETTING(filename).value<file::Path>().filename() + ".png");
     return path;
 }
 
diff --git a/Application/src/grabber/main.cpp b/Application/src/grabber/main.cpp
index 4912995..7ac1f80 100644
--- a/Application/src/grabber/main.cpp
+++ b/Application/src/grabber/main.cpp
@@ -219,7 +219,7 @@ int main(int argc, char** argv)
             settings_file = SETTING(output_dir).value<file::Path>() / settings_file;
         }
         
-        if(!settings_file.has_extension() || settings_file.extension().to_string() != "settings")
+        if(!settings_file.has_extension() || settings_file.extension() != "settings")
             settings_file = settings_file.add_extension("settings");
         
         Debug("settings: %S", &settings_file.str());
@@ -250,11 +250,11 @@ int main(int argc, char** argv)
     });
     
     pv::DataLocation::register_path("output_settings", [](file::Path) -> file::Path {
-        file::Path settings_file = SETTING(filename).value<Path>().filename().to_string();
+        file::Path settings_file(SETTING(filename).value<Path>().filename());
         if(settings_file.empty())
             U_EXCEPTION("settings_file is an empty string.");
         
-        if(!settings_file.has_extension() || settings_file.extension().to_string() != "settings")
+        if(!settings_file.has_extension() || settings_file.extension() != "settings")
             settings_file = settings_file.add_extension("settings");
         
         return pv::DataLocation::parse("output", settings_file);
@@ -579,11 +579,11 @@ int main(int argc, char** argv)
                 if(filename.has_extension())
                     filename = filename.remove_extension();
                 
-                if(utils::contains(filename.filename().to_string(), '%')) {
+                if(utils::contains((std::string)filename.filename(), '%')) {
                     filename = filename.remove_filename();
                 }
                 
-                SETTING(filename) = file::Path(file::Path(filename).filename().to_string());
+                SETTING(filename) = file::Path(file::Path(filename).filename());
                 if(SETTING(filename).value<file::Path>().empty()) {
                     SETTING(filename) = file::Path("video");
                     Warning("No output filename given. Defaulting to 'video'.");
diff --git a/Application/src/grabber/pvconvert.cpp b/Application/src/grabber/pvconvert.cpp
index cb09e89..a9f9b39 100644
--- a/Application/src/grabber/pvconvert.cpp
+++ b/Application/src/grabber/pvconvert.cpp
@@ -20,7 +20,7 @@ int main(int argc, char**argv) {
             settings_file = SETTING(output_dir).value<file::Path>() / settings_file;
         }
         
-        if(!settings_file.has_extension() || settings_file.extension().to_string() != "settings")
+        if(!settings_file.has_extension() || settings_file.extension() != "settings")
             settings_file = settings_file.add_extension("settings");
         
         return settings_file;
diff --git a/Application/src/tracker/gui/gui.cpp b/Application/src/tracker/gui/gui.cpp
index 4ca431c..e8ec323 100644
--- a/Application/src/tracker/gui/gui.cpp
+++ b/Application/src/tracker/gui/gui.cpp
@@ -1770,9 +1770,9 @@ std::tuple<Vec2, Vec2> GUI::gui_scale_with_boundary(Bounds& boundary, Section* s
 }
 
 void GUI::label_fish(gui::DrawStructure &base, track::Individual *fish, long_t frameNr, const Vec2& scale, bool highlighted) {
-    const Font font((highlighted ? 0.85 : 0.85) / (1 - ((1 - GUI::instance()->cache().zoom_level()) * 0.5)), Align::Left);
+    const Font font((highlighted ? 0.85f : 0.85f) / (1 - ((1 - GUI::instance()->cache().zoom_level()) * 0.5f)), Align::Left);
     Font secondary_font = font;
-    secondary_font.size *= 0.9;
+    secondary_font.size *= 0.9f;
     
     //const Font font(0.9 * 0.75 + 0.25 * 0.9 / interface_scale);
     Vec2 factor = Vec2(Base::default_line_spacing(font)).mul(scale.mul(base.scale()) / font.size );//.mul(Vec2(0.5,1 + GUI::instance()->cache().zoom_level() * 0.5));
@@ -1786,27 +1786,27 @@ void GUI::label_fish(gui::DrawStructure &base, track::Individual *fish, long_t f
     auto transform = base.active_section()->global_transform();
     auto screen = transform.getInverse().transformRect(Bounds(Vec2(), Size2(base.width(), base.height())));
     
-    Vec2 text_pos = _cache._fish_map[fish]->pos() + Vec2(_cache._fish_map[fish]->size().width * 0.5, 0);
+    Vec2 text_pos = _cache._fish_map[fish]->pos() + Vec2(_cache._fish_map[fish]->size().width * 0.5f, 0);
     
     if(blob) {
         auto blob_center = _cache._fish_map[fish]->fish_pos();
         
-        auto gpos = transform.transformPoint(blob_center) - Vec2(gui().width(), gui().height() * 2.25) * 0.5;
-        gpos = gpos.div(Size2(gui().width() * 0.5, gui().height() * 0.5));
+        auto gpos = transform.transformPoint(blob_center) - Vec2(gui().width(), gui().height() * 2.25f) * 0.5f;
+        gpos = gpos.div(Size2(gui().width() * 0.5f, gui().height() * 0.5f));
         //gpos = gpos.mul(gpos);
         factor = factor.mul(Vec2(- gpos.x, - gpos.y) * 10);
         //secondary_text = Meta::toStr(gpos);//+" |"+Meta::toStr(factor);
         
         auto L = factor.length();
         factor = factor / L;
-        L = L * min(gui().width(), gui().height()) / 1000.f * 0.06 / gui::interface_scale();
+        L = L * min(gui().width(), gui().height()) / 1000.f * 0.06f / gui::interface_scale();
         //L = SQR(L) * 0.5;
         
         auto text_offset = Vec2(0, Base::default_line_spacing(font));
         auto offset_from_blob = blob->calculate_bounds().height * 0.25;
         auto line_start = offset_from_blob;
         auto line_end = L + line_start;
-        text_pos = blob_center - factor * (line_end + Base::default_line_spacing(Font(0.5)));
+        text_pos = blob_center - factor * (line_end + Base::default_line_spacing(Font(0.5f)));
         
         Vec2 end = blob_center - factor * line_end;
             
@@ -3166,11 +3166,6 @@ void GUI::update_display_blobs(bool draw_blobs, Section* fishbowl) {
             //_cache.display_blobs_list.insert(_cache.display_blobs_list.end(), vector.begin(), vector.end());
             
         }, _blob_thread_pool, _cache.raw_blobs.begin(), _cache.raw_blobs.end());
-        
-#ifndef NDEBUG
-        if(_cache.frame_idx % 100 == 0)
-            Debug("%lu/%lu %lu", _cache.display_blobs.size(), _cache.raw_blobs.size(), _cache.display_blobs_list.size());
-#endif
     }
 }
 
@@ -3998,9 +3993,7 @@ void GUI::key_event(const gui::Event &event) {
                 
                 play_direction() = 1;
                 
-                long_t new_frame = frame() + inc;
-                if(size_t(frame()) > _video_source->length()-1)
-                    new_frame = _video_source->length()-1;
+                long_t new_frame = min((long_t)_video_source->length()-1, frame() + inc);
                 SETTING(gui_frame) = new_frame;
                 
                 last_increase_timer.reset();
@@ -4051,7 +4044,7 @@ void GUI::key_event(const gui::Event &event) {
                 
                 play_direction() = -1;
                 
-                long_t new_frame = frame() - inc;
+                long_t new_frame = max(0, frame() - inc);
                 if(frame() < 0)
                     new_frame = 0;
                 SETTING(gui_frame) = new_frame;
-- 
GitLab