fileout.cu 3.34 KB
#include "fileout.h"

void fileoutStruct::saveNearField(nearfieldStruct* nf)
{
    if(nearFile == "") return;

    if(field == fieldReal)
    {
        scalarslice S = nf->U.Real();
        S.toImage(nearFile, false, colormap);
    }
    if(field == fieldImag)
    {
        scalarslice S = nf->U.Imag();
        S.toImage(nearFile, false, colormap);
    }
    if(field == fieldMag)
    {
        scalarslice S = nf->U.Mag();
        S.toImage(nearFile, true, colormap);
    }
}

void fileoutStruct::saveFarField(microscopeStruct* scope)
{
    if(farFile == "") return;

    if(field == fieldReal)
    {
        scalarslice S = scope->Ud.Real();
        S.toImage(farFile, false, colormap);
    }
    if(field == fieldImag)
    {
        scalarslice S = scope->Ud.Imag();
        S.toImage(farFile, false, colormap);
    }
    if(field == fieldMag)
    {
        scalarslice S = scope->Ud.Mag();
        S.toImage(farFile, true, colormap);
    }

}

void fileoutStruct::saveDetector(microscopeStruct* scope)
{
	//intensity
    if(intFile != "")
    {
        scalarslice I = scope->getIntensity();

        if(is_binary(intFile))
		{
			if(wavenumber)
				I.toEnvi(intFile, 10000.0f/scope->nf.lambda, append);
			else
				I.toEnvi(intFile, scope->nf.lambda, append);
		}
		else
			I.toImage(intFile);
    }
    //absorbance
    if(absFile != "")
    {
        scalarslice I = scope->getAbsorbance();

        if(is_binary(absFile))
        {
			if(wavenumber)
				I.toEnvi(absFile, 10000.0f/scope->nf.lambda, append);
			else
				I.toEnvi(absFile, scope->nf.lambda, append);
		}
        else
            I.toImage(absFile);
    }
    //transmittance
    if(transFile != "")
    {
        scalarslice I = scope->getTransmittance();

        if(is_binary(transFile))
        {
			if(wavenumber)
				I.toEnvi(transFile, 10000.0f/scope->nf.lambda, append);
			else
				I.toEnvi(transFile, scope->nf.lambda, append);
		}
        else
            I.toImage(transFile);
    }

}

bool fileoutStruct::is_binary(std::string filename)
{
    //this function guesses if a file name is binary or a standard image
    //  do this by just testing extensions

    //get the extension
    size_t i = filename.find_last_of('.');

    //if there is no extension, return true
    if( i == std::string::npos )
        return true;

    //otherwise grab the extension
    std::string ext = filename.substr(i+1);
    if(ext == "bmp" ||
       ext == "jpg" ||
       ext == "tif" ||
       ext == "gif" ||
       ext == "png")
       return false;
    else
        return true;
}



void fileoutStruct::Save(microscopeStruct* scope)
{
	//save images of the fields in the microscope

	//if the user specifies an extended source
	if(scope->focalPoints.size() > 0)
	{
		//simulate the extended source and output the detector image
		scope->SimulateExtendedSource();

		//saveNearField(&scope->nf);
		saveFarField(scope);

		//save the detector images
		saveDetector(scope);

		//simulate scattering for the last point (so that you have a near field image)
		scope->SimulateScattering();
        saveNearField(&scope->nf);

	}
	else
	{
		//run the near-field simulation
		scope->SimulateScattering();

		//output the near field image
		saveNearField(&scope->nf);

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

		//saveNearField(&scope->nf);
		saveFarField(scope);

		//save the detector images
		saveDetector(scope);

	}




}