examples/featureTracker/culebrillas.h

00001 /*
00002  *      Copyright (C) 2007, 2008. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00024 
00025 #include <qvmath.h>
00026 #include <qvdta.h>
00027 #include <qvip.h>
00028 
00029 #include <QVImageCanvas>
00030 #include <QVMatrix>
00031 #include <QVWorker>
00032 
00033 #ifndef CULEBRILLAS_H
00034 #define CULEBRILLAS_H
00035 #ifndef DOXYGEN_IGNORE_THIS
00036 class Culebrilla
00037         {
00038         public:
00039                 Culebrilla(const QPointF &point, const int frameNumber, const double minPointDistance):
00040                         firstFrameNumber(frameNumber), lastFrameNumber(frameNumber), minPointDistance(minPointDistance), points()
00041                         { points.insert(frameNumber, point); }
00042 
00043                 Culebrilla(const Culebrilla &culebrilla):
00044                         firstFrameNumber(culebrilla.firstFrameNumber), lastFrameNumber(culebrilla.lastFrameNumber),
00045                         minPointDistance(culebrilla.minPointDistance), points(culebrilla.points)
00046                         { }
00047 
00048                 Culebrilla(): firstFrameNumber(-1), lastFrameNumber(-1), minPointDistance(-1), points() { }
00049 
00051 
00052                 bool operator==(const Culebrilla culebrilla) const
00053                         {
00054                         if (getFirstFrameNumber() != culebrilla.getFirstFrameNumber())
00055                                 return false;
00056                         if (getPointAtFrame(getFirstFrameNumber()) != culebrilla.getPointAtFrame(culebrilla.getFirstFrameNumber()) )
00057                                 return false;
00058 
00059                         return true;
00060                         };
00061 
00063 
00064                 const int getNumberOfFrames()   const { return 1 + lastFrameNumber - firstFrameNumber; }
00065                 const int getFirstFrameNumber() const { return firstFrameNumber; }
00066                 const int getLastFrameNumber()  const { return lastFrameNumber; }
00067                 QList<QPointF> getPointList()   const { return points.values(); }
00068 
00069                 bool addPoint(const QPointF &point, const int frameNumber);
00070                 const QPointF getPointAtFrame(const int frame) const;
00071 
00072         private:
00073                 // Guardaremos los puntos de la culebrilla, correspondientes a sus fotogramas, y el fotograma cero,
00074                 // o el nĂºmero del primer fotograma en que aparece la culebrilla.
00075                 int firstFrameNumber, lastFrameNumber;
00076                 double minPointDistance;
00077 
00078                 QMap<int, QPointF> points;
00079         };
00080 
00081 
00082 class CulebrillaContainer
00083         {
00084         public:
00085                 CulebrillaContainer(const double minPointDistance = 0.005):
00086                         lastMatchingPoints(), newMatchingPoints(), actualFrameNumber(0), minPointDistance(minPointDistance)
00087                         { }
00088 
00089                 const int getActualFrameNumber()                const { return actualFrameNumber; }
00090                 const QList< Culebrilla > getCulebrillas()      const { return newMatchingPoints.values(); }
00091                 const QList< QList<QPointF> > getCulebrillasAsPolylines() const;
00092                 void addMatching(const QPointF sourcePoint, const QPointF destinationPoint);
00093                 void step();
00094 
00095         private:
00096                 // Guardaremos los puntos del anterior fotograma que corresponden a la cola de una culebrilla.
00097                 QHash<QPointF, Culebrilla> lastMatchingPoints, newMatchingPoints;
00098                 int actualFrameNumber;
00099                 const double minPointDistance;
00100 
00101         };
00102 
00103 Q_DECLARE_METATYPE(CulebrillaContainer);
00104 
00105 // For QSet<Culebrilla>
00106 inline uint qHash(const Culebrilla &culebrilla) { return qHash(culebrilla.getFirstFrameNumber()) + qHash(culebrilla.getPointAtFrame(culebrilla.getFirstFrameNumber())); }
00107 Q_DECLARE_METATYPE(QSet<Culebrilla>);
00108 #endif
00109 #endif