|
// Variables that will keep track of the averaging data
CSpipExchange *AverageData = NULL;
int AverageCnt = 0;
IM_PWIN AverageWindow = NULL;
//-----------------------------------------------------------------
extern "C" _declspec(dllexport)
int Average()
// Read the data of the current data window and include it in the average
// calculation then show the result in the AverageWindow.
// To perform multiple averages the user clicks on
// <User Prog->Average Functions->Average> for each window to be included.
// After the first average calculation the function can conveniently be repeated
for
// other windows by clicking Shift+Ctrl+Y
{
CSpipExchange WindowData;
if (!WindowData.Get_ImageData())
{::AfxMessageBox("No data in window",MB_OK,NULL); return 0;}
if (!AverageData){
AverageData = new CSpipExchange;
if (!AverageData->Create_ImageData(WindowData.SizeX,WindowData.SizeY))
{::AfxMessageBox("No Average Data Created",MB_OK,NULL);
return 0;}
for (int i=0;i<AverageData->SizeTotal; i++)
AverageData->Data[i] = WindowData.Data[i];
AverageCnt = 1; }
else {
if (AverageData->SizeX != WindowData.SizeX ||
AverageData->SizeY != WindowData.SizeY )
{::AfxMessageBox("Data is not of same form",MB_OK,NULL); return 0;}
for (int i=0;i<AverageData->SizeTotal; i++)
AverageData->Data[i] = (AverageData->Data[i]*AverageCnt +
+ WindowData.Data[i])/(AverageCnt+1);
AverageCnt++; }
char Caption[30];
sprintf(Caption, "Average %d", AverageCnt );
AverageData->Put_Filename( Caption );
AverageData->Show_ImageData(&AverageWindow, Caption,0);
return true;
}
//-----------------------------------------------------------------
extern "C" _declspec(dllexport)
int AverageClear()
// Clear the Average Data so that we can start from fresh
{
delete AverageData;
AverageCnt = 0;
AverageData = NULL;
AverageWindow = NULL;
return true;
}
//---------------------------------------------------------------
void SpipExport()
// Tell SPIP aboout the available functions and how they shall appear in the
// popup menu
{
AddToSPIP("Average" ,"Average", "Averaging Functions",0 );
AddToSPIP("AverageClear" ,"Clear Average", "Averaging Functions",0 ); } | |