Beispiel #1
0
def point_poisson():

    global occupation_poisson

    while len(active) > 0:
        check = np.random.randint(0, len(active))
        found = None
        for n in range(k):
            s = _random_vector_function.random_vector_function(
                r, math.floor(r * 2))
            sample = []
            for i in range(0, len(s)):
                sample.append(s[i] + active[check][i])

            gcol = math.floor(sample[0] / w)
            grow = math.floor(sample[1] / w)
            ggrid = gcol + grow * cols

            if gcol > -1 and grow > -1 and gcol < cols and grow < rows:
                ok = True
                #check distance between selected point and points in the around grids
                nums = [-1, 0, 1]
                num1s = [-1, 0, 1]
                for num in nums:
                    for num1 in num1s:
                        if 0 <= gcol + num1 < cols and 0 <= grow + num < rows:
                            index = (gcol + num1) + (grow + num) * cols
                            if grid[index] is None:
                                pass
                            else:
                                d = _distance2d.dist(grid[index][0],
                                                     grid[index][1], sample[0],
                                                     sample[1])
                                if d < r:
                                    ok = None
                if ok is True:
                    found = True
                    grid[gcol + grow * cols] = sample
                    active.append(sample)
                    break
        if found is None:
            del active[check:(check + 1)]

    for i in range(len(grid)):
        if grid[i] is None:
            pass
        else:
            if (grid[i][0] < width - roundRadius[0]) and (
                    grid[i][0] > roundRadius[0]) and (
                        grid[i][1] < height - roundRadius[0]) and (
                            grid[i][1] > roundRadius[0]):
                Circles.append(
                    _Circle.Circle(grid[i][0], grid[i][1], roundRadius[0],
                                   width, height))
                occupation_poisson = occupation_poisson + 1

    # enlarge the particles
    _generateParticle.generateCircles_p(ranges[0], (maximums[0] - 2), Circles)

    print('poisson disk sampling', occupation_poisson)
def generateCircles_p(mindis, maxi, Circles):
    growing = []
    for k in range(len(Circles)):
        if Circles[k].g is True:
            growing.append([Circles[k].x, Circles[k].y])

    while len(growing) > 0:
        for i in range(len(Circles)):
            if Circles[i].g is True:
                if Circles[i].r > maxi:
                    Circles[i].g = None
                    growing.remove([Circles[i].x, Circles[i].y])
                    break
                elif Circles[i].edge() is None:
                    growing.remove([Circles[i].x, Circles[i].y])
                    break
                else:
                    for j in range(len(Circles)):
                        if (j != i) and (
                            (Circles[i].x - mindis) < Circles[j].x <
                            (Circles[i].x + mindis)) and (
                                (Circles[i].y - mindis) < Circles[j].y <
                                (Circles[i].y + mindis)):
                            dis = _distance2d.dist(Circles[i].x, Circles[i].y,
                                                   Circles[j].x, Circles[j].y)
                            if dis < (Circles[i].r + Circles[j].r):
                                Circles[i].g = None
                                growing.remove([Circles[i].x, Circles[i].y])
                                break
            Circles[i].grow()
Beispiel #3
0
def radii(q, initial_radius, range1, maximum1, Circles, cols1, w1, width,
          height):

    valid = True
    yaxis = math.floor(q / cols1)
    xaxis = math.floor(q - yaxis * cols1)

    w_use = w1
    x = np.random.randint(math.floor(xaxis * w_use),
                          math.floor((xaxis + 1) * w_use))
    y = np.random.randint(math.floor(yaxis * w_use),
                          math.floor((yaxis + 1) * w_use))

    #if the randomly selected point in the void grid is too close to borders, it will be deleted.
    m = initial_radius
    min_boundary = [x, y, (width - x), (height - y)]
    min_b = np.amin(min_boundary)
    if min_b < m:
        valid = None

#in the reseaching sphere area with 'mindis' radius
    min_around = []
    if valid is True:
        for j in range(len(Circles)):
            if ((x - range1) < Circles[j].x <
                (x + range1)) or ((y - range1) < Circles[j].y < (y + range1)):
                k = _distance2d.dist(x, y, Circles[j].x,
                                     Circles[j].y) - Circles[j].r
                if (k < m):
                    valid = None
                    break
                else:
                    min_around.append(k)

#generate particles
    if valid is True:

        if not min_around:
            min_a = 0
        else:
            min_a = np.amin(min_around)

        if min_a <= min_b:
            if min_a <= maximum1:
                Circles.append(_Circle.Circle(x, y, min_a, width, height))
                return min_a
            else:
                Circles.append(_Circle.Circle(x, y, maximum1, width, height))
                return maximum1
        elif min_a > min_b:
            if min_b <= maximum1:
                Circles.append(_Circle.Circle(x, y, min_b, width, height))
                return min_b
            else:
                Circles.append(_Circle.Circle(x, y, maximum1, width, height))
                return maximum1
    else:
        return False