summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/vision/size_thresholds.cc
diff options
context:
space:
mode:
Diffstat (limited to '2003/i/buzz/src/vision/size_thresholds.cc')
-rw-r--r--2003/i/buzz/src/vision/size_thresholds.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/2003/i/buzz/src/vision/size_thresholds.cc b/2003/i/buzz/src/vision/size_thresholds.cc
new file mode 100644
index 0000000..3a65d4c
--- /dev/null
+++ b/2003/i/buzz/src/vision/size_thresholds.cc
@@ -0,0 +1,53 @@
+// size_thresholds.cc - Chargement de seuils de taille de palets.
+// buzz - Programme du robot Efrei Robotique I1-I2 2003
+// Copyright (C) 2003 Nicolas Schodet
+#include "size_thresholds.h"
+
+#include <stdio.h>
+
+// Constructeur.
+SizeThresholds::SizeThresholds (const char *filename)
+{
+ FILE *fp;
+ SizeThreshold **pt;
+ int n;
+ int type, wm, wM, hm, hM;
+ // Ouvre le fichier.
+ fp = fopen (filename, "r");
+ if (!fp) throw "SizeThresholds::SizeThresholds: fopen failled";
+ // Charge chaque lignes.
+ pt = &m_thresholds;
+ while (!feof (fp))
+ {
+ n = fscanf (fp, "%d %d %d %d %d\n", &type, &wm, &wM,
+ &hm, &hM);
+ if (n != 5)
+ {
+ fclose (fp);
+ throw "SizeThresholds::SizeThresholds: Bad format.";
+ }
+ // Ajoute un nouveaux seuil a la collection.
+ *pt = new SizeThreshold;
+ (*pt)->type = type;
+ (*pt)->wm = wm;
+ (*pt)->wM = wM;
+ (*pt)->hm = hm;
+ (*pt)->hM = hM;
+ pt = &(*pt)->next;
+ }
+ // Ferme la liste de seuils.
+ *pt = 0;
+ // Ferme le fichier.
+ fclose (fp);
+}
+
+// Destructeur.
+SizeThresholds::~SizeThresholds (void)
+{
+ SizeThreshold *p, *p2;
+ for (p = m_thresholds; p; p = p2)
+ {
+ p2 = p->next;
+ delete p;
+ }
+}