- Many fixes to the triple axis stuff
* update after a1-a6 drive * intrduction of targets - POLDI writing - Moved HKL calculation 4 TRICS to fourlib
This commit is contained in:
195
lomax.c
195
lomax.c
@ -103,6 +103,7 @@ static int testMaximum(int *iData, int xsize, int ysize,
|
||||
{
|
||||
int testValue, x, y, half;
|
||||
int *iPtr;
|
||||
int equalCount = 0;
|
||||
|
||||
testValue = iData[j * xsize + i];
|
||||
half = window/2;
|
||||
@ -114,8 +115,16 @@ static int testMaximum(int *iData, int xsize, int ysize,
|
||||
{
|
||||
if(iPtr[x] > testValue)
|
||||
return 0;
|
||||
if(iPtr[x] == testValue)
|
||||
equalCount++;
|
||||
}
|
||||
}
|
||||
/*
|
||||
if(equalCount > 3)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
@ -144,7 +153,7 @@ int testLocalMaximum(int *iData, int xsize, int ysize,
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
int calculateCOG(int *iData, int xsize, int ysize,
|
||||
int *i, int *j, int *intensity,
|
||||
int *i, int *j, int *intensity,int *nCount,
|
||||
int cogWindow,
|
||||
float contour)
|
||||
{
|
||||
@ -153,6 +162,9 @@ int calculateCOG(int *iData, int xsize, int ysize,
|
||||
float cogTotal, cogX, cogY;
|
||||
int *iPtr;
|
||||
|
||||
if(!testBoundaries(xsize,ysize,cogWindow,*i,*j))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
preparations
|
||||
*/
|
||||
@ -175,6 +187,7 @@ int calculateCOG(int *iData, int xsize, int ysize,
|
||||
/*
|
||||
build the sums
|
||||
*/
|
||||
*nCount = 0;
|
||||
cogTotal = cogY = cogX = .0;
|
||||
for(y = yLow; y < yMax; y++)
|
||||
{
|
||||
@ -183,13 +196,14 @@ int calculateCOG(int *iData, int xsize, int ysize,
|
||||
{
|
||||
if(iPtr[x] > threshold)
|
||||
{
|
||||
*nCount++;
|
||||
cogTotal += iPtr[x];
|
||||
cogY += y * iPtr[x];
|
||||
cogX += x * iPtr[x];
|
||||
}
|
||||
}
|
||||
}
|
||||
if(cogTotal < .0)
|
||||
if(cogTotal <= .0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -200,6 +214,82 @@ int calculateCOG(int *iData, int xsize, int ysize,
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
void calculateStatistics(int *iData, int xsize, int ysize,
|
||||
float *average, float *maximum)
|
||||
{
|
||||
int i, iLength;
|
||||
int max = -9999999999999;
|
||||
long sum = 0;
|
||||
|
||||
iLength = xsize*ysize;
|
||||
for(i = 0; i < iLength; i++)
|
||||
{
|
||||
sum += iData[i];
|
||||
if(iData[i] > max)
|
||||
max = iData[i];
|
||||
}
|
||||
*average = (float)sum/(float)iLength;
|
||||
*maximum = (float)max;
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
int wellFormed(int *iData, int xsize, int ysize,
|
||||
int i, int j, int window, float contour,
|
||||
int maxBad)
|
||||
{
|
||||
int testValue, x, y, half;
|
||||
int *iPtr;
|
||||
int badCount = 0;
|
||||
|
||||
|
||||
testValue = (int)((float)iData[j * xsize + i]*contour);
|
||||
half = window/2;
|
||||
|
||||
/*
|
||||
test upper row
|
||||
*/
|
||||
iPtr = iData + (j - half) * xsize + i - half;
|
||||
for(x = 0; x < window; x++)
|
||||
{
|
||||
if(iPtr[x] > testValue)
|
||||
badCount++;
|
||||
}
|
||||
|
||||
/*
|
||||
test lower row
|
||||
*/
|
||||
iPtr = iData + (j + half) * xsize + i - half;
|
||||
for(x = 0; x < window; x++)
|
||||
{
|
||||
if(iPtr[x] > testValue)
|
||||
badCount++;
|
||||
}
|
||||
|
||||
/*
|
||||
test columns
|
||||
*/
|
||||
for(y = j - half; y < j + half; y++)
|
||||
{
|
||||
/*
|
||||
left
|
||||
*/
|
||||
if(iData[y*xsize + i - half] > testValue)
|
||||
badCount++;
|
||||
/*
|
||||
right
|
||||
*/
|
||||
if(iData[y*xsize + i + half] > testValue)
|
||||
badCount++;
|
||||
}
|
||||
|
||||
if(badCount > maxBad)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------*/
|
||||
static int checkHM(pHistMem *pHM, SicsInterp *pSics, SConnection *pCon,
|
||||
char *name, int *iDim)
|
||||
@ -247,7 +337,7 @@ int LoMaxAction(SConnection *pCon, SicsInterp *pSics,
|
||||
{
|
||||
pLoMax self = NULL;
|
||||
char pBueffel[256], pNum[20];
|
||||
int iRet, i, j, intensity;
|
||||
int iRet, i, j, intensity, count, badMax;
|
||||
int iDim[10], nDim;
|
||||
pHistMem pHM = NULL;
|
||||
CommandList *pCom = NULL;
|
||||
@ -256,6 +346,7 @@ int LoMaxAction(SConnection *pCon, SicsInterp *pSics,
|
||||
int *iData;
|
||||
double dVal;
|
||||
ObPar *ob = NULL;
|
||||
float average, maximum;
|
||||
|
||||
self = (pLoMax)pData;
|
||||
assert(pCon);
|
||||
@ -291,9 +382,9 @@ int LoMaxAction(SConnection *pCon, SicsInterp *pSics,
|
||||
return 0;
|
||||
}
|
||||
Tcl_DStringInit(&result);
|
||||
Tcl_DStringStartSublist(&result);
|
||||
iData = GetHistogramPointer(pHM,pCon);
|
||||
window = (int)ObVal(self->pParam,WINDOW);
|
||||
count = 0;
|
||||
for(i = 0 + window/2; i < iDim[0] - window/2; i++)
|
||||
{
|
||||
for(j = 0 + window/2; j < iDim[1] - window/2; j++)
|
||||
@ -305,18 +396,20 @@ int LoMaxAction(SConnection *pCon, SicsInterp *pSics,
|
||||
(int)ObVal(self->pParam,THRESHOLD),
|
||||
&intensity))
|
||||
{
|
||||
Tcl_DStringStartSublist(&result);
|
||||
sprintf(pNum,"%d", i);
|
||||
Tcl_DStringAppendElement(&result,pNum);
|
||||
sprintf(pNum,"%d", j);
|
||||
Tcl_DStringAppendElement(&result,pNum);
|
||||
if(count != 0)
|
||||
{
|
||||
Tcl_DStringAppend(&result,"@",strlen("@"));
|
||||
}
|
||||
sprintf(pNum,"%d ", i);
|
||||
Tcl_DStringAppend(&result,pNum,strlen(pNum));
|
||||
sprintf(pNum,"%d ", j);
|
||||
Tcl_DStringAppend(&result,pNum,strlen(pNum));
|
||||
sprintf(pNum,"%d", intensity);
|
||||
Tcl_DStringAppendElement(&result,pNum);
|
||||
Tcl_DStringEndSublist(&result);
|
||||
Tcl_DStringAppend(&result,pNum,strlen(pNum));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Tcl_DStringEndSublist(&result);
|
||||
SCWrite(pCon,Tcl_DStringValue(&result),eValue);
|
||||
Tcl_DStringFree(&result);
|
||||
return 1;
|
||||
@ -347,27 +440,87 @@ int LoMaxAction(SConnection *pCon, SicsInterp *pSics,
|
||||
return 0;
|
||||
}
|
||||
Tcl_DStringInit(&result);
|
||||
Tcl_DStringStartSublist(&result);
|
||||
iData = GetHistogramPointer(pHM,pCon);
|
||||
window = (int)ObVal(self->pParam,COGWINDOW);
|
||||
iRet = calculateCOG(iData,iDim[0], iDim[1], &i, &j, &intensity,
|
||||
iRet = calculateCOG(iData,iDim[0], iDim[1], &i, &j, &intensity,&count,
|
||||
window, ObVal(self->pParam,COGCONTOUR));
|
||||
if(!iRet)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: no intensity in data",eError);
|
||||
return 0;
|
||||
}
|
||||
sprintf(pNum,"%d", i);
|
||||
Tcl_DStringAppendElement(&result,pNum);
|
||||
sprintf(pNum,"%d", j);
|
||||
Tcl_DStringAppendElement(&result,pNum);
|
||||
sprintf(pNum,"%d", intensity);
|
||||
Tcl_DStringAppendElement(&result,pNum);
|
||||
Tcl_DStringEndSublist(&result);
|
||||
sprintf(pNum,"%d ", i);
|
||||
Tcl_DStringAppend(&result,pNum,strlen(pNum));
|
||||
sprintf(pNum,"%d ", j);
|
||||
Tcl_DStringAppend(&result,pNum,strlen(pNum));
|
||||
sprintf(pNum,"%d ", intensity);
|
||||
Tcl_DStringAppend(&result,pNum,strlen(pNum));
|
||||
sprintf(pNum,"%d ", count);
|
||||
Tcl_DStringAppend(&result,pNum,strlen(pNum));
|
||||
SCWrite(pCon,Tcl_DStringValue(&result),eValue);
|
||||
Tcl_DStringFree(&result);
|
||||
return 1;
|
||||
}
|
||||
else if(strcmp(argv[1],"wellformed") == 0) /* test for wellformedness */
|
||||
{
|
||||
if(argc < 6)
|
||||
{
|
||||
sprintf(pBueffel,
|
||||
"ERROR: insufficient number of arguments to %s.wellformed",
|
||||
argv[0]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
if(!checkHM(&pHM, pSics,pCon, argv[2],iDim))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(Tcl_GetInt(pSics->pTcl,argv[3],&i)!= TCL_OK)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: expected number, got %s",argv[2]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
if(Tcl_GetInt(pSics->pTcl,argv[4],&j)!= TCL_OK)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: expected number, got %s",argv[2]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
if(Tcl_GetInt(pSics->pTcl,argv[5],&badMax)!= TCL_OK)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: expected number, got %s",argv[2]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
iData = GetHistogramPointer(pHM,pCon);
|
||||
window = (int)ObVal(self->pParam,COGWINDOW);
|
||||
iRet = wellFormed(iData,iDim[0], iDim[1], i, j,
|
||||
window, ObVal(self->pParam,COGCONTOUR),
|
||||
badMax);
|
||||
sprintf(pBueffel,"%5d", iRet);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
else if(strcmp(argv[1],"stat") == 0)
|
||||
{
|
||||
if(argc < 3)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: insufficient number of arguments to %s.search",
|
||||
argv[0]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
if(!checkHM(&pHM, pSics,pCon, argv[2],iDim))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
iData = GetHistogramPointer(pHM,pCon);
|
||||
calculateStatistics(iData,iDim[0],iDim[1],&average,&maximum);
|
||||
sprintf(pBueffel," %f %f", average, maximum);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* we are handling one of the parameter commands
|
||||
|
Reference in New Issue
Block a user