How to use the desert.primitives.basePrimitive function in desert

To help you get started, we’ve selected a few desert examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inconvergent / desert / desert / primitives.py View on Github external
shape = (ng, 2)

    xy = zeros((ng, 2), npfloat)

    _cuda_sample_box(npint(ng),
                     RGEN.gen_uniform(shape, npfloat),
                     cuda.Out(xy),
                     self._s, self._mid,
                     npint(grains),
                     block=(THREADS, 1, 1),
                     grid=(int(ng//THREADS + 1), 1))

    return xy


class circle(basePrimitive):
  def __init__(self, rad, mid, dens, noise=None):
    basePrimitive.__init__(self)
    self.rad = rad
    self.mid = reshape(mid, (-1, 2)).astype(npfloat)
    self.dens = dens
    self.noise = noise

    self.num = self.mid.shape[0]

    self._mid = None
    self._cuda_init = False

  def __cuda_init(self):
    self._mid = cuda.mem_alloc(self.mid.nbytes)
    cuda.memcpy_htod(self._mid, self.mid)
github inconvergent / desert / desert / primitives.py View on Github external
ng = self.num*grains

    xy = zeros((ng, 2), npfloat)

    _cuda_sample_stroke(npint(ng),
                        self._ab,
                        RGEN.gen_uniform(ng, npfloat),
                        cuda.Out(xy),
                        npint(grains),
                        block=(THREADS, 1, 1),
                        grid=(int(ng//THREADS + 1), 1))

    return xy


class bzspl(basePrimitive):
  def __init__(self, pts, dens, closed=False, noise=None):
    basePrimitive.__init__(self)

    self.num = len(pts)

    # pts = reshape(pts, (-1, 2, self.num)).astype(npfloat)
    pts = dstack(pts).astype(npfloat)

    assert pts.shape[0] > 2, 'must have at least 3 points'

    self.pts = pts

    self.closed = closed
    self.dens = dens
    self.noise = noise
github inconvergent / desert / desert / primitives.py View on Github external
xy = zeros((ng, 2), npfloat)

    _cuda_sample_circle(npint(ng),
                        RGEN.gen_uniform(shape, npfloat),
                        cuda.Out(xy),
                        npfloat(self.rad),
                        self._mid,
                        npint(grains),
                        block=(THREADS, 1, 1),
                        grid=(int(ng//THREADS + 1), 1))

    return xy


class stroke(basePrimitive):
  def __init__(self, a, b, dens, noise=None):
    basePrimitive.__init__(self)

    a = reshape(a, (-1, 2)).astype(npfloat)
    b = reshape(b, (-1, 2)).astype(npfloat)

    assert a.shape[0] == b.shape[0], 'inconsistent number of points in a, b'

    self.ab = column_stack((a, b))

    self.num = self.ab.shape[0]
    self.dens = dens
    self.noise = noise

    self._ab = None
github inconvergent / desert / desert / primitives.py View on Github external
return self

  def est(self, imsize):
    return self._get_n(imsize) * self.num

  def _get_n(self, imsize):
    return NotImplemented

  def sample(self, imsize, verbose=False):
    return NotImplemented

  def json(self):
    return NotImplemented


class box(basePrimitive):
  def __init__(self, s, mid, dens, noise=None):
    basePrimitive.__init__(self)

    try:
      sx, sy = s
    except TypeError:
      sx = s
      sy = s

    self.s = reshape([sx, sy], (1, 2)).astype(npfloat)
    self.mid = reshape(mid, (-1, 2)).astype(npfloat)
    self.dens = dens
    self.noise = noise

    self.num = self.mid.shape[0]