void CShapeModel::GenerateShapeWithPos(double Tx, double Ty, double s, double theta, CVisDVector& param, CShape& desshape,EDataAnalysisMethod eMethod /*=ePCA*/) { GenerateShape(param, desshape, eMethod); double a = s * cos(theta); double b = s * sin(theta); double x, y; int m_iNbPoint = desshape.PointNum(); //rotate and scale for (int i = 0; i < m_iNbPoint; i++) { x = desshape.PointX(i); y = desshape.PointY(i); desshape.PointX(i) = a * x - b * y; desshape.PointY(i) = b * x + a * y; } //translate desshape.Translate(Tx, Ty); }
void CShapeModel::ApplyShapePos(double& Tx, double& Ty, double& s, double& theta, CShape& desShape, const CShape& normaledShape) { double a = s * cos(theta); double b = s * sin(theta); double x, y; int m_iNbPoint = normaledShape.PointNum(); desShape.Resize(m_iNbPoint); //rotate and scale for (int i = 0; i < m_iNbPoint; i++) { x = normaledShape.PointX(i); y = normaledShape.PointY(i); desShape.PointX(i) = a * x - b * y; desShape.PointY(i) = b * x + a * y; } //translate desShape.Translate(Tx, Ty); }
void CShapeModel::GetShapeParamAndPos(double& Tx, double& Ty, double& s, double& theta, CVisDVector& param, const CShape& srcshape, EDataAnalysisMethod eMethod /*=ePCA*/) { CShape& refShape = m_AvgShape; CShape workShape = srcshape; int m_iNbPoint = srcshape.PointNum(); // 1. Get the tranlate parameter and set the center of srcshape to (0,0) workShape.CenterPoint(Tx, Ty); workShape.Translate(-Tx, -Ty); double x, y, x1, y1; // 2. get the align parameter to avgshape (x',y') // SXX1 = E(x*x') SYY1 = E(y*y') SXY1 = E(x*y') SYX1 = E(y*x') // SXX = E(x*x) SYY = E(y*y) // x' = ax -by // y' = bx +ay // a = (SXX1+SYY1)/(SXX+SYY) // b = (SXY1-SYX1)/(SXX+SYY) double SXX, SYY, SXX1, SYY1, SXY1, SYX1; SXX = SYY = SXX1 = SYY1 = SXY1 = SYX1 = 0.0; for (int i = 0; i < m_iNbPoint; i++) { x = workShape.PointX(i); y = workShape.PointY(i); x1 = refShape.PointX(i); y1 = refShape.PointY(i); SXX += x * x; SYY += y * y; SXX1 += x * x1; SYY1 += y * y1; SXY1 += x * y1; SYX1 += y * x1; } if (SXX + SYY == 0) return; double a = (SXX1 + SYY1) / (SXX + SYY); double b = (SXY1 - SYX1) / (SXX + SYY); // 3. align the workshape // x' = ax -by // y' = bx +ay for (i = 0; i < m_iNbPoint; i++) { x = workShape.PointX(i); y = workShape.PointY(i); workShape.PointX(i) = a * x - b * y; workShape.PointY(i) = b * x + a * y; } // 4. project into tangent space double SX1X1; SX1X1 = SXX1 = 0; for (i = 0; i < m_iNbPoint; i++) { x = workShape.PointX(i); y = workShape.PointY(i); x1 = refShape.PointX(i); y1 = refShape.PointY(i); SX1X1 += x1 * x1; SXX1 += x * x1; } double stangent = SX1X1 / SXX1; workShape.Scale(stangent); // 5. get the pos and shape parameter s = sqrt(a * a + b * b) * stangent; s = 1.0 / s; theta = - atan2(b, a); GetShapeParam(param, workShape, eMethod); }