← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 1782: Added import_mesh_geometry function to import mesh files into facets

 

------------------------------------------------------------
revno: 1782
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2009-11-12 21:40:12 +0100
message:
  Added import_mesh_geometry function to import mesh files into facets
added:
  scripts/test/regular-sphere-pack.geo
  scripts/test/regular-sphere-pack.mesh
modified:
  py/utils.py
  scripts/test/regular-sphere-pack.py


--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription.
=== modified file 'py/utils.py'
--- py/utils.py	2009-11-04 15:53:24 +0000
+++ py/utils.py	2009-11-12 20:40:12 +0000
@@ -311,6 +311,53 @@
 		o.bodies[i].shape['diffuseColor']=color
 	return imported
 
+
+def import_mesh_geometry(meshfile="file.mesh",**kw):
+	""" Imports geometry from mesh file and creates facets.
+	Remaining **kw arguments are passed to utils.facet; 
+	mesh files can be easily created with GMSH http://www.geuz.org/gmsh/
+	Example added to scripts/test/regular-sphere-pack.py"""
+	infile = open(meshfile,"r")
+	lines = infile.readlines()
+	infile.close()
+
+	nodelistVector3=[]
+	numNodes = int(lines[4].split()[0])
+	for i in range(numNodes):
+		nodelistVector3.append(Vector3(0.0,0.0,0.0))
+	id = 0
+	for line in lines[5:numNodes+5]:
+		data = line.split()
+		X = float(data[0])
+		Y = float(data[1])
+		Z = float(data[2])
+		nodelistVector3[id] = Vector3(X,Y,Z)
+		id += 1
+	numTriangles = int(lines[numNodes+6].split()[0])
+	triList = []
+	for i in range(numTriangles):
+		triList.append([0,0,0,0])
+	 
+	tid = 0
+	for line in lines[numNodes+7:numNodes+7+numTriangles]:
+		data = line.split()
+		id1 = int(data[0])-1
+		id2 = int(data[1])-1
+		id3 = int(data[2])-1
+		triList[tid][0] = tid
+		triList[tid][1] = id1
+		triList[tid][2] = id2
+		triList[tid][3] = id3
+		tid += 1
+		ret=[]
+	for i in triList:
+		a=nodelistVector3[i[1]]
+		b=nodelistVector3[i[2]]
+		c=nodelistVector3[i[3]]
+		ret.append(facet((nodelistVector3[i[1]],nodelistVector3[i[2]],nodelistVector3[i[3]]),**kw))
+	return ret
+
+
 def encodeVideoFromFrames(frameSpec,out,renameNotOverwrite=True,fps=24):
 	"""Create .ogg video from external image files.
 	

=== added file 'scripts/test/regular-sphere-pack.geo'
--- scripts/test/regular-sphere-pack.geo	1970-01-01 00:00:00 +0000
+++ scripts/test/regular-sphere-pack.geo	2009-11-12 20:40:12 +0000
@@ -0,0 +1,40 @@
+Point(1) = {-2, -2, -3, 1.0};
+Point(2) = {-2, 2, -3, 1.0};
+Point(3) = {2, 2, -3, 1.0};
+Point(4) = {2, -2, -3, 1.0};
+Point(5) = {0, 0, -3, 1.0};
+Circle(1) = {2, 5, 1};
+Circle(2) = {1, 5, 4};
+Circle(3) = {4, 5, 3};
+Circle(4) = {3, 5, 2};
+Translate {0, 0, 1.5} {
+  Duplicata { Line{3, 4, 1, 2}; }
+}
+Dilate {{0, 0, 1}, 2} {
+  Duplicata { Line{2, 1, 4, 3}; }
+}
+Line(13) = {1, 18};
+Line(14) = {6, 4};
+Line(15) = {2, 13};
+Line(16) = {3, 8};
+
+Line(17) = {1, 19};
+Line(18) = {4, 21};
+Line(19) = {3, 29};
+Line(20) = {2, 24};
+Line Loop(21) = {6, -15, -4, 16};
+Ruled Surface(22) = {21};
+Line Loop(23) = {5, -16, -3, -14};
+Ruled Surface(24) = {23};
+Line Loop(25) = {8, 14, -2, 13};
+Ruled Surface(26) = {25};
+Line Loop(27) = {7, -13, -1, 15};
+Ruled Surface(28) = {27};
+Line Loop(29) = {3, 19, -12, -18};
+Ruled Surface(30) = {29};
+Line Loop(31) = {18, -9, -17, 2};
+Ruled Surface(32) = {31};
+Line Loop(33) = {17, -10, -20, 1};
+Ruled Surface(34) = {33};
+Line Loop(35) = {20, -11, -19, 4};
+Ruled Surface(36) = {35};

=== added file 'scripts/test/regular-sphere-pack.mesh'
--- scripts/test/regular-sphere-pack.mesh	1970-01-01 00:00:00 +0000
+++ scripts/test/regular-sphere-pack.mesh	2009-11-12 20:40:12 +0000
@@ -0,0 +1,425 @@
+ MeshVersionFormatted 1
+ Dimension
+ 3
+ Vertices
+ 157
+                   -2                        -2                        -3      0
+                   -2                         2                        -3      0
+                    2                         2                        -3      0
+                    2                        -2                        -3      0
+                    0                         0                        -3      0
+                    2                        -2                      -1.5      0
+                    0                         0                      -1.5      0
+                    2                         2                      -1.5      0
+                   -2                         2                      -1.5      0
+                   -2                        -2                      -1.5      0
+                   -4                        -4                        -7      0
+                    0                         0                        -7      0
+                    4                        -4                        -7      0
+                   -4                         4                        -7      0
+                    4                         4                        -7      0
+     -2.6131259297492            1.082392200301                        -3      0
+     -2.8284271247462       2.0434764991251E-12                        -3      0
+     -2.6131259297503          -1.0823922002982                        -3      0
+      -1.082392200301          -2.6131259297492                        -3      0
+ -2.0434764991251E-12          -2.8284271247462                        -3      0
+      1.0823922002982          -2.6131259297503                        -3      0
+      2.6131259297492           -1.082392200301                        -3      0
+      2.8284271247462      -2.0434764991251E-12                        -3      0
+      2.6131259297503           1.0823922002982                        -3      0
+       1.082392200301           2.6131259297492                        -3      0
+  2.0434764991251E-12           2.8284271247462                        -3      0
+     -1.0823922002982           2.6131259297503                        -3      0
+      2.6131259297492           -1.082392200301                      -1.5      0
+      2.8284271247462      -2.0434764991251E-12                      -1.5      0
+      2.6131259297503           1.0823922002982                      -1.5      0
+       1.082392200301           2.6131259297492                      -1.5      0
+  2.0434764991251E-12           2.8284271247462                      -1.5      0
+     -1.0823922002982           2.6131259297503                      -1.5      0
+     -2.6131259297492            1.082392200301                      -1.5      0
+     -2.8284271247462       2.0434764991251E-12                      -1.5      0
+     -2.6131259297503          -1.0823922002982                      -1.5      0
+      -1.082392200301          -2.6131259297492                      -1.5      0
+ -2.0434764991251E-12          -2.8284271247462                      -1.5      0
+      1.0823922002982          -2.6131259297503                      -1.5      0
+     -3.1427798335562          -4.7035024096722                        -7      0
+     -2.1647844006021          -5.2262518594984                        -7      0
+     -1.1035975171429          -5.5481593812864                        -7      0
+ -4.0869529982501E-12          -5.6568542494924                        -7      0
+       1.103597517136          -5.5481593812878                        -7      0
+      2.1647844005965          -5.2262518595007                        -7      0
+      3.1427798335537          -4.7035024096739                        -7      0
+     -4.7035024096722           3.1427798335562                        -7      0
+     -5.2262518594984           2.1647844006021                        -7      0
+     -5.5481593812864           1.1035975171429                        -7      0
+     -5.6568542494924       4.0869529982501E-12                        -7      0
+     -5.5481593812878           -1.103597517136                        -7      0
+     -5.2262518595007          -2.1647844005965                        -7      0
+     -4.7035024096739          -3.1427798335537                        -7      0
+      3.1427798335562           4.7035024096722                        -7      0
+      2.1647844006021           5.2262518594984                        -7      0
+      1.1035975171429           5.5481593812864                        -7      0
+  4.0869529982501E-12           5.6568542494924                        -7      0
+      -1.103597517136           5.5481593812878                        -7      0
+     -2.1647844005965           5.2262518595007                        -7      0
+     -3.1427798335537           4.7035024096739                        -7      0
+      4.7035024096722          -3.1427798335562                        -7      0
+      5.2262518594984          -2.1647844006021                        -7      0
+      5.5481593812864          -1.1035975171429                        -7      0
+      5.6568542494924      -4.0869529982501E-12                        -7      0
+      5.5481593812878            1.103597517136                        -7      0
+      5.2262518595007           2.1647844005965                        -7      0
+      4.7035024096739           3.1427798335537                        -7      0
+     -2.5000000000014          -2.5000000000014          -4.0000000000028      0
+     -3.0000000000009          -3.0000000000009          -5.0000000000019      0
+     -3.5000000000005          -3.5000000000005          -6.0000000000009      0
+      2.5000000000014          -2.5000000000014          -4.0000000000028      0
+      3.0000000000009          -3.0000000000009          -5.0000000000019      0
+      3.5000000000005          -3.5000000000005          -6.0000000000009      0
+      2.5000000000014           2.5000000000014          -4.0000000000028      0
+      3.0000000000009           3.0000000000009          -5.0000000000019      0
+      3.5000000000005           3.5000000000005          -6.0000000000009      0
+     -2.5000000000014           2.5000000000014          -4.0000000000028      0
+     -3.0000000000009           3.0000000000009          -5.0000000000019      0
+     -3.5000000000005           3.5000000000005          -6.0000000000009      0
+     0.55179875857147           2.7740796906432                     -2.25      0
+    -0.55179875856798           2.7740796906439                     -2.25      0
+      2.7740796906432         -0.55179875857147                     -2.25      0
+      2.7740796906439          0.55179875856798                     -2.25      0
+    -0.55179875857147          -2.7740796906432                     -2.25      0
+     0.55179875856798          -2.7740796906439                     -2.25      0
+     -2.7740796906432          0.55179875857147                     -2.25      0
+     -2.7740796906439         -0.55179875856798                     -2.25      0
+      5.0479792461586         -0.35505567377516          -6.1565576922327      0
+      3.3234612474655           1.9381178063516          -4.4408997959349      0
+      3.6142702934017          -1.5190194235244          -4.5444332014752      0
+      4.5063483206219           -2.543437469799          -6.3179572763921      0
+      4.3733777215095          0.24526028715351          -5.1946081883281      0
+      3.5122070514485          0.67793138703452           -4.058693376312      0
+      3.2470611761867          -0.7668862216033          -3.7183727616168      0
+      2.8565535692464           1.6984461402266          -3.6999186344499      0
+      2.9161694821589          -1.8409712583355          -3.8771343271828      0
+       4.083484027652          -2.2155446444777          -5.5701567524319      0
+      5.0203546348214           1.0205678755183          -6.2450699717688      0
+      3.8864344298386         -0.40220012269193          -4.5256017801011      0
+      4.8451260122149           -1.579026917017             -6.2067429646      0
+      4.1596393420579           1.4493085375803          -5.2294614041823      0
+      4.3919803804835         -0.98778292819349          -5.3663500965282      0
+      3.7585664236253           2.5020208457379          -5.3854412335108      0
+      4.4762900020786           2.3401710969288          -6.1433287682438      0
+    -0.28924498858354          -4.9808623675674          -6.0558702635564      0
+      1.9381178063516          -3.3234612474655          -4.4408997959349      0
+     -1.5516673232336          -3.3963609896359          -4.2807081824148      0
+     -2.2778430668748          -4.5063100607913          -6.1407841868101      0
+     0.24526028715351          -4.3733777215095          -5.1946081883281      0
+     0.67793138703452          -3.5122070514485           -4.058693376312      0
+     -0.7668862216033          -3.2470611761867          -3.7183727616168      0
+      1.6984461402266          -2.8565535692464          -3.6999186344499      0
+     -1.6296458263124          -2.8148550524294          -3.5998161888069      0
+     -1.3182141950721          -4.4895155980188          -5.6171654005236      0
+     -2.2716953470806          -3.6866203182072          -5.1240132463224      0
+      1.0272828673387          -5.0086026306537          -6.2306860533865      0
+    -0.53284104597107          -3.8941623987227          -4.5584926676028      0
+     -1.4394493797433          -5.0033121153324           -6.362763970178      0
+      1.4499599704998          -4.1576170626795          -5.2270640844519      0
+     -1.2207841346155          -4.0470784277258          -4.9781531769423      0
+     -0.6016909663055          -4.3973650493818          -5.2767589401631      0
+      2.5020515688442          -3.7581386810821          -5.3849617695648      0
+       2.340790036915          -4.4736706712761          -6.1404519845673      0
+     -5.0479792461586          0.35505567377516          -6.1565576922327      0
+     -3.3234612474655          -1.9381178063516          -4.4408997959349      0
+     -3.6142702934017           1.5190194235244          -4.5444332014752      0
+     -4.5063483206219            2.543437469799          -6.3179572763921      0
+     -4.3733777215095         -0.24526028715351          -5.1946081883281      0
+     -3.5122070514485         -0.67793138703452           -4.058693376312      0
+     -3.2470611761867           0.7668862216033          -3.7183727616168      0
+     -2.8565535692464          -1.6984461402266          -3.6999186344499      0
+     -2.9161694821589           1.8409712583355          -3.8771343271828      0
+      -4.083484027652           2.2155446444777          -5.5701567524319      0
+     -5.0203546348214          -1.0205678755183          -6.2450699717688      0
+     -3.8864344298386          0.40220012269193          -4.5256017801011      0
+     -4.8451260122149            1.579026917017             -6.2067429646      0
+     -4.1596393420579          -1.4493085375803          -5.2294614041823      0
+     -4.3919803804835          0.98778292819349          -5.3663500965282      0
+     -3.7585664236253          -2.5020208457379          -5.3854412335108      0
+     -4.4762900020786          -2.3401710969288          -6.1433287682438      0
+     0.35505567377516           5.0479792461586          -6.1565576922327      0
+     -1.9381178063516           3.3234612474655          -4.4408997959349      0
+      1.5190194235244           3.6142702934017          -4.5444332014752      0
+       2.543437469799           4.5063483206219          -6.3179572763921      0
+    -0.24526028715351           4.3733777215095          -5.1946081883281      0
+    -0.67793138703452           3.5122070514485           -4.058693376312      0
+      0.7668862216033           3.2470611761867          -3.7183727616168      0
+     -1.6984461402266           2.8565535692464          -3.6999186344499      0
+      1.8409712583355           2.9161694821589          -3.8771343271828      0
+      2.2155446444777            4.083484027652          -5.5701567524319      0
+     -1.0205678755183           5.0203546348214          -6.2450699717688      0
+     0.40220012269193           3.8864344298386          -4.5256017801011      0
+       1.579026917017           4.8451260122149             -6.2067429646      0
+     -1.4493085375803           4.1596393420579          -5.2294614041823      0
+     0.98778292819349           4.3919803804835          -5.3663500965282      0
+     -2.5020208457379           3.7585664236253          -5.3854412335108      0
+     -2.3401710969288           4.4762900020786          -6.1433287682438      0
+ Triangles
+ 260
+ 31 80 25 22
+ 26 80 32 22
+ 80 26 25 22
+ 80 31 32 22
+ 81 27 26 22
+ 81 32 33 22
+ 32 81 26 22
+ 27 81 33 22
+ 31 3 8 22
+ 3 31 25 22
+ 27 9 2 22
+ 9 27 33 22
+ 28 82 22 24
+ 23 82 29 24
+ 82 23 22 24
+ 82 28 29 24
+ 30 83 29 24
+ 23 83 24 24
+ 83 23 29 24
+ 83 30 24 24
+ 4 6 22 24
+ 6 28 22 24
+ 24 8 3 24
+ 8 24 30 24
+ 84 20 19 26
+ 84 37 38 26
+ 37 84 19 26
+ 20 84 38 26
+ 85 21 20 26
+ 85 38 39 26
+ 38 85 20 26
+ 21 85 39 26
+ 10 19 1 26
+ 19 10 37 26
+ 4 21 39 26
+ 6 4 39 26
+ 34 86 16 28
+ 17 86 35 28
+ 86 17 16 28
+ 86 34 35 28
+ 36 87 35 28
+ 17 87 18 28
+ 87 17 35 28
+ 87 36 18 28
+ 9 16 2 28
+ 16 9 34 28
+ 10 18 36 28
+ 18 10 1 28
+ 91 62 61 30
+ 93 23 24 30
+ 23 94 22 30
+ 93 94 23 30
+ 61 13 73 30
+ 73 91 61 30
+ 95 24 3 30
+ 95 74 89 30
+ 74 95 3 30
+ 96 71 4 30
+ 22 96 4 30
+ 73 97 91 30
+ 72 97 73 30
+ 64 98 65 30
+ 94 99 90 30
+ 64 88 98 30
+ 92 99 93 30
+ 94 93 99 30
+ 75 89 74 30
+ 98 88 92 30
+ 66 65 98 30
+ 88 64 63 30
+ 63 100 88 30
+ 89 101 93 30
+ 101 92 93 30
+ 102 92 88 30
+ 92 102 99 30
+ 94 96 22 30
+ 94 90 96 30
+ 63 62 100 30
+ 62 91 100 30
+ 103 89 75 30
+ 89 103 101 30
+ 66 104 67 30
+ 95 93 24 30
+ 89 93 95 30
+ 98 104 66 30
+ 92 101 98 30
+ 76 15 67 30
+ 104 76 67 30
+ 90 102 97 30
+ 102 90 99 30
+ 76 103 75 30
+ 103 76 104 30
+ 96 72 71 30
+ 97 72 90 30
+ 96 90 72 30
+ 100 102 88 30
+ 97 100 91 30
+ 102 100 97 30
+ 101 104 98 30
+ 103 104 101 30
+ 108 41 40 32
+ 110 20 21 32
+ 20 111 19 32
+ 110 111 20 32
+ 40 11 70 32
+ 70 108 40 32
+ 112 21 4 32
+ 112 71 106 32
+ 71 112 4 32
+ 19 113 1 32
+ 68 113 107 32
+ 113 68 1 32
+ 70 115 108 32
+ 69 115 70 32
+ 115 69 68 32
+ 107 115 68 32
+ 115 114 108 32
+ 43 116 44 32
+ 111 117 107 32
+ 43 105 116 32
+ 109 117 110 32
+ 111 110 117 32
+ 72 106 71 32
+ 116 105 109 32
+ 45 44 116 32
+ 105 43 42 32
+ 42 118 105 32
+ 114 118 108 32
+ 118 114 105 32
+ 106 119 110 32
+ 119 109 110 32
+ 107 120 115 32
+ 120 114 115 32
+ 120 107 117 32
+ 121 109 105 32
+ 114 121 105 32
+ 109 121 117 32
+ 111 113 19 32
+ 111 107 113 32
+ 120 121 114 32
+ 120 117 121 32
+ 42 41 118 32
+ 41 108 118 32
+ 122 106 72 32
+ 106 122 119 32
+ 45 123 46 32
+ 112 110 21 32
+ 106 110 112 32
+ 116 123 45 32
+ 109 119 116 32
+ 73 13 46 32
+ 123 73 46 32
+ 73 122 72 32
+ 122 73 123 32
+ 119 123 116 32
+ 122 123 119 32
+ 127 48 47 34
+ 129 17 18 34
+ 17 130 16 34
+ 129 130 17 34
+ 47 14 79 34
+ 79 127 47 34
+ 68 131 1 34
+ 131 18 1 34
+ 131 68 125 34
+ 132 77 2 34
+ 16 132 2 34
+ 79 133 127 34
+ 78 133 79 34
+ 50 134 51 34
+ 130 135 126 34
+ 50 124 134 34
+ 128 135 129 34
+ 130 129 135 34
+ 69 125 68 34
+ 134 124 128 34
+ 52 51 134 34
+ 124 50 49 34
+ 49 136 124 34
+ 125 137 129 34
+ 137 128 129 34
+ 138 128 124 34
+ 128 138 135 34
+ 130 132 16 34
+ 130 126 132 34
+ 49 48 136 34
+ 48 127 136 34
+ 139 125 69 34
+ 125 139 137 34
+ 52 140 53 34
+ 131 129 18 34
+ 125 129 131 34
+ 134 140 52 34
+ 128 137 134 34
+ 70 11 53 34
+ 140 70 53 34
+ 126 138 133 34
+ 138 126 135 34
+ 70 139 69 34
+ 139 70 140 34
+ 132 78 77 34
+ 133 78 126 34
+ 132 126 78 34
+ 136 138 124 34
+ 133 136 127 34
+ 138 136 133 34
+ 137 140 134 34
+ 139 140 137 34
+ 144 55 54 36
+ 146 26 27 36
+ 26 147 25 36
+ 146 147 26 36
+ 54 15 76 36
+ 76 144 54 36
+ 77 148 2 36
+ 148 27 2 36
+ 148 77 142 36
+ 25 149 3 36
+ 149 74 3 36
+ 76 150 144 36
+ 75 150 76 36
+ 57 151 58 36
+ 147 152 143 36
+ 57 141 151 36
+ 145 152 146 36
+ 147 146 152 36
+ 78 142 77 36
+ 151 141 145 36
+ 59 58 151 36
+ 141 57 56 36
+ 56 153 141 36
+ 142 154 146 36
+ 154 145 146 36
+ 155 145 141 36
+ 145 155 152 36
+ 147 149 25 36
+ 147 143 149 36
+ 56 55 153 36
+ 55 144 153 36
+ 156 142 78 36
+ 142 156 154 36
+ 59 157 60 36
+ 148 146 27 36
+ 142 146 148 36
+ 151 157 59 36
+ 145 154 151 36
+ 79 14 60 36
+ 157 79 60 36
+ 143 155 150 36
+ 155 143 152 36
+ 79 156 78 36
+ 156 79 157 36
+ 149 75 74 36
+ 150 75 143 36
+ 149 143 75 36
+ 153 155 141 36
+ 150 153 144 36
+ 155 153 150 36
+ 154 157 151 36
+ 156 157 154 36
+ End

=== modified file 'scripts/test/regular-sphere-pack.py'
--- scripts/test/regular-sphere-pack.py	2009-07-21 15:04:11 +0000
+++ scripts/test/regular-sphere-pack.py	2009-11-12 20:40:12 +0000
@@ -50,10 +50,13 @@
 o1,o_angl = q1.ToAxisAngle()
 O.bodies.append(utils.facetBox((-12,-12,-6+0.9),(1,0.7,0.9),(o1[0],o1[1],o1[2],o_angl),**kwBoxes))
 
+kwMeshes={'frictionAngle':0.5,'color':[1,1,0],'wire':True,'dynamic':False}
+O.bodies.append(utils.import_mesh_geometry('regular-sphere-pack.mesh',**kwMeshes))#generates facets from the mesh file
 
 try:
 	from yade import qt
 	qt.Controller()
+	qt.View()
 except ImportError: pass
 
 O.engines=[