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 "labelled_image.h"
23 LabelledImage::LabelledImage() : RichImage() {
27 LabelledImage::LabelledImage(int width, int height, int nb_targets) : RichImage(width, height) {
28 _nb_targets = nb_targets;
29 _target_poses = new Pose[_nb_targets];
32 LabelledImage::~LabelledImage() {
33 delete[] _target_poses;
36 int LabelledImage::pose_cell_label(PoseCell *cell) {
40 for(int t = 0; t < _nb_targets; t++) {
41 if(cell->contains(_target_poses + t))
43 if(!cell->negative_for_train(_target_poses + t))
47 if(positive) return 1;
48 if(negative) return -1;
52 void LabelledImage::write(ostream *out) {
53 int v = file_format_version;
55 RichImage::write(out);
56 write_var(out, &_nb_targets);
57 for(int t = 0; t < _nb_targets; t++)
58 _target_poses[t].write(out);
61 void LabelledImage::read(istream *in) {
64 if(v != file_format_version) {
65 cerr << "Pool file format version " << file_format_version << " expected,"
66 << " the file is version " << v
71 delete[] _target_poses;
72 read_var(in, &_nb_targets);
73 _target_poses = new Pose[_nb_targets];
74 for(int t = 0; t < _nb_targets; t++)
75 _target_poses[t].read(in);