// eraser.cc - Classe Eraser // robert - Programme du robot APBteam // Copyright (C) 2005 Olivier Gaillard /// @file eraser.cc Filtre les objets par leurs tailles #include #include #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 " 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 " 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; }