package yi.or;

import java.awt.*;
import yi.iu.processor.*;
import yi.iu.processor.channel.*;
import yi.iu.processor.texture.*;

public abstract class ObjRcg extends ImageProcessor
{
    boolean VERBOSE=true;
    boolean VISUALIZE=false;

    public static int LAWS_ENER_PAD_LENGTH=3;  //could be different from that in RegionInfor, see RegionInfor.java for explaination

    abstract public Region recognition(int source[], int[][] hsi, int[][] laws, int[][] diff, Dimension d);
    abstract public String objName();

    //the simple object recognition is based on HSI information and Laws texture information
    //calculate the HSI and Laws first, and call the recognition on HsiAndLaws
    public Region recognition(int source[], Dimension d)
    {
        if (VERBOSE) System.err.println("calculate hsi...");
        int[][] hsi= (new CYMaker()).getProcessed_ex(source, d);

        if (VERBOSE) System.err.println("calculate laws...");
        int[][] laws= (new LawsMaker()).getProcessed_ex(source, d, LAWS_ENER_PAD_LENGTH);

        //if (VERBOSE) System.err.println("calculate diff...");
        //int[][] diff= (new DiffMaker()).getProcessed_ex(source, d);
        int[][] diff=null;

        Region rst= recognition(source, hsi, laws, diff, d);
        hsi=null;laws=null;
        System.gc();
        return rst;
    }

    public int[] getProcessed(int[] source, Dimension d)
    {
        Region rgn= recognition (source, d);
        return rgn.getArray();
    }
    public int[] getProcessedPseudoColor(int[] source, Dimension d)
    {
        Region rgn= recognition (source, d);
        //return rgn.getMasked(source);
        int[] map_1= yi.util.ImageUtil.twoD2oneD(rgn.map);
        int[] img= yi.util.ImageUtil.makeNewImageFromLabel(map_1);

        (new yi.iu.ui.DisplayFrame("rst",img,d.width,d.height)).show();

        return img;
    }

    public static String[] getAllORs() {
        String[] ors= {
            "yi.or.OR_sky",
            "yi.or.OR_sea",
            "yi.or.OR_boat",
            "yi.or.OR_sailboat",
        };
        return ors;
    }

    public static Class[] getAllORCs() {
        Class[] ors= {
            yi.or.OR_sky.class,
            yi.or.OR_sea.class,
            yi.or.OR_boat.class,
            yi.or.OR_sailboat.class,
        };
        return ors;
    }

    public static String[] getAllObjNames() {
                Class[] orcs= getAllORCs();
                String ons[]= new String[orcs.length];

            try {
                for (int i=0;i<ons.length;i++) {
                    ObjRcg or= (ObjRcg)orcs[i].newInstance();
                    ons[i]= or.objName();
                }
            } catch (Exception e) {
                System.err.println("Can't found the object recognition processor");
            }
            return ons;
        }

        //get all the names of all the objects under examination
        public String[] getAllObjNames(ObjRcg[] ors) {
            String[] orn= new String[ors.length];
            for (int i=0;i<orn.length;i++) {
                orn[i]= ors[i].objName();
            }
            return orn;

    }

}