public CylinderDatabase(Cylinder[] givenCylinders, uint[] givenTemplateIndices) { Cylinders = givenCylinders; TemplateIndices = givenTemplateIndices; }
public static extern void createTemplate(Minutia[] minutiae, int minutiaeLenght, out Cylinder[] cylinders, out int cylinderLenght);
public Template(Cylinder[] givenCylinders) { Cylinders = givenCylinders; }
public static double[] GetTemplateSimilarityOptimized(Template query, CylinderDatabase db, int[] dbTemplateLengths) { double[] similarityRates = new double[dbTemplateLengths.Length]; bucketMatrix = new uint[dbTemplateLengths.Length, bucketsCount]; for (int k = 0; k < db.Cylinders.Length; k++) { Cylinder cylinderDb = db.Cylinders[k]; foreach (Cylinder queryCylinder in query.Cylinders) { uint[] givenXOR = queryCylinder.Values.Zip(cylinderDb.Values, (first, second) => first ^ second).ToArray(); //for (int i = 0; i < givenXOR.Length; i++) //{ // Console.Write(givenXOR[i] + ", "); //} //Console.WriteLine(); uint oneBitsCount = CylinderHelper.GetOneBitsCount(givenXOR); //Console.Write(oneBitsCount + " "); double givenXORNorm = Math.Sqrt(oneBitsCount); // Bitwise version //double givenXORNorm = CalculateCylinderNorm(givenXOR); // Stupid version if (CylinderHelper.GetAngleDiff(queryCylinder.Angle, cylinderDb.Angle) < angleThreshold && queryCylinder.Norm + cylinderDb.Norm != 0) { uint bucketIndex = (uint)Math.Floor(givenXORNorm / (queryCylinder.Norm + cylinderDb.Norm) * bucketsCount); //if (bucketIndex >= 63) //{ // Console.Write("LOOOOL"); // Console.WriteLine(k); //} if (bucketIndex == bucketsCount) { bucketIndex--; } uint row = db.TemplateIndices[k]; bucketMatrix[row, bucketIndex]++; } } } //Console.WriteLine("END"); PrintMatrix(bucketMatrix); for (int k = 0; k < dbTemplateLengths.Length; k++) { int numPairs = ComputeNumPairs(dbTemplateLengths[k], query.Cylinders.Length); int sum = 0, t = numPairs, i = 0; while (i < bucketsCount && t > 0) { sum += (int)Math.Min(bucketMatrix[k, i], t) * i; t -= (int)Math.Min(bucketMatrix[k, i], t); i++; } sum += t * (int)bucketsCount; similarityRates[k] = 1 - (float)sum / (numPairs * bucketsCount); } return(similarityRates); }