package yi.iu.processor.clc;

import yi.iu.processor.clc.*;
import yi.iu.processor.*;
import yi.iu.ui.*;
import yi.iu.processor.ort.*;
import yi.util.ImageUtil;

import java.awt.*;
import java.io.*;
import java.util.*;

public class LineClusterDemo extends yi.iu.processor.ImageProcessor
{
    int testCluster= -1;
    int fromCLs= -1;
    int interTest2= -1;

    public int getArguNum() { return 3;}

    public void setArgument(int i, String st)
    {
        if (st.length()==0) return;
        if (i==0) testCluster= Integer.valueOf(st).intValue();
        if (i==1) fromCLs= Integer.valueOf(st).intValue();
        if (i==2) interTest2= Integer.valueOf(st).intValue();
    }

    public String getArgument(int i)
    {
        if (i==0) return (new Integer(testCluster)).toString();
        if (i==1) return (new Integer(fromCLs)).toString();
        if (i==2) return (new Integer(interTest2)).toString();
        return null;
    }

    public String getArguName(int i)
    {
        if (i==0) return "TestCluster";
        if (i==1) return "from lineclusters";
        if (i==2) return "OutputCluster2";
        return null;
    }

    public int[] getProcessed(int source[], Dimension d)
    {
        return null;
    }
    public int[] getProcessedPseudoColor(int source[], Dimension d)
    {
        Vector lines= null;
        int[] colors= null;
        String filename= "coloredlines.out";
        if (fromCLs!=-1) filename="csocls.out";
        try {
            ObjectInputStream in= new ObjectInputStream(
                new FileInputStream(filename));
            if (fromCLs==-1) {
                lines= (Vector)in.readObject();
                colors= (int[])in.readObject();
            }
            else {
                LineCluster[] lcs= (LineCluster[])in.readObject();
                int size=0;
                for (int i=0;i<lcs.length;i++) size+=lcs[i].size();
                lines= new Vector();
                colors= new int[size];
                int count=0;
                for (int i=0;i<lcs.length;i++) {
                    for (int j=0;j<lcs[i].size();j++) {
                        lines.addElement(lcs[i].getLineAt(j));
                        colors[count++]=i;
                    }
                }
            }
            in.close();
        }
        catch (Exception e) {
            System.err.println(e.toString());
            return null;
        }
        int[] b= yi.util.ImageUtil.makeBackground(source);
        int[] label= new int[source.length];
        for (int i=0;i<colors.length;i++) {
            DrawUtil.ort2image(label, d, (ORTLine)lines.elementAt(i), colors[i], 1);
            if (testCluster!=-1&&colors[i]!=testCluster) continue;
            DrawUtil.ort2image(b, d, (ORTLine)lines.elementAt(i), 0xffffffff, 1);
        }
        (new SegFrame("colored lines", b, d.width, d.height, label)).show();
        return null;
    }
}



