2 * folded-ctf is an implementation of the folded hierarchy of
3 * classifiers for object detection, developed by Francois Fleuret
6 * Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
7 * Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 * This file is part of folded-ctf.
11 * folded-ctf is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 3 as
13 * published by the Free Software Foundation.
15 * folded-ctf is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with folded-ctf. If not, see <http://www.gnu.org/licenses/>.
25 #include "pose_cell_scored_set.h"
27 #include "fusion_sort.h"
29 PoseCellScoredSet::PoseCellScoredSet() {
30 _scores = new scalar_t[_max_nb];
33 PoseCellScoredSet::~PoseCellScoredSet() {
37 void PoseCellScoredSet::add_cell_with_score(PoseCell *cell, scalar_t score) {
38 _scores[_nb_added] = score;
42 void PoseCellScoredSet::decimate_hit(int level) {
43 if(_nb_added == 0) return;
45 Pose *poses = new Pose[_nb_added];
46 int *indexes = new int[_nb_added];
47 int *sorted_indexes = new int[_nb_added];
49 for(int c = 0; c < _nb_added; c++) {
50 _cells[c].get_centroid(poses + c);
54 indexed_fusion_dec_sort(_nb_added, indexes, sorted_indexes, _scores);
56 int nb_remaining = _nb_added, current = 0;
58 while(current < nb_remaining) {
60 for(int d = current + 1; d < nb_remaining; d++)
61 if(!poses[sorted_indexes[current]].hit(level, poses + sorted_indexes[d]))
62 sorted_indexes[e++] = sorted_indexes[d];
67 PoseCell *tmp_cells = new PoseCell[max_nb_cells];
68 scalar_t *tmp_scores = new scalar_t[max_nb_cells];
70 for(int n = 0; n < nb_remaining; n++) {
71 tmp_cells[n] = _cells[sorted_indexes[n]];
72 tmp_scores[n] = _scores[sorted_indexes[n]];
79 _nb_added = nb_remaining;
83 delete[] sorted_indexes;
86 void PoseCellScoredSet::decimate_collide(int level) {
87 if(_nb_added == 0) return;
89 Pose *poses = new Pose[_nb_added];
90 int *indexes = new int[_nb_added];
91 int *sorted_indexes = new int[_nb_added];
93 for(int c = 0; c < _nb_added; c++) {
94 _cells[c].get_centroid(poses + c);
98 indexed_fusion_dec_sort(_nb_added, indexes, sorted_indexes, _scores);
100 int nb_remaining = _nb_added, current = 0;
102 while(current < nb_remaining) {
104 for(int d = current + 1; d < nb_remaining; d++)
105 if(!poses[sorted_indexes[current]].collide(level, poses + sorted_indexes[d]))
106 sorted_indexes[e++] = sorted_indexes[d];
111 PoseCell *tmp_cells = new PoseCell[max_nb_cells];
112 scalar_t *tmp_scores = new scalar_t[max_nb_cells];
114 for(int n = 0; n < nb_remaining; n++) {
115 tmp_cells[n] = _cells[sorted_indexes[n]];
116 tmp_scores[n] = _scores[sorted_indexes[n]];
122 _scores = tmp_scores;
123 _nb_added = nb_remaining;
127 delete[] sorted_indexes;