package yi.iu.imgdb.learn;

import java.util.*;
import yi.iu.region.*;
import yi.graph.polygon.*;
import java.awt.Dimension;

public class PolygonFeatureRepresentationList
    extends RgnFeatureRepresentationList {

  /**
   * @param image_width
   * @param image_height
   */
  public PolygonFeatureRepresentationList(int ft_dim, int image_width, int image_height) {
    super(ft_dim, image_width, image_height);
  }

  /**
   * Draw the regions with the color representing the score of corresponding
   * feature.  After having the score from FeatureScoringCapable, the score
   * will be scaled by "scale", and then shifted by "shift".  The resultant
   * number will be put into the given pixel array
   * @param scoring
   * @param shift
   * @param scale
   * @return
   */
  public int[] drawScoreDemo(Object obj, FeatureScoringCapable scoring, double shift,
                            double scale) {
    int[] pixels = new int[imgWidth * imgHeight];
    // loop through each feature
    for (Iterator i=iterator(); i.hasNext(); ) {
      PolygonFeatureRepresentation ft = (PolygonFeatureRepresentation)i.next();
      double[] data = ft.data;
      // get the score for the feature
      double score = scoring.getFeatureScore(data, obj);
      // shift and scale the score
      score = (score * scale) + shift;
      // get the color from the score
      int color = (int)Math.round(score);

      GenericPolygon poly = ft.region;
      poly.filledDraw(pixels, imgWidth, imgHeight, color);
    }
    return pixels;
  }

  public int[] colorDemo(Dimension d) {
    d.width = imgWidth; d.height = imgHeight;

    int[] pixels = new int[imgWidth * imgHeight];
    // loop through each feature
    int i_index = 1;
    for (Iterator i=iterator(); i.hasNext(); i_index++) {
      PolygonFeatureRepresentation ft = (PolygonFeatureRepresentation)i.next();
      double[] data = ft.data;

      GenericPolygon poly = ft.region;
      poly.draw(pixels, imgWidth, imgHeight, i_index, 1);
    }
    return yi.util.ImageUtil.makeNewImageFromLabel(pixels, true);
  }

}