package au.edu.wsu;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Point2D;
import java.awt.Color;
import java.util.Arrays;
import java.util.Iterator;
import javax.swing.JFrame;
import eu.seebetter.ini.chips.DavisChip;
import net.sf.jaer.Description;
import net.sf.jaer.DevelopmentStatus;
import net.sf.jaer.chip.AEChip;
import net.sf.jaer.event.ApsDvsEvent;
import net.sf.jaer.event.ApsDvsEventPacket;
import net.sf.jaer.event.BasicEvent;
import net.sf.jaer.event.EventPacket;
import net.sf.jaer.eventprocessing.EventFilter;
import net.sf.jaer.eventprocessing.EventFilter2D;
import net.sf.jaer.graphics.DavisRenderer;
import net.sf.jaer.graphics.ImageDisplay;
import net.sf.jaer.graphics.ImageDisplay.Legend;
import ch.unizh.ini.jaer.projects.davis.frames.DavisComplementaryFilter;
        
/**
 * Extracts Polarization information using Cedric's complementary filter to 
 * obtain the absolute light intensity. 
 *
 * @author Damien Joubert, Tobi Delbruck
 */
@Description("Method to extract polarization information from a stream of APS/DVS events using Cedric's complementary filter")
@DevelopmentStatus(DevelopmentStatus.Status.Stable)
public class PolarizationComplementaryFilter extends DavisComplementaryFilter{

    // offset of f0, f45, f90 and f135 acording to the index
    private int[] indexf0, indexf45, indexf90, indexf135;
    private JFrame apsFramePola = null;
    public ImageDisplay apsDisplayPola;
    private float[] apsDisplayPixmapBuffer;
    public PolarizationComplementaryFilter(final AEChip chip) {
        super(chip);
        apsDisplayPola = ImageDisplay.createOpenGLCanvas();
        apsFramePola = new JFrame("Polarization Information DoP - AOP");
        apsFramePola.setPreferredSize(new Dimension(800, 800));
        apsFramePola.getContentPane().add(apsDisplayPola, BorderLayout.CENTER);
        apsFramePola.pack();
        apsFramePola.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(final WindowEvent e) {
                setShowAPSFrameDisplay(false);
            }
        });
        indexf0 = new int[maxIDX];
        indexf45 = new int[maxIDX];
        indexf90 = new int[maxIDX];
        indexf135 = new int[maxIDX];
        initFilter();
    }
    
    @Override
    public EventPacket<? extends BasicEvent> filterPacket(EventPacket<? extends BasicEvent> in) {
        checkMaps();
        in = super.filterPacket(in); 
        displayPreBuffer();
        if (showAPSFrameDisplay) {
            apsDisplayPola.repaint();
        }
        return in; // should be denoised output
    }
    
    private void checkMaps() {
        apsDisplayPola.checkPixmapAllocation();
        if (showAPSFrameDisplay && !apsFramePola.isVisible()) {
            apsFramePola.setVisible(true);
        }
    }

    public void displayPreBuffer() {
        if(maxIDX != indexf0.length){
            indexf0 = new int[maxIDX];
            indexf45 = new int[maxIDX];
            indexf90 = new int[maxIDX];
            indexf135 = new int[maxIDX];
            apsDisplayPixmapBuffer = new float[3 * maxIDX / 4 * 3];
            apsDisplayPola.setImageSize(width/2, height/2 * 3);
            PolarizationUtils.fillIndex(indexf0, indexf45, indexf90, indexf135, height, width);
            PolarizationUtils.drawLegend(apsDisplayPixmapBuffer, height, width);
        }
        PolarizationUtils.computePolarizationLog(logFinalFrame, apsDisplayPixmapBuffer, indexf0, indexf45, indexf90, indexf135, height, width);
        apsDisplayPola.setPixmapArray(apsDisplayPixmapBuffer);
    }
    
}

@@ -97,796 +97,302 @@
 ent.
-MouseEvent;%0Aimport java.awt.event.MouseMotionAdapter;%0Aimport java.awt.event.WindowAdapter;%0Aimport java.awt.event.WindowEvent;%0Aimport java.awt.geom.Point2D;%0Aimport java.awt.Color;%0Aimport java.util.Arrays;%0Aimport java.util.Iterator;%0Aimport javax.swing.JFrame;%0Aimport eu.seebetter.ini.chips.DavisChip;%0Aimport net.sf.jaer.Description;%0Aimport net.sf.jaer.DevelopmentStatus;%0Aimport net.sf.jaer.chip.AEChip;%0Aimport net.sf.jaer.event.ApsDvsEvent;%0Aimport net.sf.jaer.event.ApsDvsEventPacket;%0Aimport net.sf.jaer.event.BasicEvent;%0Aimport net.sf.jaer.event.EventPacket;%0Aimport net.sf.jaer.eventprocessing.EventFilter;%0Aimport net.sf.jaer.eventprocessing.EventFilter2D;%0Aimport net.sf.jaer.graphics.DavisRenderer;%0Aimport net.sf.jaer.graphics.ImageDisplay;%0Aimport net.sf.jaer.graphics.ImageDisplay.Legend
+WindowAdapter;%0Aimport java.awt.event.WindowEvent;%0Aimport javax.swing.JFrame;%0Aimport net.sf.jaer.Description;%0Aimport net.sf.jaer.DevelopmentStatus;%0Aimport net.sf.jaer.chip.AEChip;%0Aimport net.sf.jaer.event.BasicEvent;%0Aimport net.sf.jaer.event.EventPacket;%0Aimport net.sf.jaer.graphics.ImageDisplay
 ;%0Aim
@@ -3234,20 +3234,32 @@
 ffer);%0A    %7D
+            
 %0A    %0A%7D%0A

Remove useless includes