box=nmesh.box( [0.0,0.0], [1.0,1.0] ) cone = nmesh.conic([3.0,0.0],1.0,[3.0,4.0],0.0) bbox = [[-1.,-1.],[7.,6.]] mesh = nmesh.mesh(objects = [box,cone],a0=0.4, bounding_box=bbox) mesh_info=mesh.tolists() # create mesh_info lists for parts 1&2 combined and for part 2 alone [mesh_info1, mesh_info2] = viz.separate_parts(mesh_info, listOfParts=[[1,2],[2]]) # generate a VTK dataset for parts 1&2 combined vtkData, points, simplices,indices, icradii, ccradii = \ viz.mesh2vtk(mesh_info1, VTKonly=False) in2circ=viz.findRatios(icradii, ccradii, factor=2) vtkData=viz.append2vtk(vtkData, in2circ, "in2circ") vtkData=viz.append2vtk(vtkData, indices, "part indices") viz.save_vtk(vtkData, "compound_example_1.vtk") # create VTK data for part 2 alone and apply outer_skin() to it # request that only cells with two or more points on the surface are shown mesh_info2 = viz.outer_skin(mesh_info2, condition='>=2') vtkData2, points2, simplices2, indices2, icradii2, ccradii2 = \ viz.mesh2vtk(mesh_info2, VTKonly=False) in2circ2=viz.findRatios(icradii2, ccradii2, factor=2) vtkData2=viz.append2vtk(vtkData2, in2circ2, "in2circ") vtkData2=viz.append2vtk(vtkData2, indices2, "part indices") viz.save_vtk(vtkData2, "compound_example_2.vtk")
# define a simple mesh and submit request to mesher (include outer box) box = nmesh.box([0.0, 0.0], [1.0, 1.0]) cone = nmesh.conic([3.0, 0.0], 1.0, [3.0, 4.0], 0.0) bbox = [[-2., -2.], [7., 6.]] rod = 0.4 mesh = nmesh.mesh(objects=[box, cone], a0=rod, bounding_box=bbox, mesh_bounding_box=True) mesh_info = mesh.tolists() # visualise in MayaVi, using the ratio of 2*inradius:circumradius # as cell_data for a colour scale mesh_info = viz.surface_only(mesh_info) vtkData = viz.mesh2vtk(mesh_info) viz.save_vtk(vtkData, "outerbox_bug_1.vtk") ########### NOW DO THE SAME, BUT WITHOUT THE OUTER BOX ################ # define a simple mesh and submit request to mesher box = nmesh.box([0.0, 0.0], [1.0, 1.0]) cone = nmesh.conic([3.0, 0.0], 1.0, [3.0, 4.0], 0.0) bbox = [[-2., -2.], [7., 6.]] rod = 0.4 mesh2 = nmesh.mesh(objects=[box, cone], a0=rod, bounding_box=bbox) mesh_info2 = mesh2.tolists() # visualise in MayaVi, using the ratio of 2*inradius:circumradius # as cell_data for a colour scale mesh_info2 = viz.surface_only(mesh_info2)
Version: $Id$ """ import nmesh import nmesh.visual as viz # define a simple mesh and submit request to mesher # box = nmesh.box([0.0,0.0,0.0],[1.0,1.0,1.0]) cone = nmesh.conic([0.0, 0.0, 0.0], 1.0, [2.0, 0.0, 0.0], 2.0) bbox = [[-4.0, -4.0, -4.0], [4.0, 4.0, 4.0]] mesh = nmesh.mesh(objects=[cone], bounding_box=bbox) mesh_info = mesh.tolists() ##add the next line to only look at surface elements # mesh_info = viz.surface_only(mesh_info) vtkData, points, simplices, indices, icradii, ccradii = viz.mesh2vtk(mesh_info, VTKonly=False) # append the point index to each point - this will be a scalar field customScalars = [] for i in range(len(points)): customScalars.append(i) # append the data to the mesh and visualise it vtkData = viz.append2vtk(vtkData, customScalars, "point indices", sites="point") viz.save_vtk(vtkData, "example_for_tf.vtk") myv = viz.mesh2mayavi("example_for_tf.vtk") # extensive customisation of MayaVi visualisation # users are encouraged to use MayaVi GUI for similar operations dvm = myv.get_current_dvm() # data-visualisation-manager
""" import nmesh import nmesh.visual as viz # define a simple mesh and submit request to mesher box = nmesh.box([0.0, 0.0], [1.0, 1.0]) cone = nmesh.conic([3.0, 0.0], 1.0, [3.0, 4.0], 0.0) bbox = [[-2., -2.], [7., 6.]] rod = 0.4 mesh = nmesh.mesh(objects=[box, cone], a0=rod, bounding_box=bbox) mesh_info = mesh.tolists() # visualise in MayaVi, using the ratio of inradius:circumradius # as cell_data for a colour scale mesh_info2 = viz.surface_only(mesh_info) vtkData, points, simplices, indices, icradii, ccradii = viz.mesh2vtk( mesh_info2, VTKonly=False) # calculate ratio of actual:requested rod_length for surface elements rod_length2a0 = [] for i in icradii: rod_length2a0.append(i / rod) # append this as a scalar dataset and also the part indices vtkData = viz.append2vtk(vtkData, rod_length2a0, "actual/requested rod_length") vtkData = viz.append2vtk(vtkData, indices, "part indices") # display mesh from file viz.save_vtk(vtkData, 'temp.vtk') myv = viz.mesh2mayavi('temp.vtk') myv.renwin.z_plus_view()
import nmesh.visual as viz # define a simple mesh and submit request to mesher (include outer box) box = nmesh.box([0.0, 0.0], [1.0, 1.0]) cone = nmesh.conic([3.0, 0.0], 1.0, [3.0, 4.0], 0.0) bbox = [[-2.0, -2.0], [7.0, 6.0]] rod = 0.4 mesh = nmesh.mesh(objects=[box, cone], a0=rod, bounding_box=bbox, mesh_bounding_box=True) mesh_info = mesh.tolists() # visualise in MayaVi, using the ratio of 2*inradius:circumradius # as cell_data for a colour scale mesh_info = viz.surface_only(mesh_info) vtkData = viz.mesh2vtk(mesh_info) viz.save_vtk(vtkData, "outerbox_bug_1.vtk") ########### NOW DO THE SAME, BUT WITHOUT THE OUTER BOX ################ # define a simple mesh and submit request to mesher box = nmesh.box([0.0, 0.0], [1.0, 1.0]) cone = nmesh.conic([3.0, 0.0], 1.0, [3.0, 4.0], 0.0) bbox = [[-2.0, -2.0], [7.0, 6.0]] rod = 0.4 mesh2 = nmesh.mesh(objects=[box, cone], a0=rod, bounding_box=bbox) mesh_info2 = mesh2.tolists()