X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=pose_cell_scored_set.cc;fp=pose_cell_scored_set.cc;h=253c3ee6325b7ef590c4e66869d978933b6d8a7a;hb=d922ad61d35e9a6996730bec24b16f8bf7bc426c;hp=0000000000000000000000000000000000000000;hpb=3bb118f5a9462d02ff7d99ef28ecc0d7e23529f9;p=folded-ctf.git diff --git a/pose_cell_scored_set.cc b/pose_cell_scored_set.cc new file mode 100644 index 0000000..253c3ee --- /dev/null +++ b/pose_cell_scored_set.cc @@ -0,0 +1,122 @@ + +/////////////////////////////////////////////////////////////////////////// +// This program is free software: you can redistribute it and/or modify // +// it under the terms of the version 3 of the GNU General Public License // +// as published by the Free Software Foundation. // +// // +// This program is distributed in the hope that it will be useful, but // +// WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // +// General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +// // +// Written by Francois Fleuret, (C) IDIAP // +// Contact for comments & bug reports // +/////////////////////////////////////////////////////////////////////////// + +#include "pose_cell_scored_set.h" +#include "global.h" +#include "fusion_sort.h" + +PoseCellScoredSet::PoseCellScoredSet() { + _scores = new scalar_t[_max_nb]; +} + +PoseCellScoredSet::~PoseCellScoredSet() { + delete[] _scores; +} + +void PoseCellScoredSet::add_cell_with_score(PoseCell *cell, scalar_t score) { + _scores[_nb_added] = score; + add_cell(cell); +} + +void PoseCellScoredSet::decimate_hit(int level) { + if(_nb_added == 0) return; + + Pose *poses = new Pose[_nb_added]; + int *indexes = new int[_nb_added]; + int *sorted_indexes = new int[_nb_added]; + + for(int c = 0; c < _nb_added; c++) { + _cells[c].get_centroid(poses + c); + indexes[c] = c; + } + + indexed_fusion_dec_sort(_nb_added, indexes, sorted_indexes, _scores); + + int nb_remaining = _nb_added, current = 0; + + while(current < nb_remaining) { + int e = current + 1; + for(int d = current + 1; d < nb_remaining; d++) + if(!poses[sorted_indexes[current]].hit(level, poses + sorted_indexes[d])) + sorted_indexes[e++] = sorted_indexes[d]; + nb_remaining = e; + current++; + } + + PoseCell *tmp_cells = new PoseCell[max_nb_cells]; + scalar_t *tmp_scores = new scalar_t[max_nb_cells]; + + for(int n = 0; n < nb_remaining; n++) { + tmp_cells[n] = _cells[sorted_indexes[n]]; + tmp_scores[n] = _scores[sorted_indexes[n]]; + } + + delete[] _cells; + delete[] _scores; + _cells = tmp_cells; + _scores = tmp_scores; + _nb_added = nb_remaining; + + delete[] poses; + delete[] indexes; + delete[] sorted_indexes; +} + +void PoseCellScoredSet::decimate_collide(int level) { + if(_nb_added == 0) return; + + Pose *poses = new Pose[_nb_added]; + int *indexes = new int[_nb_added]; + int *sorted_indexes = new int[_nb_added]; + + for(int c = 0; c < _nb_added; c++) { + _cells[c].get_centroid(poses + c); + indexes[c] = c; + } + + indexed_fusion_dec_sort(_nb_added, indexes, sorted_indexes, _scores); + + int nb_remaining = _nb_added, current = 0; + + while(current < nb_remaining) { + int e = current + 1; + for(int d = current + 1; d < nb_remaining; d++) + if(!poses[sorted_indexes[current]].collide(level, poses + sorted_indexes[d])) + sorted_indexes[e++] = sorted_indexes[d]; + nb_remaining = e; + current++; + } + + PoseCell *tmp_cells = new PoseCell[max_nb_cells]; + scalar_t *tmp_scores = new scalar_t[max_nb_cells]; + + for(int n = 0; n < nb_remaining; n++) { + tmp_cells[n] = _cells[sorted_indexes[n]]; + tmp_scores[n] = _scores[sorted_indexes[n]]; + } + + delete[] _cells; + delete[] _scores; + _cells = tmp_cells; + _scores = tmp_scores; + _nb_added = nb_remaining; + + delete[] poses; + delete[] indexes; + delete[] sorted_indexes; +}