package yi.iu.ft.local;

public class RegularGridGlobalHistogram extends GridGlobalHistogram {
  /**
   * Grid number on x and y direction
   */
  int m_gridNumOnX, m_gridNumOnY;

  int m_singleGridBinNum;

  public RegularGridGlobalHistogram(int grid_num_x, int grid_num_y, int single_grid_bin_num) {
    m_gridNumOnX = grid_num_x;
    m_gridNumOnY = grid_num_y;
    m_singleGridBinNum = single_grid_bin_num;
  }

  /**
   * The bin number of a feature.  The feature index is given in 1 x 1 grid.
   * The histogram will be made from several 1 x 1 grid histogram.  The first
   * one corresponds to the grid(0,0); the second, (1,0); etc.  To make it easy,
   * assume that the feature_x is fallen into [0, image_width).  Eg. the image
   * width is 640, then the feature_x is supposed be in [0, 640).  Actually, it
   * should be [0, 639], but I use [0, 640) for simply.  If the grid number on x
   * direction is 2, then [0, 320), [320, 640) are the ranges
   * @param index
   * @param feature_x
   * @param feature_y
   * @param image_width
   * @param image_height
   * @return
   */
  public int getBinIndex(int index, double feature_x, double feature_y, int image_width, int image_height) {

    int grid_index_x = (int)(feature_x / image_width * m_gridNumOnX);
    int grid_index_y = (int)(feature_y / image_height * m_gridNumOnY);

    int grid_index = grid_index_y * m_gridNumOnX + grid_index_x;

    return grid_index * m_singleGridBinNum + index;

  }
  public int getBinNum() {
    return m_gridNumOnX * m_gridNumOnY * m_singleGridBinNum;
  }
}