//
// Created by martin on 23. 2. 2021.
//

#ifndef ARC_MATRIX_AAMBUILD_H
#define ARC_MATRIX_AAMBUILD_H

#include "KDTree.h"

//// equations D_{i,k} and T_{i,k} from AAM construct in original paper
double D(std::vector<cv::Point2i> A,std::vector<cv::Point2i> B);

double T(std::vector<std::vector<cv::Point2i>>& arcs,int i, int k);

/**
 * builds Arc adjacency matrix
 * @param arcs array of all the arcs in the image
 * @param arc_index arcs stored with their appropriate indexes
 * @param lambda_arc a threshold parameter
 * @return Arc adjacency matrix
 */
std::vector<std::vector<int>> AAM_Build (std::vector<std::vector<cv::Point2i>> arcs, std::vector<posArc>& arc_index,const double& lambda_arc);

/**
 * decides whether arc2 is in arc1's search region
 * @param arc1 first arc
 * @param arc2 second arc
 * @param s decides whether last point or first point of the arc is used in calculation
 * @return true if within the search region
 */
bool RegionConstraint (std::vector<cv::Point2i>& arc1, std::vector<cv::Point2i>& arc2, bool s);

/**
 * helper function for region constraint
 * @param A begining point of the arc
 * @param B end point of the arc
 * @param M position of point from other arc
 * @return 1 if M is above A->B -1 if below
 */
int side(cv::Point2i A,cv::Point2i B,cv::Point2i M);
/**
 * calculates curvature constraint
 * @param arc1 first arc
 * @param arc2 second arc
 * @param L_arc a threshold parameter
 * @return true if curvature constraint is fulfilled
 */
bool CurveCons(std::vector<cv::Point2i> &arc1, std::vector<cv::Point2i> &arc2, double L_arc);
#endif //ARC_MATRIX_AAMBUILD_H
