Package Calculo

Source Code of Calculo.ThreadProcessadoraSingle

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Calculo;

import Comunicacao.InfoSensor;
import Interface.Vetor;
import java.util.concurrent.ExecutionException;
import javax.swing.SwingWorker;

/**
*
* @author Renan
*/
public class ThreadProcessadoraSingle extends SwingWorker<InfoProc, Void> {
   
    private static final String propertyChangeName = "threadProcessadora";
    private InfoSensor info;
    private int eixos;

    /**
     *
     * @param infoSensor
     *                  informações do sensor em questão
     * @param eixos - valor do eixo sobre o qual se quer projeção:
     *                  X - 2^0
     *                  Y - 2^1
     *                  Z - 2^2
     */
    public ThreadProcessadoraSingle(InfoSensor infoSensor, int eixos) {
        info = infoSensor;
        this.eixos = eixos;
    }

    @Override
    protected InfoProc doInBackground() throws Exception {
        if (info != null){
            Vetor G = info.getVetorGravidade();
            Vetor B = info.getVetorMagnetico();
           
            B = B.normalizado();
            Vetor B_linha = G.projecao(B);
            B_linha = B.subtrai(B_linha).normalizado();
           
            InfoProc infoProc = new InfoProc();
            infoProc.ID = info.getID();
           
            double[] G_array = info.getArrayGravidade();
            double[] B_array = new double[] {B_linha.x, B_linha.y, B_linha.z};
           
            if (eixos % 2 == 1){
                double [] eixo = {1.0, 0.0, 0.0};
                double [] v = AlgoritmoMudancaDeBase.exec(G_array, B_array, eixo);
                infoProc.Proj_x = new Vetor(v);
                infoProc.Proj_x.x = (float)-v[0];
                infoProc.Proj_x.y = (float)v[2];
                infoProc.Proj_x.z = (float)-v[1];
            }
            if ( (eixos / 2) % 2 == 1){    
                double [] eixo = {0.0, 1.0, 0.0};
                double [] v = AlgoritmoMudancaDeBase.exec(G_array, B_array, eixo);
                infoProc.Proj_y = new Vetor(v);
            }
            if ( (eixos / 4) % 2 == 1){
                double [] eixo = {0.0, 0.0, 1.0};
                double [] v = AlgoritmoMudancaDeBase.exec(G_array, B_array, eixo);
                infoProc.Proj_z = new Vetor(v);
                infoProc.Proj_z.x = (float)-v[0];
                infoProc.Proj_z.y = (float)v[2];
                infoProc.Proj_z.z = (float)-v[1];
            }
           
            return infoProc;
        }
        return null;
    }

    @Override
    protected void done() {
        if (!isCancelled()){
            try {
                firePropertyChange(propertyChangeName, null, get());
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            } catch (ExecutionException ex) {
                ex.printStackTrace();
            }
        }
    }
   
    public static String getPropertyChangeName() {
        return propertyChangeName;
    }
   
}
TOP

Related Classes of Calculo.ThreadProcessadoraSingle

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.