examples/featureTracker/culebrillas.cpp

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 <culebrillas.h>
00026 
00027 bool Culebrilla::addPoint(const QPointF &point, const int frameNumber)
00028         {
00029         // 1. Comprobar que no existe ya un punto en esta culebrilla para el frame actual.
00030         if (frameNumber <= lastFrameNumber)
00031                 {
00032                 std::cout << "ERROR!" << std::endl;
00033                 return false;
00034                 }
00035         
00036         // 2. Si el punto actual está suficientemente separado del último punto añadido, añadirlo
00037         if (norm2(points[lastFrameNumber] - point) < minPointDistance)
00038                 return false;
00039 
00040         points.insert(lastFrameNumber = frameNumber, point);
00041 
00042         return true;
00043         }
00044 
00045 const QPointF Culebrilla::getPointAtFrame(const int frame) const
00046         {
00047         foreach (int key, points.keys())
00048                 if (frame <= key)
00049                         return points[key];
00050 
00051         return points[lastFrameNumber];
00052         }
00053 
00055 
00056 const QList< QList<QPointF> > CulebrillaContainer::getCulebrillasAsPolylines() const
00057         {
00058         QList< QList<QPointF> > result;
00059 
00060         foreach (Culebrilla culebrilla, getCulebrillas())
00061                 result.append(culebrilla.getPointList());
00062         
00063         return result;
00064         }
00065 
00066 void CulebrillaContainer::addMatching(const QPointF sourcePoint, const QPointF destinationPoint)
00067         {
00068         // OJO: comprobar que el punto 'destinationPoint' no está contenido en el conjunto 'newMatchingPoints',
00069         // Sea la culebrilla 'C' la asociada al punto 'sourcePoint' en el conjunto 'lastMatchingPoints':
00070         // 1. Si no existe, la creamos, conteniendo el punto 'sourcePoint'.
00071         Culebrilla C;
00072         if (lastMatchingPoints.contains(sourcePoint))
00073                 C = lastMatchingPoints[sourcePoint];
00074         else
00075                 C = Culebrilla(sourcePoint, actualFrameNumber-1, minPointDistance);
00076 
00077         // 2. Añadimos el punto 'destinationPoint' a la culebrilla 'C'.
00078         C.addPoint(destinationPoint, actualFrameNumber);
00079 
00080         // 3. Asociamos la culebrilla 'C' al punto 'destinationPoint', en la estructura 'newMatchingPoints'.
00081         newMatchingPoints.insert(destinationPoint, C);
00082         }
00083 
00084 void CulebrillaContainer::step()
00085         {
00086         // 0. Eliminamos las culebrillas que se han quedado sin correspondencia en el conjunto 'newMatchingPoints'.
00087         //      ^~~~----··· automáticamente.
00088 
00089         // 1. Copiamos contenido de la estructura 'newMatchingPoints' en 'lastMatchingPoints'.
00090         lastMatchingPoints = newMatchingPoints;
00091 
00092         // 2. Vaciamos la estructura 'newMatchingPoints'.
00093         newMatchingPoints.clear();
00094 
00095         // 3. Incrementamos el valor 'actualFrameNumber' en 1.
00096         actualFrameNumber++;
00097         }