Skip to content
Snippets Groups Projects
ProcrustesAnalysis.java 2.25 KiB
Newer Older
package cz.fidentis.analyst.procrustes;

import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.procrustes.exceptions.ProcrustesAnalysisException;
import cz.fidentis.analyst.procrustes.utils.ProcrustesAnalysisUtils;
import java.util.List;

 */
public class ProcrustesAnalysis {

    private final List<FeaturePoint> orderedFpList1;
    private final List<FeaturePoint> orderedFpList2;

    /**
     * 
     * @param fpList1
     * @param fpList2
     * @throws ProcrustesAnalysisException 
     */
    public ProcrustesAnalysis(List<FeaturePoint> fpList1, List<FeaturePoint> fpList2) throws ProcrustesAnalysisException {
        if (fpList1.size() != fpList2.size()) {
            throw new ProcrustesAnalysisException("Lists of feature points do not have the same size");
        }
        orderedFpList1 = ProcrustesAnalysisUtils.sortByFeaturePointType(fpList1);
        orderedFpList2 = ProcrustesAnalysisUtils.sortByFeaturePointType(fpList2);

        if (!ProcrustesAnalysisUtils.checkfeaturePointsType(orderedFpList1, orderedFpList2)) {
            throw new ProcrustesAnalysisException("Lists of feature points do not have the same feature point types");
        }
    }

    /**
     * Calculate scaling ratio of how much the appropriate object corresponding to the second feature
     * point list has to be scale up or shrunk. 
     * 
     * If returned ratioValue is greater 1 then it means that the second object should be scaled up ratioValue times.
     * If returned ratioValue is smaller 1 than the second object should be shrunk.
     * 
     * @return ratioValue
     */
    private double calculateScalingValue() {
        double[] distancesOfList1 = ProcrustesAnalysisUtils.calculateMeanDistancesFromOrigin(orderedFpList1);
        double[] distancesOfList2 = ProcrustesAnalysisUtils.calculateMeanDistancesFromOrigin(orderedFpList2);

        double[] ratioArray = new double[distancesOfList1.length];
        double ratioValue = 0;

        for (int i = 0; i < distancesOfList1.length; i++) {
            ratioArray[i] += distancesOfList1[i] / distancesOfList2[i];
        }
        for (double ratio: ratioArray) {
            ratioValue += ratio;
        }

        return ratioValue / distancesOfList1.length;