All pastes #445642 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-04-18 00:13 UTC
rendered paste body
    public void gatherNewPoints(int points)
        throws InterruptedException
    {
        int tolerances[][] = getToleraces();
        boolean filterThoseNearBy = true;
        long start = System.currentTimeMillis();
        short colorMap[][][] = theScript.getColorArray2d();
        int counts[][][] = new int[theNumberOfHorizontalSearchZones][theNumberOfVerticalSearchZones][theRGBs.length];
        int totalColorCounts[] = new int[theRGBs.length];
        for(int x = 0; x < theNumberOfHorizontalSearchZones; x++)
        {
            for(int y = 0; y < theNumberOfVerticalSearchZones; y++)
            {
                int xS = bounds.x + x * (int)zoneDx;
                int yS = bounds.y + y * (int)zoneDy;
                for(int k = 0; k < theRGBs.length; k++)
                {
                    int count = StaticColorMethods.numRGBs(colorMap, theRGBs[k], xS, yS, xS + (int)zoneDx, yS + (int)zoneDy, tolerances[k][0], tolerances[k][1], tolerances[k][2]);
                    counts[x][y][k] = count;
                    totalColorCounts[k] += count;
                }

            }

        }

        float actualZones[][] = new float[theNumberOfHorizontalSearchZones - 1][theNumberOfVerticalSearchZones - 1];
        float rgbWeight = 1.0F / (float)theRGBs.length;
        for(int x = 0; x < theNumberOfHorizontalSearchZones - 1; x++)
        {
            for(int y = 0; y < theNumberOfVerticalSearchZones - 1; y++)
            {
                for(int k = 0; k < theRGBs.length; k++)
                    if(totalColorCounts[k] > 0)
                    {
                        int colorCount = 0;
                        colorCount += counts[x][y][k];
                        colorCount += counts[x + 1][y][k];
                        colorCount += counts[x][y + 1][k];
                        colorCount += counts[x + 1][y + 1][k];
                        if(colorCount >= minPixleCountInBox)
                            actualZones[x][y] += (rgbWeight * (float)colorCount) / (float)totalColorCounts[k];
                    }

            }

        }

        boolean selected[][] = new boolean[theNumberOfHorizontalSearchZones - 1][theNumberOfVerticalSearchZones - 1];
        XY result[] = new XY[points];
        matchesAtAPoint = new int[points];
        hasPointBeenCompleted = new boolean[points];
        for(int i = 0; i < points; i++)
        {
            int winnerX = -1;
            int winnerY = -1;
            double winner = 0.0D;
            for(int x = 0; x < theNumberOfHorizontalSearchZones - 1; x++)
            {
                for(int y = 0; y < theNumberOfVerticalSearchZones - 1; y++)
                    if(!selected[x][y] && (double)actualZones[x][y] > winner)
                    {
                        winnerX = x;
                        winnerY = y;
                        winner = actualZones[x][y];
                    }

            }

            if(winnerX == -1 || winnerY == -1 || winner == 0.0D)
            {
                XY newResult[] = new XY[i];
                System.arraycopy(result, 0, newResult, 0, i);
                result = newResult;
                break;
            }
            selected[winnerX][winnerY] = true;
            if(filterThoseNearBy)
            {
                boolean innerXinRange = winnerX - 1 != -1;
                boolean outerXinRange = winnerX + 1 != theNumberOfHorizontalSearchZones - 1;
                boolean outerYinRange = winnerY + 1 != theNumberOfVerticalSearchZones - 1;
                boolean innerYinRange = winnerY - 1 != -1;
                if(outerXinRange)
                    selected[winnerX + 1][winnerY] = true;
                if(innerXinRange)
                    selected[winnerX - 1][winnerY] = true;
                if(outerYinRange)
                    selected[winnerX][winnerY + 1] = true;
                if(innerYinRange)
                    selected[winnerX][winnerY - 1] = true;
            }
            int minX = bounds.x + (int)(zoneDx * (float)winnerX);
            int minY = bounds.y + (int)(zoneDy * (float)winnerY);
            int maxX = bounds.x + (int)(zoneDx * (float)(winnerX + 2));
            int maxY = bounds.y + (int)(zoneDy * (float)(winnerY + 2));
            int interval = 6;
            int smallerWinnerX = -1;
            int smallerWinnerY = -1;
            int smallerWinnerCount = -1;
            for(int x = minX; x < maxX; x += 6)
            {
                for(int y = minY; y < maxY; y += 6)
                {
                    int count = 0;
                    for(int k = 0; k < theRGBs.length; k++)
                        count += StaticColorMethods.numRGBs(colorMap, theRGBs[k], x, y, x + 6, y + 6, tolerances[k][0], tolerances[k][1], tolerances[k][2]);

                    if(count > smallerWinnerCount)
                    {
                        smallerWinnerX = x + 3;
                        smallerWinnerY = y + 3;
                        smallerWinnerCount = count;
                    }
                }

            }

            if(paintSearchZones)
                theScript.paintRectangle(new Rectangle(minX, minY, maxX - minX, maxY - minY), new Color(0, 0, 0, 63), 3000);
            result[i] = new XY(smallerWinnerX, smallerWinnerY);
            matchesAtAPoint[i] = smallerWinnerCount;
        }

        thePoints = result;
        if(paintSearchZones)
            paintPoints(4000, Color.red, 1);
        theScript.debug((new StringBuilder("findRGBsCluster() took")).append(System.currentTimeMillis() - start).toString());
    }