Exemplo n.º 1
0
def make_continent_naive(veering_isosig, max_num_tetrahedra=50):
    tri, angle = isosig_to_tri_angle(veering_isosig)
    vt = veering_triangulation(tri, angle)  #, tet_shapes = tet_shapes)
    initial_tet_face = tet_face(vt, 0, 0, verts_pos=[None, None, None, None])
    con = continent(vt,
                    initial_tet_face)  #, desired_vertices = desired_vertices )
    con.build_naive(max_num_tetrahedra=max_num_tetrahedra)
    con.make_convex()
    print(len(con.triangles), len(con.vertices), len(con.tetrahedra))
    return con
Exemplo n.º 2
0
Arquivo: test.py Projeto: qiqi/home
import pylab

from continent import continent
from weather import temperature, precipitation

print 'loading...'

h = continent(13,13,0.0,8)    # good plains

# s, w = temperature(h*8, 10, 60)
# pylab.contour(h,[0])
# pylab.contour(s,[0],colors='r')
# pylab.axis('scaled')
# pylab.xlim([0, h.shape[0]-1])
# pylab.ylim([0, h.shape[0]-1])

p = precipitation(h, 10, 60)

print 'finished.'

pylab.contour(h,[0,0.001])
pylab.contour(p,[0.4,0.2,0.1,0.05,0.025,0.01])
pylab.axis('scaled')
pylab.xlim([0, h.shape[0]-1])
pylab.ylim([0, h.shape[0]-1])
Exemplo n.º 3
0
def make_continent_drill_flow_cycle(veering_isosig, flow_cycle, num_steps):
    tri, angle = isosig_to_tri_angle(veering_isosig)
    vt = veering_triangulation(tri, angle)  #, tet_shapes = tet_shapes)
    ### format for loops: it is a list of tuples,
    ### each tuple is (tet_index, edge_index within this tet that we exit through)
    tet_0 = flow_cycle[0][0]
    face_0 = 0  ### only used for initial numbering of vertices of the continent, so who cares
    initial_tet_face = tet_face(vt,
                                tet_0,
                                face_0,
                                verts_pos=[None, None, None, None])
    con = continent(vt, initial_tet_face)

    side_face_collections, side_tet_collections = edge_side_face_collections(
        vt.tri,
        vt.angle,
        tet_vert_coorientations=vt.coorientations,
        return_tets=True,
        order_bottom_to_top=False)
    # print('sfc', side_face_collections)
    # print('stc', side_tet_collections)
    ### identify the next edge in the cycle

    init_tetrahedron = con.tetrahedra[0]
    init_edge = flow_edge_in_continent(init_tetrahedron, flow_cycle[0][1])

    flow_tetrahedra = [init_tetrahedron]
    flow_edges = [init_edge]
    ### both in the continent

    upwards_flow_index = 0
    downwards_flow_index = 0
    for i in range(num_steps):
        # print(i)
        if i % 2 == 0:  ### go up
            edge = flow_edges[-1]
            last_tet = None
            while True:
                con.update_boundary()
                upper_boundary_triangles = [
                    t for t in edge.boundary_triangles if t.is_upper
                ]
                if len(upper_boundary_triangles) == 0:
                    break  ## out of while loop
                last_tet = con.bury(upper_boundary_triangles[0])
            assert last_tet != None
            upwards_flow_index = (upwards_flow_index + 1) % len(flow_cycle)
            assert last_tet.index == flow_cycle[upwards_flow_index][0]
            flow_tetrahedra.append(last_tet)
            flow_edges.append(
                flow_edge_in_continent(last_tet,
                                       flow_cycle[upwards_flow_index][1]))
            con.make_convex(
            )  ### could this take us further up dual_cycle? We don't think so
        else:  ### go down
            tet = flow_tetrahedra[0]
            edge = tet.lower_edge()
            flow_edges = [edge] + flow_edges
            ### now build the continent to get new_lowest_tet
            manifold_edge = tri.edge(edge.index)
            downwards_flow_index = (downwards_flow_index - 1) % len(flow_cycle)
            ### is the flow cycle vertical through the tetrahedron?
            tet_below = get_tet_above_edge(
                vt.tri,
                vt.angle,
                manifold_edge,
                tet_vert_coorientations=vt.coorientations,
                get_tet_below_edge=True)
            tet_below_num = tet_below.index()
            top_vert_nums = get_tet_top_vert_nums(vt.coorientations,
                                                  tet_below_num)
            top_edge_num = vert_pair_to_edge_num[tuple(top_vert_nums)]

            if (tet_below_num, top_edge_num) == flow_cycle[
                    downwards_flow_index]:  ### flow cycle went straight up
                while True:
                    con.update_boundary()
                    lower_boundary_triangles = [
                        t for t in edge.boundary_triangles if not t.is_upper
                    ]
                    if len(lower_boundary_triangles) == 0:
                        break  ## out of while loop
                    last_tet = con.bury(lower_boundary_triangles[0])
            else:
                ### find which side of the edge our tet is in
                # print('edge index', edge.index)
                side_tet_collections_at_edge = side_tet_collections[
                    edge.index]  ## index in the manifold
                side_face_collections_at_edge = side_face_collections[
                    edge.index]
                downward_path = None
                flow_step = flow_cycle[downwards_flow_index]
                for i, side_tet_collection in enumerate(
                        side_tet_collections_at_edge):
                    if flow_step in side_tet_collection:
                        downward_path = side_tet_collection[:
                                                            side_tet_collection
                                                            .index(flow_step) +
                                                            1]
                        downward_path_faces = side_face_collections_at_edge[
                            i][:side_tet_collection.index(flow_step) + 1]
                assert downward_path != None
                for j, (tet_num, edge_num) in enumerate(downward_path):
                    con.update_boundary()
                    lower_boundary_triangles = [
                        t for t in edge.boundary_triangles if not t.is_upper
                        and t.index == downward_path_faces[j][0]
                    ]
                    assert len(lower_boundary_triangles) == 1
                    last_tet = con.bury(lower_boundary_triangles[0])
            assert last_tet != None
            flow_tetrahedra = [last_tet] + flow_tetrahedra
            con.make_convex(
            )  ### could this take us further down dual_cycle? We don't think so

    con.update_boundary()
    return con, flow_tetrahedra, flow_edges
Exemplo n.º 4
0
def make_continent_drill_dual_cycle(veering_isosig, dual_cycle, num_steps):
    tri, angle = isosig_to_tri_angle(veering_isosig)
    vt = veering_triangulation(tri, angle)  #, tet_shapes = tet_shapes)
    ### initial tetrahedron is above face 0 of the dual cycle
    face0 = vt.tri.triangles()[dual_cycle[0]]
    embeds = face0.embeddings()
    tet_0, face_0 = None, None
    for embed in embeds:
        tet_num = embed.simplex().index()
        face_num = embed.face()
        if vt.coorientations[tet_num][face_num] == -1:  ## into the tet
            tet_0, face_0 = tet_num, face_num
            break
    assert tet_0 != None and face_0 != None
    initial_tet_face = tet_face(vt,
                                tet_0,
                                face_0,
                                verts_pos=[None, None, None, None])
    con = continent(vt, initial_tet_face)

    ### identify the triangle corresponding to dual_cycle[1]
    for triangle in con.triangles:
        if not triangle.is_upper and triangle.index == dual_cycle[0]:
            lowest_triangle = triangle
        if triangle.is_upper and triangle.index == dual_cycle[1]:
            highest_triangle = triangle
    triangle_path = [lowest_triangle, highest_triangle]
    lowest_path_index = 0
    highest_path_index = 1
    # for i in range(num_steps):
    #     last_added_tet = con.bury(highest_triangle)

    #     ### find next_triangle
    #     highest_triangle = None
    #     for triangle in last_added_tet.upper_triangles:
    #         if triangle.index == dual_cycle[(path_index + 1) % len(dual_cycle)]:
    #             highest_triangle = triangle
    #             break
    #     assert highest_triangle != None
    #     triangle_path.append(highest_triangle)
    #     path_index = path_index + 1

    #     con.make_convex() ### could this take us further up dual_cycle?

    for i in range(num_steps):
        if i % 2 == 0:
            last_added_tet = con.bury(triangle_path[-1])  ## go up
            for triangle in last_added_tet.upper_triangles:
                if triangle.index == dual_cycle[(highest_path_index + 1) %
                                                len(dual_cycle)]:
                    triangle_path.append(triangle)
                    break
            highest_path_index = highest_path_index + 1
        else:
            last_added_tet = con.bury(triangle_path[0])  ## go down
            for triangle in last_added_tet.lower_triangles:
                if triangle.index == dual_cycle[(lowest_path_index - 1) %
                                                len(dual_cycle)]:
                    triangle_path.insert(0, triangle)
                    break
            lowest_path_index = lowest_path_index - 1

        con.make_convex()  ### could this take us further up dual_cycle?

    con.update_boundary()
    con.triangle_path = triangle_path
    return con
Exemplo n.º 5
0
Arquivo: visual.py Projeto: qiqi/home
def initScene():
   print 'Loading...'
   # heightmap
   h = continent(4,5,0.465,8)    # penesulas
   # h = continent(7,7,0.0,8)      # mountainous
   # h = continent(13,13,0.0,8)    # good plains
   # h = continent(24,65,0.0,8)    # sahara
   h *= SCALE

   summer, winter = temperature(h, 10, 60)
   precip = precipitation(h, 10, 60)
   dh = slope(h)
   r, g, b = vegetation(h, dh, summer, winter, precip)

   # h[h == 0] = - 0.7
   # pylab.figure()
   # pylab.contour(h,25)
   # pylab.axis('scaled')
   # pylab.xlim([0, h.shape[0]-1])
   # pylab.ylim([0, h.shape[0]-1])
   # pylab.show()
   # h[h < 0] = 0.0

   n = h.shape[0]
   dh = (numpy.arange(n) / float(n-1) - 0.5) / 2.0
   dh = dh ** 2 * n * SCALE
   for i in xrange(n):
      h[:,i] -= dh
      h[i,:] -= dh

   print 'Finished.'

   # build OpenGL list
   gllist = glGenLists(1)
   glNewList(gllist, GL_COMPILE)
   for i in xrange(1, n):
      glBegin(GL_QUAD_STRIP)
      for j in xrange(n):
	 glColor3f(r[j,i-1], g[j,i-1], b[j,i-1])
         glVertex3f((i-1) * SCALE, j * SCALE, h[j,i-1])
	 glColor3f(r[j,i], g[j,i], b[j,i])
         glVertex3f(i * SCALE, j * SCALE, h[j,i])
      glEnd()
   glEndList()

   glViewport(0, 0, 1200, 800)
   glShadeModel(GL_SMOOTH)
   # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
   glEnable(GL_DEPTH_TEST)

   # atmosphere fog
   glClearColor(0.22, 0.45, 0.9, 1.0)
   glFogi(GL_FOG_MODE, GL_EXP)
   glFogfv(GL_FOG_COLOR, [0.22, 0.45, 0.9, 1.0])
   glFogf(GL_FOG_DENSITY, 0.025)
   glEnable(GL_FOG)

   glMatrixMode(GL_PROJECTION)
   glLoadIdentity()
   gluPerspective(45.0, 1.5, 0.1, 1000.0)
   glMatrixMode(GL_MODELVIEW)

   return gllist, h, dh
Exemplo n.º 6
0
import sys

import pylab
import numpy
from numpy import zeros, arange, round

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *

from continent import continent, slope
from weather import temperature, precipitation
from vegetation import vegetation

# heightmap
h = continent(4,5,0.465,8)    # penesulas
# h = continent(7,7,0.0,8)      # mountainous
# h = continent(13,13,0.0,8)    # good plains
# h = continent(24,65,0.0,8)    # sahara
h *= 10.0

summer, winter = temperature(h, 10, 60)
precip = precipitation(h, 10, 60)
dh = slope(h)
r, g, b, t = vegetation(h, dh, summer, winter, precip)

color = zeros(h.shape + (3,))
color[:,:,0] = r
color[:,:,1] = g
color[:,:,2] = b