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 as published
13 * by the Free Software Foundation, either version 3 of the License,
14 * or (at your option) any later version.
16 * folded-ctf is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with folded-ctf. If not, see <http://www.gnu.org/licenses/>.
26 #include "pose_cell_scored_set.h"
28 #include "fusion_sort.h"
30 PoseCellScoredSet::PoseCellScoredSet() {
31 _scores = new scalar_t[_max_nb];
34 PoseCellScoredSet::~PoseCellScoredSet() {
38 void PoseCellScoredSet::add_cell_with_score(PoseCell *cell, scalar_t score) {
39 _scores[_nb_added] = score;
43 void PoseCellScoredSet::decimate_hit(int level) {
44 if(_nb_added == 0) return;
46 Pose *poses = new Pose[_nb_added];
47 int *indexes = new int[_nb_added];
48 int *sorted_indexes = new int[_nb_added];
50 for(int c = 0; c < _nb_added; c++) {
51 _cells[c].get_centroid(poses + c);
55 indexed_fusion_dec_sort(_nb_added, indexes, sorted_indexes, _scores);
57 int nb_remaining = _nb_added, current = 0;
59 while(current < nb_remaining) {
61 for(int d = current + 1; d < nb_remaining; d++)
62 if(!poses[sorted_indexes[current]].hit(level, poses + sorted_indexes[d]))
63 sorted_indexes[e++] = sorted_indexes[d];
68 PoseCell *tmp_cells = new PoseCell[max_nb_cells];
69 scalar_t *tmp_scores = new scalar_t[max_nb_cells];
71 for(int n = 0; n < nb_remaining; n++) {
72 tmp_cells[n] = _cells[sorted_indexes[n]];
73 tmp_scores[n] = _scores[sorted_indexes[n]];
80 _nb_added = nb_remaining;
84 delete[] sorted_indexes;
87 void PoseCellScoredSet::decimate_collide(int level) {
88 if(_nb_added == 0) return;
90 Pose *poses = new Pose[_nb_added];
91 int *indexes = new int[_nb_added];
92 int *sorted_indexes = new int[_nb_added];
94 for(int c = 0; c < _nb_added; c++) {
95 _cells[c].get_centroid(poses + c);
99 indexed_fusion_dec_sort(_nb_added, indexes, sorted_indexes, _scores);
101 int nb_remaining = _nb_added, current = 0;
103 while(current < nb_remaining) {
105 for(int d = current + 1; d < nb_remaining; d++)
106 if(!poses[sorted_indexes[current]].collide(level, poses + sorted_indexes[d]))
107 sorted_indexes[e++] = sorted_indexes[d];
112 PoseCell *tmp_cells = new PoseCell[max_nb_cells];
113 scalar_t *tmp_scores = new scalar_t[max_nb_cells];
115 for(int n = 0; n < nb_remaining; n++) {
116 tmp_cells[n] = _cells[sorted_indexes[n]];
117 tmp_scores[n] = _scores[sorted_indexes[n]];
123 _scores = tmp_scores;
124 _nb_added = nb_remaining;
128 delete[] sorted_indexes;