package yi.iu.processor.color.reg;


import yi.iu.region.*;
import yi.util.io.output.Csvable;
import yi.iu.ft.local.RegionBased;

public class RgbColorRegion implements Csvable, java.io.Serializable, RegionBased{
  public int    r;
  public int    g;
  public int    b;
  Region m_region;

  /**
   * This constructor is for castor only.  Don't call it directly
   */
  public RgbColorRegion() {
  }

  public RgbColorRegion(int r, int g, int b, Region rg) {
    this.r = r;
    this.g = g;
    this.b = b;
    m_region = rg;
  }

  public void setRegion(Region r) {m_region=r;}
  public Region getRegion() {return m_region;}

  public double[][] toCsv() {
    double[] data = new double[] {
      r,
      g,
      b,
      m_region.m_centroidX,
      m_region.m_centroidY,
      m_region.m_majAngle,
      m_region.m_majLength,
      m_region.m_minAngle,
      m_region.m_minLength,
      m_region.m_momentX,
      m_region.m_momentY,
      m_region.m_momentXY,
      m_region.m_size,
      m_region.m_imgWidth,
      m_region.m_imgHeight
    };
    return new double[][] {data};
  }

  public static RgbColorRegion fromCsv(double[] csv) {
    Region r = new Region();
    r.m_centroidX  = (float)csv[3];
    r.m_centroidY = (float)csv[4];
    r.m_majAngle = csv[5];
    r.m_majLength = csv[6];
    r.m_minAngle = csv[7];
    r.m_minLength = csv[8];
    r.m_momentX = (float)csv[9];
    r.m_momentY = (float)csv[10];
    r.m_momentXY = (float)csv[11];
    r.m_size = (int)Math.round(csv[12]);
    r.m_imgWidth = (int)Math.round(csv[13]);
    r.m_imgHeight = (int)Math.round(csv[14]);
    return new RgbColorRegion((int)csv[0], (int)csv[1], (int)csv[2], r);
  }
}