package yi.or;

import java.awt.*;

import yi.iu.processor.*;
import yi.iu.processor.morph.*;
import yi.iu.ui.DisplayFrame;

abstract public class OR_simple extends ObjRcg
{
    static int DIFF_PAD_LENGTH_ADJUST=2;  //because the use of pad length could be different, also because small pad length leads
                    //to missing of some possible region pixels, so dilation the result region a little
                    
    //recognition based on the calculated hsi and laws results
    public Region recognition(int source[], int[][] hsi, int[][] laws, int[][] diff, Dimension d)
    {
        int size=d.width*d.height;
        Region rgn= null;
        
        int[][] filter_hsi= getHSIFilter();
        if (filter_hsi!=null) {
            if (VERBOSE) System.err.println("based on hsi...");
            Region hsi_rgn= new Region(d).rangeFilter(hsi,filter_hsi);
            if (VISUALIZE) hsi_rgn.display("hsi",source);
            if (rgn==null) rgn= hsi_rgn;
            else rgn.intersection(hsi_rgn);
        }
        
        int[][] filter_laws= getLawsFilter();
        if (filter_laws!=null) {
            if (VERBOSE) System.err.println("based on laws...");
            Region laws_rgn= new Region(d).rangeFilter(laws,filter_laws);
            if (VISUALIZE) laws_rgn.display("laws",source);
            //dilate the region to compensate the calculation of mean
            int dilation_r= (LAWS_ENER_PAD_LENGTH)*2+1;
            //dilate the region to compensate the mean calculation within too small block
            dilation_r+=getLawsDilationWidth()*2+1;
            laws_rgn.dilation(Morph.BLOCK, dilation_r);
            if (rgn==null) rgn= laws_rgn;
            else rgn.intersection(laws_rgn);
        }
        
        int[][] filter_diff= getDiffFilter();
        if (filter_diff!=null) {
            if (VERBOSE) System.err.println("based on diff...");
            Region diff_rgn= new Region(d).rangeFilter(diff,filter_diff);
            if (VISUALIZE) diff_rgn.display("diff",source);
            int dilation_r= getDiffDilationWidth()*2+1;;
            diff_rgn.dilation(Morph.BLOCK, dilation_r);
            if (rgn==null) rgn= diff_rgn;
            else rgn.intersection(diff_rgn);
        }
        
        if (VISUALIZE) rgn.display("simple_rst",source);
        
        System.gc();
        return rgn;
    }
    
    public int[][] getHSIFilter() {return null;}
    public int[][] getLawsFilter() {return null;}
    public int[][] getDiffFilter() {return null;}
    
    public int getLawsDilationWidth() {return DIFF_PAD_LENGTH_ADJUST;}
    public int getDiffDilationWidth() {return 2;}
/*    
    public int getArguNum() { return 2;}
    
    public void setArgument(int i, String st)
    {
        if (st.length()==0) return;
        if (i==0) {
            LAWS_ENER_PAD_LENGTH= Integer.valueOf(st).intValue();
        }
        if (i==1) {
            DIFF_PAD_LENGTH_ADJUST= Integer.valueOf(st).intValue();
        }
    }
    
    
    public String getArgument(int i)
    {
        if (i==0) return (new Integer(LAWS_ENER_PAD_LENGTH)).toString();
        if (i==1) return (new Integer(DIFF_PAD_LENGTH_ADJUST)).toString();
        return null;
    }
    
    public String getArguName(int i) 
    {
        if (i==0) return "laws en_pad_len";
        if (i==1) return "laws dilation adj";
        
        return null;
    }
*/    
}