summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/eraser.cc
blob: 9ca2dc38f8ac3d2cb9923b1b87c08378cd09af6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// eraser.cc - Classe Eraser
// robert - Programme du robot APBteam
// Copyright (C) 2005 Olivier Gaillard

/// @file eraser.cc Filtre les objets par leurs tailles

#include <iostream>
#include <fstream>

#include "eraser.hh"
#include "group.hh"

/// Constructeur
Eraser::Eraser (const int maxHeight, const int resolution)
    : res_ (resolution), maxHeight_ (maxHeight)
{
    oconfig_ = OConfig::getInstance (); 
}

/// Destructeur
Eraser::~Eraser (void)
{
}

/// Ouvre le fichier de donn�es
void
Eraser::init (const std::string &filename)
{
    // Ouverture du fichier de distance
    std::ifstream file (filename.c_str ()); 
    if (!file) 
      {
	throw "<Eraser::init> Error during file opening\n";
	return;
    }
    // Enl�ve les commentaires
    char trash[50];
    file.getline (trash, 50);
    char c;
    int y, min, max;
    while (!file.eof ())
      {
	file >> c >> y >> min >> max;
	add (c, y, min, max);
      }
    // Parcours des lignes et analyse
    file.close ();
    // Remplissage du reste
    add ('V', maxHeight_, tabVMin_[tabVMax_.size () - 1], tabVMax_[tabVMax_.size () -1]);
    add ('O', maxHeight_, min, max);
}

/// Remplissage de la table
void
Eraser::add (const char c, const int y, const int min, const int max)
{
    static int lastO = 0;
    static int lastV = 0;
    if (c == 'V')
      {
	for (int i = lastV; i <= y/res_; ++i)
	  {
	    tabVMin_.push_back (min);
	    tabVMax_.push_back (max);
	  }
	lastV = y/res_;
      }
    else if (c == 'O')
      {
	for (int i = lastO; i <= y/res_; ++i)
	  {
	    tabOMin_.push_back (min);
	    tabOMax_.push_back (max);
	    std::cout << i << " " << min << " " << max << "\n";
	  }
	lastO = (y+res_)/res_;
      }
    else 
      {
	throw "<Eraser::init> Bad syntax in file\n";
	return;
      }
}

/// Objet � la bonne taille ?
bool
Eraser::killOrNot (const Zone &zone)
{
    int y = zone.ymax / res_;
    if (zone.vertical)
      {
	if ((zone.area > tabVMin_[y]) || (zone.area < tabVMax_[y]))
	    return true;
      }
    else
      {
	if ((zone.area > tabOMin_[y]) || (zone.area < tabOMax_[y]))
	    return true;
      }
    return false;
}


/// Zone trop petite
bool
Eraser::isTooSmall (const Zone &zone)
{
    int y = zone.ymax / res_;
    if (zone.vertical)
      {
	if (zone.area < tabVMin_[y])
	    return true;
      }
    else
      {
	if (zone.area < tabOMin_[y])
	    return true;
      }
    return false;
}

/// Zone trop grande
bool
Eraser::isTooBig (const Zone &zone)
{
    int y = zone.ymax / res_;
    if (zone.vertical)
      {
	if (zone.area > tabVMax_[y])
	    return true;
      }
    else
      {
	if (zone.area > tabOMax_[y])
	  {
	    return true;
	  }
      }
    return false;
}