qtMainDialog.cpp 3.87 KB
#include "qtMainDialog.h"
#include <iostream>

qtMainDialog::qtMainDialog(QWidget *parent, Qt::WindowFlags flags)
    : QMainWindow(parent, flags)
{
    ui.setupUi(this);

    outfile = "ui-out.bmp";
}

qtMainDialog::~qtMainDialog()
{
    updating = false;
}

void qtMainDialog::closeEvent(QCloseEvent *event)
{
    std::cout<<"Exiting"<<std::endl;
    exit(0);

}


/********************************
Populate the user interface
********************************/
void qtMainDialog::populateUi()
{
    updating = true;

    //get the normal for the image plane
    bsVector n = SCOPE->nf.pos.n();

    ui.spinNx->setValue(n[0]);
    ui.spinNy->setValue(n[1]);
    ui.spinNz->setValue(n[2]);

    //get the center point for the image plane
    bsPoint c = SCOPE->nf.pos.p(0.5, 0.5);

    ui.spinCx->setValue(c[0]);
    ui.spinCy->setValue(c[1]);
    ui.spinCz->setValue(c[2]);

    //get the plane size (in microns)
    ptype S = SCOPE->nf.pos.X.len();
    ptype pad_div = SCOPE->padding * 2 + 1;
    S /= pad_div;

    ui.spinS->setValue(S);

    //get the detector resolution
    ui.spinR->setValue(SCOPE->Ud.R[0]);

    updating = false;
}

/*********************************
Change the image plane position
*********************************/
void qtMainDialog::positionImage()
{
    if(updating) return;

    //get the plane normal
    bsVector n(ui.spinNx->value(), ui.spinNy->value(), ui.spinNz->value());

    //get the plane center point
    bsPoint c(ui.spinCx->value(), ui.spinCy->value(), ui.spinCz->value());

    //get the plane orientation
    ptype theta = ui.spinTheta->value();

    //get the plane size
    ptype S = ui.spinS->value() * (2 * SCOPE->padding + 1);

    //create a new image plane
    SCOPE->nf.pos = rts::quad<ptype, 3>(c, n, S, S, theta);


}

/*********************************
Render an image
*********************************/
void qtMainDialog::renderImage()
{
    //run the near-field simulation
    SCOPE->SimulateScattering();


    //determine the colormap type
    rts::colormapType cmap = rts::cmGrayscale;

    if( ui.cmbColormap->currentText() == tr("brewer") )
        cmap = rts::cmBrewer;
    else
        cmap = rts::cmGrayscale;

    //near field rendering
    if( ui.radDisplayNearfield->isChecked() )
    {
        scalarslice S;
        bool positive_vals = false;

        if( ui.cmbDisplayNearfield->currentText() == tr("magnitude") )
        {
            std::cout<<"magnitude"<<std::endl;
            S = SCOPE->nf.U.Mag();
            positive_vals = true;
            //S.toImage(outfile.toStdString(), positive_vals, cmap);
        }
        else if( ui.cmbDisplayNearfield->currentText() == tr("real") )
            S = SCOPE->nf.U.Real();
        else if( ui.cmbDisplayNearfield->currentText() == tr("imaginary") )
            S = SCOPE->nf.U.Imag();

        S.toImage(outfile.toStdString(), positive_vals, cmap);
    }

    //run the far-field simulation
    SCOPE->SimulateImaging();

    //far field rendering
    if( ui.radDisplayFarfield->isChecked() )
    {
        scalarslice S;
        bool positive_vals = false;

        if( ui.cmbDisplayFarfield->currentText() == tr("magnitude") )
        {
            S = SCOPE->Ud.Mag();
            positive_vals = true;
        }
        else if( ui.cmbDisplayFarfield->currentText() == tr("real") )
            S = SCOPE->Ud.Real();
        else if( ui.cmbDisplayFarfield->currentText() == tr("imaginary") )
            S = SCOPE->Ud.Imag();

        S.toImage(outfile.toStdString(), positive_vals, cmap);
    }

    //detector rendering
    if( ui.radDisplayDetector->isChecked() )
    {
        scalarslice I;
        bool positive_vals = true;

        if( ui.cmbDisplayDetector->currentText() == tr("intensity") )
            I = SCOPE->getIntensity();

        else if( ui.cmbDisplayDetector->currentText() == tr("absorbance") )
            I = SCOPE->getAbsorbance();

        I.toImage(outfile.toStdString(), positive_vals, cmap);
    }

}