Skip to content

Commit

Permalink
added extra argument in poisson lattice to initialize from spcific po…
Browse files Browse the repository at this point in the history
…ints
  • Loading branch information
Mauro d'Arcangelo committed Jul 5, 2024
1 parent ec12b52 commit 9aab828
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion aquapointer/density_canvas/DensityCanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,12 @@ def set_hexagonal_lattice(self, nrows, ncols, spacing):
lattice = Lattice.hexagonal(nrows=nrows, ncols=ncols, spacing=spacing)
self.set_lattice(lattice, centering=True)

def set_poisson_disk_lattice(self, spacing: tuple):
def set_poisson_disk_lattice(self, spacing: tuple, init_points: ArrayLike = None):
lattice = Lattice.poisson_disk(
density=self._density,
length=(self._length_x, self._length_y),
spacing=spacing,
init_points = init_points,
)
self.set_lattice(lattice, centering=True)

Expand Down
19 changes: 13 additions & 6 deletions aquapointer/density_canvas/Lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def hexagonal(cls, nrows: int, ncols: int, spacing: numbers.Number):
return cls(np.array(coords, dtype=float), min_spacing=spacing, center=center, type="hexagonal")

@classmethod
def poisson_disk(cls, density: ArrayLike, length: tuple, spacing: tuple, max_num: int = 8000):
def poisson_disk(cls, density: ArrayLike, length: tuple, spacing: tuple, max_num: int = 8000, init_points: ArrayLike = None):
"""
Poisson disk sampling with variable radius.
density: 2d array representing probability density
Expand Down Expand Up @@ -122,11 +122,18 @@ def _index_from_position(pos):
queue = []
num = 0

# pick the first point as the density maximum and initialize queue
first_point = np.array([np.random.rand()*length_x, np.random.rand()*length_y])
coords.append(first_point)
queue.append(num)
num += 1
# if init_points is defined, inizialize queue with those points
if init_points:
for i,c in enumerate(init_points):
coords.append(np.array(c))
queue.append(i)
num = len(init_points)
# otherwise initialize queue by picking the first point as the density maximum
else:
first_point = np.array([np.random.rand()*length_x, np.random.rand()*length_y])
coords.append(first_point)
queue.append(num)
num += 1

# sample until max number is reached or points cannot be placed
while len(queue) and (num<max_num):
Expand Down

0 comments on commit 9aab828

Please sign in to comment.