package yi.iu.processor.clc;

import java.util.*;

import java.awt.*;

import yi.iu.processor.*;
import yi.iu.processor.ort.*;
import yi.util.config.*;


/**
 * CLC_CLusteringDemo is the demo wrapper for CLC_Clustering
 */

public class CLC_CLusteringDemo extends ImageProcessor{

  public int scale = 256;

  public int[] getProcessedPseudoColor(int pixels[], Dimension d)
  {
    // process
    try {

      // timing
      long startTime = System.currentTimeMillis();

      // find all the lines in an image
      DPU_Fex dp = new DPU_Fex();
      Vector[] segs= dp.getLinesAndArcs(pixels, d.width, d.height);
      Vector lines= segs[0];
      // put all lines in a line cluster
      LineClusterSet lcs = new LineClusterSet(lines, d.width, d.height);
      // construct a set of line cluster containing only one set
      LineClusterSets lcss = new LineClusterSets(d.width, d.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 = 1; true; i ++) {
        String param_name = "CLC_CLUSTERING_" + i;
        clustering_method_name = Configuration.getStringParameter(
          param_name, null);
        if (clustering_method_name == null) break;
        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.getReusableClusteres(lcss, pixels, d.width, d.height);
      }

      if (clc_clustering == null) { // no method was used
        System.err.println("specifiy the clustering methods using CLC_CLUSTERING_n");
        System.exit(0);
      }

      // print out timing
      long endTime = System.currentTimeMillis();
      System.out.println("running time: " + (endTime-startTime));

      int[] lineimg = lcss.demo(d.width, d.height, false, 2);
      return lineimg;
    } catch (Exception e) {
      System.err.println("CLC_Clustering Terminated.");
      e.printStackTrace();
    }
    return null;

  }

  public int[] getProcessed(int source[], Dimension d) {return null;}

}
