--- /dev/null
+
+///////////////////////////////////////////////////////////////////////////
+// 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 <http://www.gnu.org/licenses/>. //
+// //
+// Written by Francois Fleuret, (C) IDIAP //
+// Contact <francois.fleuret@idiap.ch> 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;
+}