summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/colorTable.cc
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert/src/ovision/see/colorTable.cc')
-rw-r--r--2005/i/robert/src/ovision/see/colorTable.cc88
1 files changed, 88 insertions, 0 deletions
diff --git a/2005/i/robert/src/ovision/see/colorTable.cc b/2005/i/robert/src/ovision/see/colorTable.cc
new file mode 100644
index 0000000..6d0780f
--- /dev/null
+++ b/2005/i/robert/src/ovision/see/colorTable.cc
@@ -0,0 +1,88 @@
+// colorTable.cc - Classe tableau de couleur
+// robert - Programme du robot APBteam
+// Copyright (C) 2005 Olivier Gaillard
+
+/// @file colorTable.cc Gestion du tableau de couleur : compression/décompression, écriture, ...
+#include <iostream>
+#include <fstream>
+#include <zlib.h>
+
+#include "segmLearn.hh"
+#include "colorTable.hh"
+
+/// Constructor ColorTable
+ColorTable::ColorTable (const char *filename)
+ : data_ (0)
+{
+ load (filename);
+}
+
+
+/// Destructor ColorTable
+ColorTable::~ColorTable ()
+{
+ delete [] data_;
+}
+
+/// Cree un tableau des couleurs segmentées pour ne plus faire de calcul
+/// et augmenter la rapidité
+/// @param testOutputMax choix de l'utilisation d'un sueil maxi pour la sortie pour éviter qu'une couleur trop différente soit attribuer à une autre couleur
+void
+ColorTable::create (const int nbOutput_, const bool testOutputMax)
+{
+ SegmLearn segm;
+ segm.buildNN (nbOutput_, Segm::loadFromFile);
+ std::cout << "ColorTable:: Creation de la table" << std::endl;
+ unsigned char x[3];
+ delete [] data_;
+ data_ = new unsigned char[colorTabSizeTotal];
+ // Parcours de toutes les valeurs possibles
+ for (int i=0; i<colorTabSize; i++)
+ for (int j=0; j<colorTabSize; j++)
+ for (int k=0; k<colorTabSize; k++)
+ {
+ // Remplissage de la table
+ x[0]=i; x[1]=j; x[2]=k;
+ data_[ i*colorTabSize2 + j*colorTabSize +k ] = segm.giveColor (x , testOutputMax);
+ }
+}
+
+/// Cree un fichier de ColorTable
+void
+ColorTable::save (const char *filename) const
+{
+ std::cout << "ColorTable:: Ecriture de la table" << std::endl;
+ gzFile file = gzopen (filename, "w+");
+ if (file)
+ {
+ gzwrite (file, (char*)data_, colorTabSizeTotal);
+ gzclose (file);
+ }
+ else
+ std::cerr << "ColorTable::CreateColorTableFile Erreur d'ouverture de fichier" << std::endl;
+
+}
+
+/// Charge un fichier de ColorTable
+bool
+ColorTable::load (const char *filename)
+{
+ /// Initialisation de data
+ delete [] data_;
+ data_ = new unsigned char[colorTabSizeTotal];
+ /// Ouverture du fichier de couleurs
+ gzFile file = gzopen (filename, "w+");
+ if (file)
+ {
+ std::cout << "ColorTable:: Chargement de la table" << std::endl;
+ gzread (file, (char*)data_, colorTabSizeTotal);
+ gzclose (file);
+ }
+ else
+ {
+ std::cerr << "ColorTable::CreateColorTableFile Erreur d'ouverture de fichier" << std::endl;
+ return false;
+ }
+ return true;
+}
+