2 ///////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify //
4 // it under the terms of the version 3 of the GNU General Public License //
5 // as published by the Free Software Foundation. //
7 // This program is distributed in the hope that it will be useful, but //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
10 // General Public License for more details. //
12 // You should have received a copy of the GNU General Public License //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
15 // Written by Francois Fleuret, (C) IDIAP //
16 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
17 ///////////////////////////////////////////////////////////////////////////
19 #include "pose_cell_scored_set.h"
21 #include "fusion_sort.h"
23 PoseCellScoredSet::PoseCellScoredSet() {
24 _scores = new scalar_t[_max_nb];
27 PoseCellScoredSet::~PoseCellScoredSet() {
31 void PoseCellScoredSet::add_cell_with_score(PoseCell *cell, scalar_t score) {
32 _scores[_nb_added] = score;
36 void PoseCellScoredSet::decimate_hit(int level) {
37 if(_nb_added == 0) return;
39 Pose *poses = new Pose[_nb_added];
40 int *indexes = new int[_nb_added];
41 int *sorted_indexes = new int[_nb_added];
43 for(int c = 0; c < _nb_added; c++) {
44 _cells[c].get_centroid(poses + c);
48 indexed_fusion_dec_sort(_nb_added, indexes, sorted_indexes, _scores);
50 int nb_remaining = _nb_added, current = 0;
52 while(current < nb_remaining) {
54 for(int d = current + 1; d < nb_remaining; d++)
55 if(!poses[sorted_indexes[current]].hit(level, poses + sorted_indexes[d]))
56 sorted_indexes[e++] = sorted_indexes[d];
61 PoseCell *tmp_cells = new PoseCell[max_nb_cells];
62 scalar_t *tmp_scores = new scalar_t[max_nb_cells];
64 for(int n = 0; n < nb_remaining; n++) {
65 tmp_cells[n] = _cells[sorted_indexes[n]];
66 tmp_scores[n] = _scores[sorted_indexes[n]];
73 _nb_added = nb_remaining;
77 delete[] sorted_indexes;
80 void PoseCellScoredSet::decimate_collide(int level) {
81 if(_nb_added == 0) return;
83 Pose *poses = new Pose[_nb_added];
84 int *indexes = new int[_nb_added];
85 int *sorted_indexes = new int[_nb_added];
87 for(int c = 0; c < _nb_added; c++) {
88 _cells[c].get_centroid(poses + c);
92 indexed_fusion_dec_sort(_nb_added, indexes, sorted_indexes, _scores);
94 int nb_remaining = _nb_added, current = 0;
96 while(current < nb_remaining) {
98 for(int d = current + 1; d < nb_remaining; d++)
99 if(!poses[sorted_indexes[current]].collide(level, poses + sorted_indexes[d]))
100 sorted_indexes[e++] = sorted_indexes[d];
105 PoseCell *tmp_cells = new PoseCell[max_nb_cells];
106 scalar_t *tmp_scores = new scalar_t[max_nb_cells];
108 for(int n = 0; n < nb_remaining; n++) {
109 tmp_cells[n] = _cells[sorted_indexes[n]];
110 tmp_scores[n] = _scores[sorted_indexes[n]];
116 _scores = tmp_scores;
117 _nb_added = nb_remaining;
121 delete[] sorted_indexes;