def solve_fold(fold_path): fold = _read_fold(fold_path) first_frame = fold.frames[0] vertices = create_vertices(first_frame.vertices) if CONFIG['NORMALIZE']: vertices = translate_to_origin(vertices) vertices = normalize_bounding_box(vertices, CONFIG['BOUNDING_BOX_DIAG_LEN']) fold.update_root_frame_vertices(list(map(lambda v: v.pos.vec, vertices))) edges = create_edges(vertices, first_frame.edges, first_frame.assignments) faces = create_faces(vertices, edges, first_frame.faces) fold_producer = FoldProducer( fold, LogFoldEncoder(frame_drop_rate=4, frame_drop_multiplier=1.25, frame_drop_change_iter=40)) for steady_state in fold.steady_states: for edge in edges: if edge.id == -1: continue edge.assignment = steady_state.assignments[edge.id] solver = Solver(vertices, edges, faces, steady_state.edges_fold_angles) solver.solve(fold_producer) fold_producer.next_transition() return fold_producer.produce()
def test_normalize_bounding(self): verts = [Vertex(0, 1.0, 1.0, 1.0), Vertex(1, -20.0, -20.0, -20.0)] scale_fac = verts[1].pos.length / 5.0 normalized = normalize_bounding_box(verts, 10) self.assertEqual( normalized[0].pos, Vector3(1.0 / scale_fac, 1.0 / scale_fac, 1.0 / scale_fac)) self.assertEqual( normalized[1].pos, Vector3(-20.0 / scale_fac, -20.0 / scale_fac, -20.0 / scale_fac))
def test_does_nothing_for_vertices_on_the_edge(self): verts = [ Vertex(1, 1.0, 1.0, 1.0), Vertex(2, 1.0, 1.0, -1.0), Vertex(4, 1.0, -1.0, 1.0), Vertex(5, -1.0, 1.0, 1.0), Vertex(6, -1.0, -1.0, 1.0), Vertex(7, 1.0, -1.0, -1.0), Vertex(8, -1.0, 1.0, -1.0), Vertex(9, -1.0, -1.0, -1.0), ] initial_positions = list(map(lambda v: v.pos, verts)) normalized = normalize_bounding_box(verts, 2 * math.sqrt(3)) self.assertEqual(initial_positions, list(map(lambda v: v.pos, normalized)))
def test_does_nothing_when_all_correctly_bound(self): verts = [Vertex(0, 0.0, 0.0, 0.0), Vertex(1, 1.0, 1.0, 1.0)] normalized = normalize_bounding_box(verts, 2 * math.sqrt(3)) self.assertEqual(list(map(lambda vert: vert.pos, normalized)), [Vector3(0, 0, 0), Vector3(1, 1, 1)])
def test_zero_division_does_not_throw(self): verts = [Vertex(0, 0, 0, 0)] normalize_bounding_box(verts, 10)