rendered paste body private void scan() { long startTime = UTILITIES.getTimer(); int bestValue = Integer.MAX_VALUE; int vx = this.getScanVarianceX(); int vy = this.getScanVarianceY(); if (b.getWidth() <= a.getWidth()) { // vx = 0; } if (b.getHeight() <= a.getHeight()) { // vy = 0; } vx = Math.min(vx, b.getWidth()); vy = Math.min(vy, b.getHeight()); int scanXFrom = -vx; int scanXTo = a.getWidth() - b.getWidth() + vx; int scanYFrom = -vy; int scanYTo = a.getHeight() - b.getHeight() + vy; int tmp; if (scanXTo < scanXFrom) { tmp = scanXTo; scanXTo = scanXFrom; scanXFrom = tmp; } if (scanYTo < scanYFrom) { tmp = scanYTo; scanYTo = scanYFrom; scanYFrom = tmp; } double maxHeight = a.getHeight(); double maxWidth = a.getWidth(); int value; Letter intersection = new Letter(); for (int xx = getJumperStart(scanXFrom, scanXTo); checkJumper(xx, scanXFrom, scanXTo); xx = nextJump(xx, scanXFrom, scanXTo, 1)) { for (int yy = getJumperStart(scanYFrom, scanYTo); checkJumper(yy, scanYFrom, scanYTo); yy = nextJump(yy, scanYFrom, scanYTo, 1)) { int left = Math.max(0, xx); int right = Math.min(xx + b.getWidth(), a.getWidth()); int top = Math.max(0, yy); int bottom = Math.min(yy + b.getHeight(), a.getHeight()); int tmpIntersectionWidth = right - left; int tmpIntersectionHeight = bottom - top; // logger.info(xx+"/"+yy+" - "+left+"/"+top+" - // "+tmpIntersectionWidth+"/"+tmpIntersectionHeight); if (tmpIntersectionWidth <= 0 || tmpIntersectionHeight <= 0) { logger.warning("Scannvarianzen zu groß: " + tmpIntersectionWidth + "/" + tmpIntersectionHeight); continue; } int pixelAll = 0; int pixelBButNotA = 0; int pixelAButNotB = 0; int pixelBoth = 0; double errorA; double errorB; double errorTotal; double localHeightPercent; double localWidthPercent; double heightFaktor; double widthFaktor; double coverageFaktorA = 0; double coverageFaktorB = 0; Vector<Vector<Integer>> bothElements = new Vector<Vector<Integer>>(); int[][] elementGrid = new int[tmpIntersectionWidth][tmpIntersectionHeight]; int[][] grid = new int[0][0]; if (isCreateIntersectionLetter()) { intersection = new Letter(); intersection.setOwner(owner); grid = new int[tmpIntersectionWidth][tmpIntersectionHeight]; intersection.setGrid(grid); } int both = 0x660099; int bna = 0x0000ff; int anb = 0xff0000; int bnaFiltered = 0xccccff; int anbFiltered = 0xffcccc; Vector<Integer> element; for (int x = 0; x < tmpIntersectionWidth; x++) { for (int y = 0; y < tmpIntersectionHeight; y++) { int pixelType = getPixelType(x, y, xx, yy, left, top); // logger.info(x+"/"+y+"->"+pixelType); pixelAll++; switch (pixelType) { case 0: if (isCreateIntersectionLetter()) grid[x][y] = both; getElement(x, y, xx, yy, left, top, pixelType, elementGrid, element = new Vector<Integer>()); if (element.size() > jas.getInteger("minCleftSize")) bothElements.add(element); pixelBoth++; break; case 1: if (hasNeighbour(x, y, xx, yy, left, top, pixelType) > 0) { pixelBButNotA++; if (isCreateIntersectionLetter()) grid[x][y] = bna; } else { if (isCreateIntersectionLetter()) grid[x][y] = bnaFiltered; } break; case 2: if (hasNeighbour(x, y, xx, yy, left, top, pixelType) > 0) { pixelAButNotB++; if (isCreateIntersectionLetter()) grid[x][y] = anb; } else { if (isCreateIntersectionLetter()) grid[x][y] = anbFiltered; } break; default: if (isCreateIntersectionLetter()) grid[x][y] = 0xffffff; } } } if (pixelAll > 0) { errorA = (double) pixelAButNotB / (double) (pixelBoth + pixelAButNotB); errorB = (double) pixelBButNotA / (double) (pixelBButNotA + pixelBoth); errorTotal = (errorA * jas.getDouble("errorAWeight") + errorB * jas.getDouble("errorBWeight")); coverageFaktorA = Math.min(1.0, (1.0 - ((double) pixelBoth / (double) a.getElementPixel())) * jas.getDouble("coverageFaktorAWeight")); coverageFaktorB = Math.min(1.0, (1.0 - ((double) pixelBoth / (double) b.getElementPixel())) * jas.getDouble("coverageFaktorBWeight")); localHeightPercent = (double) tmpIntersectionHeight / maxHeight; localWidthPercent = (double) tmpIntersectionWidth / maxWidth; heightFaktor = Math.min(1.0, Math.pow(1.0 - localHeightPercent, 2) * jas.getDouble("intersectionDimensionWeight")); widthFaktor = Math.min(1.0, Math.pow(1.0 - localWidthPercent, 3) * jas.getDouble("intersectionDimensionWeight")); double tmpError = errorTotal; tmpError += coverageFaktorA; tmpError += coverageFaktorB; tmpError += heightFaktor; tmpError += widthFaktor; tmpError += (bothElements.size() - 1) * jas.getDouble("cleftFaktor"); tmpError /= 5.0; tmpError = Math.min(1.0, tmpError); // logger.info(pixelBoth+"_"+(tmpIntersectionHeight * // tmpIntersectionWidth)); if ((pixelBoth * 8) < (tmpIntersectionHeight * tmpIntersectionWidth)) { tmpError = errorA = errorB = errorTotal = 1.0; } value = (int) (a.getMaxPixelValue() * tmpError); if (value < bestValue) { bestValue = value; this.setCompareValue(bestValue); this.setHeightFaktor(heightFaktor); this.setWidthFaktor(widthFaktor); this.setIntersectionHeight(tmpIntersectionHeight); this.setIntersectionWidth(tmpIntersectionWidth); this.setIntersectionStartX(xx); this.setIntersectionStartY(yy); this.setBothElementNum(bothElements.size()); this.setCoverageFaktorA(coverageFaktorA); this.setCoverageFaktorB(coverageFaktorB); this.setPixelErrorA(errorA); this.setPixelErrorB(errorB); this.setPixelANotB(pixelAButNotB); this.setPixelBNotA(pixelBButNotA); this.setPixelBoth(pixelBoth); this.setPixelErrorB(errorB); this.setTotalPixelError(errorTotal); if (isCreateIntersectionLetter()) { this.setIntersectionLetter(intersection); } } } } } this.scanTime = (int) (UTILITIES.getTimer() - startTime); }