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 //
16 // (C) Idiap Research Institute //
18 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
19 ///////////////////////////////////////////////////////////////////////////
21 #include "pose_cell_scored_set.h"
23 #include "fusion_sort.h"
25 PoseCellScoredSet::PoseCellScoredSet() {
26 _scores = new scalar_t[_max_nb];
29 PoseCellScoredSet::~PoseCellScoredSet() {
33 void PoseCellScoredSet::add_cell_with_score(PoseCell *cell, scalar_t score) {
34 _scores[_nb_added] = score;
38 void PoseCellScoredSet::decimate_hit(int level) {
39 if(_nb_added == 0) return;
41 Pose *poses = new Pose[_nb_added];
42 int *indexes = new int[_nb_added];
43 int *sorted_indexes = new int[_nb_added];
45 for(int c = 0; c < _nb_added; c++) {
46 _cells[c].get_centroid(poses + c);
50 indexed_fusion_dec_sort(_nb_added, indexes, sorted_indexes, _scores);
52 int nb_remaining = _nb_added, current = 0;
54 while(current < nb_remaining) {
56 for(int d = current + 1; d < nb_remaining; d++)
57 if(!poses[sorted_indexes[current]].hit(level, poses + sorted_indexes[d]))
58 sorted_indexes[e++] = sorted_indexes[d];
63 PoseCell *tmp_cells = new PoseCell[max_nb_cells];
64 scalar_t *tmp_scores = new scalar_t[max_nb_cells];
66 for(int n = 0; n < nb_remaining; n++) {
67 tmp_cells[n] = _cells[sorted_indexes[n]];
68 tmp_scores[n] = _scores[sorted_indexes[n]];
75 _nb_added = nb_remaining;
79 delete[] sorted_indexes;
82 void PoseCellScoredSet::decimate_collide(int level) {
83 if(_nb_added == 0) return;
85 Pose *poses = new Pose[_nb_added];
86 int *indexes = new int[_nb_added];
87 int *sorted_indexes = new int[_nb_added];
89 for(int c = 0; c < _nb_added; c++) {
90 _cells[c].get_centroid(poses + c);
94 indexed_fusion_dec_sort(_nb_added, indexes, sorted_indexes, _scores);
96 int nb_remaining = _nb_added, current = 0;
98 while(current < nb_remaining) {
100 for(int d = current + 1; d < nb_remaining; d++)
101 if(!poses[sorted_indexes[current]].collide(level, poses + sorted_indexes[d]))
102 sorted_indexes[e++] = sorted_indexes[d];
107 PoseCell *tmp_cells = new PoseCell[max_nb_cells];
108 scalar_t *tmp_scores = new scalar_t[max_nb_cells];
110 for(int n = 0; n < nb_remaining; n++) {
111 tmp_cells[n] = _cells[sorted_indexes[n]];
112 tmp_scores[n] = _scores[sorted_indexes[n]];
118 _scores = tmp_scores;
119 _nb_added = nb_remaining;
123 delete[] sorted_indexes;