Removed the definition of basename, which confuses an existing system one.
[folded-ctf.git] / labelled_image.cc
1 /*
2  *  folded-ctf is an implementation of the folded hierarchy of
3  *  classifiers for object detection, developed by Francois Fleuret
4  *  and Donald Geman.
5  *
6  *  Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
7  *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
8  *
9  *  This file is part of folded-ctf.
10  *
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.
14  *
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.
19  *
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/>.
22  *
23  */
24
25 #include "labelled_image.h"
26
27 LabelledImage::LabelledImage() : RichImage() {
28   _target_poses = 0;
29 }
30
31 LabelledImage::LabelledImage(int width, int height, int nb_targets) : RichImage(width, height) {
32   _nb_targets = nb_targets;
33   _target_poses = new Pose[_nb_targets];
34 }
35
36 LabelledImage::~LabelledImage() {
37   delete[] _target_poses;
38 }
39
40 int LabelledImage::pose_cell_label(PoseCell *cell) {
41   int positive = 0;
42   int negative = 1;
43
44   for(int t = 0; t < _nb_targets; t++) {
45     if(cell->contains(_target_poses + t))
46       positive = 1;
47     if(!cell->negative_for_train(_target_poses + t))
48       negative = 0;
49   }
50
51   if(positive) return 1;
52   if(negative) return -1;
53   return 0;
54 }
55
56 void LabelledImage::write(ostream *out) {
57   int v = file_format_version;
58   write_var(out, &v);
59   RichImage::write(out);
60   write_var(out, &_nb_targets);
61   for(int t = 0; t < _nb_targets; t++)
62     _target_poses[t].write(out);
63 }
64
65 void LabelledImage::read(istream *in) {
66   int v;
67   read_var(in, &v);
68   if(v != file_format_version) {
69     cerr << "Pool file format version " << file_format_version << " expected,"
70          << " the file is version " << v
71          << endl;
72     exit(1);
73   }
74   RichImage::read(in);
75   delete[] _target_poses;
76   read_var(in, &_nb_targets);
77   _target_poses = new Pose[_nb_targets];
78   for(int t = 0; t < _nb_targets; t++)
79     _target_poses[t].read(in);
80 }