Example #1
0
WAVEFUNC::WAVEFUNC( WAVEFUNC& other )
{
	iPosX = other.iPosX;
	iPosY = other.iPosY;
	detPosX = other.detPosX;
	detPosY = other.detPosY;

	strcpy(fileStart, other.fileStart);
	strcpy(fileout, other.fileout);
	strcpy(avgName, other.avgName);

	nx = other.nx;
	ny = other.ny;

	diffpat = float2D(nx,ny,"diffpat");
	avgArray = float2D(nx,ny,"avgArray");

#if FLOAT_PRECISION == 1
	wave = complex2Df(nx, ny, "wave");
	fftPlanWaveForw = fftwf_plan_dft_2d(nx,ny,wave[0],wave[0],FFTW_FORWARD, FFTW_ESTIMATE);
	fftPlanWaveInv = fftwf_plan_dft_2d(nx,ny,wave[0],wave[0],FFTW_BACKWARD, FFTW_ESTIMATE);
#else
	wave = complex2D(nx, ny, "wave");
	fftPlanWaveForw = fftw_plan_dft_2d(nx,ny,wave[0],wave[0],FFTW_FORWARD,
		fftMeasureFlag);
	fftPlanWaveInv = fftw_plan_dft_2d(nx,ny,wave[0],wave[0],FFTW_BACKWARD,
		fftMeasureFlag);
#endif
}
Example #2
0
WAVEFUNC::WAVEFUNC(int x, int y) :
detPosX(0),
detPosY(0),
iPosX(0),
iPosY(0),
thickness(0.0),
nx(0),
ny(0)
{
	char waveFile[256];
	const char *waveFileBase = "mulswav";
	nx = x;
	ny = y;
	diffpat = float2D(nx,ny,"diffpat");
	avgArray = float2D(nx,ny,"avgArray");

#if FLOAT_PRECISION == 1
	wave = complex2Df(nx, ny, "wave");
	fftPlanWaveForw = fftwf_plan_dft_2d(nx,ny,wave[0],wave[0],FFTW_FORWARD, FFTW_ESTIMATE);
	fftPlanWaveInv = fftwf_plan_dft_2d(nx,ny,wave[0],wave[0],FFTW_BACKWARD, FFTW_ESTIMATE);
#else
	wave = complex2D(nx, ny, "wave");
	fftPlanWaveForw = fftw_plan_dft_2d(nx,ny,wave[0],wave[0],FFTW_FORWARD,
		fftMeasureFlag);
	fftPlanWaveInv = fftw_plan_dft_2d(nx,ny,wave[0],wave[0],FFTW_BACKWARD,
		fftMeasureFlag);
#endif

	sprintf(waveFile,"%s.img",waveFileBase);
	strcpy(fileout,waveFile);
	sprintf(fileStart,"mulswav.img");
}
Example #3
0
Detector::Detector(int nx, int ny, float_tt resX, float_tt resY) :
  error(0),
  shiftX(0),
  shiftY(0),
  Navg(0),
  thickness(0)
{
#if FLOAT_PRECISION == 1
	image = float2D(nx,ny,"ADFimag");
	image2 = float2D(nx,ny,"ADFimag");
#else
	image = double2D(nx,ny,"ADFimag");	
	image2 = double2D(nx,ny,"ADFimag");	
#endif
	m_imageIO=ImageIOPtr(new CImageIO(nx, ny, thickness, resX, resY, std::vector<double>(2+nx*ny), "STEM image"));
}
Example #4
0
WAVEFUNC::WAVEFUNC(int x, int y, float_tt resX, float_tt resY) :
detPosX(0),
detPosY(0),
iPosX(0),
iPosY(0),
thickness(0.0),
nx(x),
ny(y),
resolutionX(resX),
resolutionY(resY)
{
	char waveFile[256];
	const char *waveFileBase = "mulswav";
#if FLOAT_PRECISION == 1
	diffpat = float2D(nx,ny,"diffpat");
	avgArray = float2D(nx,ny,"avgArray");
#else
	diffpat = double2D(nx,ny,"diffpat");
	avgArray = double2D(nx,ny,"avgArray");
#endif

	m_imageIO=ImageIOPtr(new CImageIO(nx, ny, thickness, resolutionX, resolutionY));
	

#if FLOAT_PRECISION == 1
	wave = complex2Df(nx, ny, "wave");
	fftPlanWaveForw = fftwf_plan_dft_2d(nx,ny,wave[0],wave[0],FFTW_FORWARD, FFTW_ESTIMATE);
	fftPlanWaveInv = fftwf_plan_dft_2d(nx,ny,wave[0],wave[0],FFTW_BACKWARD, FFTW_ESTIMATE);
#else
	wave = complex2D(nx, ny, "wave");
	fftPlanWaveForw = fftw_plan_dft_2d(nx,ny,wave[0],wave[0],FFTW_FORWARD,
		fftMeasureFlag);
	fftPlanWaveInv = fftw_plan_dft_2d(nx,ny,wave[0],wave[0],FFTW_BACKWARD,
		fftMeasureFlag);
#endif

	sprintf(waveFile,"%s.img",waveFileBase);
	strcpy(fileout,waveFile);
	sprintf(fileStart,"mulswav.img");
}
Example #5
0
void main()
{
	char fileout[NCMAX];
	int ix, iy, nx, ny, ixmid, iymid, i, ismoth;
	float rmin, rmax, aimin, aimax;
	float *param, **pixr, **pixi;
	double  kx, ky, ky2, k2, k2max, v0, wavlen,
		ax, by, rx2, ry2, pi, dx, dy, scale, pixel,
		Cs, df, chi1, chi2, sum, chi, time;

/*  Echo version date  */

	printf( "c-probe version dated 3-oct-1997 ejk\n");

/*  Get desired image size, etc. */

	printf("Name of file to get focussed probe wavefunction:\n");
	scanf("%s", fileout );

	printf("Desired size of output image in pixels Nx,Ny:\n");
	scanf("%d %d", &nx, &ny );

	if( (nx != powerof2(nx)) || (ny != powerof2(ny)) ) {
		printf("Nx=%d, Ny=%d must be a power of 2,\n"
			"try again.\n", nx, ny);
		exit( 0 );
	}

	printf("Size of output image in Angstroms ax,by:\n");
	scanf("%lf %lf", &ax, &by );

	printf("Beam voltage in kilovolts:\n");
	scanf("%lf", &v0 );

	printf("Spherical aberration in mm.:\n");
	scanf("%lf", &Cs );
	Cs = Cs * 1.0e7;

	printf("Defocus in Angstroms:\n");
	scanf("%lf", &df );

	printf("Aperture in mrad:\n");
	scanf("%lf", &k2max );
        k2max = k2max * 0.001;

	printf("Type 1 for smooth aperture:\n");
	scanf("%d", &ismoth );

	printf("Probe position in Angstroms:\n");
	scanf("%lf %lf", &dx, &dy );

/*  Calculate misc constants  */

	time = cputim( );
        pi = 4.0 * atan( 1.0 );
	
        rx2 = 1.0/ax;
        rx2 = rx2 * rx2;
        ry2 = 1.0/by;
        ry2 = ry2 * ry2;
        
        ixmid = nx/2;
        iymid = ny/2;
        
        wavlen = 12.26/ sqrt( v0*1.e3 + v0*v0*0.9788 );
        chi1 = pi*wavlen;
        chi2 = 0.5 * Cs * wavlen*wavlen;
        k2max = k2max/wavlen;
        k2max = k2max * k2max;

	param = float1D( NPARAM, "probe-param" );
	for( i=0; i<NPARAM; i++) param[i] = 0.0F;
	pixr = float2D( 2*nx, ny, "pixr" );
	pixi = pixr + nx;

/*   Calculate MTF 
	NOTE zero freg is in the bottom left corner and
	expandes into all other corners - not in the center
	this is required for FFT

	PIXEL = diagonal width of pixel squared
	if a pixel is on the apertur boundary give it a weight
	of 1/2 otherwise 1 or 0
*/
	pixel = ( rx2 + ry2 );

	for( iy=0; iy<ny; iy++) {
	   ky = (double) iy;
	   if( iy > iymid ) ky = (double) (iy-ny);
	   ky2 = ky*ky*ry2;
	   for( ix=0; ix<nx; ix++) {
		kx = (double) ix;
		if( ix > ixmid ) kx = (double) (ix-nx);
		k2 = kx*kx*rx2 + ky2;
		if ( ( ismoth != 0) && 
			( fabs(k2-k2max) <= pixel) ) {
		   chi= chi1*k2* (chi2*k2-df) -
			2.0F*pi*( (dx*kx/ax) + (dy*ky/by) );
                   pixr[ix][iy]= (float) ( 0.5 * cos(chi));
                   pixi[ix][iy]= (float) (-0.5 * sin(chi));
                   printf("smooth by 0.5 at ix=%d, iy=%d\n", ix, iy );
		} else if ( k2 <= k2max ) {
		   chi= chi1*k2* (chi2*k2-df) -
			2.0F*pi*( (dx*kx/ax) + (dy*ky/by) );
                   pixr[ix][iy]= (float)  cos(chi);
                   pixi[ix][iy]= (float) -sin(chi);
		} else {
                   pixr[ix][iy] = pixi[ix][iy] = 0.0F;
                }
	   }
	}

	fft2d( pixr, pixi, nx, ny, -1);

/*  Normalize probe intensity to unity  */

        sum = 0.0;
        for( ix=0; ix<nx; ix++) for( iy=0; iy<ny; iy++) 
	        sum +=  pixr[ix][iy]*pixr[ix][iy]
	        		+ pixi[ix][iy]*pixi[ix][iy];

	scale = 1.0 / sum;
	scale = scale * ((double)nx) * ((double)ny);
	scale = (double) sqrt( scale );

        for( ix=0; ix<nx; ix++) 
           for( iy=0; iy<ny; iy++) {
		pixr[ix][iy] *= (float) scale;
		pixi[ix][iy] *= (float) scale;
	}

/*  Output results and find min and max to echo
    remember that complex pix are stored in the file in FORTRAN
		order for compatability
*/

        rmin = pixr[0][0];
        rmax = rmin;
        aimin = pixi[0][0];
        aimax = aimin;
        for( iy=0; iy<ny; iy++) {
           for( ix=0; ix<nx; ix++) {
		if( pixr[ix][iy] < rmin ) rmin = pixr[ix][iy];
		if( pixr[ix][iy] > rmax ) rmax = pixr[ix][iy];
		if( pixi[ix][iy] < aimin ) aimin = pixi[ix][iy];
		if( pixi[ix][iy] > aimax ) aimax = pixi[ix][iy];
	   }
	}

	param[pRMAX] = rmax;
	param[pIMAX] = aimax;
	param[pRMIN] = rmin;
	param[pIMIN] = aimin;
	param[pDEFOCUS]= (float) df;
	param[pDX]= (float) (ax / nx);
	param[pDY]= (float) (by / ny);
	param[pENERGY]= (float) v0;
	param[pWAVEL]= (float) ( sqrt(k2max) * wavlen);
	param[pCS]= (float) Cs;
	param[27]= (float) dx;
	param[28]= (float) dy;

	if( tcreateFloatPixFile( fileout, pixr, (long) (2*nx), (long) ny,
			 2, param ) != 1 )
		printf( "probe cannot write an output file.\n");

	printf( "Pix range %15.7g to %15.7g real,\n"
		"      and %15.7g to %15.7g imaginary\n",
		rmin, rmax, aimin, aimax );
	time = cputim() - time;
	printf("\nCPU time = %f sec\n", time );

}  /* end main() */
Example #6
0
void level::_readFile(string fileName)
{
	FILE * currentFile = NULL;
	int fileSize = 0;
	int count = 0;
	int xSize, ySize, tileSize;
	char * readBuffer;
	string currentValue = "";
	float2D playerStart;
	float2D goalPosition;
	fopen_s(&currentFile, &fileName[0], "rb");
	if(currentFile == NULL)
	{
		cout << "that level file is not available, exiting program";
		for(int i = 0; i < 3; i++)
		{
			Sleep(500);
			cout << ".";
		}
		exit(100);
	}
	if(!currentFile) return;
	//The file lay out is as follow
	/*
		first line
		is the tile size
		second line
		x and y size of map
		
		next is the grid 
		0s for a blocked path
		1s for a clear path

		next line is the x and y start position
		next line is the x and y goal position

		after that is the information needed for 
		the generation of the lights in the map

		the next line is the start position
		the next line is the goal position

		the next series of lines is the lighting data

	*/
	fseek(currentFile, 0, SEEK_END);
	fileSize = ftell(currentFile);
	rewind(currentFile);
	readBuffer = new char[fileSize];
	fread_s(readBuffer, fileSize, sizeof(char), fileSize, currentFile);
	while(readBuffer[count] != '\n')
	{
		currentValue += readBuffer[count];
		count++;
	}
	tileSize = atoi(&currentValue[0]);
	currentValue = "";
	count++;
	while(readBuffer[count] != ' ')
	{
		currentValue += readBuffer[count];
		count++;
	}
	xSize = atoi(&currentValue[0]);
	currentValue = "";
	count++;
	while(readBuffer[count] != '\n')
	{
		currentValue += readBuffer[count];
		count++;
	}
	ySize = atoi(&currentValue[0]);
	map = new bool*[ySize];

	for(int i = ySize; i--;)
		map[i] = new bool[xSize];
	count++;
	for(int i = ySize; i--;)
	{
		for(int j = 0; j < xSize; j++)
		{
			while(readBuffer[count] != '1' && readBuffer[count] != '0')
			{
				count++;
				if(count > fileSize) return;
			}
			if(readBuffer[count] == '1')
				map[i][j] = true;
			else
				map[i][j] = false;
			count++;
		}
	}
	_tileSize = tileSize;
	_size = int2D(xSize, ySize);
	colorArray = new float3D[_size.getX()*_size.getY() * 6];
	vertexArray = new int2D[_size.getX()*_size.getY() * 6];
	//Now we need to set up the start position and the goal goal position
	currentValue = "";
	count++;
	while(readBuffer[count] != ' ')
	{
		currentValue += readBuffer[count];
		count++;
	}
	playerStart = float2D(float(atoi(&currentValue[0])), 0);
	count++;
	currentValue = "";
	while(readBuffer[count] != '\n')
	{
		currentValue += readBuffer[count];
		count++;
	}
	playerStart = float2D(playerStart.getX(), float(atoi(&currentValue[0])));
	//Now we need to set up the start position and the goal goal position
	currentValue = "";
	count++;
	while(readBuffer[count] != ' ')
	{
		currentValue += readBuffer[count];
		count++;
	}
	goalPosition = float2D(float(atoi(&currentValue[0])), 0);
	count++;
	currentValue = "";
	while(readBuffer[count] != '\n')
	{
		currentValue += readBuffer[count];
		count++;
	}
	goalPosition = float2D(goalPosition.getX(), float(atoi(&currentValue[0])));
	count++;
	_generateTexture();
	//Next get the values for the light volume that will be built
	//which are minimum radiance followed by the levels, and then by passes
	while(readBuffer[count] != ' ')
	{
		currentValue += readBuffer[count];
		count++;
	}
	count++;
	_minimumIntensity = atof(&currentValue[0]);
	currentValue = "";
	while(readBuffer[count] != ' ')
	{
		currentValue += readBuffer[count];
		count++;
	}
	count++;
	_levels = atoi(&currentValue[0]);
	currentValue = "";
	while(readBuffer[count] != '\n')
	{
		currentValue += readBuffer[count];
		count++;
	}
	count++;
	_passes = atoi(&currentValue[0]);
	currentValue = "";
	//Now get the lights that the users want to build
	//These are the light variables
	float lightXPos, lightYPos, lightDirection;
	int radianceAngle, rayNumber, rayIntensity;
	//now run through the file and get all of the lighting information
	while(count < fileSize)
	{
		while(readBuffer[count] != ' ')
		{
			currentValue += readBuffer[count];
			count++;
		}
		count++;
		lightXPos = atoi(&currentValue[0]);
		currentValue = "";
		while(readBuffer[count] != ' ')
		{
			currentValue += readBuffer[count];
			count++;
		}
		count++;
		lightYPos = atoi(&currentValue[0]);
		currentValue = "";
		while(readBuffer[count] != ' ')
		{
			currentValue += readBuffer[count];
			count++;
		}
		count++;
		lightDirection = stof(&currentValue[0]);
		currentValue = "";
		while(readBuffer[count] != ' ')
		{
			currentValue += readBuffer[count];
			count++;
		}
		count++;
		radianceAngle = atoi(&currentValue[0]);
		currentValue = "";
		while(readBuffer[count] != ' ')
		{
			currentValue += readBuffer[count];
			count++;
		}
		count++;
		rayNumber = atoi(&currentValue[0]);
		currentValue = "";
		while(readBuffer[count] != '\n')
		{
			currentValue += readBuffer[count];
			count++;
		}
		count++;
		rayIntensity = atoi(&currentValue[0]);
		currentValue = "";
		addLight(float2D(lightXPos, lightYPos), lightDirection, radianceAngle, rayNumber, rayIntensity);
	}
	fclose(currentFile);
}
Example #7
0
void level::renderLevel(character &currentCharacter, level &currentLevel)
{
	float2D tempPos;
	switch(_colorModel)
	{
		//This is the full color mode
		//This is black tiles
		case 1:
			currentCharacter.render();
			_render();
			break;
			//This is feathered lighting model and the
			//point light model
		case 2:
			//check if the player has moved
			tempPos = currentCharacter.getPosition() + float2D().polarRotate(currentCharacter.getViewAngle())*currentCharacter.getSize();
			if(!(_previousCharacterPos == tempPos) || currentCharacter.getViewAngle() != _flashLightAngle)
			{
				_frontSound = 0;
				_leftSound = 0;
				_backSound = 0;
				_rightSound = 0;
				//if the player has moved then set the 
				//previous position to the new position
				_previousCharacterPos = tempPos;
				_flashLightAngle = currentCharacter.getViewAngle();
				//next update the flash light
				_flashLight = new light(_previousCharacterPos, TO_DEGREE(_flashLightAngle) - (135 / 2), 135, 135, 100);
				//_flashLight = new light(_previousCharacterPos, TO_DEGREE(_flashLightAngle), 1, 1, 200);
				_flashLight->buildEmitter(currentLevel, currentCharacter);
				cout << endl;
				cout << "Front sound: " << _frontSound << endl;
				cout << "Back sound: " << _backSound << endl;
				cout << "Left sound: " << _leftSound << endl;
				cout << "Right sound: " << _rightSound << endl;
				ALchangeGain(_frontSound, _leftSound, _backSound, _rightSound);
			}
			currentCharacter.render();
			_render();
			break;
		case 3:
		case 4:
			_render();
			_renderRayTexture();
			currentCharacter.render();
			
			
			
			break;
			//This is the mode you can see the 
			//rays in i.e. the light debug render
		case 5:
			//check if the player has moved
			tempPos = currentCharacter.getPosition() + float2D().polarRotate(currentCharacter.getViewAngle())*currentCharacter.getSize();
			if(!(_previousCharacterPos == tempPos) || currentCharacter.getViewAngle() != _flashLightAngle)
			{
				_frontSound = 0;
				_leftSound = 0;
				_backSound = 0;
				_rightSound = 0;
				//if the player has moved then set the 
				//previous position to the new position
				_previousCharacterPos = tempPos;
				_flashLightAngle = currentCharacter.getViewAngle();
				//next update the flash light
				_flashLight = new light(_previousCharacterPos, TO_DEGREE(_flashLightAngle) - (135/2), 135, 135, 100);
				//_flashLight = new light(_previousCharacterPos, TO_DEGREE(_flashLightAngle), 1, 1, 200);
				_flashLight->buildEmitter(currentLevel, currentCharacter);
				
				cout << "Front sound: " << _frontSound << endl;
				cout << "Back sound: " << _backSound << endl;
				cout << "Left sound: " << _leftSound << endl;
				cout << "Right sound: " << _rightSound << endl;
			}
			currentCharacter.render();
			_flashLight->debugRender();
			_render();
			break;
			//This will be the flash light mode
		case 6:
			break;
			//This is the sound model
		case 7:
			break;
		default:;
	}
}
Example #8
0
void level::_renderRayTexture(void)
{
	int maxX = _size.getX()*_tileSize, maxY = _size.getY()*_tileSize;

	glEnable(GL_TEXTURE_2D);

	switch(_colorModel)
	{
		case 3:
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, maxX, maxY, 0, GL_RGBA, GL_FLOAT, &_rayTexture[0]);
			glBindTexture(GL_TEXTURE_2D, _interpolatedTexture);
			break;
		case 4:
		default:
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, maxX, maxY, 0, GL_RGBA, GL_FLOAT, &_pointTexture[0]);
			glBindTexture(GL_TEXTURE_2D, _outlineTexture);
			break;
	}
	

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glClear(GL_DEPTH_BUFFER_BIT);
	float2D textureArray[6];
	int2D corners[6];
	float3D colors[6];
	corners[0] = int2D(0, 0);
	textureArray[0] = float2D(0, 0);
	corners[1] = int2D(0, maxY);
	textureArray[1] = float2D(0, 1.f);
	corners[2] = int2D(maxX, maxY);
	textureArray[2] = float2D(1.f, 1.f);
	corners[3] = int2D(maxX, maxY);
	textureArray[3] = float2D(1.f, 1.f);
	corners[4] = int2D(maxX, 0);
	textureArray[4] = float2D(1.f, 0);
	corners[5] = int2D(0, 0);
	textureArray[5] = float2D(0, 0);
	for(int i = 0; i < 6; i++) colors[i] = float3D(1.f, 1.f, 1.f);

	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glColorPointer(3, GL_FLOAT, 0, &colors[0]);
	glVertexPointer(2, GL_INT, 0, &corners[0]);
	glTexCoordPointer(2, GL_FLOAT, 0, &textureArray[0]);
	glDrawArrays(GL_TRIANGLES, 0, 6);

	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	
	glClear(GL_DEPTH_BUFFER_BIT);
	glDisable(GL_TEXTURE_2D);
	

}