package yi.iu.processor.clc;

import java.util.*;

import yi.iu.imgdb.learn.*;
import yi.iu.processor.ort.*;

/**
 * Wrapper of CLC_Clustering which will generate FeatureRepresentable (as
 * specified in interface RepresentableFeatureGenerator)
 */

public class LineStructGenerator implements RepresentableFeatureGenerator {

  public String[] steps = {
      "yi.iu.processor.clc.CLC_Color",
      "yi.iu.processor.clc.CLC_Orientation",
      "yi.iu.processor.clc.CLC_Spatial"
  };

  public LineStructGenerator() {
  }

  public FeatureRepresentable generateFeatureRepresentable(String feature_type, int[] pixels, int width, int height) {
    FeatureRepresentable rst = null;

    // find all the lines in an image
    yi.iu.processor.ort.DPU_Fex dp = new DPU_Fex();
    Vector[] segs= dp.getLinesAndArcs(pixels, width, height);
    Vector lines= segs[0];

    // put all lines in a line cluster
    LineClusterSet lcs = new LineClusterSet(lines, width, height);
    // construct a set of line cluster containing only one set
    LineClusterSets lcss = new LineClusterSets(width, height);
    lcss.put(lcs, lcs);

    // clustering the lines use the all the clustering method specified in the
    // configurations
    String clustering_method_name = null;
    CLC_Clustering clc_clustering = null;
    for (int i = 0; i < steps.length; i ++) {
      clustering_method_name = steps[i];
      System.out.println("clusterig step " + i + ": " + clustering_method_name);
      try {
        Class clustering_class = Class.forName(clustering_method_name);
        clc_clustering = (CLC_Clustering)clustering_class.newInstance();
      } catch (Exception e) {
        e.printStackTrace();
      }
      lcss = clc_clustering.getClusters(lcss, pixels, width, height);
    }

    return lcss;
  }

}