examples/realtimePlanarRectificator/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 <QVImageCanvas>
00026 
00027 #include <qvmath.h>
00028 #include <qvdta.h>
00029 #include <qvip.h>
00030 
00031 #include <QVMatrix>
00032 #include <QVWorker>
00033 
00034 #ifndef CULEBRILLAS_H
00035 #define CULEBRILLAS_H
00036 #ifndef DOXYGEN_IGNORE_THIS
00037 class Culebrilla
00038         {
00039         public:
00040                 Culebrilla(const QPointF &point, const int frameNumber, const double minPointDistance):
00041                         firstFrameNumber(frameNumber), lastFrameNumber(frameNumber), minPointDistance(minPointDistance), points()
00042                         { points.insert(frameNumber, point); }
00043 
00044                 Culebrilla(const Culebrilla &culebrilla):
00045                         firstFrameNumber(culebrilla.firstFrameNumber), lastFrameNumber(culebrilla.lastFrameNumber),
00046                         minPointDistance(culebrilla.minPointDistance), points(culebrilla.points)
00047                         { }
00048 
00049                 Culebrilla(): firstFrameNumber(-1), lastFrameNumber(-1), minPointDistance(-1), points() { }
00050 
00052 
00053                 bool operator==(const Culebrilla culebrilla) const
00054                         {
00055                         if (getFirstFrameNumber() != culebrilla.getFirstFrameNumber())
00056                                 return false;
00057                         if (getPointAtFrame(getFirstFrameNumber()) != culebrilla.getPointAtFrame(culebrilla.getFirstFrameNumber()) )
00058                                 return false;
00059 
00060                         return true;
00061                         };
00062 
00064 
00065                 const int getNumberOfFrames()   const { return 1 + lastFrameNumber - firstFrameNumber; }
00066                 const int getFirstFrameNumber() const { return firstFrameNumber; }
00067                 const int getLastFrameNumber()  const { return lastFrameNumber; }
00068                 QList<QPointF> getPointList()   const { return points.values(); }
00069 
00070                 bool addPoint(const QPointF &point, const int frameNumber);
00071                 const QPointF getPointAtFrame(const int frame) const;
00072 
00073         private:
00074                 // Guardaremos los puntos de la culebrilla, correspondientes a sus fotogramas, y el fotograma cero,
00075                 // o el nĂºmero del primer fotograma en que aparece la culebrilla.
00076                 int firstFrameNumber, lastFrameNumber;
00077                 double minPointDistance;
00078 
00079                 QMap<int, QPointF> points;
00080         };
00081 
00082 
00083 class CulebrillaContainer
00084         {
00085         public:
00086                 CulebrillaContainer(const double minPointDistance = 0.005):
00087                         lastMatchingPoints(), newMatchingPoints(), actualFrameNumber(0), minPointDistance(minPointDistance)
00088                         { }
00089 
00090                 const int getActualFrameNumber()                const { return actualFrameNumber; }
00091                 const QList< Culebrilla > getCulebrillas()      const { return newMatchingPoints.values(); }
00092                 const QList< QList<QPointF> > getCulebrillasAsPolylines() const;
00093                 void addMatching(const QPointF sourcePoint, const QPointF destinationPoint);
00094                 void step();
00095 
00096         private:
00097                 // Guardaremos los puntos del anterior fotograma que corresponden a la cola de una culebrilla.
00098                 QHash<QPointF, Culebrilla> lastMatchingPoints, newMatchingPoints;
00099                 int actualFrameNumber;
00100                 const double minPointDistance;
00101 
00102         };
00103 
00104 Q_DECLARE_METATYPE(CulebrillaContainer);
00105 
00106 // For QSet<Culebrilla>
00107 inline uint qHash(const Culebrilla &culebrilla) { return qHash(culebrilla.getFirstFrameNumber()) + qHash(culebrilla.getPointAtFrame(culebrilla.getFirstFrameNumber())); }
00108 Q_DECLARE_METATYPE(QSet<Culebrilla>);
00109 #endif
00110 #endif