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
Example #2
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
Example #3
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
Example #4
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)
Example #5
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
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)