Index: trunk/FACT++/drive/FilterLed.cc
===================================================================
--- trunk/FACT++/drive/FilterLed.cc	(revision 18620)
+++ trunk/FACT++/drive/FilterLed.cc	(revision 18621)
@@ -5,13 +5,8 @@
 #include <iostream> // cout
 
-#include <TMath.h>
-
 #include "Led.h"
-#include "Leds.h"
 #include "Ring.h"
 
-#include "MGMap.h"
-
-ClassImp(FilterLed);
+#include "MGImage.h"
 
 using namespace std;
@@ -20,22 +15,22 @@
 {
 private:
-    byte *fImg;
-
-    UInt_t fW;
-    UInt_t fH;
-
-    Int_t fX0;
-    Int_t fX1;
-
-    Int_t fY0;
-    Int_t fY1;
-
-    UInt_t fLimitingSize;
-
-    UInt_t fCount;
-    Float_t fSumX;
-    Float_t fSumY;
-
-    Float_t FindCluster(Int_t x, Int_t y)
+    uint8_t *fImg;
+
+    uint32_t fW;
+    uint32_t fH;
+
+    int32_t fX0;
+    int32_t fX1;
+
+    int32_t fY0;
+    int32_t fY1;
+
+    uint32_t fLimitingSize;
+
+    uint32_t fCount;
+    float fSumX;
+    float fSumY;
+
+    float FindCluster(int32_t x, int32_t y)
     {
         // if edge is touched stop finding cluster
@@ -47,5 +42,5 @@
 
         // get the value
-        Float_t val = fImg[y*fW+x];
+        float val = fImg[y*fW+x];
 
         // if its empty we have found the border of the cluster
@@ -60,5 +55,5 @@
         fCount++;
 
-        Float_t rc[4];
+        float rc[4];
         rc[0] = FindCluster(x+1, y  );
         rc[1] = FindCluster(x,   y+1);
@@ -78,5 +73,5 @@
 
 public:
-    ClusterFinder(byte *img, UInt_t w, UInt_t h) : fImg(0), fLimitingSize(999)
+    ClusterFinder(uint8_t *img, uint32_t w, uint32_t h) : fImg(0), fLimitingSize(999)
     {
         fW = w;
@@ -88,5 +83,5 @@
         fY1 = fH;
 
-        fImg = new byte[fW*fH];
+        fImg = new uint8_t[fW*fH];
 
         memcpy(fImg, img, fW*fH);
@@ -100,9 +95,9 @@
     Double_t GetSumY() const { return fSumY; }
 
-    UInt_t GetCount() const { return fCount; }
-
-    void SetLimitingSize(UInt_t lim) { fLimitingSize=lim; }
-
-    Float_t FindClusterAt(Int_t x, Int_t y)
+    uint32_t GetCount() const { return fCount; }
+
+    void SetLimitingSize(uint32_t lim) { fLimitingSize=lim; }
+
+    float FindClusterAt(int32_t x, int32_t y)
     {
         fCount = 0;
@@ -113,5 +108,5 @@
     }
 
-    void SetRange(Int_t x0=0, Int_t y0=0, Int_t x1=0, Int_t y1=0)
+    void SetRange(int32_t x0=0, int32_t y0=0, int32_t x1=0, int32_t y1=0)
     {
         fX0 = x0;
@@ -121,5 +116,5 @@
     }
 
-    void FindCluster(Leds &leds, Int_t x0=0, Int_t y0=0, Int_t x1=0, Int_t y1=0)
+    void FindCluster(vector<Led> &leds, int32_t x0=0, int32_t y0=0, int32_t x1=0, int32_t y1=0)
     {
         fX0 = x0;
@@ -128,12 +123,12 @@
         fY1 = y1==0?fH:y1;
 
-        for (Int_t x=fX0; x<fX1; x++)
-            for (Int_t y=fY0; y<fY1; y++)
+        for (int32_t x=fX0; x<fX1; x++)
+            for (int32_t y=fY0; y<fY1; y++)
             {
-                const byte &b = fImg[y*fW+x];
+                const uint8_t &b = fImg[y*fW+x];
                 if (b==0)
                     continue;
 
-                const Float_t mag = FindClusterAt(x, y);
+                const float mag = FindClusterAt(x, y);
                 if (fCount>999)
                 {
@@ -142,8 +137,8 @@
                 }
 
-                if (mag>0 && fCount>6)
-                    leds.Add(fSumX/mag, fSumY/mag, 0, 0, mag);
+                if (mag>0 && fCount>4)
+                    leds.push_back(Led(fSumX/mag, fSumY/mag, 0, mag));
             }
-        leds.Compress();
+        //leds.Compress();
     }
 };
@@ -154,8 +149,8 @@
                         const int col) const
 {
-    MGMap::DrawBox(fImg, 768, 576, x1, y1, x2, y2, col);
-}
-
-void FilterLed::MarkPoint(Float_t px, Float_t py, Float_t mag) const
+    MGImage::DrawBox(fImg, 768, 576, x1, y1, x2, y2, col);
+}
+
+void FilterLed::MarkPoint(float px, float py, float mag) const
 {
     const int x = (int)(px+.5);
@@ -172,5 +167,5 @@
 {
     /*
-    Int_t M = (int)(log(led.GetMag())*20);
+    int32_t M = (int)(log(led.GetMag())*20);
 
     cout << led.GetMag() << endl;
@@ -188,36 +183,36 @@
 }
 
-void FilterLed::DrawCircle(float cx, float cy, float r, byte col) const
-{
-    MGMap::DrawCircle(fImg, 768, 576, cx, cy, r, col);
-}
-
-void FilterLed::DrawHexagon(float cx, float cy, float r, byte col) const
-{
-    MGMap::DrawHexagon(fImg, 768, 576, cx, cy, r, col);
-}
-
-void FilterLed::DrawCircle(const Ring &l, byte col) const
+void FilterLed::DrawCircle(float cx, float cy, float r, uint8_t col) const
+{
+    MGImage::DrawCircle(fImg, 768, 576, cx, cy, r, col);
+}
+
+void FilterLed::DrawHexagon(float cx, float cy, float r, uint8_t col) const
+{
+    MGImage::DrawHexagon(fImg, 768, 576, cx, cy, r, col);
+}
+
+void FilterLed::DrawCircle(const Ring &l, uint8_t col) const
 {
     DrawCircle(l.GetX(), l.GetY(), l.GetR(), col);
 }
 
-void FilterLed::DrawCircle(const Ring &l, double r, byte col) const
+void FilterLed::DrawCircle(const Ring &l, double r, uint8_t col) const
 {
     DrawCircle(l.GetX(), l.GetY(), r, col);
 }
 
-void FilterLed::DrawHexagon(const Ring &l, double r, byte col) const
+void FilterLed::DrawHexagon(const Ring &l, double r, uint8_t col) const
 {
     DrawHexagon(l.GetX(), l.GetY(), r, col);
 }
 
-void FilterLed::GetMinMax(const int offset, byte *min, byte *max) const
+void FilterLed::GetMinMax(const int offset, uint8_t *min, uint8_t *max) const
 {
     *min = fImg[0];
     *max = fImg[0];
 
-    byte *s = (byte*)fImg;
-    const byte *e0 = s+fW*fH;
+    uint8_t *s = (uint8_t*)fImg;
+    const uint8_t *e0 = s+fW*fH;
 
     //
@@ -226,5 +221,5 @@
     while (s<e0)
     {
-        const byte *e = s+fH-offset;
+        const uint8_t *e = s+fH-offset;
         s += offset;
 
@@ -260,5 +255,5 @@
         for (int dy=y-boxy; dy<y+boxy+1; dy++)
         {
-            const byte &m = fImg[dy*fW+dx];
+            const uint8_t &m = fImg[dy*fW+dx];
 
             sumx += m*dx;
@@ -287,9 +282,9 @@
     // Improved algorithm:
     // 1. Look for the largest five-pixel-cross signal inside the box
-    int x0 = TMath::Max(x-boxx+1,   0);
-    int y0 = TMath::Max(y-boxy+1,   0);
-
-    int x1 = TMath::Min(x+boxx+1-1, fW);
-    int y1 = TMath::Min(y+boxy+1-1, fH);
+    int x0 = max(x-boxx+1,   0);
+    int y0 = max(y-boxy+1,   0);
+
+    int x1 = min(x+boxx+1-1, fW);
+    int y1 = min(y+boxy+1-1, fH);
 
     int maxx=0;
@@ -323,5 +318,5 @@
     find.SetRange(x0, y0, x1, y1);
 
-    const Float_t mag = find.FindClusterAt(maxx, maxy);
+    const float mag = find.FindClusterAt(maxx, maxy);
 
     mx = find.GetSumX()/mag;
@@ -341,34 +336,5 @@
 }
 
-void FilterLed::ExecuteAndMark(Leds &leds, int xc, int yc) const
-{
-    const Int_t first = leds.GetEntriesFast();
-
-    Execute(leds, xc, yc);
- 
-    // Mark Stars in image
-    for (int i=first; i<leds.GetEntriesFast(); i++)
-        MarkPoint(leds(i));
-}
-
-
-void FilterLed::ExecuteAndMark(Leds &leds, int xc, int yc, double &bright) const
-{
-    const Int_t first = leds.GetEntriesFast();
-
-    Execute(leds, xc, yc, bright);
- 
-    // Mark Stars in image
-    for (int i=first; i<leds.GetEntriesFast(); i++)
-        MarkPoint(leds(i));
-}
-
-void FilterLed::Execute(int xc, int yc) const
-{
-    Leds leds;
-    ExecuteAndMark(leds, xc, yc);
-}
-
-void FilterLed::Execute(Leds &leds, int xc, int yc) const
+void FilterLed::Execute(vector<Led> &leds, int xc, int yc) const
 {
     double bright;
@@ -376,10 +342,10 @@
 }
 
-void FilterLed::Execute(Leds &leds, int xc, int yc, double &bright) const
-{
-    const int x0 = TMath::Max(xc-fBoxX, 0);
-    const int y0 = TMath::Max(yc-fBoxY, 0);
-    const int x1 = TMath::Min(xc+fBoxX, fW);
-    const int y1 = TMath::Min(yc+fBoxY, fH);
+void FilterLed::Execute(vector<Led> &leds, int xc, int yc, double &bright) const
+{
+    const int x0 = max(xc-fBoxX, 0);
+    const int y0 = max(yc-fBoxY, 0);
+    const int x1 = min(xc+fBoxX, fW);
+    const int y1 = min(yc+fBoxY, fH);
 
     const int wx = x1-x0;
@@ -392,5 +358,5 @@
         for (int y=y0; y<y1; y++)
         {
-            byte &b = fImg[y*fW+x];
+            uint8_t &b = fImg[y*fW+x];
 
             // Skip saturating pixels
@@ -410,5 +376,5 @@
     // 254 because b<=max and not b<max
     const double sdev = sqrt(sq-sum*sum);
-    const byte   max  = sum+fCut*sdev>254 ? 254 : (byte)(sum+fCut*sdev);
+    const uint8_t   max  = sum+fCut*sdev>254 ? 254 : (uint8_t)(sum+fCut*sdev);
 
     //
@@ -419,5 +385,5 @@
         for (int y=y0; y<y1; y++)
         {
-            byte &b = fImg[y*fW+x];
+            uint8_t &b = fImg[y*fW+x];
             if (b<=max)
                 b = 0;
@@ -428,5 +394,5 @@
 }
 
-void FilterLed::FindStar(Leds &leds, int xc, int yc, bool box) const
+void FilterLed::FindStar(vector<Led> &leds, int xc, int yc, bool box) const
 {
     // fBox: radius of the inner (signal) box
@@ -436,8 +402,8 @@
     // Define inner box in which to search the signal
     //
-    const int x0 = TMath::Max(xc-fBoxX, 0);
-    const int y0 = TMath::Max(yc-fBoxY, 0);
-    const int x1 = TMath::Min(xc+fBoxX, fW);
-    const int y1 = TMath::Min(yc+fBoxY, fH);
+    const int x0 = max(xc-fBoxX, 0);
+    const int y0 = max(yc-fBoxY, 0);
+    const int x1 = min(xc+fBoxX, fW);
+    const int y1 = min(yc+fBoxY, fH);
 
     //
@@ -448,8 +414,8 @@
     const double sqrt2 = sqrt(2.);
 
-    const int xa = TMath::Max(xc-TMath::Nint(fBoxX*sqrt2), 0);
-    const int ya = TMath::Max(yc-TMath::Nint(fBoxY*sqrt2), 0);
-    const int xb = TMath::Min(xc+TMath::Nint(fBoxX*sqrt2), fW);
-    const int yb = TMath::Min(yc+TMath::Nint(fBoxY*sqrt2), fH);
+    const int xa = max(xc-(int)nearbyint(fBoxX*sqrt2), 0);
+    const int ya = max(yc-(int)nearbyint(fBoxY*sqrt2), 0);
+    const int xb = min(xc+(int)nearbyint(fBoxX*sqrt2), fW);
+    const int yb = min(yc+(int)nearbyint(fBoxY*sqrt2), fH);
 
     //
@@ -468,5 +434,5 @@
                 continue;
 
-            byte &b = fImg[y*fW+x];
+            uint8_t &b = fImg[y*fW+x];
 
             sum += b;
@@ -480,5 +446,5 @@
     // 254 because b<=max and not b<max
     const double sdev = sqrt(sq-sum*sum);
-    const byte   max  = sum+fCut*sdev>254 ? 254 : (byte)(sum+fCut*sdev);
+    const uint8_t   max  = sum+fCut*sdev>254 ? 254 : (uint8_t)(sum+fCut*sdev);
 
     //
@@ -490,5 +456,5 @@
         for (int y=y0; y<y1; y++)
         {
-            byte &b = fImg[y*fW+x];
+            uint8_t &b = fImg[y*fW+x];
             if (b<=max)
                 b = 0;
@@ -531,10 +497,10 @@
     //    cout << "Sum/n = " << sum << "/" << n << " = " << (n==0?0:mag/n) << endl;
 
-    leds.Add(mx, my, 0, 0, -2.5*log10((float)mag)+13.7);
+    leds.push_back(Led(mx, my, 0, -2.5*log10((float)mag)+13.7));
 }
 
 void FilterLed::Stretch() const
 {
-    byte min, max;
+    uint8_t min, max;
     GetMinMax(25, &min, &max);
 
@@ -544,6 +510,6 @@
     const float scale = 255./(max-min);
 
-    byte *b = fImg;
-    const byte *e = fImg+fW*fH;
+    uint8_t *b = fImg;
+    const uint8_t *e = fImg+fW*fH;
 
     while (b<e)
@@ -559,5 +525,5 @@
             continue;
         }
-        *b = (byte)((*b-min)*scale);
+        *b = (uint8_t)((*b-min)*scale);
         b++;
     }
Index: trunk/FACT++/drive/FilterLed.h
===================================================================
--- trunk/FACT++/drive/FilterLed.h	(revision 18620)
+++ trunk/FACT++/drive/FilterLed.h	(revision 18621)
@@ -2,17 +2,13 @@
 #define CAOS_FilterLed
 
-#ifndef __CINT__
-#include <TROOT.h>
-#endif
-
-typedef unsigned char byte;
+#include <stdint.h>
+#include <vector>
 
 class Led;
-class Leds;
 class Ring;
 
 class FilterLed
 {
-    byte *fImg;
+    uint8_t *fImg;
     int fW;
     int fH;
@@ -21,8 +17,8 @@
     float fCut;
 
-    Float_t FindCluster(int &cnt, float *sum, UInt_t x, UInt_t y,
-                        UInt_t x0, UInt_t y0, UInt_t x1, UInt_t y1) const;
+    float FindCluster(int &cnt, float *sum, uint32_t x, uint32_t y,
+                        uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1) const;
 
-    void GetMinMax(const int offset, byte *min, byte *max) const;
+    void GetMinMax(const int offset, uint8_t *min, uint8_t *max) const;
     int  GetMeanPosition(const int x, const int y, const int boxx, const int boxy) const;
     int  GetMeanPosition(const int x, const int y, const int boxx, const int boxy,
@@ -40,11 +36,11 @@
 
 public:
-    FilterLed(byte *img, int w, int h, double cut=2.5)
-      : fImg(img), fW(w), fH(h), fBoxX(w), fBoxY(h), fCut(cut)
+    FilterLed(uint8_t *img, int w, int h, double cut=2.5) : fImg(img),
+        fW(w), fH(h), fBoxX(w), fBoxY(h), fCut(cut)
     {
     }
 
-    FilterLed(byte *img, int w, int h, int boxx, int boxy, double cut=2.5)
-      : fImg(img), fW(w), fH(h), fBoxX(boxx), fBoxY(boxy), fCut(cut)
+    FilterLed(uint8_t *img, int w, int h, int boxx, int boxy, double cut=2.5) : fImg(img),
+        fW(w), fH(h), fBoxX(boxx), fBoxY(boxy), fCut(cut)
     {
     }
@@ -53,26 +49,21 @@
     void SetBox(int box)   { fBoxX = fBoxY = box; }
     void SetBox(int boxx, int boxy)   { fBoxX = boxx; fBoxY = boxy; }
-    void SetCut(float cut) { fCut = cut; } 
-    void FindStar(Leds &leds, int xc, int yc, bool circle=false) const;
-    
-    void Execute(Leds &leds, int xc, int yc, double &bright) const;
-    void Execute(Leds &leds, int xc, int yc) const;
-    void Execute(Leds &leds) const { Execute(leds, fW/2, fH/2); }
-    void ExecuteAndMark(Leds &leds, int xc, int yc) const;
-    void ExecuteAndMark(Leds &leds, int xc, int yc, double &bright) const;
-    void ExecuteAndMark(Leds &leds) const { ExecuteAndMark(leds, fW/2, fH/2); }
-    void Execute(int xc, int yc) const;
-    void Execute() const { Execute(fW/2, fH/2); }
+    void SetCut(float cut) { fCut = cut; }
+    void FindStar(std::vector<Led> &leds, int xc, int yc, bool circle=false) const;
+
+    void Execute(std::vector<Led> &leds, int xc, int yc, double &bright) const;
+    void Execute(std::vector<Led> &leds, int xc, int yc) const;
+    void Execute(std::vector<Led> &leds) const { Execute(leds, fW/2, fH/2); }
+
     void MarkPoint(const Led &led) const;
-    void MarkPoint(Float_t x, Float_t y, Float_t mag) const;
+    void MarkPoint(float x, float y, float mag) const;
     void Stretch() const;
-    void DrawCircle(float cx, float cy, float r, byte col=0x40) const;
-    void DrawCircle(float r, byte col=0x40) const { DrawCircle(fW/2, fH/2, r, col); }
-    void DrawCircle(const Ring &c, byte col=0x40) const;
-    void DrawCircle(const Ring &c, double r, byte col) const;
-    void DrawHexagon(float cx, float cy, float r, byte col=0x40) const;
-    void DrawHexagon(const Ring &c, double r, byte col) const;
 
-    ClassDef(FilterLed, 0)
+    void DrawCircle(float cx, float cy, float r, uint8_t col=0x40) const;
+    void DrawCircle(float r, uint8_t col=0x40) const { DrawCircle(fW/2, fH/2, r, col); }
+    void DrawCircle(const Ring &c, uint8_t col=0x40) const;
+    void DrawCircle(const Ring &c, double r, uint8_t col) const;
+    void DrawHexagon(float cx, float cy, float r, uint8_t col=0x40) const;
+    void DrawHexagon(const Ring &c, double r, uint8_t col) const;
 };
 
