예제 #1
0
  def wrap(steps_itt, render):

    global i

    t1 = time()

    steps(DF)
    fn = None

    #edges_coordinates = DF.get_edges_coordinates()
    #sorted_vert_coordinates = DF.get_sorted_vert_coordinates()
    #fn = './res/ani{:04d}.png'.format(i)
    #show_detail(render,edges_coordinates,sorted_vert_coordinates,fn)

    edges_coordinates = DF.get_edges_coordinates()
    fn = './res/ani{:04d}.png'.format(i)
    show(render,edges_coordinates,fn)

    #sorted_vert_coordinates = DF.get_sorted_vert_coordinates()
    #fn = './res/ani{:04d}.png'.format(i)
    #show_closed(render,sorted_vert_coordinates,fn)

    t2 = time()
    print_stats(render.steps, t2-t1, DF)

    i += 1

    return True
def steps(dm):

  from time import time
  from modules.helpers import print_stats

  from numpy import array

  t1 = time()

  dm.find_nearby_sources()

  henum = dm.get_henum()

  surface_edges = array([
    dm.is_surface_edge(i)>0 and r<dm.get_edge_intensity(i)
    for i,r in enumerate(random(size=henum))
    ],
    'bool'
    ).nonzero()[0]

  rnd = random(len(surface_edges)*2)
  the = (1.-2*rnd[::2])*pi
  rad = rnd[1::2]*0.5*H
  dx = cos(the)*rad
  dy = sin(the)*rad

  dm.new_triangles_from_surface_edges(
      surface_edges,
      len(surface_edges),
      H,
      dx,
      dy,
      MINIMUM_LENGTH,
      MAXIMUM_LENGTH,
      1
      )

  dm.optimize_position(
      ATTRACT_STP,
      REJECT_STP,
      TRIANGLE_STP,
      ALPHA,
      DIMINISH,
      1
      )

  henum = dm.get_henum()

  # dm.optimize_edges(2.0*H, NEARL*0.5)
  dm.optimize_edges(SPLIT_LIMIT, FLIP_LIMIT)

  if dm.safe_vertex_positions(3*H)<0:

    print('vertices reached the boundary. stopping.')
    return False

  t2 = time()
  print_stats(0, t2-t1, dm)

  return True
예제 #3
0
def steps(dm):

  from time import time
  from modules.helpers import print_stats

  from numpy import array

  global steps_runs
  steps_runs += 1

  t1 = time()

  dm.optimize_position(
    ATTRACT_SCALE,
    REJECT_SCALE,
    TRIANGLE_SCALE,
    ALPHA,
    DIMINISH,
    -1
  )

  henum = dm.get_henum()

  surface_edges = array(
    [dm.is_surface_edge(i)>0 \
    for i in range(henum)],
    'bool').nonzero()[0]

  rnd = random(len(surface_edges)*2)
  the = (1.-2*rnd[::2])*pi
  rad = rnd[1::2]*0.5*H
  dx = cos(the)*rad
  dy = sin(the)*rad

  dm.new_triangles_from_surface_edges(
    surface_edges,
    len(surface_edges),
    H,
    dx,
    dy,
    MINIMUM_LENGTH,
    MAXIMUM_LENGTH,
    1
  )

  dm.optimize_edges(
    SPLIT_LIMIT,
    FLIP_LIMIT
  )

  if dm.safe_vertex_positions(3*H)<0:

    print('vertices reached the boundary. stopping.')
    return False

  t2 = time()
  print_stats(steps_runs, t2-t1, dm)

  return True
예제 #4
0
def main():

    from time import time
    from itertools import count

    from differentialLine import DifferentialLine

    from modules.helpers import print_stats
    from modules.helpers import get_exporter

    from modules.show import sandstroke
    from modules.show import show
    from modules.show import dots

    DF = DifferentialLine(NMAX, FARL * 2, NEARL, FARL, PROCS)
    exporter = get_exporter(NMAX)

    orderd_verts = zeros((NMAX, 2), 'double')

    ## arc

    # angles = sorted(random(INIT_NUM)*pi*1.5)
    # xys = []
    # for a in angles:
    # x = 0.5 + cos(a)*0.2
    # y = 0.5 + sin(a)*0.2
    # xys.append((x,y))

    # DF.init_line_segment(xys, lock_edges=1)

    angles = sorted(random(INIT_NUM) * TWOPI)
    DF.init_circle_segment(MID, MID, 0.2, angles)

    for i in count():

        t_start = time()

        DF.optimize_position(STP)
        spawn_curl(DF, NEARL, 0.016)

        if i % EXPORT_ITT == 0:

            exporter(
                DF,
                {
                    'nearl': NEARL,
                    'farl': FARL,
                    'stp': STP,
                    'size': SIZE,
                    'procs': PROCS,
                    'prefix': PREFIX
                },
                i,
            )

        t_stop = time()

        print_stats(i, t_stop - t_start, DF)
def steps(dm):

    from time import time
    from modules.helpers import print_stats

    from numpy import array

    global steps_runs
    steps_runs += 1

    t1 = time()

    dm.find_nearby_sources()

    henum = dm.get_henum()

    surface_edges = array([
        dm.is_surface_edge(i) > 0 and r < dm.get_edge_intensity(i)
        for i, r in enumerate(random(size=henum))
    ], 'bool').nonzero()[0]

    rnd = random(len(surface_edges) * 2)
    the = (1. - 2 * rnd[::2]) * pi
    rad = rnd[1::2] * 0.5 * H
    dx = cos(the) * rad
    dy = sin(the) * rad

    dm.new_triangles_from_surface_edges(surface_edges, len(surface_edges), H,
                                        dx, dy, MINIMUM_LENGTH, MAXIMUM_LENGTH,
                                        1)

    dm.optimize_position(ATTRACT_STP, REJECT_STP, TRIANGLE_STP, ALPHA,
                         DIMINISH, -1)

    henum = dm.get_henum()

    # dm.optimize_edges(2.0*H, NEARL*0.5)
    dm.optimize_edges(SPLIT_LIMIT, FLIP_LIMIT)

    if dm.safe_vertex_positions(3 * H) < 0:

        print('vertices reached the boundary. stopping.')
        return False

    t2 = time()
    print_stats(steps_runs, t2 - t1, dm)

    return True
예제 #6
0
def main():

  from time import time
  from itertools import count

  from render.render import Render
  from modules.helpers import print_stats
  from modules.show import show
  from modules.show import show_closed

  from differentialLine import DifferentialLine


  DF = DifferentialLine(NMAX, FARL*2, NEARL, FARL, PROCS)

  render = Render(SIZE, BACK, FRONT)

  render.ctx.set_source_rgba(*FRONT)
  render.ctx.set_line_width(LINEWIDTH)

  angles = sorted(random(NINIT)*TWOPI)

  DF.init_circle_segment(MID,MID,RAD, angles)

  t_start = time()


  for i in count():

    DF.optimize_position(STP)
    spawn_curl(DF,NEARL)

    if i % STAT_ITT == 0:

      print_stats(i,time()-t_start,DF)

    if i % EXPORT_ITT == 0:

      fn = './res/oryx_bb_{:010d}.png'.format(i)
      num = DF.np_get_edges_coordinates(np_edges)
      show(render,np_edges[:num,:],fn)

      fn = './res/oryx_bb_closed_{:010d}.png'.format(i)
      num = DF.np_get_sorted_vert_coordinates(np_verts)
      show_closed(render,np_verts[:num,:],fn)
예제 #7
0
def main():

  from time import time
  from itertools import count

  from render.render import Render
  from modules.helpers import print_stats
  from modules.show import show

  from differentialLine import DifferentialLine


  DF = DifferentialLine(NMAX, NZ, NEARL, FARL, PROCS)

  render = Render(SIZE, BACK, FRONT)

  render.ctx.set_source_rgba(*FRONT)
  render.ctx.set_line_width(LINEWIDTH)

  #angles = sorted(random(INIT_NUM)*TWOPI)
  #DF.init_passive_circle_segment(MID,MID,100*ONE, angles)

  angles = sorted(random(INIT_NUM)*pi*5/8)
  xys = []
  for a in angles:
    x = 0.5 + cos(a)*0.01
    y = 0.5 + sin(a)*0.01
    xys.append((x,y))

  DF.init_passive_line_segment(xys)


  for i in count():

    t_start = time()

    steps(DF,STEPS_ITT)

    t_stop = time()

    print_stats(i*STEPS_ITT,t_stop-t_start,DF)

    fn = './res/collapse_e_{:010d}.png'.format(i*STEPS_ITT)
    num = DF.np_get_edges_coordinates(np_coords)
    show(render,np_coords[:num,:],fn,ONE)
예제 #8
0
def steps(dm):

    from time import time
    from modules.helpers import print_stats

    from numpy import array

    global steps_runs
    steps_runs += 1

    t1 = time()

    dm.optimize_position(ATTRACT_STP, REJECT_STP, TRIANGLE_STP, ALPHA,
                         DIMINISH, -1)

    henum = dm.get_henum()

    surface_edges = array(
      [dm.is_surface_edge(i)>0 \
      for i in range(henum)],
      'bool').nonzero()[0]

    rnd = random(len(surface_edges) * 2)
    the = (1. - 2 * rnd[::2]) * pi
    rad = rnd[1::2] * 0.5 * H

    num_new = dm.new_triangles_from_surface_edges(surface_edges,
                                                  len(surface_edges), H,
                                                  cos(the) * rad,
                                                  sin(the) * rad,
                                                  MINIMUM_LENGTH,
                                                  MAXIMUM_LENGTH, 1)

    dm.optimize_edges(SPLIT_LIMIT, FLIP_LIMIT)

    if dm.safe_vertex_positions(3 * H) < 0:

        print('vertices reached the boundary. stopping.')
        return False

    t2 = time()
    print_stats(steps_runs, t2 - t1, dm)

    return True
예제 #9
0
  def wrap(steps_itt, render):

    global i
    global np_coords
    global np_vert_coords

    fn = None

    t1 = time()

    steps(DF)

    #coord_num = DF.np_get_edges_coordinates(np_coords)
    ##fn = './res/ani{:04d}.png'.format(i)
    #sandstroke(render,np_coords[:coord_num,:],10,fn)


    #if i%2==0:
      #fn = './res/ani{:04d}.png'.format(i)
    #else:
      #fn=None

    render.set_front(FRONT)
    vert_num = DF.np_get_vert_coordinates(np_vert_coords)
    dots(render,np_vert_coords[:vert_num,:],fn)

    #render.set_front([0,0.8,0.8,0.05])
    #coord_num = DF.np_get_edges_coordinates(np_coords)
    #sandstroke(render,np_coords[:coord_num,:],8,None)

    #coord_num = DF.np_get_edges_coordinates(np_coords)
    #show(render,np_coords[:coord_num,:],clear=True)

    if i%10==0:
      coord_num = DF.np_get_edges_coordinates(np_coords)
      sandstroke(render,np_coords[:coord_num,:],8,None)

    t2 = time()
    print_stats(render.steps, t2-t1, DF)

    i += 1

    return True
예제 #10
0
def steps(df):

    from time import time
    from modules.helpers import print_stats

    t1 = time()

    df.optimize_position(STP)
    spawn_curl(df, NEARL)

    if df.safe_vertex_positions(3 * STP) < 0:

        print('vertices reached the boundary. stopping.')
        return False

    t2 = time()
    print_stats(0, t2 - t1, df)

    return True
예제 #11
0
def main():

  from time import time
  from itertools import count

  from render.render import Render
  from modules.helpers import print_stats
  from modules.show import show
  from modules.show import show_closed

  from differentialLine import DifferentialLine


  DF = DifferentialLine(NMAX, FARL*2, NEARL, FARL, PROCS)

  render = Render(SIZE, BACK, FRONT)

  render.ctx.set_source_rgba(*FRONT)
  render.ctx.set_line_width(LINEWIDTH)

  angles = sorted(random(NINIT))

  DF.init_circle_segment(MID,MID,RAD, angles)


  for i in count():

    t_start = time()

    steps(DF,STEPS_ITT)

    t_stop = time()

    print_stats(i*STEPS_ITT,t_stop-t_start,DF)

    fn = './res/oryx_bb_{:010d}.png'.format(i*STEPS_ITT)
    edges_coordinates = DF.get_edges_coordinates()
    show(render,edges_coordinates,fn)


    fn = './res/oryx_bb_closed_{:010d}.png'.format(i*STEPS_ITT)
    sorted_vert_coordinates = DF.get_sorted_vert_coordinates()
    show_closed(render,sorted_vert_coordinates,fn)
def steps(df):

  from time import time
  from modules.helpers import print_stats

  t1 = time()

  df.optimize_position(STP)
  spawn_curl(df, NEARL)

  if df.safe_vertex_positions(3*STP)<0:

    print('vertices reached the boundary. stopping.')
    return False

  t2 = time()
  print_stats(0, t2-t1, df)

  return True
예제 #13
0
def main():

    from time import time
    from itertools import count

    from render.render import Render
    from modules.helpers import print_stats
    from modules.show import show
    from modules.show import show_closed

    from differentialLine import DifferentialLine

    DF = DifferentialLine(NMAX, FARL * 2, NEARL, FARL, PROCS)

    render = Render(SIZE, BACK, FRONT)

    render.ctx.set_source_rgba(*FRONT)
    render.ctx.set_line_width(LINEWIDTH)

    angles = sorted(random(NINIT))

    DF.init_circle_segment(MID, MID, RAD, angles)

    for i in count():

        t_start = time()

        steps(DF, STEPS_ITT)

        t_stop = time()

        print_stats(i * STEPS_ITT, t_stop - t_start, DF)

        fn = './res/oryx_bb_{:010d}.png'.format(i * STEPS_ITT)
        edges_coordinates = DF.get_edges_coordinates()
        show(render, edges_coordinates, fn)

        fn = './res/oryx_bb_closed_{:010d}.png'.format(i * STEPS_ITT)
        sorted_vert_coordinates = DF.get_sorted_vert_coordinates()
        show_closed(render, sorted_vert_coordinates, fn)
  def wrap(steps_itt, render):

    global i
    global np_coords

    t1 = time()

    steps(DF)#

    if i%3 == 0:
      fn = './res/ani{:04d}.png'.format(i)
    else:
      fn = None

    num = DF.np_get_edges_coordinates(np_coords)
    show(render,np_coords[:num,:],fn,ONE)
    #sandstroke(render,np_coords[:num,:],8,None)

    t2 = time()
    print_stats(render.steps, t2-t1, DF)

    i += 1

    return True
def steps(dm):

  from numpy import cos
  from numpy import sin
  from numpy import unique
  from numpy.random import randint, random
  from time import time
  from modules.helpers import print_stats

  global steps_runs
  steps_runs += 1

  t1 = time()
  for i in range(STEPS_ITT):

    dm.optimize_position(
      ATTRACT_STP,
      REJECT_STP,
      TRIANGLE_STP,
      ALPHA,
      DIMINISH,
      -1
    )

    henum = dm.get_henum()

    edges = unique(randint(henum,size=(henum)))
    en = len(edges)
    rnd = 1-2*random(en*2)
    make_island = random(size=en)>0.85

    for i,(he,isl) in enumerate(zip(edges,make_island)):

      if dm.is_surface_edge(he)>0:

        the = pi*rnd[2*i]
        rad = rnd[2*i+1]*0.5
        dx = cos(the)
        dy = sin(the)

        if not isl:

          dm.new_triangle_from_surface_edge(
            he,
            H,
            dx*rad*H,
            dy*rad*H,
            minimum_length=MINIMUM_LENGTH,
            maximum_length=MAXIMUM_LENGTH,
            merge_ragged_edge=1
          )

        else:

          dm.throw_seed_triangle(
            he,
            H,
            dx*rad*H,
            dy*rad*H,
            NEARL*0.5,
            the
          )

    dm.optimize_edges(
      SPLIT_LIMIT,
      FLIP_LIMIT
    )

    if dm.safe_vertex_positions(3*H)<0:

      print('vertices reached the boundary. stopping.')
      return False

  t2 = time()
  print_stats(steps_runs, t2-t1, dm)

  return True
예제 #16
0
def main():

  from differentialMesh import DifferentialMesh
  from render.render import Render
  from time import time
  from modules.helpers import print_stats

  from numpy.random import randint, random

  from numpy import unique


  DM = DifferentialMesh(NMAX, 2*FARL, NEARL, FARL, PROCS)

  DM.new_faces_in_ngon(MID, MID, H, 6, 0.0)

  render = Render(SIZE, BACK, FRONT)
  render.set_line_width(LINEWIDTH)


  tsum = 0

  for i in xrange(10000):

    t1 = time()
    for _ in xrange(STEPS_ITT):

      DM.optimize_position(
        ATTRACT_SCALE,
        REJECT_SCALE,
        TRIANGLE_SCALE,
        ALPHA,
        DIMINISH,
        -1
      )

      henum = DM.get_henum()

      edges = unique(randint(henum,size=(henum)))
      en = len(edges)
      rnd = 1-2*random(size=en*2)
      make_island = random(size=en)>0.85

      for i,(he,isl) in enumerate(zip(edges,make_island)):

        if DM.is_surface_edge(he)>0:

          the = pi*rnd[2*i]
          rad = rnd[2*i+1]*0.5
          dx = cos(the)*rad*H
          dy = sin(the)*rad*H

          if not isl:

            DM.new_triangle_from_surface_edge(
              he,
              H,
              dx*rad*H,
              dy*rad*H,
              minimum_length=MINIMUM_LENGTH,
              maximum_length=MAXIMUM_LENGTH,
              merge_ragged_edge=1
            )

          else:

            DM.throw_seed_triangle(
              he,
              H,
              dx*rad*H,
              dy*rad*H,
              NEARL*0.5,
              the
            )

      DM.optimize_edges(
        SPLIT_LIMIT,
        FLIP_LIMIT
      )

      tsum += time() - t1

    print_stats(render.num_img, tsum, DM)
    show(render, DM)
    tsum = 0
예제 #17
0
def main():

  from time import time
  from itertools import count

  from render.render import Render
  from modules.helpers import print_stats
  from modules.show import show
  # from modules.show import show_closed

  from differentialLine import DifferentialLine
  from modules.helpers import get_exporter

  from numpy.random import random

  from fn import Fn

  DF = DifferentialLine(NMAX, FARL*2, NEARL, FARL, PROCS)

  fn = Fn(prefix='./res/')

  exporter = get_exporter(
    NMAX,
    {
      'nearl': NEARL,
      'farl': FARL,
      'stp': STP,
      'size': SIZE,
      'procs': PROCS
    }
  )

  render = Render(SIZE, BACK, FRONT)

  render.ctx.set_source_rgba(*FRONT)
  render.ctx.set_line_width(LINEWIDTH)

  angles = sorted(random(INIT_NUM)*TWOPI)

  DF.init_circle_segment(MID,MID,INIT_RAD, angles)

  t_start = time()


  for i in count():

    DF.optimize_position(STP)
    # spawn_curl(DF,NEARL)
    spawn(DF, NEARL, 0.03)

    if i % STAT_ITT == 0:

      print_stats(i,time()-t_start,DF)

    if i % EXPORT_ITT == 0:

      name = fn.name()

      num = DF.np_get_edges_coordinates(np_edges)
      show(render,np_edges[:num,:],name+'.png')

      exporter(
        DF,
        name+'.2obj'
      )
예제 #18
0
def main():

    from differentialMesh import DifferentialMesh
    from render.render import Render
    from time import time
    from modules.helpers import print_stats

    from numpy.random import randint, random

    from numpy import unique

    DM = DifferentialMesh(NMAX, 2 * FARL, NEARL, FARL, PROCS)

    DM.new_faces_in_ngon(MID, MID, H, 6, 0.0)

    render = Render(SIZE, BACK, FRONT)
    render.set_line_width(LINEWIDTH)

    tsum = 0

    for i in xrange(10000):

        t1 = time()
        for _ in xrange(STEPS_ITT):

            DM.optimize_position(ATTRACT_STP, REJECT_STP, TRIANGLE_STP, ALPHA,
                                 DIMINISH, -1)

            henum = DM.get_henum()

            edges = unique(randint(henum, size=(henum)))
            en = len(edges)
            rnd = 1 - 2 * random(size=en * 2)
            make_island = random(size=en) > 0.85

            for i, (he, isl) in enumerate(zip(edges, make_island)):

                if DM.is_surface_edge(he) > 0:

                    the = pi * rnd[2 * i]
                    rad = rnd[2 * i + 1] * 0.5
                    dx = cos(the) * rad * H
                    dy = sin(the) * rad * H

                    if not isl:

                        DM.new_triangle_from_surface_edge(
                            he,
                            H,
                            dx * rad * H,
                            dy * rad * H,
                            minimum_length=MINIMUM_LENGTH,
                            maximum_length=MAXIMUM_LENGTH,
                            merge_ragged_edge=1)

                    else:

                        DM.throw_seed_triangle(he, H, dx * rad * H,
                                               dy * rad * H, NEARL * 0.5, the)

            DM.optimize_edges(SPLIT_LIMIT, FLIP_LIMIT)

            tsum += time() - t1

        print_stats(render.num_img, tsum, DM)
        show(render, DM)
        tsum = 0
예제 #19
0
def main():

  from differentialMesh import DifferentialMesh
  from render.render import Render
  from time import time
  from modules.helpers import print_stats
  from numpy import array


  DM = DifferentialMesh(NMAX, 2*FARL, NEARL, FARL, PROCS)

  DM.new_faces_in_ngon(MID, MID, H, 6, 0.0)

  render = Render(SIZE, BACK, FRONT)
  render.set_line_width(LINEWIDTH)

  # st = named_sub_timers()

  tsum = 0


  for i in xrange(10000000):

    t1 = time()
    for _ in xrange(STEPS_ITT):

      # st.start()
      DM.optimize_position(
        ATTRACT_SCALE,
        REJECT_SCALE,
        TRIANGLE_SCALE,
        ALPHA,
        DIMINISH,
        -1
      )
      # st.t('opt')

      henum = DM.get_henum()
      # st.t('rnd')

      surface_edges = array(
        [DM.is_surface_edge(e)>0
        for e in range(henum)],
        'bool').nonzero()[0]

      # st.t('surf')

      rnd = random(size=len(surface_edges)*2)
      the = (1.-2*rnd[::2])*pi
      rad = rnd[1::2]*0.5*H
      dx = cos(the)*rad
      dy = sin(the)*rad
      # st.t('rnd2')

      DM.new_triangles_from_surface_edges(
        surface_edges,
        len(surface_edges),
        H,
        dx,
        dy,
        MINIMUM_LENGTH,
        MAXIMUM_LENGTH,
        1
      )
      # st.t('tri')

      # st.start()
      DM.optimize_edges(
        SPLIT_LIMIT,
        FLIP_LIMIT
      )
      # st.t('opte')

      tsum += time() - t1

    print_stats(i*STEPS_ITT, tsum, DM)
    show(render, DM)
    tsum = 0
예제 #20
0
def main():

    from time import time
    from itertools import count

    from differentialLine import DifferentialLine

    from render.render import Render
    from modules.helpers import print_stats

    from modules.show import sandstroke
    from modules.show import show
    from modules.show import dots

    np_coords = zeros(shape=(NMAX, 4), dtype='float')
    np_vert_coords = zeros(shape=(NMAX, 2), dtype='float')

    DF = DifferentialLine(NMAX, FARL * 2, NEARL, FARL, PROCS)

    render = Render(SIZE, BACK, FRONT)

    render.ctx.set_source_rgba(*FRONT)
    render.ctx.set_line_width(LINEWIDTH)

    ## arc

    #angles = sorted(random(INIT_NUM)*pi*1.5)
    #xys = []
    #for a in angles:
    #x = 0.5 + cos(a)*0.2
    #y = 0.5 + sin(a)*0.2
    #xys.append((x,y))

    ## vertical line

    #yy = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
    #xx = MID+0.005*(0.5-random(INIT_NUM))
    #xys = []
    #for x,y in zip(xx,yy):
    #xys.append((x,y))

    #DF.init_line_segment(xys, lock_edges=1)

    ## diagonal line

    yy = sorted(MID + 0.2 * (1 - 2 * random(INIT_NUM)))
    xx = sorted(MID + 0.2 * (1 - 2 * random(INIT_NUM)))
    xys = []
    for x, y in zip(xx, yy):
        xys.append((x, y))

    DF.init_line_segment(xys, lock_edges=1)

    for i in count():

        t_start = time()

        DF.optimize_avoid(STP)
        spawn_curl(DF, NEARL)

        if i % 100 == 0:
            fn = './res/line_expand_ab_{:04d}.png'.format(i)
        else:
            fn = None

        render.set_front(FRONT)
        num = DF.np_get_edges_coordinates(np_coords)
        sandstroke(render, np_coords[:num, :], 20, fn)

        if i % 40 == 0:
            render.set_front([0, 0, 0, 0.3])
            num = DF.np_get_edges_coordinates(np_coords)
            sandstroke(render, np_coords[:num, :], 10, fn)

        t_stop = time()

        print_stats(i, t_stop - t_start, DF)
예제 #21
0
def main():

  from time import time
  from itertools import count

  from numpy import pi
  from numpy.random import random

  from modules.growth import spawn_curl
  from modules.utils import get_exporter
  from modules.helpers import env_or_default
  from modules.helpers import print_stats

  from differentialLine import DifferentialLine


  comm = MPI.COMM_WORLD
  nodes = comm.Get_size()
  rank = comm.Get_rank()

  if rank == 0:

    size = env_or_default('SIZE', SIZE)
    nmax = env_or_default('NMAX', NMAX)
    one = 1.0/size

    export_itt = env_or_default('EXPORT_ITT', EXPORT_ITT)
    stat_itt = env_or_default('STAT_ITT', STAT_ITT)

    data = {
      'size': size,
      'nmax': nmax,
      'vmax': env_or_default('VMAX', NMAX),
      'procs': env_or_default('PROCS', PROCS),
      'nodes': nodes,
      'prefix': env_or_default('PREFIX', PREFIX),
      'ninit': env_or_default('NINIT', NINIT),
      'rad': env_or_default('RAD', RAD),
      'one': one,
      'stp': env_or_default('STP', STP)*one,
      'nearl': env_or_default('NEARL', NEARL)*one,
      'farl': env_or_default('FARL', FARL)*one
    }

  else:
    data = None

  data = comm.bcast(data, root=0)

  DF = DifferentialLine(
    data['nmax'],
    zonewidth = data['farl'],
    nearl = data['nearl'],
    farl = data['farl'],
    procs = data['procs'],
    nodes = data['nodes']
  )

  if rank == 0:

    angles = sorted(random(data['ninit'])*pi*2)

    DF.init_circle_segment(0.5, 0.5, data['rad'], angles)

    t_start = time()
    do_export = get_exporter(nmax, t_start)

  for i in count():

    DF.optimize_position(data['stp'])

    if DF.get_vnum()>data['vmax']:
      if rank == 0:
        do_export(DF, data, i, final=True)
      return

    if rank == 0:

      spawn_curl(DF,data['nearl'])

      if i % stat_itt == 0:
        print_stats(i,time()-t_start,DF)
      if i % export_itt == 0:
          do_export(DF, data, i)
def steps(dm):

    from numpy import cos
    from numpy import sin
    from numpy import unique
    from numpy.random import randint, random
    from time import time
    from modules.helpers import print_stats

    global steps_runs
    steps_runs += 1

    t1 = time()
    for i in range(STEPS_ITT):

        dm.optimize_position(ATTRACT_STP, REJECT_STP, TRIANGLE_STP, ALPHA,
                             DIMINISH, -1)

        henum = dm.get_henum()

        edges = unique(randint(henum, size=(henum)))
        en = len(edges)
        rnd = 1 - 2 * random(en * 2)
        make_island = random(size=en) > 0.85

        for i, (he, isl) in enumerate(zip(edges, make_island)):

            if dm.is_surface_edge(he) > 0:

                the = pi * rnd[2 * i]
                rad = rnd[2 * i + 1] * 0.5
                dx = cos(the)
                dy = sin(the)

                if not isl:

                    dm.new_triangle_from_surface_edge(
                        he,
                        H,
                        dx * rad * H,
                        dy * rad * H,
                        minimum_length=MINIMUM_LENGTH,
                        maximum_length=MAXIMUM_LENGTH,
                        merge_ragged_edge=1)

                else:

                    dm.throw_seed_triangle(he, H, dx * rad * H, dy * rad * H,
                                           NEARL * 0.5, the)

        dm.optimize_edges(SPLIT_LIMIT, FLIP_LIMIT)

        if dm.safe_vertex_positions(3 * H) < 0:

            print('vertices reached the boundary. stopping.')
            return False

    t2 = time()
    print_stats(steps_runs, t2 - t1, dm)

    return True
예제 #23
0
def main():

  from time import time
  from itertools import count

  from iutils.render import Render
  from modules.helpers import print_stats
  from modules.show import show
  # from modules.show import show_closed

  from differentialLine import DifferentialLine
  from modules.helpers import get_exporter

  from numpy.random import random

  from fn import Fn

  DF = DifferentialLine(NMAX, FARL*2, NEARL, FARL, PROCS)

  fn = Fn(prefix='./res/')

  exporter = get_exporter(
    NMAX,
    {
      'nearl': NEARL,
      'farl': FARL,
      'stp': STP,
      'size': SIZE,
      'procs': PROCS
    }
  )

  render = Render(SIZE, BACK, FRONT)

  render.ctx.set_source_rgba(*FRONT)
  render.ctx.set_line_width(LINEWIDTH)

  angles = sorted(random(INIT_NUM)*TWOPI)

  DF.init_circle_segment(MID,MID,INIT_RAD, angles)

  t_start = time()


  for i in count():

    DF.optimize_position(STP)
    # spawn_curl(DF,NEARL)
    spawn(DF, NEARL, 0.03)

    if i % STAT_ITT == 0:

      print_stats(i,time()-t_start,DF)

    if i % EXPORT_ITT == 0:

      name = fn.name()

      num = DF.np_get_edges_coordinates(np_edges)
      show(render,np_edges[:num,:],name+'.png')

      exporter(
        DF,
        name+'.2obj'
      )
예제 #24
0
def main():

    from time import time
    from itertools import count

    from differentialLine import DifferentialLine

    from iutils.render import Render
    from modules.helpers import print_stats

    from modules.show import sandstroke
    from modules.show import show
    from modules.show import dots

    np_coords = zeros(shape=(NMAX, 4), dtype='float')
    np_vert_coords = zeros(shape=(NMAX, 2), dtype='float')

    DF = DifferentialLine(NMAX, FARL * 2, NEARL, FARL, PROCS)

    render = Render(SIZE, BACK, FRONT)

    render.ctx.set_source_rgba(*FRONT)
    render.ctx.set_line_width(LINEWIDTH)

    angles = sorted(random(INIT_NUM) * TWOPI)
    DF.init_circle_segment(MID, MID, 0.025, angles)

    # arc

    # angles = sorted(random(INIT_NUM)*pi*1.5)
    # xys = []
    # for a in angles:
    #   x = 0.5 + cos(a)*0.2
    #   y = 0.5 + sin(a)*0.2
    #   xys.append((x,y))

    # DF.init_line_segment(xys, lock_edges=1)

    # vertical line

    # yy = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
    # xx = MID+0.005*(0.5-random(INIT_NUM))
    # xys = []
    # for x, y in zip(xx, yy):
    #     xys.append((x, y))

    # DF.init_line_segment(xys, lock_edges=1)

    # diagonal line

    # yy = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
    # xx = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
    # xys = []
    # for x, y in zip(xx, yy):
    #     xys.append((x, y))

    # DF.init_line_segment(xys, lock_edges=1)

    for i in count():

        t_start = time()

        DF.optimize_position(STP)
        spawn_curl(DF, NEARL, 0.016)

        if i % 500 == 0:
            fn = './res/chris_bd_{:04d}.png'.format(i)
        else:
            fn = None

        render.set_front(FRONT)
        num = DF.np_get_edges_coordinates(np_coords)
        #sandstroke(render, np_coords[:num, :], 20, fn)

        if random() < 0.05:
            sandstroke(render, np_coords[:num, :], 30, None)

        vert_num = DF.np_get_vert_coordinates(np_vert_coords)
        #dots(render, np_vert_coords[:vert_num, :], None)
        dots(render, np_vert_coords[:vert_num, :], fn)

        t_stop = time()

        print_stats(i, t_stop - t_start, DF)
예제 #25
0
def main(args):

    from differentialCloud import DifferentialCloud
    from modules.helpers import print_stats
    from modules.helpers import make_info_str
    from modules.utils import get_initial_cloud
    from dddUtils.ioOBJ import export as export_obj
    from numpy.random import random
    from numpy import array, zeros

    reject = args.reject * args.stp
    attract = args.attract * args.stp
    stat = args.stat
    export = args.export
    out = args.out
    vnum_max = args.vnum
    start_num = args.startNum
    start_rad = args.startRad
    nearl = args.nearl
    midl = args.midl
    farl = args.farl

    np_verts = zeros((args.nmax, 3), 'float')

    DC = DifferentialCloud(nmax=args.nmax,
                           zonewidth=args.farl,
                           nearl=nearl,
                           midl=midl,
                           farl=farl,
                           procs=args.procs)

    xyz, mode = get_initial_cloud(start_num, start_rad)

    DC.init_cloud(xyz, mode)
    DC.init_rules(array([[1.0, 1.0], [1.0, -1.0]], 'double'),
                  array([[nearl, farl], [nearl, farl]], 'double'))

    for i in xrange(args.itt):

        try:

            rnd = (random(size=DC.get_vnum()) < 0.001).nonzero()[0]
            if len(rnd) > 0:
                DC.spawn(rnd)

            DC.optimize_position(reject, attract, nearl * 0.1)

            if i % stat == 0:
                print_stats(i, DC, meta=None)

            if i % export == 0:

                vnum = DC.np_get_vertices(np_verts)
                export_obj(obj_name='cloud',
                           fn='{:s}_{:012d}.obj'.format(out, i),
                           verts=np_verts[:vnum, :],
                           tris=None,
                           meta=make_info_str(args))

            if DC.get_vnum() > vnum_max:
                return

        except KeyboardInterrupt:

            break
예제 #26
0
def main():

  from differentialMesh import DifferentialMesh
  from iutils.render import Render
  from time import time
  from modules.helpers import print_stats
  from numpy import array

  from modules.utils import get_exporter
  exporter = get_exporter(NMAX)

  DM = DifferentialMesh(NMAX, 2*FARL, NEARL, FARL, PROCS)

  DM.new_faces_in_ngon(MID, MID, H, 6, 0.0)

  render = Render(SIZE, BACK, FRONT)
  render.set_line_width(LINEWIDTH)

  fn = Fn(prefix='./res/')


  # st = named_sub_timers()

  tsum = 0


  for i in range(10000000):

    t1 = time()
    for _ in range(STEPS_ITT):

      # st.start()
      DM.optimize_position(
        ATTRACT_STP,
        REJECT_STP,
        TRIANGLE_STP,
        ALPHA,
        DIMINISH,
        -1
      )
      # st.t('opt')

      henum = DM.get_henum()
      # st.t('rnd')

      surface_edges = array(
        [DM.is_surface_edge(e)>0
        for e in range(henum)],
        'bool').nonzero()[0]

      # st.t('surf')

      rnd = random(size=len(surface_edges)*2)
      the = (1.-2*rnd[::2])*pi
      rad = rnd[1::2]*0.5*H
      dx = cos(the)*rad
      dy = sin(the)*rad
      # st.t('rnd2')

      DM.new_triangles_from_surface_edges(
        surface_edges,
        len(surface_edges),
        H,
        dx,
        dy,
        MINIMUM_LENGTH,
        MAXIMUM_LENGTH,
        1
      )
      # st.t('tri')

      # st.start()
      DM.optimize_edges(
        SPLIT_LIMIT,
        FLIP_LIMIT
      )
      # st.t('opte')

      tsum += time() - t1

    print_stats(i*STEPS_ITT, tsum, DM)
    name = fn.name()

    ## export png
    show(render, DM, name+'.png')

    ## export obj
    exporter(
      DM,
      name + '.2obj',
      {
        'procs': PROCS,
        'nearl': NEARL,
        'farl': FARL,
        'reject_stp': 0,
        'attract_stp': 0,
        'triangle_stp': 0,
        'size': SIZE
      },
      i*STEPS_ITT
    )
    tsum = 0
def main():

  from time import time
  from iutils.render import Render
  from differentialMesh import DifferentialMesh
  from modules.helpers import darts
  from modules.helpers import print_stats
  from numpy import array


  DM = DifferentialMesh(NMAX, 2*FARL, NEARL, FARL, PROCS)

  DM.new_faces_in_ngon(MID,MID, H, 7, 0)
  DM.set_edge_intensity(1, 1)

  sources = [(x,y) for x,y in darts(NUM_SOURCES, MID, MID, 0.43, 0.002)]
  DM.initialize_sources(sources, NEARL)

  render = Render(SIZE, BACK, FRONT)


  for i in range(1000000):

    t1 = time()
    for _ in range(STEPS_ITT):

      DM.find_nearby_sources()

      henum = DM.get_henum()

      surface_edges = array(
        [DM.is_surface_edge(e)>0 and r<DM.get_edge_intensity(e)
        for e,r in enumerate(random(size=henum))],
        'bool').nonzero()[0]

      rnd = random(size=len(surface_edges)*2)
      the = (1.-2*rnd[::2])*pi
      rad = rnd[1::2]*0.5*H
      dx = cos(the)*rad
      dy = sin(the)*rad

      DM.new_triangles_from_surface_edges(
        surface_edges,
        len(surface_edges),
        H,
        dx,
        dy,
        MINIMUM_LENGTH,
        MAXIMUM_LENGTH,
        1
      )

      DM.optimize_position(
        ATTRACT_STP,
        REJECT_STP,
        TRIANGLE_STP,
        ALPHA,
        DIMINISH,
        -1
      )

      henum = DM.get_henum()

      DM.optimize_edges(
        SPLIT_LIMIT,
        FLIP_LIMIT
      )

      if DM.safe_vertex_positions(3*H)<0:

        show_circles(render, DM, sources)
        print('vertices reached the boundary. stopping.')
        return

    show_circles(render, DM, sources)

    t2 = time()
    print_stats(i*STEPS_ITT, t2-t1, DM)
예제 #28
0
def main(args):

  from differentialCloud import DifferentialCloud
  from modules.helpers import print_stats
  from modules.helpers import make_info_str
  from modules.utils import get_initial_cloud
  from dddUtils.ioOBJ import export as export_obj
  from numpy.random import random
  from numpy import array, zeros

  reject = args.reject*args.stp
  attract = args.attract*args.stp
  stat = args.stat
  export = args.export
  out = args.out
  vnum_max = args.vnum
  start_num = args.startNum
  start_rad = args.startRad
  nearl = args.nearl
  midl = args.midl
  farl = args.farl

  np_verts = zeros((args.nmax, 3), 'float')

  DC = DifferentialCloud(
    nmax = args.nmax,
    zonewidth = args.farl,
    nearl = nearl,
    midl = midl,
    farl = farl,
    procs = args.procs
  )

  xyz, mode = get_initial_cloud(start_num, start_rad)

  DC.init_cloud(xyz, mode)
  DC.init_rules(
    array(
      [
        [1.0,1.0],
        [1.0,-1.0]
      ],
      'double'
    ),
    array(
      [
        [nearl,farl],
        [nearl,farl]
      ],
      'double'
    )
  )

  for i in xrange(args.itt):

    try:

      rnd = (random(size=DC.get_vnum())<0.001).nonzero()[0]
      if len(rnd)>0:
        DC.spawn(rnd)

      DC.optimize_position(
        reject,
        attract,
        nearl*0.1
      )

      if i%stat==0:
        print_stats(i, DC, meta=None)

      if i%export==0:

        vnum = DC.np_get_vertices(np_verts)
        export_obj(
          obj_name = 'cloud',
          fn = '{:s}_{:012d}.obj'.format(out, i),
          verts = np_verts[:vnum,:],
          tris = None,
          meta = make_info_str(args)
        )

      if DC.get_vnum()>vnum_max:
        return

    except KeyboardInterrupt:

      break
def main():

  from time import time
  from itertools import count

  from differentialLine import DifferentialLine

  from modules.helpers import print_stats
  from modules.helpers import get_exporter

  from modules.show import sandstroke
  from modules.show import show
  from modules.show import dots


  DF = DifferentialLine(NMAX, FARL*2, NEARL, FARL, PROCS)
  exporter = get_exporter(NMAX)

  orderd_verts = zeros((NMAX,2), 'double')


  ## arc

  # angles = sorted(random(INIT_NUM)*pi*1.5)
  # xys = []
  # for a in angles:
    # x = 0.5 + cos(a)*0.2
    # y = 0.5 + sin(a)*0.2
    # xys.append((x,y))

  # DF.init_line_segment(xys, lock_edges=1)

  angles = sorted(random(INIT_NUM)*TWOPI)
  DF.init_circle_segment(MID,MID,0.2, angles)


  for i in count():

    t_start = time()

    DF.optimize_position(STP)
    spawn_curl(DF,NEARL,0.016)

    if i % EXPORT_ITT == 0:

      exporter(
        DF, 
        {
          'nearl': NEARL,
          'farl': FARL,
          'stp': STP,
          'size': SIZE,
          'procs': PROCS,
          'prefix': PREFIX
        },
        i,
      )


    t_stop = time()

    print_stats(i,t_stop-t_start,DF)
예제 #30
0
def main():

  from time import time
  from itertools import count

  from differentialLine import DifferentialLine

  from render.render import Render
  from modules.helpers import print_stats

  from modules.show import sandstroke
  from modules.show import show
  from modules.show import dots


  np_coords = zeros(shape=(NMAX,4), dtype='float')
  np_vert_coords = zeros(shape=(NMAX,2), dtype='float')


  DF = DifferentialLine(NMAX, FARL*2, NEARL, FARL, PROCS)

  render = Render(SIZE, BACK, FRONT)

  render.ctx.set_source_rgba(*FRONT)
  render.ctx.set_line_width(LINEWIDTH)

  ## arc

  angles = sorted(random(INIT_NUM)*pi*1.5)
  xys = []
  for a in angles:
    x = 0.5 + cos(a)*0.2
    y = 0.5 + sin(a)*0.2
    xys.append((x,y))

  DF.init_line_segment(xys, lock_edges=1)

  ## vertical line

  #yy = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
  #xx = MID+0.005*(0.5-random(INIT_NUM))
  #xys = []
  #for x,y in zip(xx,yy):
    #xys.append((x,y))

  #DF.init_line_segment(xys, lock_edges=1)

  ## diagonal line

  # yy = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
  # xx = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
  # xys = []
  # for x,y in zip(xx,yy):
    # xys.append((x,y))

  # DF.init_line_segment(xys, lock_edges=1)


  for i in count():

    t_start = time()

    DF.optimize_position(STP)
    spawn_curl(DF,NEARL,0.016)

    if i%100==0:
      fn = './res/sider_arc_ac_{:04d}.png'.format(i)
    else:
      fn = None

    render.set_front(FRONT)
    num = DF.np_get_edges_coordinates(np_coords)
    sandstroke(render,np_coords[:num,:],20,fn)


    if random()<0.05:
      sandstroke(render,np_coords[:num,:],30,None)

    vert_num = DF.np_get_vert_coordinates(np_vert_coords)
    dots(render,np_vert_coords[:vert_num,:],None)


    t_stop = time()

    print_stats(i,t_stop-t_start,DF)
예제 #31
0
def main():

  from time import time
  from render.render import Render
  from differentialMesh import DifferentialMesh
  from modules.helpers import darts
  from modules.helpers import print_stats
  from numpy import array


  DM = DifferentialMesh(NMAX, 2*FARL, NEARL, FARL, PROCS)

  DM.new_faces_in_ngon(MID,MID, H, 7, 0)
  DM.set_edge_intensity(1, 1)

  sources = [(x,y) for x,y in darts(NUM_SOURCES, MID, MID, 0.43, 0.002)]
  DM.initialize_sources(sources, NEARL)

  render = Render(SIZE, BACK, FRONT)


  for i in xrange(1000000):

    t1 = time()
    for _ in xrange(STEPS_ITT):

      DM.find_nearby_sources()

      henum = DM.get_henum()

      surface_edges = array(
        [DM.is_surface_edge(e)>0 and r<DM.get_edge_intensity(e)
        for e,r in enumerate(random(size=henum))],
        'bool').nonzero()[0]

      rnd = random(size=len(surface_edges)*2)
      the = (1.-2*rnd[::2])*pi
      rad = rnd[1::2]*0.5*H
      dx = cos(the)*rad
      dy = sin(the)*rad

      DM.new_triangles_from_surface_edges(
        surface_edges,
        len(surface_edges),
        H,
        dx,
        dy,
        MINIMUM_LENGTH,
        MAXIMUM_LENGTH,
        1
      )

      DM.optimize_position(
        ATTRACT_STP,
        REJECT_STP,
        TRIANGLE_STP,
        ALPHA,
        DIMINISH,
        -1
      )

      henum = DM.get_henum()

      DM.optimize_edges(
        SPLIT_LIMIT,
        FLIP_LIMIT
      )

      if DM.safe_vertex_positions(3*H)<0:

        show_circles(render, DM, sources)
        print('vertices reached the boundary. stopping.')
        return

    show_circles(render, DM, sources)

    t2 = time()
    print_stats(i*STEPS_ITT, t2-t1, DM)