/****************************************************************************
*
* Copyright (c) 2006 by JIA Pei, all rights reserved.
* Copyright (c) 2006 by Vision Open: http://www.visionopen.com/
*
* Author: JIA Pei
* Contact: jp4work@gmail.com
* URL: http://www.visionopen.com/members/jiapei.php
* The author administrates Vision Open -- http://www.visionopen.com
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* This software is partly based on the following open source:
*
* - Boost
* - OpenCV
*
* This software is using IMM Face Database, which can be downloaded from
* http://www2.imm.dtu.dk/~aam/.
*
* M. B. Stegmann, B. K. Ersb{\o}ll, and R. Larsen. FAME - a flexible appearance
* modelling environment. IEEE Trans. on Medical Imaging, 22(10):1319-1331, 2003
*
****************************************************************************/
// $Id: lv_aamtriangle2d.cpp,v 1.1.1.1 2006-09-03 17:49:04 JIA Pei Exp $
#include <string>
#include <iostream>
#include "lv_aamtriangle2d.h"
using namespace std;
double lv_aamtriangle2d::Calc_dD() const
{
double x1, x2, x3, y1, y2, y3;
x1 = this->m_vVertexes[0].x;
x2 = this->m_vVertexes[1].x;
x3 = this->m_vVertexes[2].x;
y1 = this->m_vVertexes[0].y;
y2 = this->m_vVertexes[1].y;
y3 = this->m_vVertexes[2].y;
return (+x2*y3-x2*y1-x1*y3-x3*y2+x3*y1+x1*y2);
}
/*
// Get the warp parameters for a specific point inside the triangle "IdxOfTriangle"
void lv_aamtriangle2d::GetWarpParameters(const CvPoint2D32f &p, double &alpha, double &beta, double &gamma ) const
{
double x, y, x1, x2, x3, y1, y2, y3;
x = p.x;
y = p.y;
x1 = this->m_vVertexes[0].x;
x2 = this->m_vVertexes[1].x;
x3 = this->m_vVertexes[2].x;
y1 = this->m_vVertexes[0].y;
y2 = this->m_vVertexes[1].y;
y3 = this->m_vVertexes[2].y;
alpha = y*x3-y3*x+x*y2-x2*y+x2*y3-x3*y2;
beta = -y*x3+x1*y+x3*y1+y3*x-x1*y3-x*y1;
gamma = -x*y2+x*y1+x1*y2+x2*y-x2*y1-x1*y;
alpha /= this->m_dD;
beta /= this->m_dD;
gamma /= this->m_dD;
}
void lv_aamtriangle2d::GetWarpedPointPositionByKnownParameters(
CvPoint2D32f &p, double alpha, double beta, double gamma) const
{
double x1, x2, x3, y1, y2, y3;
x1 = this->m_vVertexes[0].x;
x2 = this->m_vVertexes[1].x;
x3 = this->m_vVertexes[2].x;
y1 = this->m_vVertexes[0].y;
y2 = this->m_vVertexes[1].y;
y3 = this->m_vVertexes[2].y;
p.x = alpha*x1 + beta*x2 + gamma*x3;
p.y = alpha*y1 + beta*y2 + gamma*y3;
}
*/