interactivemie.h 8.75 KB
#ifndef INTERACTIVEMIE_H
#define INTERACTIVEMIE_H

#include <QtWidgets/QMainWindow>
#include <QDragEnterEvent>
#include <qmimedata.h>
#include <qfiledialog.h>
#include <qinputdialog.h>
#include "ui_interactivemie.h"
#include "qtDistortionDialog.h"
#include "globals.h"

extern qtDistortionDialog* distortionDialog;

class InteractiveMie : public QMainWindow
{
Q_OBJECT

public:
InteractiveMie(QWidget *parent = 0, Qt::WindowFlags flags = 0);
~InteractiveMie();
void closeEvent(QCloseEvent *event);
bool updating;

void refreshUI()
{
	updating = true;

	ui.spinNuMin->setValue(nuMin);
	ui.spinNuMax->setValue(nuMax);
	ui.spinAMin->setValue(aMin);
	ui.spinAMax->setValue(aMax);
	ui.spinRadius->setValue(radius);
	ui.spinBaseIR->setValue(baseIR);
	ui.spinScaleK->setValue(cA);
	ui.spinObjNAi->setValue(oNAi);
	ui.spinObjNAo->setValue(oNAo);
	ui.spinCondNAi->setValue(cNAi);
	ui.spinCondNAo->setValue(cNAo);
	ui.spinError->setValue(minMSE);
	ui.spinMaxIter->setValue(maxFitIter);
	ui.spinI0Scale->setValue(scaleI0);

	//display spectra values
	ui.chkDisplaySimSpec->setChecked(dispSimSpec);
	ui.chkDisplayRefSpec->setChecked(dispRefSpec);
	ui.chkDisplaySimK->setChecked(dispSimK);
	ui.chkDisplayMatK->setChecked(dispMatK);
	ui.chkDisplaySimN->setChecked(dispSimN);
	ui.chkDisplayMatN->setChecked(dispMatN);
	ui.spinDispScaleK->setValue(kMax);
	ui.spinDispScaleN->setValue(nMag);

	//material selection combo box
	ui.cmbMaterial->clear();
	for(unsigned int i=0; i<MaterialList.size(); i++)
		ui.cmbMaterial->addItem(MaterialList[i].name.c_str(), i);
	ui.cmbMaterial->setCurrentIndex(currentMaterial);

	updating = false;
}

void dragEnterEvent(QDragEnterEvent *event)
{
	cout<<"This is a test."<<endl;
	QStringList s = event->mimeData()->formats();
	if (event->mimeData()->hasFormat("application/x-qt-windows-mime;value=\"FileName\"") ||
			event->mimeData()->hasFormat("text/plain"))
	{
		event->acceptProposedAction();

	}
}

void dropEvent(QDropEvent *event)
{
	//cout<<"Challenge Accepted."<<endl;
	RefSpectrum.clear();
	RefSpectrum.push_back(SetReferenceSpectrum(event->mimeData()->text().toLatin1().data()));
	UpdateDisplay();
}

private:
Ui::InteractiveMieClass ui;

public slots:
//display parameters
void on_spinNuMin_valueChanged(int i) {
	if(updating) return;
	nuMin = (float)i;
	UpdateDisplay();
}
void on_spinNuMax_valueChanged(int i) {
	if(updating) return;
	nuMax = (float)i;
	UpdateDisplay();
}
void on_spinAMin_valueChanged(double d) {
	if(updating) return;
	aMin = d;
	UpdateDisplay();
}
void on_spinAMax_valueChanged(double d) {
	if(updating) return;
	aMax = d;
	UpdateDisplay();
}
void on_chkDisplaySimSpec_clicked(bool b) {
	if(updating) return;
	dispSimSpec = b;
	UpdateDisplay();
}
void on_chkDisplayRefSpec_clicked(bool b) {
	if(updating) return;
	dispRefSpec = b;
	UpdateDisplay();
}
void on_chkDisplaySimK_clicked(bool b) {
	if(updating) return;
	dispSimK = b;
	UpdateDisplay();
}
void on_chkDisplayMatK_clicked(bool b) {
	if(updating) return;
	dispMatK = b;
	UpdateDisplay();
}
void on_chkDisplaySimN_clicked(bool b) {
	if(updating) return;
	dispSimN = b;
	UpdateDisplay();
}
void on_chkDisplayMatN_clicked(bool b) {
	if(updating) return;
	dispMatN = b;
	UpdateDisplay();
}
void on_spinDispScaleK_valueChanged(double d) {
	if(updating) return;
	kMax = d;
	UpdateDisplay();
}
void on_spinDispScaleN_valueChanged(double d) {
	if(updating) return;
	nMag = d;
	UpdateDisplay();
}
void on_radDisplayAbsorbance_clicked(bool b) {
	if(updating) return;
	dispSimType = AbsorbanceSpecType;
	SimulateSpectrum();
	UpdateDisplay();
}
void on_radDisplayIntensity_toggled(bool b) {
	if(updating) return;
	dispSimType = IntensitySpecType;
	SimulateSpectrum();
	UpdateDisplay();
}
void on_chkNormalize_clicked(bool b) {
	if(updating) return;
	dispNormalize = b;
	SimulateSpectrum();
	UpdateDisplay();
}
void on_spinNormFactor_valueChanged(double d) {
	if(updating) return;
	dispNormFactor = d;
	SimulateSpectrum();
	UpdateDisplay();
}

//material parameters
void on_spinRadius_valueChanged(double d) {
	if(updating) return;
	radius = d;
	SimulateSpectrum();
	UpdateDisplay();
}
void on_chkAdjustIR_clicked(bool b) {
	if(updating) return;
	//allow the user to change the mean n and k values
	ui.spinBaseIR->setEnabled(b);
	ui.spinScaleK->setEnabled(b);
	
}
void on_spinBaseIR_valueChanged(double d) {
	if(updating) return;
	baseIR = d;
	ChangeAbsorbance();
	SimulateSpectrum();
	UpdateDisplay();
}
void on_spinScaleK_valueChanged(double d) {
	if(updating) return;
	cA = d;
	ChangeAbsorbance();
	SimulateSpectrum();
	UpdateDisplay();
}
void on_chkApplyMaterial_clicked(bool b) {
	if(updating) return;
	applyMaterial = b;
	SimulateSpectrum();
	UpdateDisplay();
}
void on_cmbMaterial_currentIndexChanged(int i) {
	if(updating) return;

	currentMaterial = i;
	SetMaterial();
	SimulateSpectrum();
	UpdateDisplay();
	refreshUI();
}

//optical parameters
void on_spinCondNAi_valueChanged(double d) {
	cNAi = d;
	SimulateSpectrum();
	UpdateDisplay();
}
void on_spinCondNAo_valueChanged(double d) {
	cNAo = d;
	SimulateSpectrum();
	UpdateDisplay();
}
void on_spinObjNAi_valueChanged(double d) {
	oNAi = d;
	SimulateSpectrum();
	UpdateDisplay();
}
void on_spinObjNAo_valueChanged(double d) {
	oNAo = d;
	SimulateSpectrum();
	UpdateDisplay();
}
void on_radTransmissionOptics_clicked(bool d) {
	ui.spinCondNAi->setEnabled(true);
	ui.spinCondNAo->setEnabled(true);
	opticsMode = TransmissionOpticsType;
	SimulateSpectrum();
	UpdateDisplay();
}
void on_radReflectionOptics_clicked(bool d) {
	ui.spinCondNAi->setEnabled(false);
	ui.spinCondNAo->setEnabled(false);
	ui.radDisplayAbsorbance->setEnabled(false);
	ui.radDisplayIntensity->setChecked(true);
	opticsMode = ReflectionOpticsType;
	SimulateSpectrum();
	UpdateDisplay();
}
void on_chkPointDetector_clicked(bool b) {
	if(b)
	{
		pointDetector = true;
		ui.spinObjectiveSamples->setEnabled(false);
	}
	else
	{
		pointDetector = false;
		ui.spinObjectiveSamples->setEnabled(true);
	}

	SimulateSpectrum();
	UpdateDisplay();
}

void on_spinObjectiveSamples_valueChanged(int i) {
	objectiveSamples = i;
	SimulateSpectrum();
	UpdateDisplay();
}

//Fitting
void on_spinMaxIter_valueChanged(int i) {
	maxFitIter = i;
}
void on_spinError_valueChanged(double d) {
	minMSE = d;
}
void on_spinI0Scale_valueChanged(double d) {
	scaleI0 = d;
	SimulateSpectrum();
	UpdateDisplay();
}
void on_spinRefSlope_valueChanged(double d) {
	refSlope = d;
	UpdateDisplay();
}

//display settings

//Buttons
void on_btnFit_clicked() {
	FitDisplay();
	refreshUI();
}
void on_btnSave_clicked() {
	SaveState();
}
void on_btnReset_clicked() {
	SetDefaults();
	SimulateSpectrum();
	UpdateDisplay();
	refreshUI();
}
void on_btnResetK_clicked() {
	ChangeAbsorbance();
	SimulateSpectrum();
	UpdateDisplay();
}
void on_btnEstimateK_clicked() {
	EstimateMaterial();
	SimulateSpectrum();
	UpdateDisplay();
}
void on_btnDistortion_clicked() {
	//ComputeDistortion();
	//DistortionMap();
	cout<<"Distortion"<<endl;
	distortionDialog->show();
}
void on_btnTimings_clicked() {
	PD.PrintResults(cout);
}

//menu items
void on_mnuLoadReference_triggered() {
	QString fileName = QFileDialog::getOpenFileName(this, tr("Open Reference Spectrum"));

	if(fileName != QString::null) {
		RefSpectrum.clear();
		RefSpectrum.push_back(LoadSpectrum(fileName.toLatin1().data()));
	}
	UpdateDisplay();
}

void on_mnuLoadMaterial_triggered() {

	//first load the imaginary part
	QString fileName = QFileDialog::getOpenFileName(this, tr("Open Material Spectrum"));

	//exit if no file was selected
	/*if(kFileName == QString::null)
		return;

	QString nFileName = QFileDialog::getOpenFileName(this, tr("Open Imaginary (n) Spectrum"));*/

	//request the material name
	QString matName = QInputDialog::getText(this, tr("Material Name"), tr("Enter material name:"));

	//if a real part was given, load both
	/*if(nFileName != QString::null)
		LoadMaterial(kFileName.toAscii().data(), nFileName.toAscii().data(), matName.toAscii().data());
	else
		LoadMaterial(kFileName.toAscii().data(), matName.toAscii().data());*/
	LoadMaterial(fileName.toLatin1().data(), matName.toLatin1().data());

	//add the new material to the combo box
	refreshUI();
}
void on_mnuLoadSource_triggered() {
	cout<<"Load source."<<endl;
}
void on_chkSourceSpectrum_clicked(bool b) {

	useSourceSpectrum = b;
	SimulateSpectrum();
	UpdateDisplay();

}

void on_mnuSaveSim_triggered() {
	//first load the imaginary part
	QString fileName = QFileDialog::getSaveFileName(this, tr("Save Simulated Spectrum"));
	SaveSimulation(fileName.toLatin1().data());
}

/*void on_mnuSaveK_triggered() {
	//first load the imaginary part
	QString fileName = QFileDialog::getSaveFileName(this, tr("Save Imaginary Index of Refraction (k)"));
	SaveK(fileName.toAscii().data());
}*/

void on_mnuSaveMaterial_triggered() {
	//first load the imaginary part
	QString fileName = QFileDialog::getSaveFileName(this, tr("Save Real Index of Refraction (n)"));
	SaveMaterial(fileName.toLatin1().data());
}



};

#endif // INTERACTIVEMIE_H