//Source file: D:\\Projects\\src\\yi\\iu\\imgdb\\learn\\StatModelAdapter.java

package yi.iu.imgdb.learn;

import java.util.LinkedList;
import yi.util.io.output.*;
import java.io.*;
import yi.util.config.*;
import yi.util.io.*;
import java.util.*;
import yi.ds.hash.*;
import org.jmat.gui.*;

/**
 * Create model to learn the object features from images.
 */
public class StatModelAdapter implements Serializable, Configurable{

  /**
   * verbose in test.  Usually when measuring the proformance, we don't want
   * to verbose.  But some times, we want to see more when analysis a testing
   */
  transient public boolean VERBOSE_IN_TEST = false;


  transient protected ImgDataCenter m_imgDataCenter;
  protected LinkedList m_featureList;
  transient protected LinkedList m_imageList;
  protected LinkedList m_objectList;

  static final long serialVersionUID = -2428622272202019328L;

  protected StatModelAdapter() {
    Configuration.configParameters(this);
  }

  /**
   * @param data_center
   * @param features
   * @param imgs
   */
  public StatModelAdapter(ImgDataCenter data_center, LinkedList img_list, LinkedList ft_list, LinkedList obj_list)
  {
    Configuration.configParameters(this);
    m_imgDataCenter = data_center;
    m_featureList = (ft_list != null)? ft_list: data_center.getFeatureList();
    m_imageList = (img_list != null)? img_list: data_center.getImageList();
    m_objectList = (obj_list != null)? obj_list: data_center.getObjectList();
  }

  /**
   * Test the given model with the specified images
   * @param imgs
   * @return StatTestRst
   */
  public StatTestRst test(LinkedList imgs) {
    return null;
  }

  /**
   * Locate the object in each of the image.  Probably some demo images are
   * written to the disk and a html index file is generated
   * @param imgs
   * @param obj_list
   * @param ft_desc
   * @param rp_desc
   * @param exp_name
   * @return
   * @throws Exception
   */
  public boolean locateObject(LinkedList imgs, LinkedList obj_list,
                              FeatureDescriptor ft_desc, RepresentationDescriptor rp_desc,
                              String exp_name) throws Exception{
    return false;
  }

  /**
   * Locate the objects in each of the image using features specified in the
   * "ft_descs".  Since different feature may use different rescaled image,
   * the size of the result is passed in too.
   * @param imgs
   * @param obj_list
   * @param ft_descs
   * @param rp_descs
   * @param exp_name
   * @param size
   * @return
   * @throws Exception
   */
  public boolean locateObject(LinkedList imgs, LinkedList obj_list,
                              FeatureDescriptor[] ft_descs, RepresentationDescriptor[] rp_descs,
                              String exp_name, int rst_size) throws Exception{
    return false;
  }

  /**
   * Write the image data center as a java object to file
   * @param file
   */
  public void writeToFile(String file) throws java.io.IOException {
    DOU_Ser.output(file, this);
  }

  /**
   * create a image data center reading from a file
   *
   * @param file
   * @return ImgDataCenter
   */
  public static StatModelAdapter createFromFile(String file) throws Exception {
    return (StatModelAdapter) yi.util.io.input.DIU_Ser.input(file);
  }

  public ImgDataCenter getImgDataCenter(){
    return m_imgDataCenter;
  }

  public LinkedList getFeatureList(){
    return m_featureList;
  }

  public LinkedList getImageList(){
    return m_imageList;
  }

  public LinkedList getObjectList(){
    return m_objectList;
  }


  /**
   * Print out the model for review
   */
  public static class Print {
    public final static String USAGE = "Usage: -m model_file";

    public static void main(String[] args) {

      // init configuration
      Configuration.init(args);
      String represent_path = Configuration.getParameter("REPRESENTATION_PATH", "");
      String learn_path = Configuration.getParameter("LEARNING_PATH", "");

      try {

        String model_file = ReadArgu.getOption('m', args);
        if (model_file == null) {
          System.err.println(USAGE);
          System.exit(1);
        }

        StatModelAdapter sma = (StatModelAdapter)yi.util.io.input.DIU_Ser.input(learn_path + model_file);
        System.out.print(sma);

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

  public String[] getParameterNames() {
    return new String[] {};
  }


}