Package horcher

Source Code of horcher.Main$Lissner$Ausfuhrer

/*
* Created on 01.02.2007
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package horcher;

import horcher.maths2.Addinfo;
import horcher.maths2.Calculationen;
import horcher.maths2.ComplexD;
import horcher.maths2.Correlation;
import horcher.maths2.Datensatz;
import horcher.maths2.Fensterfunktion;
import horcher.maths2.Kreuzleistungsspektrum;
import horcher.maths2.Signal;
import horcher.maths2.Spectrum;
import horcher.sound.DirectInput;
import horcher.sound.FileInput;
import horcher.sound.Input;
import horcher.visual.Graph;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Vector;

import javax.media.j3d.BadTransformException;
import javax.swing.JOptionPane;
import javax.vecmath.Vector3d;

/**
* @author HP_Besitzer
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class Main {
  protected class Lissner implements ActionListener {
    private class Ausfuhrer extends Thread {

      ActionEvent aktuellesEvent;

      public Ausfuhrer(final ActionEvent aktuellesEvent) {
        this.aktuellesEvent = aktuellesEvent;
      }

      @Override
      public void run() {
        try {
          if (this.aktuellesEvent.getActionCommand() == Main.this.r
              .getString("mQODatei")) {
            Main.this.input = new FileInput();
            Main.this.input();
          } else if (this.aktuellesEvent.getActionCommand() == Main.this.r
              .getString("mQOHardware")) {
            Main.this.input = new DirectInput();
            Main.this.input();
          } else if (this.aktuellesEvent.getActionCommand() == Main.this.r
              .getString("mQSkip")) {
            window.clear();
            correlation2 = null;
            kreuzleistungsspektrum = null;
            correlation = null;
            signal = null;
            spectrum = null;
            Main.this.input();
          } else if (this.aktuellesEvent.getActionCommand() == Main.this.r
              .getString("mBStarten"))
            Main.this.caluculate();
          else if (this.aktuellesEvent.getActionCommand() == Main.this.r
              .getString("mQSchliessen"))
            Main.this.close();
          else if (this.aktuellesEvent.getActionCommand() == Main.this.r
              .getString("mQOHardware"))
            Main.this.input();
          else if (this.aktuellesEvent.getActionCommand() == Main.this.r
              .getString("mQOHardware"))
            Main.this.input();
        } catch (final Fehler eR) {
          eR.show(Main.this.r);
          eR.printStackTrace();
        } catch (final IOException eR) {
          Main.fehler("fIO", Main.this.r);
          eR.printStackTrace();
        }
      }
    }

    public void actionPerformed(final ActionEvent e) {
      new Ausfuhrer(e).start();
    }
  }
  // "Constanten":
  public static int N_MAX = 1;
  public static double D_IN_M = 1;
  public static double C_SCHALL = 343;
  public static int N_Kanale = 4;
  public static int LENGTH = (int) (Math.pow(2, 12));
  protected static void fehler(final String code, final ResourceBundle r) {
    JOptionPane.showMessageDialog(null, r.getString(code), r
        .getString("Fehler"), JOptionPane.ERROR_MESSAGE);
  }
  public static void main(final String[] args) {
    new Main();
  }
  ResourceBundle r;
  /*
   * Declaration:
   */
  Window window;
  Input input;
  Signal[] signal, signal2;
  Spectrum[] spectrum;
  Kreuzleistungsspektrum[] kreuzleistungsspektrum;

  Correlation[] correlation;

  Correlation[] correlation2;

  Vector<Ton> tone;

  private Main() {
    try {
      this.r = ResourceBundle.getBundle("horcher.ressourcen", Locale
          .getDefault());
    } catch (final MissingResourceException e) {
      System.out.println("Ressourcendatei nicht gefunden!");
    }
    this.tone = new Vector<Ton>();
    final Lissner lissner = new Lissner();
    this.window = new Window(lissner, this.r);
    this.window.setSize(this.window.getToolkit().getScreenSize());
    this.window.setSize(this.window.getWidth() * 100 / 141, this.window
        .getHeight() * 100 / 141);
    this.window.setLocation(this.window.getWidth() * 20 / 100, this.window
        .getHeight() * 20 / 100);
    this.window.reSize();
    this.window.setVisible(true);
  }

  public void caluculate() {
    this.window.recalc();
    this.spectrum = new Spectrum[Main.N_Kanale];
    this.signal2 = new Signal[Main.N_Kanale];
    this.kreuzleistungsspektrum = new Kreuzleistungsspektrum[Main.N_Kanale - 1];
    this.correlation = new Correlation[Main.N_Kanale - 1];
    this.correlation2 = new Correlation[Main.N_Kanale - 1];
    Graph<ComplexD> tmpG;
    Fensterfunktion hanning=new Fensterfunktion(Fensterfunktion.HANNING,signal[0].size());
    this.window.auto.graphen.add(new Graph<ComplexD>(hanning, "Hanning " ));
    for (int i = 0; i < Main.N_Kanale; i++) {
      this.signal[i].mul(hanning);
      this.spectrum[i] = this.signal[i].fft();
      this.spectrum[i].zBewerten();
      tmpG = new Graph<ComplexD>(this.spectrum[i], "Specturm " + (i + 1));
      tmpG.setLog(true);
      this.window.ffts.graphen.add(tmpG);
      this.signal2[i] = this.signal[i].copy();
      if (i > 0) {
        this.kreuzleistungsspektrum[i - 1] = this.spectrum[0]
            .correlate(this.spectrum[i]);
        this.correlation[i - 1] = this.kreuzleistungsspektrum[i - 1]
            .correlation();
        tmpG = new Graph<ComplexD>(this.correlation[i - 1], "Correlation 1, "
            + (i));
        // tmpG.setLog(true);
        this.window.vers.graphen.add(tmpG);
        /*
         * this.kreuzleistungsspektrum[i-1].removeAllTo(this.correlation[i-1].getMaxP(),
         * 0.3);
         * correlation2[i-1]=this.kreuzleistungsspektrum[i-1].correlation();
         * tmpG=new Graph<ComplexD>(this.correlation2[i-1],"Correlaion2 "
         * +(i+1)); //tmpG.setLog(true); this.window.auto.graphen.add(tmpG);
         */
        int shift = this.correlation[i - 1].getMaxP();
        Collections.rotate(this.signal2[i], shift);
        this.signal2[i].sub(this.signal[0]);
        Collections.rotate(this.signal2[i], -shift);

      }
     // this.window.auto.graphen.add(new Graph<ComplexD>(this.signal2[i],
     //     "signal2 " + (i)));
    }
    final Vector<Datensatz<Addinfo<ComplexD, Integer>>> maxima = new Vector<Datensatz<Addinfo<ComplexD, Integer>>>();
    for (final Correlation c : this.correlation)
      maxima.add(new Datensatz<Addinfo<ComplexD, Integer>>(c.getGoodMaxima()));//GoodMaxima()));
    for (int i = 0; i < 1; i++)
      for (int j = 0; j < maxima.size(); j++) {
        // maxima.setElementAt((Datensatz<Addinfo<ComplexD, Integer>>)
        // Addinfo.withoutAddinfo(maxima.get(j).getMaxima()), j);
      }

    for (final Datensatz<Addinfo<ComplexD, Integer>> maximum : maxima) {
      Collections.sort(maximum);
      Collections.reverse(maximum);
    }
    final Iterator<Addinfo<ComplexD, Integer>> a = maxima.get(0).iterator();

    final Iterator<Addinfo<ComplexD, Integer>> b = maxima.get(1).iterator();

    final Iterator<Addinfo<ComplexD, Integer>> c = maxima.get(2).iterator();

    Vector3d abcXYZ;

    int i = 0;
    while (a.hasNext() && b.hasNext() && c.hasNext() && (i < Main.N_MAX)) {
      abcXYZ = new Vector3d(a.next().getInfo(), b.next().getInfo(), c.next()
          .getInfo());
      System.out.println(abcXYZ);
      abcXYZ.scale(Main.C_SCHALL / this.correlation[0].getSamplerate()
          / Main.D_IN_M);
      System.out.println(abcXYZ);
      abcXYZ = Calculationen.coords(abcXYZ);
      abcXYZ.scale(Main.D_IN_M);
      System.out.println(abcXYZ);
      try {
        this.tone.add(new Ton(abcXYZ, (10 - i) / 100.0f));
        this.window.panel3d.addBranchGroup(this.tone.lastElement());
      } catch (final BadTransformException e) {
        Main.fehler("keineLos", this.r);
      }
      i++;
    }
    // System.out.println((i-1)+": "+this.deltaS[i-1]);
    // this.window.info[1][i-1].setText(""+this.deltaT[i-1]);

    // System.out.println("a: "+this.deltaS[0]*Main.D_IN_M+" b:
    // "+this.deltaS[1]*Main.D_IN_M+" c: "+this.deltaS[2]*Main.D_IN_M+" ");
    // System.out.println("x: "+pos.getX()+" y: "+pos.getY()+" z: "+pos.getZ()+"
    // ");
    // this.window.info[1][3].setText(""+pos);
    this.window.reSize();
    this.window.repaint();
  }

  public void close() throws Fehler, IOException {
    final Iterator<Ton> it = this.tone.iterator();
    while (it.hasNext()) {
      this.window.panel3d.removeBranchGroup(it.next());
      it.remove();
    }
    this.window.clear();
    this.input.close();
    this.correlation2 = null;
    this.kreuzleistungsspektrum = null;
    this.correlation = null;
    this.signal = null;
    this.spectrum = null;
    this.input = null;
  }

  public void input() {
    this.window.setTitle(this.r.getString("title") + " - "
        + this.input.getSourceName());
    this.signal = new Signal[Main.N_Kanale];
    for (int i = 0; i < Main.N_Kanale; i++) {
      try {
        this.signal[i] = this.input.input(i, Main.LENGTH);
      } catch (final Fehler e) {
        e.show(this.r);
        e.printStackTrace();
      } catch (final IOException e) {
        Main.fehler("fIO", this.r);
        e.printStackTrace();
      }
     
      this.window.signale.graphen.add(new Graph<ComplexD>(this.signal[i],
          "Signal " + (i + 1)));
    }
    this.window.menu.mQOffnen.setEnabled(false);
    this.window.menu.mQSchliessen.setEnabled(true);
    this.window.menu.mBStarten.setEnabled(true);
    this.window.reSize();
  }

}
TOP

Related Classes of horcher.Main$Lissner$Ausfuhrer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.