points_t = Property(Tuple) def _get_points_t(self): x, y, z, s = self.p c = self.vot return x * c, y * c, z * c, s * c viz3d_classes = dict(default=PointCloudViz3D, something_else=PointCloudShiftedViz3D) if __name__ == '__main__': pc = PointCloud(anim_t_start=0, anim_t_end=40) ftv = FTV() ftv.add(pc.viz3d['default']) # ftv.add(pc.viz3d['something_else']) fta = FTA(ftv=ftv) fta.init_view(a=0, e=0, d=8, f=(0, 0, 0), r=0) # fta.add_cam_move(e=50, n=20, # duration=10, # azimuth_move='linear', # elevation_move='damped', # distance_move='damped') # fta.add_cam_move(e=0, n=20, # duration=30, # azimuth_move='damped', # elevation_move='damped', # distance_move='damped')
if __name__ == '__main__': from oricreate.crease_pattern.crease_pattern_viz3d import \ CreasePatternThickViz3D fname_eft_front = 'eft_areas_standard_03.png' fname_eft_back = 'eft_mission_standard_trans_EF02.png' fheight = 0.011 front_offset = 0.011 tube_radius = 0.01 plane_offsets = [0.005, -0.004] edge_len = 2.0 x_offset = 1.0 c45 = np.cos(np.pi / 4) twist_folding_process = TwistFoldingProcess() ftv = FTV() tt = twist_folding_process.sim_task cp = tt.formed_object eft_thick_viz3d = CreasePatternThickViz3D( label='EFT thick', vis3d=tt.sim_history, facet_color=(64.0 / 255.0, 127.0 / 255.0, 183.0 / 255.0), plane_offsets=plane_offsets) tt.sim_history.viz3d['cp'].L_selection = tt.L_selection tt.sim_history.viz3d['cp'].set(tube_radius=tube_radius, facet_color=( 64.0 / 255.0, 127.0 / 255.0, 183.0 / 255.0), ) ftv.add(tt.sim_history.viz3d['cp']) # ftv.add(eft_thick_viz3d)
cp = fat.formed_object if False: import matplotlib.pyplot as plt fig, ax = plt.subplots() cp.plot_mpl(ax, facets=True) plt.tight_layout() plt.show() fot = miura_fp.fold_task fot.u_1 lot = miura_fp.load_task lot.u_1 ftv = FTV() lot.sim_history.set(anim_t_start=0, anim_t_end=50) lot.sim_history.viz3d['displ'].set(tube_radius=0.002, warp_scale_factor=5.0) ftv.add(lot.sim_history.viz3d['displ']) gu_dofs_viz3d = lot.config.gu['dofs'].viz3d['default'] gu_dofs_viz3d.scale_factor = 1 ftv.add(gu_dofs_viz3d) ftv.add(lot.config.fu.viz3d['default']) lot.config.fu.viz3d['default'].set(anim_t_start=00, anim_t_end=50) fta = FTA(ftv=ftv) fta.init_view(a=-45, e=65, d=60, f=(0, 0, 0), r=-50) fta.add_cam_move(a=-80, e=80, n=20,
rho=10.0, psi_max=-np.pi / 2.03 * 0.3, fixed_z=[24, 35], fixed_y=[24, 35], fixed_x=[24, 35], link_z=[[15], [44]] ) if __name__ == '__main__': from oricreate.api import \ FTV bsf_process = HPShellFormingProcess(**hp_shell_kw_2) ftv = FTV() fa = bsf_process.factory_task if True: import pylab as p ax = p.axes() fa.formed_object.plot_mpl(ax, nodes=True, facets=False) p.show() it = bsf_process.init_displ_task ft = bsf_process.fold_deform_task show_init = True if show_init: # ftv.add(it.target_faces[0].viz3d['default']) ft.sim_history.viz3d['cp'].set(tube_radius=0.02)
sim_config = SimulationConfig(goal_function_type='none', gu={ 'cl': gu_constant_length, 'dofs': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-5, MAX_ITER=10) sim_task = SimulationTask(previous_task=cpf, config=sim_config, n_steps=5) cp = sim_task.formed_object cp.u[cpf.N_grid[(0, -1), 1], 2] = -1.0 sim_task.u_1 ftv = FTV() #ftv.add(sim_task.sim_history.viz3d['node_numbers'], order=5) ftv.add(sim_task.sim_history.viz3d['cp']) ftv.add(gu_dof_constraints.viz3d['default']) fta = FTA(ftv=ftv) fta.init_view(a=200, e=35, d=50, f=(0, 0, 0), r=0) fta.add_cam_move( a=200, e=34, n=5, d=50, r=0, duration=10, # vot_fn=lambda cmt: np.linspace(0, 1, 4), azimuth_move='damped',
im_widths=[2], im_offsets=[[0, 0, 0.001]], vis3d=cp) print('x_refs', efttitle_viz3d.x_refs) print('im_files', efttitle_viz3d.im_files) print('im_shapes', efttitle_viz3d.im_shapes) print('im_scales', efttitle_viz3d.im_scales) print('im_centers', efttitle_viz3d.im_centers) print('bases', efttitle_viz3d.bases) print('rotated bases', efttitle_viz3d.rotated_bases) print('glb_centers', efttitle_viz3d.glb_centers) print('glb_angles', efttitle_viz3d.glb_euler_angles) ftv = FTV() ftv.add(cp.viz3d['cp']) ftv.add(efttitle_viz3d) ftv.add(eftlogo_bases) m = ftv.mlab fig = m.gcf() m.figure(figure=fig, bgcolor=(1, 1, 1)) ftv.plot() cp.u[1, 2] = 1.0 cp.u = np.copy(cp.u) cp.viz3d_notify_change() efttitle_viz3d.vis3d_changed = True
''' def _p_default(self): x, y, z, s = np.random.random((4, 100)) print('s_default', s) return x, y, z, s points_t = Property(Tuple) def _get_points_t(self): x, y, z, s = self.p c = self.vot return x * c, y * c, z * c, s * c viz3d_classes = dict(default=PointCloudViz3D, something_else=PointCloudShiftedViz3D) ftv = FTV() pc = PointCloud() ftv.add(pc.viz3d['default']) ftv.add(pc.viz3d['something_else']) ftv.plot() ftv.configure_traits() ftv.plot() ftv.update(vot=0.9) ftv.update(vot=0.8) ftv.show()
MAXITER=100, #psi_max=-np.pi / 2.03 * 0.5, fixed_z=[8, 88, 72, 152], fixed_y=[8, 72], fixed_x_plus=[8, 88], fixed_x_minus=[72, 152], ) if __name__ == '__main__': from oricreate.api import \ FTV bsf_process = HexagonalShellFormingProcess(**shell_kw_2) ftv = FTV() fa = bsf_process.factory_task if True: import pylab as p ax = p.axes() fa.formed_object.plot_mpl(ax, nodes=True, facets=False) p.show() it = bsf_process.init_displ_task print 'n_dofs', it.formed_object.n_dofs ft = bsf_process.fold_task show_init_task = False show_fold_task = True
sim_config = SimulationConfig(goal_function_type='none', gu={'cl': gu_constant_length, 'dofs': gu_dof_constraints, 'psi': gu_psi_constraints}, acc=1e-5, MAX_ITER=100) sim_task = SimulationTask(previous_task=cpf, config=sim_config, n_steps=20) cp = sim_task.formed_object cp.u[cpf.N_grid[::2, :].flatten(), 2] = -0.1 cp.u[cpf.N_grid[0, ::2].flatten(), 2] = -0.2 sim_task.u_1 ftv = FTV() # ftv.add(sim_task.sim_history.viz3d_dict['node_numbers'], order=5) ftv.add(sim_task.sim_history.viz3d['cp']) ftv.add(gu_dof_constraints.viz3d['default']) fta = FTA(ftv=ftv) fta.init_view(a=200, e=35, d=50, f=(0, 0, 0), r=0) fta.add_cam_move(a=200, e=34, n=5, d=50, r=0, duration=10, azimuth_move='damped', elevation_move='damped', distance_move='damped') fta.plot() fta.configure_traits()
F_ext_list=F_ext_list) # (2 * n, 2, -1)]) sim_config._fu = fu_tot_poteng sim_task = SimulationTask(previous_task=cp_factory_task, config=sim_config, n_steps=10) cp = sim_task.formed_object cp.x_0 = np.copy(sim_task.previous_task.formed_object.X) cp.u[:, :] = 0.0 fu_tot_poteng.forming_task = sim_task cp.u[1:n + 1, 2] = np.linspace(0, -0.001, n) cp.u[n + 1:(2 * n) + 1, 2] = np.linspace(0, -0.0005, n) print('kinematic simulation: u', sim_task.u_1) cp = sim_task.formed_object iL_phi = cp.iL_psi - cp.iL_psi_0 print('phi', iL_phi) iL_length = np.linalg.norm(cp.iL_vectors, axis=1) iL_m = sim_config._fu.kappa * iL_phi * iL_length print('moments', iL_m) ftv = FTV() ftv.add(sim_task.sim_history.viz3d['displ']) ftv.add(sim_task.config.gu['dofs'].viz3d['default']) ftv.add(sim_task.config.fu.viz3d['default']) sim_task.config.fu.viz3d['default'].set(anim_t_start=30, anim_t_end=50) ftv.add(sim_task.config.fu.viz3d['node_load']) ftv.plot() ftv.configure_traits()
cp = fat.formed_object if False: import matplotlib.pyplot as plt fig, ax = plt.subplots() cp.plot_mpl(ax, facets=True) plt.tight_layout() plt.show() fot = miura_fp.fold_task fot.u_1 lot = miura_fp.load_task lot.u_1 ftv = FTV() lot.sim_history.set(anim_t_start=0, anim_t_end=50) lot.sim_history.viz3d['displ'].set(tube_radius=0.002, warp_scale_factor=5.0) ftv.add(lot.sim_history.viz3d['displ']) gu_dofs_viz3d = lot.config.gu['dofs'].viz3d['default'] gu_dofs_viz3d.scale_factor = 1 ftv.add(gu_dofs_viz3d) ftv.add(lot.config.fu.viz3d['default']) lot.config.fu.viz3d['default'].set(anim_t_start=00, anim_t_end=50) fta = FTA(ftv=ftv) fta.init_view(a=-45, e=65, d=60, f=(0, 0, 0), r=-50) fta.add_cam_move(a=-80, e=80, n=20, d=35, r=-45, duration=10, azimuth_move='damped',
debug_level=0, use_f_du=False, gu={'cl': gu_constant_length, 'dofs': gu_dof_constraints}, acc=1e-5, MAX_ITER=100) fu_tot_poteng = FuPotEngTotal(kappa=10, F_ext_list=[(3, 2, -1), (4, 2, -1)]) sim_config._fu = fu_tot_poteng sim_task = SimulationTask(previous_task=cp_factory_task, config=sim_config, n_steps=1) cp.u[4, 2] = 0.001 print 'kinematic simulation: u', sim_task.u_1 cp = sim_task.formed_object iL_phi = cp.iL_psi2 - cp.iL_psi_0 print 'phi', iL_phi iL_length = np.linalg.norm(cp.iL_vectors, axis=1) iL_m = sim_config._fu.kappa * iL_phi * iL_length print 'moments', iL_m ftv = FTV() ftv.add(sim_task.formed_object.viz3d) ftv.add(gu_dof_constraints.viz3d) ftv.add(fu_tot_poteng.viz3d) ftv.plot() ftv.update(vot=1, force=True) ftv.show()
F_ext_list=F_ext_list) # (2 * n, 2, -1)]) sim_config._fu = fu_tot_poteng sim_task = SimulationTask(previous_task=cp_factory_task, config=sim_config, n_steps=10) cp = sim_task.formed_object cp.x_0 = np.copy(sim_task.previous_task.formed_object.X) cp.u[:, :] = 0.0 fu_tot_poteng.forming_task = sim_task cp.u[1:n + 1, 2] = np.linspace(0, -0.001, n) cp.u[n + 1:(2 * n) + 1, 2] = np.linspace(0, -0.0005, n) print 'kinematic simulation: u', sim_task.u_1 cp = sim_task.formed_object iL_phi = cp.iL_psi - cp.iL_psi_0 print 'phi', iL_phi iL_length = np.linalg.norm(cp.iL_vectors, axis=1) iL_m = sim_config._fu.kappa * iL_phi * iL_length print 'moments', iL_m ftv = FTV() ftv.add(sim_task.sim_history.viz3d['displ']) ftv.add(sim_task.config.gu['dofs'].viz3d['default']) ftv.add(sim_task.config.fu.viz3d['default']) sim_task.config.fu.viz3d['default'].set(anim_t_start=30, anim_t_end=50) ftv.add(sim_task.config.fu.viz3d['node_load']) ftv.plot() ftv.configure_traits()
return x, y, z, s points_t = Property(Tuple) def _get_points_t(self): x, y, z, s = self.p c = self.vot return x * c, y * c, z * c, s * c viz3d_classes = dict(default=PointCloudViz3D, something_else=PointCloudShiftedViz3D) if __name__ == '__main__': pc = PointCloud(anim_t_start=0, anim_t_end=40) ftv = FTV() ftv.add(pc.viz3d['default']) # ftv.add(pc.viz3d['something_else']) fta = FTA(ftv=ftv) fta.init_view(a=0, e=0, d=8, f=(0, 0, 0), r=0) # fta.add_cam_move(e=50, n=20, # duration=10, # azimuth_move='linear', # elevation_move='damped', # distance_move='damped') # fta.add_cam_move(e=0, n=20, # duration=30, # azimuth_move='damped', # elevation_move='damped', # distance_move='damped')
gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) sim_config = SimulationConfig(goal_function_type='none', gu={'cl': gu_constant_length, 'u': gu_dof_constraints, 'psi': gu_psi_constraints}, acc=1e-8, MAX_ITER=100) sim_task = SimulationTask(previous_task=cp_factory_task, config=sim_config, n_steps=25) cp.u[(0, 3), 2] = -0.1 cp.u[(1), 2] = 0.1 sim_task.u_1 cp = sim_task.formed_object ftv = FTV() ftv.add(sim_task.sim_history.viz3d_dict['node_numbers'], order=5) ftv.add(sim_task.sim_history.viz3d) ftv.add(gu_dof_constraints.viz3d) fta = FTA(ftv=ftv) fta.init_view(a=200, e=35, d=5, f=(0, 0, 0), r=0) fta.add_cam_move(a=200, e=34, n=5, d=5, r=0, duration=10, vot_fn=lambda cmt: np.linspace(0, 1, 4), azimuth_move='damped', elevation_move='damped', distance_move='damped') fta.plot() fta.render()
'cl': gu_constant_length, 'dofs': gu_dof_constraints }, acc=1e-5, MAX_ITER=100) fu_tot_poteng = FuPotEngTotal(kappa=10, F_ext_list=[(3, 2, -1), (4, 2, -1)]) sim_config._fu = fu_tot_poteng sim_task = SimulationTask(previous_task=cp_factory_task, config=sim_config, n_steps=1) cp.u[4, 2] = 0.001 print('kinematic simulation: u', sim_task.u_1) cp = sim_task.formed_object iL_phi = cp.iL_psi2 - cp.iL_psi_0 print('phi', iL_phi) iL_length = np.linalg.norm(cp.iL_vectors, axis=1) iL_m = sim_config._fu.kappa * iL_phi * iL_length print('moments', iL_m) ftv = FTV() ftv.add(sim_task.formed_object.viz3d) ftv.add(gu_dof_constraints.viz3d) ftv.add(fu_tot_poteng.viz3d) ftv.plot() ftv.update(vot=1, force=True) ftv.show()
hp_shell_kw_2 = dict(L_x=10, L_y=10, psi_lines=[ 10, 23, 35, 40, 7, 20, 41, 44], n_stripes=2, n_steps=10, psi_max=-np.pi / 2.03, fixed_z=[9, 14], fixed_y=[8, 15], fixed_x=[8, 15], link_z=[[8], [15]] ) bsf_process = HPShellFormingProcess(**hp_shell_kw_2) ftv = FTV() ft = bsf_process.fold_task # ftv.add(it.target_faces[0].viz3d['default']) ft.sim_history.set(anim_t_start=0, anim_t_end=100) ft.sim_history.viz3d['cp'].set(tube_radius=0.01) ftv.add(ft.sim_history.viz3d['cp']) #ftv.add(it.formed_object.viz3d['node_numbers'], order=5) # ft.config.gu['dofs'].viz3d['default'].scale_factor = 0.5 # ftv.add(ft.config.gu['dofs'].viz3d['default']) ft.u_1 #ftv.plot() #ftv.configure_traits()
Plot the results of single vertex example. ''' if __name__ == '__main__': from docs.howtos.ex04_cp_operators.cp_F_L_bases import \ create_cp from oricreate.crease_pattern import \ CreasePatternBasesViz3D from oricreate.api import FTV cp = create_cp() viz3d_normals = CreasePatternBasesViz3D( label='normals', vis3d=cp) ftv = FTV() ftv.add(cp.viz3d) ftv.add(viz3d_normals) m = ftv.mlab fig = m.gcf() m.figure(figure=fig, bgcolor=(1, 1, 1)) ftv.plot() m.show() arr = m.screenshot() import pylab as p p.imshow(arr) p.axis('off') p.show()
def run_sim(): cp_factory, L_selection = create_cp_factory() cp = cp_factory.formed_object if False: fig, ax = plt.subplots() cp.plot_mpl(ax, facets=True) plt.tight_layout() plt.show() return # Configure simulation gu_constant_length = GuConstantLength() dof_constraints = \ fix([0], [0, 1, 2]) +\ fix([1], [1, 2]) +\ fix([5], [2]) +\ fix([3], [0], lambda t: t * -1.9599) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) sim_config = SimulationConfig(gu={'cl': gu_constant_length, 'dofs': gu_dof_constraints}, acc=1e-5, MAX_ITER=1000) sim_step = SimulationStep(forming_task=cp_factory, config=sim_config) if False: # Configure rendering visualization operators eftlabels_viz3d = FacetsWithTextViz3D( label='EFT labels', vis3d=cp) efttitle_viz3d = FacetsWithImageViz3D( label='EFT title', vis3d=cp, F_ref=[0, 2, 4, 6, 8], N_ref=[0, 3, 15, 12, 7], F_covered=[[0, 9], [2, 11], [4, 13], [6, 15], [8, 17]], atimes=[90.0, 180.0, -90, 0, 135], im_files=['eft_01.png', 'eft_01.png', 'eft_01.png', 'eft_01.png', 'eft_01.png'], im_widths=[2, 2, 2, 2, 2], im_offsets=[[0, 0, 0.004], [0, 0, 0.004], [0, 0, 0.004], [0, 0, 0.004], [-.295, -.295, 0.004]], ) else: fname_eft_front = 'eft_areas_standard_02.png' fname_eft_back = 'eft_mission_standard_trans_EF01.png' fheight = 0.011 front_offset = 0.006 tube_radius = 0.01 plane_offsets = [0.005, -0.010] edge_len = 2.0 x_offset = 1.0 c45 = np.cos(np.pi / 4) shift_x = x_offset + edge_len / c45 - edge_len shift_l = shift_x * c45 print 'shift_l', shift_l F_ref = [0, 2, 4, 6, 8, 16, 1, 12, 14, ] N_ref = [0, 3, 15, 12, 7, 4, 1, 11, 13] F_covered = [[0, 9], [2, 11], [4, 13], [6, 15], [8, 17], [16, 7], [1, 10], [12, 3], [14, 5]] atimes = [90.0, 180.0, -90, 0, 45, 90, 90.0, -90.0, 0.0] im_widths = [4, 4, 4, 4, 4, 4, 4, 4, 4] imfiles_front = [ fname_eft_front, fname_eft_front, fname_eft_front, fname_eft_front, fname_eft_front, fname_eft_front, fname_eft_front, fname_eft_front, fname_eft_front, ] imfiles_back = [ fname_eft_back, fname_eft_back, fname_eft_back, fname_eft_back, fname_eft_back, fname_eft_back, fname_eft_back, fname_eft_back, fname_eft_back, ] im_front_offsets = [ [0, 0, front_offset], [0, 0, front_offset], [0, 0, front_offset], [0, 0, front_offset], [-shift_l, -shift_l, front_offset], [0, -1, front_offset], [-2, 0, front_offset], [0, -1, front_offset], [0, -1, front_offset] ] im_back_offsets = [ [0, 0, -fheight], [0, 0, -fheight], [0, 0, -fheight], [0, 0, -fheight], [-shift_l, -shift_l, -fheight], [0, -1, -fheight], [-2, 0, -fheight], [0, -1, -fheight], [0, -1, -fheight] ] efttitle_back_viz3d = FacetsWithImageViz3D( label='EFT back', vis3d=cp, F_ref=F_ref, # + F_ref, N_ref=N_ref, # + N_ref, F_covered=F_covered, # + F_covered, atimes=atimes, # + atimes, im_files=imfiles_back, # imfiles_front + im_widths=im_widths, # + im_widths, im_offsets=im_back_offsets, # im_front_offsets + ) efttitle_front_viz3d = FacetsWithImageViz3D( label='EFT front', vis3d=cp, F_ref=F_ref, N_ref=N_ref, F_covered=F_covered, atimes=atimes, im_files=imfiles_front, im_widths=im_widths, im_offsets=im_front_offsets ) eftlogo_normals = CreasePatternNormalsViz3D( label='EFT normals', vis3d=cp) eftlogo_bases = CreasePatternBasesViz3D( label='EFT bases', vis3d=cp) eft_thick_viz3d = CreasePatternThickViz3D( label='EFT thick', vis3d=cp, plane_offsets=plane_offsets) cp.viz3d['cp'].set(tube_radius=tube_radius) # Configure scene ftv = FTV() ftv.add(cp.viz3d['cp']) ftv.add(eft_thick_viz3d) ftv.add(efttitle_front_viz3d) ftv.add(efttitle_back_viz3d) # ftv.add(eftlabels_viz3d) # ftv.add(eftlogo_normals) # ftv.add(eftlogo_bases) m = ftv.mlab m.figure(bgcolor=(1, 1, 1), fgcolor=(0, 0, 0)) fig = m.gcf() ftv.plot() # oricreate_mlab_label(m) a, e, d, f = m.view() e = 135 # 10 a = 270 # -45 # 120 f = sim_step.forming_task.formed_object.center m.view(a, e, d, f) show = False if show: m.show() n_u = 30 # Control the folding by a fold angle phi_range = np.linspace(0.01, np.pi - 0.01, n_u) dramaturgy = False animation = True def circular_folding(phi_range): bot_e = 160 top_e = 10 if dramaturgy: phi_unfolded = phi_range[0] * np.ones_like(phi_range) phi_folded = phi_range[-1] * np.ones_like(phi_range) phi_range_u = np.hstack( [phi_range, phi_folded, phi_range[::-1], phi_unfolded]) else: phi_range_u = phi_range u_range = np.cos(phi_range_u) - 1 phi_range_e = np.linspace(0.01, np.pi - 0.01, n_u * 4) azimuth_step = 360.0 / 4 / n_u elevation_range = np.cos( 2 * phi_range_e)**2 * top_e + np.sin(2 * phi_range_e)**2 * bot_e time_range = slice(None) return u_range, elevation_range, azimuth_step, time_range def eft_folding(phi_range): n_u12 = 30 n_c = 60 n_u23 = 75 phi_12_range = damped_range(np.pi * 0.3, 0.012, n_u12) phi_c = np.ones((n_c,), dtype='float_') * 0.01 phi_23_range = damped_range(0.01, np.pi - 0.005, n_u23) phi_range_u = np.hstack([phi_12_range, phi_c, phi_23_range]) u_range = np.cos(phi_range_u) - 1 conf1 = 230, 50, 52, 1.14 confc = 230, 50, 20, 1.14 conf2 = 100, 160, 0, 1.1 conf3 = 270, 179, 0., 0.5 azimuth_range = np.hstack([damped_range(conf1[0], confc[0], n_u12), damped_range(confc[0], conf2[0], n_c), damped_range(conf2[0], conf3[0], n_u23)]) elevation_range = np.hstack([damped_range(conf1[1], confc[1], n_u12), damped_range(confc[1], conf2[1], n_c), damped_range(conf2[1], conf3[1], n_u23)]) roll_range = np.hstack([damped_range(conf1[2], confc[2], n_u12), damped_range(confc[2], conf2[2], n_c), damped_range(conf2[2], conf3[2], n_u23)]) d_range = np.hstack([damped_range(conf1[3], confc[3], n_u12) * d, damped_range(confc[3], conf2[3], n_c) * d, damped_range(conf2[3], conf3[3], n_u23) * d]) time_range = slice(None) #time_range = np.array([-1], dtype=int) return u_range, elevation_range, azimuth_range, roll_range, time_range, d_range def eft_unfolding(phi_range): n_u1 = 30 n_u2 = 60 n_u3 = 60 phi_u1 = np.pi - 0.012 phi_u2 = np.pi * 0.86 phi_u3 = 0.012 phi_1 = damped_range(phi_u1, phi_u2, n_u1) phi_2 = np.ones((n_u2,), dtype='float_') * phi_u2 phi_3 = damped_range(phi_u2, phi_u3, n_u3) phi_range_u = np.hstack([phi_1, phi_2, phi_3]) u_range = np.cos(phi_range_u) - 1 conf1 = 270, 179, 0., 0.5 conf2 = 230, 140, 60., 0.6 conf3 = 150, 70, 70., 0.64 conf4 = 45, 1, 314., 1.14 azimuth_range = np.hstack([damped_range(conf1[0], conf2[0], n_u1), damped_range(conf2[0], conf3[0], n_u2), damped_range(conf3[0], conf4[0], n_u3)]) elevation_range = np.hstack([damped_range(conf1[1], conf2[1], n_u1), damped_range(conf2[1], conf3[1], n_u2), damped_range(conf3[1], conf4[1], n_u3)]) roll_range = np.hstack([damped_range(conf1[2], conf2[2], n_u1), damped_range(conf2[2], conf3[2], n_u2), damped_range(conf3[2], conf4[2], n_u3)]) d_range = np.hstack([damped_range(conf1[3], conf2[3], n_u1) * d, damped_range(conf2[3], conf3[3], n_u2) * d, damped_range(conf3[3], conf4[3], n_u3) * d, ]) time_range = slice(None) #time_range = np.array([0], dtype=int) return u_range, elevation_range, azimuth_range, roll_range, time_range, d_range # u_range, elevation_range, azimuth_range, roll_range, time_range, d_range = eft_folding( # phi_range) u_range, elevation_range, azimuth_range, roll_range, time_range, d_range = eft_unfolding( phi_range) tdir = tempfile.mkdtemp() fname_list = [] for i, (u, e, a, r, d) in enumerate(zip(u_range[time_range], elevation_range[time_range], azimuth_range[time_range], roll_range[time_range], d_range[time_range])): gu_dof_constraints.dof_constraints[-1][-1] = u sim_step._solve_nr() f = sim_step.forming_task.formed_object.center print 'perspective - before', ftv.mlab.view() print 'roll', ftv.mlab.roll() print 'a,e,d,f', a, e, d, f ftv.mlab.view(a, e, d, f) ftv.mlab.roll(r) print 'perspective', ftv.mlab.view() print 'roll', ftv.mlab.roll() ftv.update(force=True) fname = os.path.join(tdir, 'eftlogo%03d.jpg' % i) fname_list.append(fname) ftv.mlab.savefig(fname, magnification=2.2) if animation: animation_file = os.path.join(tdir, 'anim01.gif') images = string.join(fname_list, ' ') destination = animation_file import platform if platform.system() == 'Linux': os.system( 'convert -delay 8 -loop 1 ' + images + ' ' + destination) # os.system('png2swf -o%s ' % destination + images) else: raise NotImplementedError( 'film production available only on linux') print 'animation saved in', destination ftv.show()
def _ftv_default(self): return FTV()
n_stripes=4, n_steps=1, psi_max=-np.pi / 2.03 * 0.1, fixed_z=[15, 44], fixed_y=[24, 35], fixed_x=[24, 35], link_z=[[24], [35]]) if __name__ == '__main__': from oricreate.api import \ FTV bsf_process = HPShellFormingProcess(**hp_shell_kw_2) ftv = FTV() fa = bsf_process.factory_task if False: import pylab as p ax = p.axes() fa.formed_object.plot_mpl(ax, nodes=True, facets=False) p.show() it = bsf_process.init_displ_task ft = bsf_process.fold_task # ftv.add(it.target_faces[0].viz3d['default']) ft.formed_object.viz3d['cp'].set(tube_radius=0.02) ftv.add(ft.sim_history.viz3d['cp']) #ftv.add(it.formed_object.viz3d['node_numbers'], order=5)
fts4.u_1 single_step_fold_task = bsf_process.get_single_step_fold_task(fts4) single_step_fold_task.u_1 sscp = single_step_fold_task.formed_object print 'phi', sscp.iL_psi fts = fts4 fts = single_step_fold_task #ftt = FormingTaskTree(root=bsf_process.factory_task) # ftt.configure_traits() ftv = FTV() # ft.sim_history.set(anim_t_start=0, anim_t_end=10) # ft.sim_history.viz3d['cp'].set(tube_radius=0.005) # ftv.add(ft.sim_history.viz3d['cp']) fts.sim_history.set(anim_t_start=0, anim_t_end=100) fts.sim_history.viz3d['cp'].set(tube_radius=0.01) ftv.add(fts.sim_history.viz3d['cp']) ftv.plot() ftv.configure_traits() if True: n_cam_move = 20 fta = FTA(ftv=ftv) fta.init_view(a=45.0,
''' def _p_default(self): x, y, z, s = np.random.random((4, 100)) print 's_default', s return x, y, z, s points_t = Property(Tuple) def _get_points_t(self): x, y, z, s = self.p c = self.vot return x * c, y * c, z * c, s * c viz3d_classes = dict(default=PointCloudViz3D, something_else=PointCloudShiftedViz3D) ftv = FTV() pc = PointCloud() ftv.add(pc.viz3d['default']) ftv.add(pc.viz3d['something_else']) ftv.plot() ftv.configure_traits() ftv.plot() ftv.update(vot=0.9) ftv.update(vot=0.8) ftv.show()
dof_constraints = fix([0], [0, 1, 2]) + fix([1], [1, 2]) \ + fix([2], [2]) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) sim_config = SimulationConfig(goal_function_type='none', gu={ 'cl': gu_constant_length, 'u': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-5, MAX_ITER=100) sim_task = SimulationTask(previous_task=cp_factory_task, config=sim_config, n_steps=5) sim_task.u_1 cp = sim_task.formed_object ftv = FTV() ftv.add(sim_task.sim_history.viz3d['node_numbers'], order=5) ftv.add(sim_task.sim_history.viz3d['cp']) ftv.add(gu_dof_constraints.viz3d['default']) fta = FTA(ftv=ftv) fta.init_view(a=200, e=35, d=5, f=(0, 0, 0), r=0) fta.plot() fta.configure_traits()
if __name__ == '__main__': bsf_process = OctahederFormingProcess(n_steps=40, phi_max=np.pi / 2.556) cp = bsf_process.factory_task.formed_object fact = bsf_process.factory_task # ft = bsf_process.fold_seq_task fts = bsf_process.fold_task # ft.u_1 fts.u_1 ftv = FTV() # ft.sim_history.set(anim_t_start=0, anim_t_end=10) # ft.sim_history.viz3d['cp'].set(tube_radius=0.005) # ftv.add(ft.sim_history.viz3d['cp']) fts.sim_history.set(anim_t_start=0, anim_t_end=20) fts.sim_history.viz3d['cp'].set(tube_radius=0.005) ftv.add(fts.sim_history.viz3d['cp']) ftv.plot() ftv.configure_traits() n_cam_move = 20 fta = FTA(ftv=ftv) fta.init_view(a=45.0, e=54.7356103172, d=7.77,
def run_sim(): cp_factory, L_selection = create_cp_factory() cp = cp_factory.formed_object if False: fig, ax = plt.subplots() cp.plot_mpl(ax, facets=True) plt.tight_layout() plt.show() return # Configure simulation gu_constant_length = GuConstantLength() dof_constraints = \ fix([0], [0, 1, 2]) +\ fix([1], [1, 2]) +\ fix([5], [2]) +\ fix([3], [0], lambda t: t * -1.9599) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) sim_config = SimulationConfig(gu={'cl': gu_constant_length, 'dofs': gu_dof_constraints}, acc=1e-5, MAX_ITER=1000) sim_step = SimulationStep(forming_task=cp_factory, config=sim_config) if False: # Configure rendering visualization operators eftlabels_viz3d = FacetsWithTextViz3D( label='EFT labels', vis3d=cp) efttitle_viz3d = FacetsWithImageViz3D( label='EFT title', vis3d=cp, F_ref=[0, 2, 4, 6, 8], N_ref=[0, 3, 15, 12, 7], F_covered=[[0, 9], [2, 11], [4, 13], [6, 15], [8, 17]], atimes=[90.0, 180.0, -90, 0, 135], im_files=['eft_01.png', 'eft_01.png', 'eft_01.png', 'eft_01.png', 'eft_01.png'], im_widths=[2, 2, 2, 2, 2], im_offsets=[[0, 0, 0.004], [0, 0, 0.004], [0, 0, 0.004], [0, 0, 0.004], [-.295, -.295, 0.004]], ) else: fname_eft_front = 'eft_areas_standard_02.png' fname_eft_back = 'eft_mission_standard_trans_EF01.png' fheight = 0.011 front_offset = 0.006 tube_radius = 0.01 plane_offsets = [0.005, -0.010] edge_len = 2.0 x_offset = 1.0 c45 = np.cos(np.pi / 4) shift_x = x_offset + edge_len / c45 - edge_len shift_l = shift_x * c45 print('shift_l', shift_l) F_ref = [0, 2, 4, 6, 8, 16, 1, 12, 14, ] N_ref = [0, 3, 15, 12, 7, 4, 1, 11, 13] F_covered = [[0, 9], [2, 11], [4, 13], [6, 15], [8, 17], [16, 7], [1, 10], [12, 3], [14, 5]] atimes = [90.0, 180.0, -90, 0, 45, 90, 90.0, -90.0, 0.0] im_widths = [4, 4, 4, 4, 4, 4, 4, 4, 4] imfiles_front = [ fname_eft_front, fname_eft_front, fname_eft_front, fname_eft_front, fname_eft_front, fname_eft_front, fname_eft_front, fname_eft_front, fname_eft_front, ] imfiles_back = [ fname_eft_back, fname_eft_back, fname_eft_back, fname_eft_back, fname_eft_back, fname_eft_back, fname_eft_back, fname_eft_back, fname_eft_back, ] im_front_offsets = [ [0, 0, front_offset], [0, 0, front_offset], [0, 0, front_offset], [0, 0, front_offset], [-shift_l, -shift_l, front_offset], [0, -1, front_offset], [-2, 0, front_offset], [0, -1, front_offset], [0, -1, front_offset] ] im_back_offsets = [ [0, 0, -fheight], [0, 0, -fheight], [0, 0, -fheight], [0, 0, -fheight], [-shift_l, -shift_l, -fheight], [0, -1, -fheight], [-2, 0, -fheight], [0, -1, -fheight], [0, -1, -fheight] ] efttitle_back_viz3d = FacetsWithImageViz3D( label='EFT back', vis3d=cp, F_ref=F_ref, # + F_ref, N_ref=N_ref, # + N_ref, F_covered=F_covered, # + F_covered, atimes=atimes, # + atimes, im_files=imfiles_back, # imfiles_front + im_widths=im_widths, # + im_widths, im_offsets=im_back_offsets, # im_front_offsets + ) efttitle_front_viz3d = FacetsWithImageViz3D( label='EFT front', vis3d=cp, F_ref=F_ref, N_ref=N_ref, F_covered=F_covered, atimes=atimes, im_files=imfiles_front, im_widths=im_widths, im_offsets=im_front_offsets ) eftlogo_normals = CreasePatternNormalsViz3D( label='EFT normals', vis3d=cp) eftlogo_bases = CreasePatternBasesViz3D( label='EFT bases', vis3d=cp) eft_thick_viz3d = CreasePatternThickViz3D( label='EFT thick', vis3d=cp, plane_offsets=plane_offsets) cp.viz3d['cp'].set(tube_radius=tube_radius) # Configure scene ftv = FTV() ftv.add(cp.viz3d['cp']) ftv.add(eft_thick_viz3d) ftv.add(efttitle_front_viz3d) ftv.add(efttitle_back_viz3d) # ftv.add(eftlabels_viz3d) # ftv.add(eftlogo_normals) # ftv.add(eftlogo_bases) m = ftv.mlab m.figure(bgcolor=(1, 1, 1), fgcolor=(0, 0, 0)) fig = m.gcf() ftv.plot() # oricreate_mlab_label(m) a, e, d, f = m.view() e = 135 # 10 a = 270 # -45 # 120 f = sim_step.forming_task.formed_object.center m.view(a, e, d, f) show = False if show: m.show() n_u = 30 # Control the folding by a fold angle phi_range = np.linspace(0.01, np.pi - 0.01, n_u) dramaturgy = False animation = True def circular_folding(phi_range): bot_e = 160 top_e = 10 if dramaturgy: phi_unfolded = phi_range[0] * np.ones_like(phi_range) phi_folded = phi_range[-1] * np.ones_like(phi_range) phi_range_u = np.hstack( [phi_range, phi_folded, phi_range[::-1], phi_unfolded]) else: phi_range_u = phi_range u_range = np.cos(phi_range_u) - 1 phi_range_e = np.linspace(0.01, np.pi - 0.01, n_u * 4) azimuth_step = 360.0 / 4 / n_u elevation_range = np.cos( 2 * phi_range_e)**2 * top_e + np.sin(2 * phi_range_e)**2 * bot_e time_range = slice(None) return u_range, elevation_range, azimuth_step, time_range def eft_folding(phi_range): n_u12 = 30 n_c = 60 n_u23 = 75 phi_12_range = damped_range(np.pi * 0.3, 0.012, n_u12) phi_c = np.ones((n_c,), dtype='float_') * 0.01 phi_23_range = damped_range(0.01, np.pi - 0.005, n_u23) phi_range_u = np.hstack([phi_12_range, phi_c, phi_23_range]) u_range = np.cos(phi_range_u) - 1 conf1 = 230, 50, 52, 1.14 confc = 230, 50, 20, 1.14 conf2 = 100, 160, 0, 1.1 conf3 = 270, 179, 0., 0.5 azimuth_range = np.hstack([damped_range(conf1[0], confc[0], n_u12), damped_range(confc[0], conf2[0], n_c), damped_range(conf2[0], conf3[0], n_u23)]) elevation_range = np.hstack([damped_range(conf1[1], confc[1], n_u12), damped_range(confc[1], conf2[1], n_c), damped_range(conf2[1], conf3[1], n_u23)]) roll_range = np.hstack([damped_range(conf1[2], confc[2], n_u12), damped_range(confc[2], conf2[2], n_c), damped_range(conf2[2], conf3[2], n_u23)]) d_range = np.hstack([damped_range(conf1[3], confc[3], n_u12) * d, damped_range(confc[3], conf2[3], n_c) * d, damped_range(conf2[3], conf3[3], n_u23) * d]) time_range = slice(None) #time_range = np.array([-1], dtype=int) return u_range, elevation_range, azimuth_range, roll_range, time_range, d_range def eft_unfolding(phi_range): n_u1 = 30 n_u2 = 60 n_u3 = 60 phi_u1 = np.pi - 0.012 phi_u2 = np.pi * 0.86 phi_u3 = 0.012 phi_1 = damped_range(phi_u1, phi_u2, n_u1) phi_2 = np.ones((n_u2,), dtype='float_') * phi_u2 phi_3 = damped_range(phi_u2, phi_u3, n_u3) phi_range_u = np.hstack([phi_1, phi_2, phi_3]) u_range = np.cos(phi_range_u) - 1 conf1 = 270, 179, 0., 0.5 conf2 = 230, 140, 60., 0.6 conf3 = 150, 70, 70., 0.64 conf4 = 45, 1, 314., 1.14 azimuth_range = np.hstack([damped_range(conf1[0], conf2[0], n_u1), damped_range(conf2[0], conf3[0], n_u2), damped_range(conf3[0], conf4[0], n_u3)]) elevation_range = np.hstack([damped_range(conf1[1], conf2[1], n_u1), damped_range(conf2[1], conf3[1], n_u2), damped_range(conf3[1], conf4[1], n_u3)]) roll_range = np.hstack([damped_range(conf1[2], conf2[2], n_u1), damped_range(conf2[2], conf3[2], n_u2), damped_range(conf3[2], conf4[2], n_u3)]) d_range = np.hstack([damped_range(conf1[3], conf2[3], n_u1) * d, damped_range(conf2[3], conf3[3], n_u2) * d, damped_range(conf3[3], conf4[3], n_u3) * d, ]) time_range = slice(None) #time_range = np.array([0], dtype=int) return u_range, elevation_range, azimuth_range, roll_range, time_range, d_range # u_range, elevation_range, azimuth_range, roll_range, time_range, d_range = eft_folding( # phi_range) u_range, elevation_range, azimuth_range, roll_range, time_range, d_range = eft_unfolding( phi_range) tdir = tempfile.mkdtemp() fname_list = [] for i, (u, e, a, r, d) in enumerate(zip(u_range[time_range], elevation_range[time_range], azimuth_range[time_range], roll_range[time_range], d_range[time_range])): gu_dof_constraints.dof_constraints[-1][-1] = u sim_step._solve_nr() f = sim_step.forming_task.formed_object.center print('perspective - before', ftv.mlab.view()) print('roll', ftv.mlab.roll()) print('a,e,d,f', a, e, d, f) ftv.mlab.view(a, e, d, f) ftv.mlab.roll(r) print('perspective', ftv.mlab.view()) print('roll', ftv.mlab.roll()) ftv.update(force=True) fname = os.path.join(tdir, 'eftlogo%03d.jpg' % i) fname_list.append(fname) ftv.mlab.savefig(fname, magnification=2.2) if animation: animation_file = os.path.join(tdir, 'anim01.gif') images = string.join(fname_list, ' ') destination = animation_file import platform if platform.system() == 'Linux': os.system( 'convert -delay 8 -loop 1 ' + images + ' ' + destination) # os.system('png2swf -o%s ' % destination + images) else: raise NotImplementedError( 'film production available only on linux') print('animation saved in', destination) ftv.show()