
/**
 * @author Morgan McGuire
 * @version 2001-10-10
 * @since   2001-10-10
 */
public class Collage extends AbstractELOperator implements ELOperator {
    static private Segmentation segmentation;
    /**
       The segmentation is set on program load and is the same for all
       expressions.  This must be set immediately on load.
    */
    static void setSegmentation(Segmentation s) {
        segmentation = s;
    }

    public int getMaxNumArguments() {
        return segmentation.getNumSegments();
    }

    public int getMinNumArguments() {
        return segmentation.getNumSegments();
    }

    public void apply(ELMatrix argument[], ELMatrix out) {
        checkArguments(argument);
        
        int numArguments = argument.length;
        float weight[] = new float[numArguments];

        if (! segmentation.isSameSize(out.getWidth(), out.getHeight())) {
            throw new Error("Not implemented unless segmentation resolution == sample resolution");
        }
        
        for (int i = out.red.length - 1; i >= 0; i--) {
            int s = segmentation.getBin(i);
            out.red[i] = argument[s].red[i];
            out.grn[i] = argument[s].grn[i];
            out.blu[i] = argument[s].blu[i];
        }
    }
                
    public String unparse() {
        return name();
    }

    public String name() {
        return "Collage";
    }

    public String description() {
        return "Colors different segments with different textures.";
    }

}
