void testComputePercentile() { //////////////////// // Test 1 // char testData1[3][9] = { {5,1,4,3,2,4,1,6,9}, {13,9,11,11,10,11,12,10,11}, {1,0,0,1,2,1,1,2,0} }; printf("\nTEST PERCENTILE\n"); float percentile = computePercentile(testData1[0], 9, 0.95); printf("Expected: 7.80, Actual: %.2f\n", percentile); percentile = computePercentile(testData1[0], 9, 0.05); printf("Expected: 1.00, Actual: %.2f\n", percentile); percentile = computePercentile(testData1[0], 9, 0.7); printf("Expected: 4.60, Actual: %.2f\n", percentile); percentile = computePercentile(testData1[0], 9, 1.0); printf("Expected: 9.00, Actual: %.2f\n", percentile); percentile = computePercentile(testData1[0], 9, 0.0); printf("Expected: 1.00, Actual: %.2f\n", percentile); percentile = computePercentile(testData1[0], 9, 0.5); printf("Expected: 4.00, Actual: %.2f\n", percentile); }
/** * points : 3 x num_points * points[0] : all x co-ords * points[1] : all y co-ords * points[2] : all z co-ords */ void calcBiometrics( double **points, // 3 x numPoints array int numPoints, //the number of points in 'points' float minEasting, //easting of bottome left corner of grid float minNorthing, //norhting of bottom left corner of grid int blockSize, //block dimension in meters float xBlock, //x block position in grid float yBlock, //y block position in grid int outRes, //resolution of output int zThreshold //z threshold value ) { float *** outArr; float *** lhqArr; float *** ccfArr; float blockEasting, blockNorthing; int dimensions; dimensions = blockSize / outRes; //must be an integer blockEasting = minEasting + (xBlock * blockSize); blockNorthing = minNorthing + (yBlock * blockSize); /** ouput arrays **/ outArr = initFloatBuffer3D(8 , dimensions, dimensions, -999.0); lhqArr = initFloatBuffer3D(21, dimensions, dimensions, -999.0); ccfArr = initFloatBuffer3D(21, dimensions, dimensions, -999.0); float xStart, yStart, xEnd, yEnd; int j, i; for(j = 0; j < dimensions; j++){ for(i = 0; i < dimensions; i++) { xStart = blockEasting + outRes * j; yStart = blockNorthing + outRes * i; xEnd = xStart + outRes; yEnd = yStart + outRes; Array1D A; A = filterByArea(points, numPoints, xStart, yStart, xEnd, yEnd); if(A.size == 0) continue; int numAll = A.size; A = filterByZThreshold(A.points, A.size, zThreshold); float * z_threshold = A.points; int numThresh = A.size; if(numThresh == 0) continue; if(numThresh <= zThreshold)// why is this necessary continue; qsort(z_threshold, numThresh, sizeof(float), floatCompare); computeRugosity(z_threshold, numThresh, &outArr[0][j][i]); computeGap(numThresh, numAll, &outArr[1][j][i]); computePercentile(z_threshold, numThresh, 0.85, &outArr[2][j][i]); if(A.size < 75) continue; float * lMoments = computeLMoments(z_threshold, numThresh); outArr[3][j][i] = lMoments[0]; outArr[4][j][i] = lMoments[1]; outArr[5][j][i] = lMoments[2]; outArr[6][j][i] = lMoments[3]; /***************************************************************************** *********************** LHQ Statistics ************************** *****************************************************************/ int band, rank1, rank2; float fRank, iRank, difRank; for(band = 0; band <= 20; band++) { fRank = (band/20.0) * (numThresh + 1); iRank = (int)fRank; //Todo: make sure case truncates difRank = fRank - iRank; rank1 = iRank - 1; if(rank1 < 0) rank1 = 0; rank2 = iRank; if(band < 20) { lhqArr[band][j][i] = (1 - difRank) * z_threshold[rank1] + difRank * z_threshold[rank2]; } else { lhqArr[band][j][i] = z_threshold[numThresh-1]; // max.. this sorted so it should be max } if( band == 17 ) { outArr[7][j][i] = lhqArr[band][j][i]; } } /***************************************************************************** *********************** CCF Statistics ************************** *****************************************************************/ int numDivs, ccfCount; float minHeight, maxHeight, curHeight, ccfPercent, htIncrement; minHeight = zThreshold; maxHeight = getMax(z_threshold, numThresh); // = z_threshold[numThresh-1] numDivs = 20; htIncrement = (maxHeight - minHeight) / numDivs; for(band = 0; band <= 20; band++) { curHeight = minHeight + (htIncrement * band); ccfCount = getCCFCount(z_threshold, numThresh, curHeight); ccfPercent = ccfCount / numAll; ccfArr[band][j][i] = ccfPercent; } } } }