From cba9d9da5349ad0bd24c94d2e4cd5fdc0055c028 Mon Sep 17 00:00:00 2001 From: Tristan Walter <twalter@orn.mpg.de> Date: Fri, 6 Nov 2020 20:27:02 +0100 Subject: [PATCH] * changing track_max_individuals to unsigned int * as well as gui_focus_group, manual_identities and other variables related to identities --- Application/src/commons/common/gui/GLImpl.cpp | 28 ++++++----- Application/src/commons/common/gui/Graph.cpp | 47 ++++++++++--------- .../src/commons/common/gui/GuiTypes.cpp | 4 +- Application/src/commons/common/gui/colors.h | 4 +- Application/src/commons/common/misc/Image.cpp | 6 +++ Application/src/commons/common/misc/Image.h | 2 + .../src/commons/common/misc/detail.cpp | 6 +-- Application/src/commons/common/misc/detail.h | 2 +- Application/src/commons/common/misc/math.h | 8 ++-- Application/src/grabber/main.cpp | 6 +-- .../src/grabber/misc/InteractiveCamera.cpp | 4 +- Application/src/tracker/gui/DrawFish.cpp | 2 +- Application/src/tracker/gui/DrawMenu.cpp | 10 ++-- Application/src/tracker/gui/DrawPosture.cpp | 2 +- Application/src/tracker/gui/DrawPosture.h | 2 +- Application/src/tracker/gui/GUICache.cpp | 28 +++++------ Application/src/tracker/gui/GUICache.h | 34 +++++++------- .../src/tracker/gui/IdentityHeatmap.cpp | 30 ++++++++---- Application/src/tracker/gui/InfoCard.cpp | 36 +++++++------- .../src/tracker/gui/RecognitionSummary.cpp | 22 ++++----- Application/src/tracker/gui/Timeline.h | 2 +- Application/src/tracker/gui/gui.cpp | 8 ++-- Application/src/tracker/main.cpp | 8 ++-- Application/src/tracker/misc/Output.cpp | 20 ++++---- .../src/tracker/misc/default_config.cpp | 10 ++-- .../src/tracker/tracking/Accumulation.cpp | 22 ++++----- .../src/tracker/tracking/Accumulation.h | 4 +- Application/src/tracker/tracking/FOI.h | 8 ++-- .../src/tracker/tracking/Individual.cpp | 15 +++--- Application/src/tracker/tracking/Individual.h | 26 ++++++---- Application/src/tracker/tracking/Outline.h | 2 +- Application/src/tracker/tracking/Posture.cpp | 2 +- Application/src/tracker/tracking/Posture.h | 4 +- Application/src/tracker/tracking/Tracker.cpp | 18 +++---- Application/src/tracker/tracking/Tracker.h | 6 +-- .../src/tracker/tracking/TrainingData.cpp | 6 +-- .../src/tracker/tracking/TrainingData.h | 8 ++-- .../src/tracker/tracking/VisualField.cpp | 42 ++++++++--------- .../src/tracker/tracking/VisualField.h | 4 +- docs/parameters_tgrabs.rst | 2 +- docs/parameters_trex.rst | 8 ++-- 41 files changed, 272 insertions(+), 236 deletions(-) diff --git a/Application/src/commons/common/gui/GLImpl.cpp b/Application/src/commons/common/gui/GLImpl.cpp index b9e1a3f..ea86c3a 100644 --- a/Application/src/commons/common/gui/GLImpl.cpp +++ b/Application/src/commons/common/gui/GLImpl.cpp @@ -215,7 +215,7 @@ LoopStatus GLImpl::update_loop() { glViewport(0, 0, display_w, display_h); if(_frame_capture_enabled) - init_pbo(display_w, display_h); + init_pbo((uint)display_w, (uint)display_h); glClearColor(_clear_color.r / 255.f, _clear_color.g / 255.f, _clear_color.b / 255.f, _clear_color.a / 255.f); glClear(GL_COLOR_BUFFER_BIT); @@ -280,7 +280,7 @@ void GLImpl::update_pbo() { // read pixels from framebuffer to PBO // glReadPixels() should return immediately. glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[index]); - glReadPixels(0, 0, pboImage->cols, pboImage->rows, GL_BGRA, GL_UNSIGNED_BYTE, 0); + glReadPixels(0, 0, (GLsizei)pboImage->cols, (GLsizei)pboImage->rows, GL_BGRA, GL_UNSIGNED_BYTE, 0); // map the PBO to process its data by CPU glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[nextIndex]); @@ -362,14 +362,16 @@ TexturePtr GLImpl::texture(const Image * ptr) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei(GL_UNPACK_ALIGNMENT, ptr->dims != 4 ? ptr->dims : 0); + glPixelStorei(GL_UNPACK_ALIGNMENT, ptr->dims != 4 ? (GLint)ptr->dims : 0); #if !CMN_USE_OPENGL2 #define GL_LUMINANCE 0x1909 #define GL_LUMINANCE_ALPHA 0x190A #endif - auto output_type = GL_RGBA8, input_type = GL_RGBA; + GLint output_type = GL_RGBA8; + GLenum input_type = GL_RGBA; + if OPENGL3_CONDITION { if(ptr->dims == 1) { output_type = GL_RED; @@ -403,7 +405,7 @@ TexturePtr GLImpl::texture(const Image * ptr) { glTexImage2D(GL_TEXTURE_2D, 0, output_type, width, height, 0, input_type, GL_UNSIGNED_BYTE, empty.data()); - glTexSubImage2D(GL_TEXTURE_2D,0,0,0, ptr->cols, ptr->rows, input_type, GL_UNSIGNED_BYTE, ptr->data()); + glTexSubImage2D(GL_TEXTURE_2D,0,0,0, (GLsizei)ptr->cols, (GLsizei)ptr->rows, input_type, GL_UNSIGNED_BYTE, ptr->data()); glBindTexture(GL_TEXTURE_2D, 0); return std::unique_ptr<PlatformTexture>(new PlatformTexture{ @@ -462,9 +464,9 @@ void GLImpl::update_texture(PlatformTexture& id_, const Image *ptr) { glBindTexture(GL_TEXTURE_2D, _id); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei(GL_UNPACK_ALIGNMENT, ptr->dims != 4 ? ptr->dims : 0); + glPixelStorei(GL_UNPACK_ALIGNMENT, ptr->dims != 4 ? (GLint)ptr->dims : 0); - auto input_type = GL_RGBA; + GLenum input_type = GL_RGBA; if OPENGL3_CONDITION { if(ptr->dims == 1) { input_type = GL_RED; @@ -486,17 +488,17 @@ void GLImpl::update_texture(PlatformTexture& id_, const Image *ptr) { if (empty.size() < capacity) empty.resize(capacity, 0); - if (ptr->cols != id_.width || ptr->rows != id_.height) { - glTexSubImage2D(GL_TEXTURE_2D, 0, ptr->cols, 0, id_.width - ptr->cols, id_.height, input_type, GL_UNSIGNED_BYTE, empty.data()); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, ptr->rows, ptr->cols, id_.height - ptr->rows, input_type, GL_UNSIGNED_BYTE, empty.data()); + if (ptr->cols != (uint)id_.width || ptr->rows != (uint)id_.height) { + glTexSubImage2D(GL_TEXTURE_2D, 0, (GLint)ptr->cols, 0, GLint(id_.width) - GLint(ptr->cols), id_.height, input_type, GL_UNSIGNED_BYTE, empty.data()); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, (GLint)ptr->rows, (GLint)ptr->cols, GLint(id_.height) - GLint(ptr->rows), input_type, GL_UNSIGNED_BYTE, empty.data()); //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, id_.width, id_.height, input_type, GL_UNSIGNED_BYTE, empty.data()); } - glTexSubImage2D(GL_TEXTURE_2D,0,0,0, ptr->cols, ptr->rows, input_type, GL_UNSIGNED_BYTE, ptr->data()); + glTexSubImage2D(GL_TEXTURE_2D,0,0,0, (GLint)ptr->cols, (GLint)ptr->rows, input_type, GL_UNSIGNED_BYTE, ptr->data()); //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ptr->cols, ptr->rows, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptr->data()); glBindTexture(GL_TEXTURE_2D, 0); - id_.image_width = ptr->cols; - id_.image_height = ptr->rows; + id_.image_width = int(ptr->cols); + id_.image_height = int(ptr->rows); } void GLImpl::set_title(std::string title) { diff --git a/Application/src/commons/common/gui/Graph.cpp b/Application/src/commons/common/gui/Graph.cpp index 39418ee..ed09f9f 100644 --- a/Application/src/commons/common/gui/Graph.cpp +++ b/Application/src/commons/common/gui/Graph.cpp @@ -4,6 +4,7 @@ #include <gui/DrawSFBase.h> #include <misc/cnpy_wrapper.h> #include <misc/metastring.h> +#include <misc/checked_casts.h> using namespace cmn; using namespace gui; @@ -133,8 +134,8 @@ void Graph::update() { return !(A == highlighted || (B != highlighted && A < B)); }); - advance(new Vertices(Vec2(0, (1.0 - y_offset_percent) * max_height) + _margin, - Vec2(max_width, (1.0 - y_offset_percent) * max_height) + _margin, + advance(new Vertices(Vec2(0, (1.0f - y_offset_percent) * max_height) + _margin, + Vec2(max_width, (1.0f - y_offset_percent) * max_height) + _margin, fg)); advance(new Vertices(Vec2(custom_y_axis_offset, 0) + _margin, @@ -146,7 +147,7 @@ void Graph::update() { if(lengthx > 5) value = roundf(value * 100) / 100; - Vec2 pt(x, (1.0 - y_offset_percent) * max_height); + Vec2 pt(x, (1.0f - y_offset_percent) * max_height); pt += _margin; std::stringstream ss; @@ -154,7 +155,7 @@ void Graph::update() { std::string str = ss.str(); advance(new Vertices(pt - Vec2(0, 2), pt + Vec2(0, 2), fg)); - return advance(new Text(str, pt + Vec2(0, Base::default_line_spacing(x_label_font)*0.5+5), fg, x_label_font)); + return advance(new Text(str, pt + Vec2(0, Base::default_line_spacing(x_label_font)*0.5f+5), fg, x_label_font)); }; auto label_point_y = [&](float y_visual, float value) { @@ -170,7 +171,7 @@ void Graph::update() { std::string str = ss.str(); advance(new Vertices(pt - Vec2(2, 0), pt + Vec2(2, 0), fg)); - advance(new Text(str, pt - Vec2(5, Base::default_line_spacing(y_label_font)*0.5), fg, y_label_font)); + advance(new Text(str, pt - Vec2(5, Base::default_line_spacing(y_label_font)*0.5f), fg, y_label_font)); }; #define TYPE_IS(X) ( (int)f._type & (int)Type:: X ) @@ -184,7 +185,7 @@ void Graph::update() { } if(has_discrete) { - float spacing = max(1, round(rx.length() * 0.1)); + float spacing = max(1, round(rx.length() * 0.1f)); for(auto i = round(rx.start); i<=round(rx.end); i+=spacing) { float x = (i-rx.start) / lengthx + x_offset_percent; label_point_x(x, i); @@ -192,7 +193,7 @@ void Graph::update() { } else { // label x starting at 0 / rx.start - float spacing = lengthx * 0.1; + float spacing = lengthx * 0.1f; for (float i=rx.start < 0 && rx.end > 0 ? 0 : rx.start; i<rx.end; i+=spacing) { float x = (i-rx.start) / lengthx + x_offset_percent; label_point_x(x, i); @@ -210,7 +211,7 @@ void Graph::update() { if(_xyaxis & (char)Axis::Y) { // label y - auto spacing = (lengthy) * 0.1; + auto spacing = (lengthy) * 0.1f; float limit = ry.start < 0 && ry.end > 0 ? 0 : ry.start; for (float i=10-y_offset_percent*10; i>=0; i--) { float x = limit + i * spacing; @@ -229,7 +230,7 @@ void Graph::update() { auto split_polygon = [this, &max_height, &y_offset_percent](const std::vector<Vertex>& vertices){ auto work = std::make_shared<std::vector<Vec2>>(); - const Vec2 null = Vec2(0, (1.0 - y_offset_percent) * max_height + _margin.y); + const Vec2 null = Vec2(0, (1.0f - y_offset_percent) * max_height + _margin.y); auto make_polygon = [&]() { if(work->empty()) @@ -282,7 +283,7 @@ void Graph::update() { float percentx = (pt.x-rx.start) / lengthx + x_offset_percent; float x = percentx * max_width - y_axis_offset; - float y = (1.0 - (pt.y / lengthy + y_offset_percent)) * max_height; + float y = (1.0f - (pt.y / lengthy + y_offset_percent)) * max_height; auto current = Vec2(x, y) + _margin; auto ptr = std::make_shared<Circle>(OFFSET(current), 3, f._color); @@ -310,8 +311,8 @@ void Graph::update() { continue; } - const int step_nr = max_width * (TYPE_IS(DISCRETE) || TYPE_IS(POINTS) ? 1.0 : 0.25); - const float step_size = 1.0 / step_nr; + const int step_nr = narrow_cast<int>(max_width / (TYPE_IS(DISCRETE) || TYPE_IS(POINTS) ? 1 : 4)); + const float step_size = 1.0f / step_nr; const float stepx = lengthx * step_size; Vec2 prev(0, 0); @@ -339,7 +340,7 @@ void Graph::update() { float percentx = (x0-rx.start) / lengthx + x_offset_percent; float x = percentx * max_width - y_axis_offset; - float y0 = f._get_y(x0); + float y0 = narrow_cast<float>(f._get_y(x0)); float y; if (cmn::isinf(y0)) { @@ -348,7 +349,7 @@ void Graph::update() { y = prev_y0; clr = fg; } else - y = (1.0 - ((y0) / lengthy + y_offset_percent)) * max_height; + y = (1.0f - ((y0) / lengthy + y_offset_percent)) * max_height; prev_y0 = y0; prev_x0 = x0; @@ -441,7 +442,7 @@ Vec2 Graph::transform_point(Vec2 pt) { float percentx = (pt.x-rx.start) / lengthx + x_offset_percent; float x = percentx * max_width - y_axis_offset; - float y = (1.0 - (pt.y / lengthy + y_offset_percent)) * max_height; + float y = (1.0f - (pt.y / lengthy + y_offset_percent)) * max_height; return Vec2(x, y) + _margin; } @@ -562,16 +563,16 @@ void Graph::export_data(const std::string &filename, std::function<void(float)> Table table(header); const Rangef& rx = _x_range; - table.reserve(cmn::abs(rx.end - rx.start)); + table.reserve(sign_cast<size_t>(cmn::abs(rx.end - rx.start))); Row row; int print_step = max(1, int((rx.end - rx.start) * 0.1)); - for(int x=rx.start; x<=rx.end; x++) { + for(float x=rx.start; x<=rx.end; x++) { row.clear(); row.add(x); for (auto &f : _functions) { - float y0 = f._get_y(x); + auto y0 = f._get_y(x); if (cmn::isinf(y0)) { // no value can be found at this location @@ -584,11 +585,11 @@ void Graph::export_data(const std::string &filename, std::function<void(float)> } table.add(row); - if (x%print_step == 0 && rx.end - rx.start > 10000) { + if (int(x)%print_step == 0 && rx.end - rx.start > 10000) { Debug("%d/%.0f done", x, rx.end); } - if(percent_callback && x%100 == 0) { + if(percent_callback && int(x)%100 == 0) { (*percent_callback)(cmn::abs(x-rx.start) / cmn::abs(rx.end - rx.start)); } } @@ -628,12 +629,12 @@ void Graph::save_npz(const std::string &filename, std::function<void(float)> *pe std::unordered_map<const gui::Graph::Function*, std::vector<float>> results; for (auto &f : _functions) - results[&f].reserve(_x_range.length()+1); + results[&f].reserve((size_t)_x_range.length()+1); int print_step = max(1, int((rx.end - rx.start) * 0.1f)); for(float x=rx.start; x<=rx.end; x++) { for (auto &f : _functions) { - float y0 = f._get_y(x); + auto y0 = f._get_y(x); if (cmn::isinf(y0)) { // no value can be found at this location @@ -641,7 +642,7 @@ void Graph::save_npz(const std::string &filename, std::function<void(float)> *pe results[&f].push_back(infinity<float>()); } else { - results[&f].push_back(y0); + results[&f].push_back(float(y0)); } } diff --git a/Application/src/commons/common/gui/GuiTypes.cpp b/Application/src/commons/common/gui/GuiTypes.cpp index cd96bc6..57b4e19 100644 --- a/Application/src/commons/common/gui/GuiTypes.cpp +++ b/Application/src/commons/common/gui/GuiTypes.cpp @@ -396,7 +396,7 @@ void reduce_vertex_line(const std::vector<Vertex>& points, std::vector<Vertex>& // returns [-1,1] values from 180°-0° (upper half of the unit circle) // 90°-180° is < 0, while 0°-90° is >= 0 // move it to [-2,0], take absolute and multiply by 0.5, so we get 0-180° -> [0,1] - float a = cmn::abs(previous_vec.dot(line) - 1) * 0.5; + float a = cmn::abs(previous_vec.dot(line) - 1) * 0.5f; //Debug("%f (%f,%f) -> (%f,%f) : %f | %f, len:%f", previous_vec.dot(line), previous_vec.x, previous_vec.y, line.x, line.y, a, threshold, len); if (cumlen < dim * threshold * 0.005 && color_diff < threshold * 0.01 && a < threshold * 0.1) continue; @@ -541,7 +541,7 @@ void ExternalImage::update_with(const gpuMat& mat) { || (int)_source->rows != mat.rows || (int)_source->dims != mat.channels()) { - _source->create(mat.rows, mat.cols, mat.dims); + _source->create((uint)mat.rows, (uint)mat.cols, (uint)mat.dims); set_size(Vec2(_source->cols, _source->rows)); } diff --git a/Application/src/commons/common/gui/colors.h b/Application/src/commons/common/gui/colors.h index f81c033..b004dd3 100644 --- a/Application/src/commons/common/gui/colors.h +++ b/Application/src/commons/common/gui/colors.h @@ -5,7 +5,7 @@ #include <gui/types/Basic.h> class ColorWheel { - long_t _index; + uint32_t _index; /*constexpr static gui::Color colors[] = { gui::Color(0,0,255), gui::Color(80,170,0), @@ -64,7 +64,7 @@ class ColorWheel { //int _offset; public: - constexpr ColorWheel(long_t index = 0) : _index(index), _hue(int(255 + index * (index + 1) * 0.5 * step)) { + constexpr ColorWheel(uint32_t index = 0) : _index(index), _hue(int(255 + index * (index + 1) * 0.5 * step)) { } constexpr gui::Color next() { diff --git a/Application/src/commons/common/misc/Image.cpp b/Application/src/commons/common/misc/Image.cpp index c2bc8f9..7046908 100644 --- a/Application/src/commons/common/misc/Image.cpp +++ b/Application/src/commons/common/misc/Image.cpp @@ -70,6 +70,12 @@ namespace cmn { return data()[x * dims + channel + y * cols * dims]; } + uchar* Image::ptr(uint y, uint x) const { + assert(y < rows); + assert(x < cols); + return data() + (x * dims + y * cols * dims); + } + void Image::set_pixel(uint x, uint y, const gui::Color& color) const { assert(y < rows); assert(x < cols); diff --git a/Application/src/commons/common/misc/Image.h b/Application/src/commons/common/misc/Image.h index 4192677..0cfe208 100644 --- a/Application/src/commons/common/misc/Image.h +++ b/Application/src/commons/common/misc/Image.h @@ -71,6 +71,8 @@ namespace cmn { //! access pixel at y,x and channel uchar at(uint y, uint x, uint channel = 0) const; + uchar* ptr(uint y, uint x) const; + void set_pixel(uint x, uint y, const gui::Color& color) const; void get(cv::Mat& matrix) const; diff --git a/Application/src/commons/common/misc/detail.cpp b/Application/src/commons/common/misc/detail.cpp index 4a94d6b..fbad8b0 100644 --- a/Application/src/commons/common/misc/detail.cpp +++ b/Application/src/commons/common/misc/detail.cpp @@ -996,11 +996,11 @@ namespace cmn { Viridis::value_t {0.99324789, 0.90615657, 0.1439362 } }}; - gui::Color Viridis::value(float percent) { - size_t index = min(1.f, cmn::abs(percent)) * 255; + gui::Color Viridis::value(double percent) { + size_t index = size_t(min(1.0, cmn::abs(percent)) * 255); auto& [r, g, b] = data_bgr[index]; - return gui::Color(r * 255, g * 255, b * 255, 255); + return gui::Color((uint8_t)saturate(r * 255), (uint8_t)saturate(g * 255), (uint8_t)saturate(b * 255), 255); } HorizontalLine::operator MetaObject() const { diff --git a/Application/src/commons/common/misc/detail.h b/Application/src/commons/common/misc/detail.h index 26a618b..d39aec7 100644 --- a/Application/src/commons/common/misc/detail.h +++ b/Application/src/commons/common/misc/detail.h @@ -892,6 +892,6 @@ namespace cmn { private: static const std::array<value_t, 256> data_bgr; public: - static gui::Color value(float percent); + static gui::Color value(double percent); }; } diff --git a/Application/src/commons/common/misc/math.h b/Application/src/commons/common/misc/math.h index d82d160..49a7555 100644 --- a/Application/src/commons/common/misc/math.h +++ b/Application/src/commons/common/misc/math.h @@ -113,9 +113,11 @@ namespace cmn { return ::atan2f(y, x); } - template<typename T> - constexpr inline T abs(const T& x, typename std::enable_if< std::is_integral<T>::value || std::is_floating_point<T>::value, bool>::type * = NULL) { - return std::copysign(x, static_cast<T>(1)); + template<typename T, typename K = typename std::remove_reference<typename std::remove_cv<T>::type>::type> + constexpr inline auto abs(T&& x) + -> typename std::enable_if< std::is_integral< K >::value || std::is_floating_point< K >::value, K >::type + { + return std::copysign(std::forward<T>(x), static_cast<K>(1)); } template<typename T> diff --git a/Application/src/grabber/main.cpp b/Application/src/grabber/main.cpp index 7ac1f80..26860c0 100644 --- a/Application/src/grabber/main.cpp +++ b/Application/src/grabber/main.cpp @@ -636,10 +636,10 @@ int main(int argc, char** argv) Debug("Logging to '%S'.", &path.str()); } - if(SETTING(manual_identities).value<std::set<track::idx_t>>().empty() && SETTING(track_max_individuals).value<track::idx_t>() != 0) + if(SETTING(manual_identities).value<std::set<uint32_t>>().empty() && SETTING(track_max_individuals).value<uint32_t>() != 0) { - std::set<track::idx_t> vector; - for(track::idx_t i=0; i<SETTING(track_max_individuals).value<track::idx_t>(); ++i) { + std::set<uint32_t> vector; + for(uint32_t i=0; i<SETTING(track_max_individuals).value<uint32_t>(); ++i) { vector.insert(i); } SETTING(manual_identities) = vector; diff --git a/Application/src/grabber/misc/InteractiveCamera.cpp b/Application/src/grabber/misc/InteractiveCamera.cpp index 629f2ae..dbe5e1c 100644 --- a/Application/src/grabber/misc/InteractiveCamera.cpp +++ b/Application/src/grabber/misc/InteractiveCamera.cpp @@ -78,12 +78,12 @@ InteractiveCamera::InteractiveCamera() { _size = cv::Size(SETTING(cam_resolution).value<cv::Size>().width, SETTING(cam_resolution).value<cv::Size>().height); if constexpr(use_dynamic) { - const size_t number_individuals = SETTING(track_max_individuals).value<long_t>(); + const auto number_individuals = SETTING(track_max_individuals).value<uint32_t>(); constexpr auto random_number = [](const Rangel& range) { return Float2_t(rand()) / Float2_t(RAND_MAX) * range.length() + range.start; }; - _fishies.resize(number_individuals ? number_individuals : 3); + _fishies.resize(number_individuals ? number_individuals : 3u); for(auto &fish : _fishies) { fish.position = Vec2(random_number(Rangel(0, _size.width)), random_number(Rangel(0, _size.height))); diff --git a/Application/src/tracker/gui/DrawFish.cpp b/Application/src/tracker/gui/DrawFish.cpp index 0128531..e35ce05 100644 --- a/Application/src/tracker/gui/DrawFish.cpp +++ b/Application/src/tracker/gui/DrawFish.cpp @@ -49,7 +49,7 @@ CREATE_STRUCT(CachedGUIOptions, GUI::cache().set_tracking_dirty(); }); on_click([ID, this](auto) { - std::vector<idx_t> selections = SETTING(gui_focus_group); + std::vector<uint32_t> selections = SETTING(gui_focus_group); if(stage() && !(stage()->is_key_pressed(gui::LShift) || stage()->is_key_pressed(gui::RShift))) { if(!selections.empty() && selections.front() == ID) diff --git a/Application/src/tracker/gui/DrawMenu.cpp b/Application/src/tracker/gui/DrawMenu.cpp index 415be71..5f85a8c 100644 --- a/Application/src/tracker/gui/DrawMenu.cpp +++ b/Application/src/tracker/gui/DrawMenu.cpp @@ -439,9 +439,9 @@ public: for(auto key : to_delete) overall.sizes.erase(key); - stats->set_origin(Vec2(0.5)); - Size2 intended_size(ddsize.width * base.scale().x * 0.85, ddsize.height * base.scale().y * 0.3); - float margin = intended_size.width * 0.005; + stats->set_origin(Vec2(0.5f)); + Size2 intended_size(ddsize.width * base.scale().x * 0.85f, ddsize.height * base.scale().y * 0.3f); + float margin = intended_size.width * 0.005f; stats->update([&](Entangled& base) { Size2 bars(intended_size.width / float(overall.sizes.size()), intended_size.height - margin * 2 - 20 * 3); @@ -470,11 +470,11 @@ public: size_t i=0; for(auto && [name, size] : overall.sizes) { auto color = wheel.next(); - double h = double((size - mi) / double(ma - mi)) * bars.height; + float h = float((size - mi) / float(ma - mi)) * bars.height; //Debug("%S: %f (%lu, %lu)", &name, h, size - mi, ma - mi); base.advance(new Rect(Bounds(x + margin, margin + bars.height - h, bars.width - margin * 2, h), color)); auto text = elements.at(i); - auto pos = Vec2(x + bars.width * 0.5, margin + bars.height + margin); + auto pos = Vec2(x + bars.width * 0.5f, margin + bars.height + margin); if(!text) { text = std::make_shared<StaticText>(utils::trim(utils::find_replace(name, "_", " ")) + "\n<ref>" + Meta::toStr(FileSize{size})+"</ref>", pos, Vec2(bars.width, 20)); elements.at(i) = text; diff --git a/Application/src/tracker/gui/DrawPosture.cpp b/Application/src/tracker/gui/DrawPosture.cpp index e4ce014..0655e8c 100644 --- a/Application/src/tracker/gui/DrawPosture.cpp +++ b/Application/src/tracker/gui/DrawPosture.cpp @@ -256,7 +256,7 @@ namespace gui { set_content_changed(true); // if this map gets too big (cached scale values), remove a few of them - if((track::idx_t)_scale.size() > FAST_SETTINGS(track_max_individuals)) { + if((uint32_t)_scale.size() > FAST_SETTINGS(track_max_individuals)) { for (auto it = _scale.begin(); it != _scale.end();) { if(!_fish || it->first != _fish->identity().ID()) { it = _scale.erase(it); diff --git a/Application/src/tracker/gui/DrawPosture.h b/Application/src/tracker/gui/DrawPosture.h index 4772599..80b8915 100644 --- a/Application/src/tracker/gui/DrawPosture.h +++ b/Application/src/tracker/gui/DrawPosture.h @@ -18,7 +18,7 @@ namespace gui { //gui::Rect _background; bool _average_active; - std::map<track::idx_t, std::deque<float>> _scale; + std::map<uint32_t, std::deque<float>> _scale; public: Posture(const Bounds& size); diff --git a/Application/src/tracker/gui/GUICache.cpp b/Application/src/tracker/gui/GUICache.cpp index eb6f59b..a516986 100644 --- a/Application/src/tracker/gui/GUICache.cpp +++ b/Application/src/tracker/gui/GUICache.cpp @@ -80,18 +80,18 @@ namespace gui { selected.clear(); } - bool GUICache::is_selected(idx_t id) const { + bool GUICache::is_selected(uint32_t id) const { return contains(selected, id); } - void GUICache::do_select(idx_t id) { + void GUICache::do_select(uint32_t id) { if(!is_selected(id)) { selected.push_back(id); SETTING(gui_focus_group) = selected; } } - void GUICache::deselect(idx_t id) { + void GUICache::deselect(uint32_t id) { auto it = std::find(selected.begin(), selected.end(), id); if(it != selected.end()) { selected.erase(it); @@ -99,7 +99,7 @@ namespace gui { } } - void GUICache::deselect_all_select(idx_t id) { + void GUICache::deselect_all_select(uint32_t id) { selected.clear(); selected.push_back(id); @@ -170,7 +170,7 @@ namespace gui { } else if(_statistics.size() > _tracker._statistics.size()) { auto start = _statistics.begin(); - std::advance(start, _tracker._statistics.size()); + std::advance(start, (int64_t)_tracker._statistics.size()); _statistics.erase(start, _statistics.end()); } @@ -178,7 +178,7 @@ namespace gui { if(properties) { active = _tracker.active_individuals(frameIndex); individuals = _tracker.individuals(); - selected = SETTING(gui_focus_group).value<std::vector<idx_t>>(); + selected = SETTING(gui_focus_group).value<std::vector<uint32_t>>(); active_blobs.clear(); inactive_ids.clear(); active_ids.clear(); @@ -189,7 +189,7 @@ namespace gui { auto delete_callback = [this](Individual* fish) { std::lock_guard<std::recursive_mutex> guard(GUI::instance()->gui().lock()); - auto id = fish->identity().ID(); + auto id = narrow_cast<int32_t>(fish->identity().ID()); auto it = individuals.find(id); if(it != individuals.end()) individuals.erase(it); @@ -221,7 +221,7 @@ namespace gui { } else { for(auto id : FAST_SETTINGS(manual_identities)) { - auto it = individuals.find(id); + auto it = individuals.find((idx_t)id); if(it != individuals.end()) { it->second->register_delete_callback((void*)12341337, delete_callback); } @@ -286,7 +286,7 @@ namespace gui { } else { // display blobs that are selected for(auto id : selected) { - auto it = individuals.find(id); + auto it = individuals.find((idx_t)id); if(it != individuals.end()) { auto blob = it->second->compressed_blob(frameIndex); if(blob) @@ -328,7 +328,7 @@ namespace gui { try { auto file = static_cast<pv::File*>(GUI::instance()->video_source()); - file->read_frame(processed_frame.frame(), frameIndex); + file->read_frame(processed_frame.frame(), (size_t)frameIndex); std::lock_guard<std::mutex> guard(GUI::instance()->blob_thread_pool_mutex()); Tracker::instance()->preprocess_frame(processed_frame, prev_active, &GUI::instance()->blob_thread_pool()); @@ -377,7 +377,7 @@ namespace gui { max_vec = max(max_vec, blob->bounds().pos() + blob->bounds().size()); } - _num_pixels += blob->bounds().width * blob->bounds().height; + _num_pixels += size_t(blob->bounds().width * blob->bounds().height); if(reload_blobs) { std::unique_ptr<gui::ExternalImage> ptr; @@ -448,7 +448,7 @@ namespace gui { } } - bool GUICache::has_probs(long_t fdx) { + bool GUICache::has_probs(uint32_t fdx) { if(checked_probs.find(fdx) != checked_probs.end()) { return probabilities.find(fdx) != probabilities.end(); } @@ -456,7 +456,7 @@ namespace gui { return probs(fdx) != nullptr; } - const std::map<uint32_t, Individual::Probability>* GUICache::probs(long_t fdx) { + const std::map<uint32_t, Individual::Probability>* GUICache::probs(uint32_t fdx) { if(checked_probs.find(fdx) != checked_probs.end()) { auto it = probabilities.find(fdx); if(it != probabilities.end()) @@ -472,7 +472,7 @@ namespace gui { if(it != processed_frame.cached_individuals.end()) { auto && [fdx, cache] = *it; for(auto blob : processed_frame.blobs) { - auto p = individuals.count(fdx) ? individuals.at(fdx)->probability(cache, frame_idx, blob) : Individual::Probability{0,0,0,0}; + auto p = individuals.count((idx_t)fdx) ? individuals.at((idx_t)fdx)->probability(cache, frame_idx, blob) : Individual::Probability{0,0,0,0}; if(p.p >= FAST_SETTINGS(matching_probability_threshold)) probabilities[fdx][blob->blob_id()] = p; } diff --git a/Application/src/tracker/gui/GUICache.h b/Application/src/tracker/gui/GUICache.h index 8e565c1..83e56bb 100644 --- a/Application/src/tracker/gui/GUICache.h +++ b/Application/src/tracker/gui/GUICache.h @@ -28,8 +28,8 @@ namespace gui { int last_threshold; long_t last_frame; Bounds boundary; - std::vector<idx_t> previous_active_fish; - std::set<idx_t> previous_active_blobs, active_blobs; + std::vector<uint32_t> previous_active_fish; + std::set<uint32_t> previous_active_blobs, active_blobs; Vec2 previous_mouse_position; bool _dirty; FOIStatus _current_foi; @@ -61,15 +61,15 @@ namespace gui { std::map<uint32_t, long_t> automatic_assignments; std::unordered_map<idx_t, Individual*> individuals; - std::set<idx_t> active_ids; - std::set<idx_t> inactive_ids; - std::set<idx_t> recognized_ids; - std::map<idx_t, std::shared_ptr<gui::Circle>> recognition_circles; - std::map<idx_t, Timer> recognition_timer; + std::set<uint32_t> active_ids; + std::set<uint32_t> inactive_ids; + std::set<uint32_t> recognized_ids; + std::map<uint32_t, std::shared_ptr<gui::Circle>> recognition_circles; + std::map<uint32_t, Timer> recognition_timer; Tracker::set_of_individuals_t _registered_callback; - std::map<idx_t, long_t> fish_selected_blobs; + std::map<uint32_t, long_t> fish_selected_blobs; Tracker::set_of_individuals_t active; //std::vector<std::shared_ptr<gui::ExternalImage>> blob_images; std::vector<std::shared_ptr<SimpleBlob>> raw_blobs; @@ -79,8 +79,8 @@ namespace gui { std::vector<Vec2> inactive_estimates; protected: - std::map<idx_t, std::map<uint32_t, Individual::Probability>> probabilities; - std::set<idx_t> checked_probs; + std::map<uint32_t, std::map<uint32_t, Individual::Probability>> probabilities; + std::set<uint32_t> checked_probs; public: std::map<Individual*, std::unique_ptr<gui::Fish>> _fish_map; @@ -90,20 +90,20 @@ namespace gui { std::vector<float> connectivity_matrix; PPFrame processed_frame; - std::vector<idx_t> selected; + std::vector<uint32_t> selected; public: bool has_selection() const; Individual * primary_selection() const; void deselect_all(); - bool is_selected(idx_t id) const; - void do_select(idx_t id); + bool is_selected(uint32_t id) const; + void do_select(uint32_t id); - void deselect(idx_t id); - void deselect_all_select(idx_t id); + void deselect(uint32_t id); + void deselect_all_select(uint32_t id); - const std::map<uint32_t, Individual::Probability>* probs(long_t fdx); - bool has_probs(long_t fdx); + const std::map<uint32_t, Individual::Probability>* probs(uint32_t fdx); + bool has_probs(uint32_t fdx); void set_tracking_dirty(); void set_blobs_dirty(); diff --git a/Application/src/tracker/gui/IdentityHeatmap.cpp b/Application/src/tracker/gui/IdentityHeatmap.cpp index 78182bb..38943f6 100644 --- a/Application/src/tracker/gui/IdentityHeatmap.cpp +++ b/Application/src/tracker/gui/IdentityHeatmap.cpp @@ -90,7 +90,7 @@ void HeatmapController::paint_heatmap() { _image->update_with(_viridis); //_viridis.copyTo(_image->get()); _image->set_pos(Vec2()); - _image->set_scale(Vec2(smooth_heatmap_factor > 0 ? 1.0 / smooth_heatmap_factor : stride)); + _image->set_scale(Vec2(smooth_heatmap_factor > 0 ? 1.0f / smooth_heatmap_factor : stride)); push_timing("gui_heatmap", timer.elapsed()); @@ -134,7 +134,7 @@ void HeatmapController::save() { per_frame.reserve(expected); size_t count_frames = 0; - size_t max_frames = Tracker::end_frame() - Tracker::start_frame(); + size_t max_frames = sign_cast<size_t>(Tracker::end_frame() - Tracker::start_frame()); size_t print_step = max_frames / 10 + 1; std::vector<long_t> frames; for(long_t frame = Tracker::start_frame(); frame <= Tracker::end_frame(); ++frame) { @@ -170,7 +170,7 @@ void HeatmapController::sort_data_into_custom_grid() { static Timer timer; timer.reset(); - Float2_t minimum = 0, maximum = 0; + double minimum = 0, maximum = 0; std::vector<double> values; std::fill(_array_samples.begin(), _array_samples.end(), _normalization == normalization_t::cell ? 1 : 0); std::fill(_array_grid.begin(), _array_grid.end(), 0); @@ -335,12 +335,27 @@ void HeatmapController::sort_data_into_custom_grid() { else mat.setTo(empty); - Float2_t percentage; + double percentage; auto ML = maximum - minimum; if(ML == 0) ML = 1; - for (uint32_t x = 0; x < N; ++x) { + auto samples = _array_samples.data(); + auto grid_values = _array_grid.data(); + + static_assert(sizeof(Color) == sizeof(cv::Vec4b), "sizeof(Color) and cv::Vec4b are assumed to be equal."); + for (auto ptr = (Color*)grid_image->data(), to = ptr + grid_image->cols * grid_image->rows; ptr != to; ++ptr, ++samples, ++grid_values) + { + if(*samples > 0) { + percentage = (*grid_values / *samples - minimum) / ML; + if(_normalization == normalization_t::variance) + percentage = 1 - percentage; + + *ptr = Viridis::value(percentage).alpha(uint8_t(percentage * 200)); + } + } + + /*for (uint32_t x = 0; x < N; ++x) { for (uint32_t y = 0; y < N; ++y) { size_t i = y * N + x; if(_array_samples[i] > 0) { @@ -350,8 +365,7 @@ void HeatmapController::sort_data_into_custom_grid() { mat.at<cv::Vec4b>(y, x) = Viridis::value(percentage).alpha(uint8_t(percentage * 200)); } } - } - + }*/ //tf::imshow("Viridis", mat); push_timing("sort_data_into_custom_grid", timer.elapsed()); @@ -410,7 +424,7 @@ HeatmapController::UpdatedStats HeatmapController::update_data(long_t current_fr if(!updated.add_range.empty()) { data.clear(); - data.reserve(frame_range * 2 * max(1, FAST_SETTINGS(track_max_individuals))); + data.reserve(frame_range * 2u * max(1u, FAST_SETTINGS(track_max_individuals))); Individual::segment_map::const_iterator kit; auto &range = updated.add_range; diff --git a/Application/src/tracker/gui/InfoCard.cpp b/Application/src/tracker/gui/InfoCard.cpp index 0d4d2a8..1ef7300 100644 --- a/Application/src/tracker/gui/InfoCard.cpp +++ b/Application/src/tracker/gui/InfoCard.cpp @@ -40,11 +40,11 @@ void InfoCard::update() { else if(clr.b < 80) clr = clr + clr * ((80 - clr.b) / 80.f); //auto layout = std::make_shared<VerticalLayout>(Vec2(10, 10)); - advance(new Text(_fish->identity().name(), Vec2(11,11), White.alpha(clr.a * 0.7), Font(0.9, Style::Bold))); - auto text = advance(new Text(_fish->identity().name(), Vec2(10, 10), clr, Font(0.9, Style::Bold))); + advance(new Text(_fish->identity().name(), Vec2(11,11), White.alpha(clr.a * 0.7f), Font(0.9f, Style::Bold))); + auto text = advance(new Text(_fish->identity().name(), Vec2(10, 10), clr, Font(0.9f, Style::Bold))); if(!_fish->has(_frameNr)) { - advance(new Text(" (inactive)", text->pos() + Vec2(text->width(), 0), Gray.alpha(clr.a), Font(0.9, Style::Bold))); + advance(new Text(" (inactive)", text->pos() + Vec2(text->width(), 0), Gray.alpha(clr.a), Font(0.9f, Style::Bold))); } auto segments = _fish->frame_segments(); @@ -54,7 +54,7 @@ void InfoCard::update() { ,fish #endif ](const auto& segments, float offx) { - auto text = advance(new Text(Meta::toStr(segments.size())+" segments", txt->pos() + Vec2(offx, Base::default_line_spacing(txt->font())), White, Font(0.8))); + auto text = advance(new Text(Meta::toStr(segments.size())+" segments", txt->pos() + Vec2(offx, Base::default_line_spacing(txt->font())), White, Font(0.8f))); #if DEBUG_ORIENTATION auto reason = fish->why_orientation(frameNr); @@ -102,12 +102,12 @@ void InfoCard::update() { for (; it != segments.end() && cmn::abs(std::distance(it0, it)) < 5; ++it, ++i) { auto str = std::to_string(range_of(it).start())+"-"+std::to_string(range_of(it).end()); - auto p = Vec2(width() - 10 + offx, float(height() - 40) * 0.5 + ((i - 2) + 1) * (float)Base::default_line_spacing(Font(1.1))); - text = advance(new Text(str, p, White.alpha(25 + 230 * (1 - cmn::abs(i-2) / 5.0)), Font(0.8), Vec2(1), Vec2(1, 0.5))); + auto p = Vec2(width() - 10 + offx, float(height() - 40) * 0.5f + ((i - 2) + 1) * (float)Base::default_line_spacing(Font(1.1f))); + text = advance(new Text(str, p, White.alpha(25 + 230 * (1 - cmn::abs(i-2) / 5.0f)), Font(0.8f), Vec2(1), Vec2(1, 0.5f))); if(range_of(*it).start() == current_segment) { bool inside = range_of(*it).contains(_frameNr); - auto offy = - (inside ? 0.f : (Base::default_line_spacing(Font(1.1))*0.5)); + auto offy = - (inside ? 0.f : (Base::default_line_spacing(Font(1.1f))*0.5f)); advance(new Line(Vec2(10+offx, p.y + offy), Vec2(text->pos().x - text->width() - 10, p.y + offy), inside ? White : White.alpha(125))); } } @@ -174,7 +174,7 @@ void InfoCard::update() { advance_wrap(*next); advance_wrap(*prev); - float y = Base::default_line_spacing(Font(1.1)) * 8 + 40; + float y = Base::default_line_spacing(Font(1.1f)) * 8 + 40; bool fish_has_frame = _fish->has(_frameNr); if(!fish_has_frame) bg = Color(100, 100, 100, 125); @@ -191,7 +191,7 @@ void InfoCard::update() { float max_w = 200; auto rect = advance(new Rect(tmp, bg.alpha(detail ? 50 : bg.a))); - auto text = advance(new Text("matching", Vec2(10, y), White, Font(0.8, Style::Bold))); + auto text = advance(new Text("matching", Vec2(10, y), White, Font(0.8f, Style::Bold))); if(!detail_button->parent()) { detail_button->set_toggleable(true); @@ -203,7 +203,7 @@ void InfoCard::update() { }); } - detail_button->set_pos(Vec2(text->width() + text->pos().x + 15, y + (text->height() - detail_button->height()) * 0.5)); + detail_button->set_pos(Vec2(text->width() + text->pos().x + 15, y + (text->height() - detail_button->height()) * 0.5f)); advance_wrap(*detail_button); if(detail_button->pos().x + detail_button->width() + 10 > max_w) @@ -211,7 +211,7 @@ void InfoCard::update() { if(_fish->is_automatic_match(_frameNr)) { y += text->height(); - text = advance(new Text("(automatic match)", Vec2(10, y), White.alpha(150), Font(0.8, Style::Italic))); + text = advance(new Text("(automatic match)", Vec2(10, y), White.alpha(150), Font(0.8f, Style::Italic))); y += text->height(); if(!automatic_button) { @@ -240,7 +240,7 @@ void InfoCard::update() { y += text->height(); std::string speed_str = Meta::toStr(cache.processed_frame.cached_individuals.at(fdx).speed) + "cm/s"; - y += advance(new Text(speed_str, Vec2(10, y), White.alpha(125), Font(0.8)))->height(); + y += advance(new Text(speed_str, Vec2(10, y), White.alpha(125), Font(0.8f)))->height(); track::Match::prob_t max_prob = 0; int64_t bdx = -1; @@ -268,8 +268,8 @@ void InfoCard::update() { if(detail) probs_str += " (p:"+Meta::toStr(probs.p_pos)+" a:"+Meta::toStr(probs.p_angle)+" s:"+Meta::toStr(probs.p_pos / probs.p_angle)+" t:"+Meta::toStr(probs.p_time)+")"; - auto text = advance(new Text(Meta::toStr(blob->blob_id())+": ", Vec2(10, y), White, Font(0.8))); - auto second = advance(new Text(probs_str, text->pos() + Vec2(text->width(), 0), color, Font(0.8))); + auto text = advance(new Text(Meta::toStr(blob->blob_id())+": ", Vec2(10, y), White, Font(0.8f))); + auto second = advance(new Text(probs_str, text->pos() + Vec2(text->width(), 0), color, Font(0.8f))); y += text->height(); auto w = second->pos().x + second->width() + 10; @@ -313,11 +313,11 @@ void InfoCard::update() { p_sum = max(p_sum, value); float max_w = 200; - auto text = advance(new Text(title, Vec2(10, y), White, Font(0.8, Style::Bold))); + auto text = advance(new Text(title, Vec2(10, y), White, Font(0.8f, Style::Bold))); y += text->height(); max_w = max(max_w, 10 + text->width() + text->pos().x); - text = advance(new Text(Meta::toStr(segment), Vec2(10, y), Color(220,220,220,255), Font(0.8, Style::Italic))); + text = advance(new Text(Meta::toStr(segment), Vec2(10, y), Color(220,220,220,255), Font(0.8f, Style::Italic))); y += text->height(); max_w = max(max_w, 10 + text->width() + text->pos().x); @@ -346,7 +346,7 @@ void InfoCard::update() { std::string str = Meta::toStr(fdx) + ": " + Meta::toStr(p); Color color = White * (1 - p/p_sum) + Red * (p / p_sum); - auto text = advance(new Text(str, current_pos, color, Font(0.8))); + auto text = advance(new Text(str, current_pos, color, Font(0.8f))); auto w = text->pos().x + text->width() + 10; if(w > max_w) @@ -403,7 +403,7 @@ void InfoCard::update() { } set_origin(Vec2(0, 0)); - set_bounds(Bounds((10) / base.scale().x, 100 / base.scale().y, 200, Base::default_line_spacing(Font(1.1)) * 7 + 60)); + set_bounds(Bounds((10) / base.scale().x, 100 / base.scale().y, 200, Base::default_line_spacing(Font(1.1f)) * 7 + 60)); set_scale(base.scale().reciprocal()); } } diff --git a/Application/src/tracker/gui/RecognitionSummary.cpp b/Application/src/tracker/gui/RecognitionSummary.cpp index f26a190..24cbcbc 100644 --- a/Application/src/tracker/gui/RecognitionSummary.cpp +++ b/Application/src/tracker/gui/RecognitionSummary.cpp @@ -11,13 +11,13 @@ namespace gui { const float interface_scale = GUI_SETTINGS(gui_interface_scale); - Font title_font(0.9 / interface_scale, Style::Bold, Align::Center); - Font font(0.8 / interface_scale); - Font side_font(0.8 / interface_scale, Align::Right); - Font bottom_font(0.8 / interface_scale, Align::Center); + Font title_font(0.9f / interface_scale, Style::Bold, Align::Center); + Font font(0.8f / interface_scale); + Font side_font(0.8f / interface_scale, Align::Right); + Font bottom_font(0.8f / interface_scale, Align::Center); auto manual_identities = FAST_SETTINGS(manual_identities); - std::set<idx_t> sorted(manual_identities.begin(), manual_identities.end()); + std::set<uint32_t> sorted(manual_identities.begin(), manual_identities.end()); for(auto id : manual_identities) { if(cache.individuals.find(id) == cache.individuals.end()) sorted.erase(id); @@ -27,7 +27,7 @@ namespace gui { obj.set_scale(base.scale().reciprocal().mul(interface_scale)); const float margin = 5 / interface_scale, - bar_width = 80 / (interface_scale * 1.25), + bar_width = 80 / (interface_scale * 1.25f), title_height = Base::default_line_spacing(title_font) + margin; float sidebar_width = 0; @@ -39,14 +39,14 @@ namespace gui { sidebar_width += 3 * margin; obj.set_origin(Vec2(0.5)); - obj.set_bounds(Bounds(Vec2(Tracker::average().cols, Tracker::average().rows) * 0.5, - Size2(sidebar_width * 1.5, Base::default_line_spacing(font) + margin + title_height) + Size2(margin * 2) + bar_width * Size2(output_size, sorted.size()))); + obj.set_bounds(Bounds(Vec2(Tracker::average().cols, Tracker::average().rows) * 0.5f, + Size2(sidebar_width * 1.5f, Base::default_line_spacing(font) + margin + title_height) + Size2(margin * 2) + bar_width * Size2(output_size, sorted.size()))); obj.set_background(Black.alpha(150)); if(!cache.recognition_updated) { obj.update([&] (Entangled& base) { std::vector<float> outputs; - base.advance(new Text("recognition summary", Vec2(obj.width() * 0.5, margin + (title_height - margin) * 0.5), White, title_font)); + base.advance(new Text("recognition summary", Vec2(obj.width() * 0.5f, margin + (title_height - margin) * 0.5f), White, title_font)); size_t counter = 0, j = 0; std::map<long_t, size_t> fdx_to_idx; @@ -101,7 +101,7 @@ namespace gui { base.advance(new Rect(bounds, Transparent, White.alpha(200))); // draw vertical bar (active fish) - pos = Vec2(margin) + Vec2(sidebar_width - 10 / interface_scale, bar_width * 0.5 - Base::default_line_spacing(font) * 0.5 + title_height); + pos = Vec2(margin) + Vec2(sidebar_width - 10 / interface_scale, bar_width * 0.5f - Base::default_line_spacing(font) * 0.5f + title_height); size_t row = 0; for(auto id : sorted) { @@ -111,7 +111,7 @@ namespace gui { } // draw horizontal bar (matched fish from network) - pos = Vec2(margin) + Vec2(sidebar_width + bar_width * 0.5, bounds.height + margin + Base::default_line_spacing(font) * 0.5 + title_height); + pos = Vec2(margin) + Vec2(sidebar_width + bar_width * 0.5f, bounds.height + margin + Base::default_line_spacing(font) * 0.5f + title_height); for(size_t idx = 0; idx < output_size; ++idx) { base.advance(new Text(Meta::toStr(idx), pos, White, bottom_font)); pos += Vec2(bar_width, 0); diff --git a/Application/src/tracker/gui/Timeline.h b/Application/src/tracker/gui/Timeline.h index 415d637..6d11eec 100644 --- a/Application/src/tracker/gui/Timeline.h +++ b/Application/src/tracker/gui/Timeline.h @@ -26,7 +26,7 @@ namespace gui { float mx, my; size_t small_count; - track::idx_t current_count; + uint32_t current_count; size_t big_count; size_t up_to_this_frame; diff --git a/Application/src/tracker/gui/gui.cpp b/Application/src/tracker/gui/gui.cpp index e8ec323..2d4f86e 100644 --- a/Application/src/tracker/gui/gui.cpp +++ b/Application/src/tracker/gui/gui.cpp @@ -2255,7 +2255,7 @@ void GUI::draw_tracking(DrawStructure& base, long_t frameNr, bool draw_graph) { if(SETTING(gui_show_uniqueness)) { static Graph graph(Bounds(50, 100, 800, 400), "uniqueness"); static std::mutex mutex; - static std::map<long_t, float> estimated_uniqueness; + static std::map<uint32_t, float> estimated_uniqueness; static std::vector<Vec2> uniquenesses; static bool running = false; @@ -3928,7 +3928,7 @@ void GUI::key_event(const gui::Event &event) { if(key.code >= Codes::Num0 && key.code <= Codes::Num9) { std::lock_guard<std::recursive_mutex> lock(_gui.lock()); Identity id(int(key.code - Codes::Num0)); - SETTING(gui_focus_group) = std::vector<idx_t>{id.ID()}; + SETTING(gui_focus_group) = std::vector<uint32_t>{id.ID()}; set_redraw(); return; } @@ -4109,7 +4109,7 @@ void GUI::key_event(const gui::Event &event) { } else break; - SETTING(gui_focus_group) = std::vector<idx_t>{id.ID()}; + SETTING(gui_focus_group) = std::vector<uint32_t>{id.ID()}; break; } @@ -4134,7 +4134,7 @@ void GUI::key_event(const gui::Event &event) { } else break; - SETTING(gui_focus_group) = std::vector<idx_t>{id.ID()}; + SETTING(gui_focus_group) = std::vector<uint32_t>{id.ID()}; break; } diff --git a/Application/src/tracker/main.cpp b/Application/src/tracker/main.cpp index 33ec9d3..1ce40a2 100644 --- a/Application/src/tracker/main.cpp +++ b/Application/src/tracker/main.cpp @@ -925,7 +925,7 @@ int main(int argc, char** argv) if(SETTING(auto_number_individuals).value<bool>() == default_map.get<bool>("auto_number_individuals").value()) { - SETTING(auto_number_individuals) = SETTING(track_max_individuals).value<idx_t>() == default_map.get<idx_t>("track_max_individuals").value(); + SETTING(auto_number_individuals) = SETTING(track_max_individuals).value<uint32_t>() == default_map.get<uint32_t>("track_max_individuals").value(); } if(SETTING(auto_minmax_size).value<bool>() == default_map.get<bool>("auto_minmax_size").value()) @@ -936,10 +936,10 @@ int main(int argc, char** argv) Tracker::auto_calculate_parameters(video); - if(SETTING(manual_identities).value<std::set<idx_t>>().empty() && SETTING(track_max_individuals).value<idx_t>() != 0) + if(SETTING(manual_identities).value<std::set<uint32_t>>().empty() && SETTING(track_max_individuals).value<uint32_t>() != 0) { - std::set<idx_t> vector; - for(idx_t i=0; i<SETTING(track_max_individuals).value<idx_t>(); ++i) { + std::set<uint32_t> vector; + for(uint32_t i=0; i<SETTING(track_max_individuals).value<uint32_t>(); ++i) { vector.insert(i); } SETTING(manual_identities) = vector; diff --git a/Application/src/tracker/misc/Output.cpp b/Application/src/tracker/misc/Output.cpp index 500b9a6..fc09645 100644 --- a/Application/src/tracker/misc/Output.cpp +++ b/Application/src/tracker/misc/Output.cpp @@ -322,7 +322,7 @@ Individual* Output::ResultsFormat::read_individual(cmn::Data &ref, const CacheHi ID = (uint32_t)sid; } - Individual *fish = new Individual(narrow_cast<long_t>(ID)); + Individual *fish = new Individual(ID); if(_header.version <= Output::ResultsFormat::Versions::V_15) { ref.seek(ref.tell() + sizeof(data_long_t) * 2); @@ -341,10 +341,10 @@ Individual* Output::ResultsFormat::read_individual(cmn::Data &ref, const CacheHi std::string name; ref.read<std::string>(name); - Identity id((long_t)ID); + Identity id(ID); if(name != id.raw_name() && !name.empty()) { auto map = FAST_SETTINGS(individual_names); - map[(long_t)ID] = name; + map[ID] = name; SETTING(individual_names) = map; } } @@ -361,7 +361,7 @@ Individual* Output::ResultsFormat::read_individual(cmn::Data &ref, const CacheHi } } - fish->identity().set_ID((long_t)ID); + fish->identity().set_ID(ID); //PhysicalProperties *prev = NULL; //PhysicalProperties *prev_weighted = NULL; @@ -1185,7 +1185,7 @@ void TrackingResults::update_fois(const std::function<void(const std::string&, f prev_props = nullptr; _tracker.update_consecutive(active, props.frame, false); - _tracker.update_warnings(props.frame, props.time, number_fish, (long_t)n, (long_t)prev, &props, prev_props, active, iterator_map); + _tracker.update_warnings(props.frame, props.time, (long_t)number_fish, n, prev, &props, prev_props, active, iterator_map); prev = n; prev_props = &props; @@ -1310,7 +1310,7 @@ void TrackingResults::update_fois(const std::function<void(const std::string&, f file._property_cache->push(prop.frame, &prop); // read the individuals - std::map<long_t, Individual*> map_id_ptr; + std::map<uint32_t, Individual*> map_id_ptr; std::vector<Individual*> fishes; file.read<uint64_t>(L); @@ -1338,7 +1338,7 @@ void TrackingResults::update_fois(const std::function<void(const std::string&, f if(biggest_id < fish->identity().ID()) biggest_id = fish->identity().ID(); map_id_ptr[fish->identity().ID()] = fish; - _tracker._individuals[fish->identity().ID()] = fish; + _tracker._individuals[(long_t)fish->identity().ID()] = fish; } } @@ -1359,7 +1359,7 @@ void TrackingResults::update_fois(const std::function<void(const std::string&, f if(check_analysis_range && (frameIndex > analysis_range.end || frameIndex < analysis_range.start)) continue; - auto it = map_id_ptr.find((long_t)ID); + auto it = map_id_ptr.find(ID); if (it == map_id_ptr.end()) U_EXCEPTION("Cannot find individual with ID %ld in map.", ID); active.insert(it->second); @@ -1429,9 +1429,9 @@ void TrackingResults::update_fois(const std::function<void(const std::string&, f } if(config.has("gui_focus_group")) { - SETTING(gui_focus_group) = config["gui_focus_group"].value<std::vector<idx_t>>(); + SETTING(gui_focus_group) = config["gui_focus_group"].value<std::vector<uint32_t>>(); } else - SETTING(gui_focus_group) = std::vector<idx_t>{}; + SETTING(gui_focus_group) = std::vector<uint32_t>{}; SETTING(gui_frame).value<long_t>() = (long_t)file.header().gui_frame; } diff --git a/Application/src/tracker/misc/default_config.cpp b/Application/src/tracker/misc/default_config.cpp index 716a925..89db6d1 100644 --- a/Application/src/tracker/misc/default_config.cpp +++ b/Application/src/tracker/misc/default_config.cpp @@ -353,7 +353,7 @@ file::Path conda_environment_path() { CONFIG("gui_single_identity_color", gui::Transparent, "If set to something else than transparent, all individuals will be displayed with this color."); CONFIG("gui_zoom_limit", Size2(300, 300), ""); CONFIG("gui_recording_format", gui_recording_format_t::avi, "Sets the format for recording mode (when R is pressed in the GUI). Supported formats are 'avi', 'jpg' and 'png'. JPEGs have 75%% compression, AVI is using MJPEG compression."); - CONFIG("individual_names", std::map<idx_t, std::string>{}, "A map of {individual-id: \"individual-name\", ...} that names individuals in the GUI and exported data."); + CONFIG("individual_names", std::map<uint32_t, std::string>{}, "A map of {individual-id: \"individual-name\", ...} that names individuals in the GUI and exported data."); CONFIG("individual_prefix", std::string("fish"), "The prefix that is added to all the files containing certain IDs. So individual 0 will turn into '[prefix]0' for all the npz files and within the program."); CONFIG("outline_approximate", uint8_t(3), "If this is a number > 0, the outline detected from the image will be passed through an elliptical fourier transform with `outline_approximate` number of coefficients. When the given number is sufficiently low, the outline will be smoothed significantly (and more so for lower numbers of coefficients)."); CONFIG("outline_smooth_step", uint8_t(1), "Jump over N outline points when smoothing (reducing accuracy)."); @@ -376,7 +376,7 @@ file::Path conda_environment_path() { CONFIG("matching_probability_threshold", float(0.1), "The probability below which a possible connection between blob and identity is considered too low. The probability depends largely upon settings like `track_max_speed`."); CONFIG("track_do_history_split", true, "If disabled, blobs will not be split automatically in order to separate overlapping individuals. This usually happens based on their history."); CONFIG("track_end_segment_for_speed", true, "Sometimes individuals might be assigned to blobs that are far away from the previous position. This could indicate wrong assignments, but not necessarily. If this variable is set to true, consecutive frame segments will end whenever high speeds are reached, just to be on the safe side. For scenarios with lots of individuals (and no recognition) this might spam yellow bars in the timeline and may be disabled."); - CONFIG("track_max_individuals", idx_t(0), "The maximal number of individual that are assigned at the same time (infinite if set to zero). If the given number is below the actual number of individual, then only a (random) subset of individual are assigned and a warning is shown."); + CONFIG("track_max_individuals", uint32_t(0), "The maximal number of individual that are assigned at the same time (infinite if set to zero). If the given number is below the actual number of individual, then only a (random) subset of individual are assigned and a warning is shown."); CONFIG("blob_size_ranges", BlobSizeRange({Rangef(0.1f, 3)}), "Blobs below the lower bound are recognized as noise instead of individuals. Blobs bigger than the upper bound are considered to potentially contain more than one individual. The unit is #pixels * (`meta_real_width` / video_width)."); CONFIG("blob_split_max_shrink", float(0.2), "The minimum percentage of the starting blob size (after thresholding), that a blob is allowed to be reduced to during splitting. If this value is set too low, the program might start recognizing parts of individual as other individual too quickly."); CONFIG("blob_split_global_shrink_limit", float(0.2), "The minimum percentage of the minimum in `blob_size_ranges`, that a blob is allowed to be reduced to during splitting. If this value is set too low, the program might start recognizing parts of individual as other individual too quickly."); @@ -399,7 +399,7 @@ file::Path conda_environment_path() { CONFIG("enable_absolute_difference", true, "If set to true, the threshold values will be applied to abs(image - background). Otherwise max(0, image - background)."); CONFIG("track_time_probability_enabled", bool(true), ""); CONFIG("track_max_reassign_time", float(0.5), "Distance in time (seconds) where the matcher will stop trying to reassign an individual based on previous position. After this time runs out, depending on the settings, the tracker will try to find it based on other criteria, or generate a new individual."); - CONFIG("manual_identities", std::set<idx_t>{}, "", SYSTEM); + CONFIG("manual_identities", std::set<uint32_t>{}, "", SYSTEM); CONFIG("pixel_grid_cells", size_t(25), ""); CONFIG("web_quality", int(75), "JPEG quality of images transferred over the web interface."); @@ -538,7 +538,7 @@ file::Path conda_environment_path() { CONFIG("terminate_training", bool(false), "Setting this to true aborts the training in progress."); CONFIG("manually_approved", std::map<long_t,long_t>(), "A list of ranges of manually approved frames that may be used for generating training datasets {232:232,5555:5560}."); - CONFIG("gui_focus_group", std::vector<idx_t>(), "Focus on this group of individuals."); + CONFIG("gui_focus_group", std::vector<uint32_t>(), "Focus on this group of individuals."); CONFIG("track_ignore", std::vector<std::vector<Vec2>>(), "If this is not empty, objects within the given rectangles or polygons (>= 3 points) [[x0,y0],[x1,y1](, ...)], ...] will be ignored during tracking."); CONFIG("track_include", std::vector<std::vector<Vec2>>(), "If this is not empty, objects within the given rectangles or polygons (>= 3 points) [[x0,y0],[x1,y1](, ...)], ...] will be the only objects being tracked. (overwrites `track_ignore`)"); @@ -649,7 +649,7 @@ file::Path conda_environment_path() { if(GUI::instance() && SETTING(frame_rate).value<int>() == GUI::instance()->video_source()->framerate()) exclude_fields.push_back("frame_rate"); - if((track::idx_t)FAST_SETTINGS(manual_identities).size() == FAST_SETTINGS(track_max_individuals)) + if((uint32_t)FAST_SETTINGS(manual_identities).size() == FAST_SETTINGS(track_max_individuals)) exclude_fields.push_back("manual_identities"); /** diff --git a/Application/src/tracker/tracking/Accumulation.cpp b/Application/src/tracker/tracking/Accumulation.cpp index 04c94da..5bd8295 100644 --- a/Application/src/tracker/tracking/Accumulation.cpp +++ b/Application/src/tracker/tracking/Accumulation.cpp @@ -468,7 +468,7 @@ std::tuple<std::shared_ptr<TrainingData>, std::vector<Image::Ptr>, std::map<long return {data, disc_images, disc_frame_map}; } -std::tuple<float, std::map<long_t, float>, float> Accumulation::calculate_uniqueness(bool internal, const std::vector<Image::Ptr>& images, const std::map<long_t, Range<size_t>>& map_indexes) +std::tuple<float, std::map<uint32_t, float>, float> Accumulation::calculate_uniqueness(bool internal, const std::vector<Image::Ptr>& images, const std::map<long_t, Range<size_t>>& map_indexes) { std::vector<std::vector<float>> predictions; if(internal) { @@ -513,18 +513,18 @@ std::tuple<float, std::map<long_t, float>, float> Accumulation::calculate_unique size_t good_frames = 0; size_t bad_frames = 0; double percentages = 0, rpercentages = 0; - std::map<long_t, float> unique_percent; - std::map<long_t, float> unique_percent_raw; + std::map<uint32_t, float> unique_percent; + std::map<uint32_t, float> unique_percent_raw; - std::map<long_t, float> unique_percent_per_identity; - std::map<long_t, float> per_identity_samples; + std::map<uint32_t, float> unique_percent_per_identity; + std::map<uint32_t, float> per_identity_samples; for(auto && [frame, range] : map_indexes) { - std::set<long_t> unique_ids; - std::map<long_t, float> probs; + std::set<uint32_t> unique_ids; + std::map<uint32_t, float> probs; for (auto i = range.start; i < range.end; ++i) { - long_t max_id = -1; + int64_t max_id = -1; float max_p = 0; if(predictions.at(i).size() < FAST_SETTINGS(manual_identities).size()) { @@ -541,8 +541,8 @@ std::tuple<float, std::map<long_t, float>, float> Accumulation::calculate_unique } if(max_id != -1) { - unique_ids.insert(max_id); - probs[max_id] = max(probs[max_id], max_p); + unique_ids.insert((uint32_t)max_id); + probs[(uint32_t)max_id] = max(probs[(uint32_t)max_id], max_p); } } @@ -598,7 +598,7 @@ std::tuple<float, std::map<long_t, float>, float> Accumulation::calculate_unique } float Accumulation::good_uniqueness() { - return (float(FAST_SETTINGS(manual_identities).size()) - 0.5) / float(FAST_SETTINGS(manual_identities).size()); + return (float(FAST_SETTINGS(manual_identities).size()) - 0.5f) / float(FAST_SETTINGS(manual_identities).size()); } Accumulation::Accumulation(TrainingMode::Class mode) : _mode(mode), _accumulation_step(0), _counted_steps(0), _last_step(1337) { diff --git a/Application/src/tracker/tracking/Accumulation.h b/Application/src/tracker/tracking/Accumulation.h index f311f78..215cdfe 100644 --- a/Application/src/tracker/tracking/Accumulation.h +++ b/Application/src/tracker/tracking/Accumulation.h @@ -47,7 +47,7 @@ class Accumulation { std::vector<Image::Ptr> _disc_images; std::map<long_t, Range<size_t>> _disc_frame_map; std::vector<long_t> _checked_ranges_output; - std::map<long_t, float> unique_map, temp_unique; + std::map<uint32_t, float> unique_map, temp_unique; std::map<Rangel, std::tuple<double, FrameRange>> assigned_unique_averages; size_t _accumulation_step; size_t _counted_steps, _last_step; @@ -89,7 +89,7 @@ public: void confirm_weights(); void update_coverage(const TrainingData& data); - static std::tuple<float, std::map<long_t, float>, float> calculate_uniqueness(bool internal, const std::vector<Image::Ptr>&, const std::map<long_t, Range<size_t>>&); + static std::tuple<float, std::map<uint32_t, float>, float> calculate_uniqueness(bool internal, const std::vector<Image::Ptr>&, const std::map<long_t, Range<size_t>>&); static std::tuple<std::shared_ptr<TrainingData>, std::vector<Image::Ptr>, std::map<long_t, Range<size_t>>> generate_discrimination_data(const std::shared_ptr<TrainingData>& source = nullptr); static void setup(); static void unsetup(); diff --git a/Application/src/tracker/tracking/FOI.h b/Application/src/tracker/tracking/FOI.h index 6c06c8f..5608c93 100644 --- a/Application/src/tracker/tracking/FOI.h +++ b/Application/src/tracker/tracking/FOI.h @@ -14,8 +14,8 @@ namespace track { }; struct fdx_t { - idx_t id; - explicit fdx_t(idx_t i) : id(i) {} + uint32_t id; + explicit fdx_t(uint32_t i) : id(i) {} bool operator <(const fdx_t& other) const { return id < other.id; } @@ -32,8 +32,8 @@ namespace track { }; struct bdx_t { - long_t id; - explicit bdx_t(long_t i) : id(i) {} + uint32_t id; + explicit bdx_t(uint32_t i) : id(i) {} bool operator <(bdx_t other) const { return id < other.id; } diff --git a/Application/src/tracker/tracking/Individual.cpp b/Application/src/tracker/tracking/Individual.cpp index c0d24f1..6718570 100644 --- a/Application/src/tracker/tracking/Individual.cpp +++ b/Application/src/tracker/tracking/Individual.cpp @@ -26,15 +26,15 @@ using prob_t = track::Match::prob_t; PPFrame::PPFrame() : blob_grid(Tracker::average().bounds().size()) {} -std::atomic<idx_t> RUNNING_ID(0); +std::atomic<uint32_t> RUNNING_ID(0); -void Identity::set_running_id(idx_t value) { RUNNING_ID = value; } -idx_t Identity::running_id() { return RUNNING_ID; } +void Identity::set_running_id(uint32_t value) { RUNNING_ID = value; } +uint32_t Identity::running_id() { return RUNNING_ID; } -Identity::Identity(idx_t myID) - : _color(myID != -1 ? ColorWheel(myID).next() : ColorWheel(RUNNING_ID+1).next()), _myID(myID != -1 ? myID : (++RUNNING_ID)), _name(Meta::toStr(_myID)) +Identity::Identity(uint32_t myID) + : _color(myID != InvalidID ? ColorWheel(myID).next() : ColorWheel(RUNNING_ID).next()), _myID(myID != InvalidID ? myID : (RUNNING_ID++)), _name(Meta::toStr(_myID)) { - if(myID != -1 && RUNNING_ID < myID) { + if(myID != InvalidID && RUNNING_ID < myID) { RUNNING_ID = myID + 1; } } @@ -439,7 +439,8 @@ MinimalOutline::Ptr Individual::outline(long_t frameIndex) const { return ptr ? ptr->outline : nullptr; } -Individual::Individual(long_t id) : _identity(id), _last_posture_added(-1), _startFrame(-1), _endFrame(-1) +Individual::Individual(Identity&& id) + : _identity(std::move(id)) { if(FAST_SETTINGS(manual_identities).count(identity().ID())) identity().set_manual(true); diff --git a/Application/src/tracker/tracking/Individual.h b/Application/src/tracker/tracking/Individual.h index 54b1201..ffc087c 100644 --- a/Application/src/tracker/tracking/Individual.h +++ b/Application/src/tracker/tracking/Individual.h @@ -92,7 +92,7 @@ namespace track { std::vector<std::shared_ptr<pv::Blob>> blobs, original_blobs; std::vector<std::shared_ptr<pv::Blob>> filtered_out; - std::map<idx_t, IndividualCache> cached_individuals; + std::map<uint32_t, IndividualCache> cached_individuals; std::map<uint32_t, std::set<long_t>> blob_cliques, fish_cliques; std::set<uint32_t> split_blobs; std::map<uint32_t, pv::BlobPtr> bdx_to_ptr; @@ -113,17 +113,25 @@ namespace track { }; class Identity { + public: + static constexpr auto InvalidID = std::numeric_limits<uint32_t>::infinity(); + + protected: GETTER_SETTER(gui::Color, color) - idx_t _myID; + uint32_t _myID; std::string _name; GETTER_SETTER(bool, manual) public: - static void set_running_id(idx_t value); - static idx_t running_id(); - Identity(idx_t myID = -1); + static void set_running_id(uint32_t value); + static uint32_t running_id(); + Identity(uint32_t myID = InvalidID); decltype(_myID) ID() const { return _myID; } - void set_ID(idx_t val) { _color = ColorWheel(val).next(); _myID = val; _name = Meta::toStr(_myID); } + void set_ID(uint32_t val) { + _color = ColorWheel(val).next(); + _myID = val; + _name = Meta::toStr(_myID); + } const std::string& raw_name(); std::string raw_name() const; std::string name() const; @@ -210,7 +218,7 @@ namespace track { protected: //! dense array of all posture related stuff we are saving GETTER(std::vector<std::shared_ptr<PostureStuff>>, posture_stuff) - long_t _last_posture_added; + long_t _last_posture_added = -1; public: struct SegmentInformation : public FrameRange { @@ -276,7 +284,7 @@ namespace track { std::map<long_t, float> _average_recognition; GETTER(size_t, average_recognition_samples) - long_t _startFrame, _endFrame; + long_t _startFrame = -1, _endFrame = -1; public: //! These data are generated in order to reduce work-load @@ -326,7 +334,7 @@ namespace track { std::set<long_t> added_postures; public: - Individual(long_t id = -1); + Individual(Identity&& id = Identity()); ~Individual(); #if DEBUG_ORIENTATION diff --git a/Application/src/tracker/tracking/Outline.h b/Application/src/tracker/tracking/Outline.h index be4a23c..63138bb 100644 --- a/Application/src/tracker/tracking/Outline.h +++ b/Application/src/tracker/tracking/Outline.h @@ -18,7 +18,7 @@ namespace track { struct DebugInfo { long_t frameIndex; - long_t fdx; + uint32_t fdx; bool debug; //Vec2 previous_position; }; diff --git a/Application/src/tracker/tracking/Posture.cpp b/Application/src/tracker/tracking/Posture.cpp index dbb6386..c5b5b74 100644 --- a/Application/src/tracker/tracking/Posture.cpp +++ b/Application/src/tracker/tracking/Posture.cpp @@ -22,7 +22,7 @@ namespace track { Vec2(-1,0) }; - Posture::Posture(long_t frameIndex, long_t fishID) + Posture::Posture(long_t frameIndex, uint32_t fishID) : _outline_points(std::make_shared<std::vector<Vec2>>()), frameIndex(frameIndex), fishID(fishID), _outline(_outline_points, frameIndex), _normalized_midline(NULL) { } diff --git a/Application/src/tracker/tracking/Posture.h b/Application/src/tracker/tracking/Posture.h index e271806..08428cd 100644 --- a/Application/src/tracker/tracking/Posture.h +++ b/Application/src/tracker/tracking/Posture.h @@ -30,12 +30,12 @@ namespace track { std::shared_ptr<std::vector<Vec2>> _outline_points; long_t frameIndex; - long_t fishID; + uint32_t fishID; GETTER(Outline, outline) GETTER_PTR(Midline::Ptr, normalized_midline) public: - Posture(long_t frameIndex, long_t fishID); + Posture(long_t frameIndex, uint32_t fishID); ~Posture() { } diff --git a/Application/src/tracker/tracking/Tracker.cpp b/Application/src/tracker/tracking/Tracker.cpp index 755eca8..bce3b15 100644 --- a/Application/src/tracker/tracking/Tracker.cpp +++ b/Application/src/tracker/tracking/Tracker.cpp @@ -1926,11 +1926,11 @@ void Tracker::clear_properties() { for(auto b : frame.blobs) { id_to_blob[b->blob_id()] = b; - blob_grid.insert(b->bounds().x + b->bounds().width * 0.5, b->bounds().y + b->bounds().height * 0.5, b->blob_id()); + blob_grid.insert(b->bounds().x + b->bounds().width * 0.5f, b->bounds().y + b->bounds().height * 0.5f, b->blob_id()); } for(auto b : frame.filtered_out) { id_to_blob[b->blob_id()] = b; - blob_grid.insert(b->bounds().x + b->bounds().width * 0.5, b->bounds().y + b->bounds().height * 0.5, b->blob_id()); + blob_grid.insert(b->bounds().x + b->bounds().width * 0.5f, b->bounds().y + b->bounds().height * 0.5f, b->blob_id()); } // see if there are manually fixed matches for this frame @@ -2240,7 +2240,7 @@ void Tracker::clear_properties() { // create correct identities //assert(_individuals.empty()); - idx_t max_id = Identity::running_id(); + uint32_t max_id = Identity::running_id(); for (auto m : manual_identities) { if(_individuals.find(m) == _individuals.end()) { @@ -3224,7 +3224,7 @@ void Tracker::update_iterator_maps(long_t frame, const Tracker::set_of_individua } void Tracker::update_consecutive(const Tracker::set_of_individuals_t &active, long_t frameIndex, bool update_dataset) { - bool all_good = FAST_SETTINGS(track_max_individuals) == (track::idx_t)active.size(); + bool all_good = FAST_SETTINGS(track_max_individuals) == (uint32_t)active.size(); //bool manual = false; /*Rangel manual_approval; @@ -3617,7 +3617,7 @@ void Tracker::update_iterator_maps(long_t frame, const Tracker::set_of_individua while (recognition_pool.queue_length() && count < _individuals.size()) { recognition_pool.wait_one(); - callback(count / float(_individuals.size()) * 0.5); + callback(count / float(_individuals.size()) * 0.5f); ++count; } @@ -3654,10 +3654,10 @@ void Tracker::update_iterator_maps(long_t frame, const Tracker::set_of_individua }; static const auto sigmoid = [](Match::prob_t x) { - return 1.f/(1.f + expf((0.5f-x)*2.f*M_PI)); + return 1.f/(1.f + expf((0.5f-x)*2.f*float(M_PI))); }; - const size_t n_lower_bound = max(5, FAST_SETTINGS(frame_rate) * 0.1); + const size_t n_lower_bound = max(5, FAST_SETTINGS(frame_rate) * 0.1f); // iterate through segments, find matches for segments. // try to find the longest segments and assign them to virtual fish @@ -4239,7 +4239,7 @@ pv::BlobPtr Tracker::find_blob_noisy(std::map<uint32_t, pv::BlobPtr>& blob_to_id Median<float> blob_size; pv::Frame frame; std::multiset<float> values; - const uint32_t number_fish = (uint32_t)SETTING(track_max_individuals).value<idx_t>(); + const uint32_t number_fish = SETTING(track_max_individuals).value<uint32_t>(); std::vector<std::multiset<float>> blobs; Median<float> median; @@ -4323,7 +4323,7 @@ pv::BlobPtr Tracker::find_blob_noisy(std::map<uint32_t, pv::BlobPtr>& blob_to_id if(SETTING(auto_number_individuals).value<bool>()) { if(!quiet) Debug("Setting number of individuals as %d.", median_number); - SETTING(track_max_individuals) = track::idx_t(median_number); + SETTING(track_max_individuals) = uint32_t(median_number); } } } diff --git a/Application/src/tracker/tracking/Tracker.h b/Application/src/tracker/tracking/Tracker.h index 0433b59..58dd021 100644 --- a/Application/src/tracker/tracking/Tracker.h +++ b/Application/src/tracker/tracking/Tracker.h @@ -36,7 +36,7 @@ namespace track { using mmatches_t = std::map<long_t, std::map<idx_t, int64_t>>; using msplits_t = std::map<long_t, std::set<int64_t>>; -using inames_t = std::map<idx_t, std::string>; +using inames_t = std::map<uint32_t, std::string>; using mapproved_t = std::map<long_t,long_t>; using analrange_t = std::pair<long_t,long_t>; @@ -53,7 +53,7 @@ CREATE_STRUCT(Settings, (int, track_threshold), (int, track_threshold_2), (Rangef, threshold_ratio_range), - (idx_t, track_max_individuals), + (uint32_t, track_max_individuals), (int, track_posture_threshold), (uint8_t, outline_smooth_step), (uint8_t, outline_smooth_samples), @@ -68,7 +68,7 @@ CREATE_STRUCT(Settings, (float, matching_probability_threshold), (size_t, posture_direction_smoothing), (file::Path, tags_path), - (std::set<idx_t>, manual_identities), + (std::set<uint32_t>, manual_identities), (std::vector<Vec2>, grid_points), (std::vector<std::vector<Vec2>>, recognition_shapes), (float, grid_points_scaling), diff --git a/Application/src/tracker/tracking/TrainingData.cpp b/Application/src/tracker/tracking/TrainingData.cpp index f25cfd3..8d758d5 100644 --- a/Application/src/tracker/tracking/TrainingData.cpp +++ b/Application/src/tracker/tracking/TrainingData.cpp @@ -237,11 +237,11 @@ void TrainingData::apply_mapping(const std::map<long_t, long_t>& mapping) { } } -void TrainingData::set_classes(const std::set<long_t>& classes) { +void TrainingData::set_classes(const std::set<uint32_t>& classes) { _all_classes = classes; } -std::unique_ptr<Image> TrainingData::draw_coverage(const std::map<long_t, float>& unique_percentages, const std::vector<Rangel>& next_ranges, const std::vector<Rangel>& added_ranges, const std::map<long_t, float>& uniquenesses_temp, std::shared_ptr<TrainingData::DataRange> current_salt, const std::map<Rangel, std::tuple<double, FrameRange>>& assigned_unique_averages) const +std::unique_ptr<Image> TrainingData::draw_coverage(const std::map<uint32_t, float>& unique_percentages, const std::vector<Rangel>& next_ranges, const std::vector<Rangel>& added_ranges, const std::map<uint32_t, float>& uniquenesses_temp, std::shared_ptr<TrainingData::DataRange> current_salt, const std::map<Rangel, std::tuple<double, FrameRange>>& assigned_unique_averages) const { auto analysis_range = Tracker::analysis_range(); auto image = std::make_unique<Image>(500, 1800, 4); @@ -781,7 +781,7 @@ std::shared_ptr<TrainingData::DataRange> TrainingData::add_salt(const std::share std::map<long_t, std::tuple<size_t, size_t, size_t, size_t>> individual_added_salt; std::map<long_t, std::tuple<size_t, size_t>> individual_samples_before_after; - const double number_classes = SETTING(track_max_individuals).value<idx_t>(); + const double number_classes = SETTING(track_max_individuals).value<uint32_t>(); const double gpu_max_sample_mb = double(SETTING(gpu_max_sample_gb).value<float>()) * 1000; const Size2 output_size = SETTING(recognition_image_size); const double max_images_per_class = gpu_max_sample_mb * 1000 * 1000 / number_classes / output_size.width / output_size.height / 4; diff --git a/Application/src/tracker/tracking/TrainingData.h b/Application/src/tracker/tracking/TrainingData.h index e720945..3f56163 100644 --- a/Application/src/tracker/tracking/TrainingData.h +++ b/Application/src/tracker/tracking/TrainingData.h @@ -163,10 +163,10 @@ private: using d_type = std::set<std::shared_ptr<DataRange>>; GETTER(d_type, data) - GETTER(std::set<long_t>, all_classes) + GETTER(std::set<uint32_t>, all_classes) GETTER_NCONST(MidlineFilters, filters) - using s_type = std::map<long_t, std::set<FrameRange>>; + using s_type = std::map<uint32_t, std::set<FrameRange>>; GETTER(s_type, included_segments) //FrameRanges frames; @@ -241,9 +241,9 @@ public: } //! used as an override for when data is just used to initialize the network and nothing more. - void set_classes(const std::set<long_t>& classes); + void set_classes(const std::set<uint32_t>& classes); - std::unique_ptr<Image> draw_coverage(const std::map<long_t, float>& uniquenesses = {}, const std::vector<Rangel>& = {}, const std::vector<Rangel>& added_ranges = {}, const std::map<long_t, float>& uniquenesses_temp = {}, std::shared_ptr<DataRange> current_salt = nullptr, const std::map<Rangel, std::tuple<double, FrameRange>>& assigned_unique_averages = {}) const; + std::unique_ptr<Image> draw_coverage(const std::map<uint32_t, float>& uniquenesses = {}, const std::vector<Rangel>& = {}, const std::vector<Rangel>& added_ranges = {}, const std::map<uint32_t, float>& uniquenesses_temp = {}, std::shared_ptr<DataRange> current_salt = nullptr, const std::map<Rangel, std::tuple<double, FrameRange>>& assigned_unique_averages = {}) const; }; } diff --git a/Application/src/tracker/tracking/VisualField.cpp b/Application/src/tracker/tracking/VisualField.cpp index e34ab70..0da695d 100644 --- a/Application/src/tracker/tracking/VisualField.cpp +++ b/Application/src/tracker/tracking/VisualField.cpp @@ -8,7 +8,7 @@ namespace track { static constexpr double right_angle = RADIANS(90); - VisualField::VisualField(idx_t fish_id, long_t frame, const std::shared_ptr<Individual::BasicStuff>& basic, const std::shared_ptr<Individual::PostureStuff>& posture, bool blocking) + VisualField::VisualField(uint32_t fish_id, long_t frame, const std::shared_ptr<Individual::BasicStuff>& basic, const std::shared_ptr<Individual::PostureStuff>& posture, bool blocking) : max_d(SQR(Tracker::average().cols) + SQR(Tracker::average().rows)), _fish_id(fish_id), _frame(frame) { calculate(basic, posture, blocking); @@ -59,10 +59,10 @@ namespace track { if(x1 == -1) x1 = x0; - const int start = max(0, x0 - 0.5); - const int end = x1 + 0.5; + const uint start = (uint)max(0, x0 - 0.5); + const uint end = (uint)max(0, x1 + 0.5); - for (int i=start; i<=end && i < int(field_resolution); i++) { + for (uint i=start; i<=end && i < field_resolution; ++i) { //! Remember multiple depth map layers, // but only remember each fish once per angle. // (layers are only there in order to account for missing Z components) @@ -81,11 +81,11 @@ namespace track { e._depth[i] = d; e._visible_ids[i] = (long_t)id; e._visible_points[i] = point; - e._fov[i] = min(1.0, SQR(1.0 - d / max_d)) * 255; + e._fov[i] = uchar(SQR(1.0 - min(1.0, max(0.0, d / max_d))) * 255); e._visible_head_distance[i] = hd; /* remove 2. stage after self occlusions */ - if(id == _fish_id) { + if(id == (int64_t)_fish_id) { if(e._depth[i + field_resolution] != FLT_MAX) e._depth[i + field_resolution] = FLT_MAX; } @@ -97,7 +97,7 @@ namespace track { e._depth[i + field_resolution] = d; e._visible_ids[i + field_resolution] = (long_t)id; e._visible_points[i + field_resolution] = point; - e._fov[i + field_resolution] = min(1.0, SQR(1.0 - d / max_d)) * 255; + e._fov[i + field_resolution] = uchar(SQR(1.0 - min(1.0, max(0.0, d / max_d))) * 255); e._visible_head_distance[i + field_resolution] = hd; static_assert(layers == 2, "only tested with 2 layers"); @@ -400,17 +400,17 @@ namespace track { static const Rangef fov_range(-VisualField::symmetric_fov, VisualField::symmetric_fov); static const double len = fov_range.end - fov_range.start; double percent = double(i) / double(VisualField::field_resolution) * len + fov_range.start + eye.angle; - crosses.emplace_back(eye.pos + Vec2(cos(percent), sin(percent)) * sqrt(max_d) * 0.5, eye.clr); + crosses.emplace_back(eye.pos + Vec2(Float2_t(cos(percent)), Float2_t( sin(percent))) * sqrtf(max_d) * 0.5f, eye.clr); //if(&eye == &_eyes[0]) // base.line(eye.pos, eye.pos + Vec2(cos(percent), sin(percent)) * max_d, Red.alpha(100)); } - if(eye._depth[i + VisualField::field_resolution] < FLT_MAX && eye._visible_ids[i + VisualField::field_resolution] != fish->identity().ID()) + if(eye._depth[i + VisualField::field_resolution] < FLT_MAX && eye._visible_ids[i + VisualField::field_resolution] != (long_t)fish->identity().ID()) { auto w = (1 - sqrt(eye._depth[i + VisualField::field_resolution]) / (sqrt(max_d) * 0.5)); //crosses.push_back(eye._visible_points[i + VisualField::field_resolution]); - base.line(eye.pos, eye._visible_points[i + VisualField::field_resolution], Black.alpha(50 * w * w + 10)); + base.line(eye.pos, eye._visible_points[i + VisualField::field_resolution], Black.alpha((uint8_t)saturate(50 * w * w + 10))); } } @@ -428,10 +428,10 @@ namespace track { base.line(eye.pos, eye.pos + straight * 11, 1, Black); - auto left = Vec2(cos(eye.angle - symmetric_fov), - sin(eye.angle - symmetric_fov)); - auto right = Vec2(cos(eye.angle + symmetric_fov), - sin(eye.angle + symmetric_fov)); + auto left = Vec2((Float2_t)cos(eye.angle - symmetric_fov), + (Float2_t)sin(eye.angle - symmetric_fov)); + auto right = Vec2((Float2_t)cos(eye.angle + symmetric_fov), + (Float2_t)sin(eye.angle + symmetric_fov)); /*std::vector<Vertex> vertices; for (int i=0; i<15; ++i) { @@ -446,8 +446,8 @@ namespace track { ptr->set_fill_clr(eye.clr.alpha(80)); base.add_object(ptr);*/ - base.line(eye.pos, eye.pos + left * 100, 1, eye.clr.brighten(0.65)); - base.line(eye.pos, eye.pos + right * 100, 1, eye.clr.brighten(0.65)); + base.line(eye.pos, eye.pos + left * 100, 1, eye.clr.brighten(0.65f)); + base.line(eye.pos, eye.pos + right * 100, 1, eye.clr.brighten(0.65f)); } } @@ -484,7 +484,7 @@ namespace track { if(ptr) { assert(ptr->eyes().size() == 2); - for(int j=0; j<2; j++) { + for(uint j=0; j<2; j++) { auto &e = ptr->eyes()[j]; //Image mat(e._colored); @@ -509,14 +509,14 @@ namespace track { } } - clr = clr.alpha(clr.a * 1.0); + clr = clr.alpha(clr.a); cids.at<cv::Vec4b>(0, i) = cv::Scalar(clr); clr = Black; if(d != -1) { clr = Color(d, d, d, 255); } - clr = clr.alpha(clr.a * 1.0); + clr = clr.alpha(clr.a); cd.at<cv::Vec4b>(0, i) = cv::Scalar(clr); } @@ -529,9 +529,9 @@ namespace track { float y = 0; float scale_x = 2; - float scale_y = float(Tracker::average().rows * s->scale().reciprocal().y - 125 * 2) * 0.25 / (range + 1); + float scale_y = float(Tracker::average().rows * s->scale().reciprocal().y - 125 * 2) * 0.25f / (range + 1); int height_per_row = scale_y * (range + 1); - Vec2 offset((Tracker::average().cols * s->scale().reciprocal().x - VisualField::field_resolution * scale_x) * 0.5 - 10, + Vec2 offset((Tracker::average().cols * s->scale().reciprocal().x - VisualField::field_resolution * scale_x) * 0.5f - 10, 125); for(int i=0; i<2; i++) { diff --git a/Application/src/tracker/tracking/VisualField.h b/Application/src/tracker/tracking/VisualField.h index 338e38d..e46aae3 100644 --- a/Application/src/tracker/tracking/VisualField.h +++ b/Application/src/tracker/tracking/VisualField.h @@ -43,11 +43,11 @@ namespace track { GETTER(Vec2, fish_pos) GETTER(double, fish_angle) - GETTER(idx_t, fish_id) + GETTER(uint32_t, fish_id) GETTER(long_t, frame) public: - VisualField(idx_t fish_id, long_t frame,const std::shared_ptr<Individual::BasicStuff>& basic, const std::shared_ptr<Individual::PostureStuff>& posture, bool blocking); + VisualField(uint32_t fish_id, long_t frame,const std::shared_ptr<Individual::BasicStuff>& basic, const std::shared_ptr<Individual::PostureStuff>& posture, bool blocking); const decltype(_eyes)& eyes() const { return _eyes; } void calculate(const std::shared_ptr<Individual::BasicStuff>& basic, const std::shared_ptr<Individual::PostureStuff>& posture, bool blocking = true); diff --git a/docs/parameters_tgrabs.rst b/docs/parameters_tgrabs.rst index 4cb5e0e..4e9ed17 100644 --- a/docs/parameters_tgrabs.rst +++ b/docs/parameters_tgrabs.rst @@ -28,7 +28,7 @@ TGrabs parameters .. seealso:: :func:`stop_after_minutes`, -.. function:: average_samples(int) +.. function:: average_samples(uint) :noindex: **default value:** 100 diff --git a/docs/parameters_trex.rst b/docs/parameters_trex.rst index 44f0263..0509ccc 100644 --- a/docs/parameters_trex.rst +++ b/docs/parameters_trex.rst @@ -565,7 +565,7 @@ TRex parameters -.. function:: gui_focus_group(array<int>) +.. function:: gui_focus_group(array<uint>) **default value:** [] @@ -1067,7 +1067,7 @@ TRex parameters -.. function:: individual_names(map<int,string>) +.. function:: individual_names(map<uint,string>) **default value:** {} @@ -1112,7 +1112,7 @@ TRex parameters -.. function:: manual_identities(set<int>) +.. function:: manual_identities(set<uint>) **default value:** [] @@ -1777,7 +1777,7 @@ TRex parameters -.. function:: track_max_individuals(int) +.. function:: track_max_individuals(uint) **default value:** 0 -- GitLab