← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2305: 1. Orientation in ymport module is changed according to https://lists.launchpad.net/yade-dev/msg0...

 

------------------------------------------------------------
revno: 2305
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
branch nick: trunk
timestamp: Tue 2010-06-29 23:36:43 +0200
message:
  1. Orientation in ymport module is changed according to https://lists.launchpad.net/yade-dev/msg04886.html
  
  2. Shift parameter is changed in ymport module to Vector3.
  PLEASE update your code
  
  3. Code cleaning
modified:
  examples/regular-sphere-pack/regular-sphere-pack.py
  py/ymport.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 'examples/regular-sphere-pack/regular-sphere-pack.py'
--- examples/regular-sphere-pack/regular-sphere-pack.py	2010-06-29 21:02:29 +0000
+++ examples/regular-sphere-pack/regular-sphere-pack.py	2010-06-29 21:36:43 +0000
@@ -47,24 +47,26 @@
 
 
 # Example of utils.facetBox usage 
-q1 = Quaternion(Vector3(0,0,1),(3.14159/3))
-O.bodies.append(utils.facetBox((12,0,-6+0.9),(1,0.7,0.9),q1,**kwBoxes))
-
-q1 = Quaternion(Vector3(0,0,1),(3.14159/2))
-O.bodies.append(utils.facetBox((0,12,-6+0.9),(1,0.7,0.9),q1,**kwBoxes))
-
-q1 = Quaternion(Vector3(0,0,1),(3.14159))
-O.bodies.append(utils.facetBox((-12,-12,-6+0.9),(1,0.7,0.9),q1,**kwBoxes))
+oriBody = Quaternion(Vector3(0,0,1),(3.14159/3))
+O.bodies.append(utils.facetBox((12,0,-6+0.9),(1,0.7,0.9),oriBody,**kwBoxes))
+
+oriBody = Quaternion(Vector3(0,0,1),(3.14159/2))
+O.bodies.append(utils.facetBox((0,12,-6+0.9),(1,0.7,0.9),oriBody,**kwBoxes))
+
+oriBody = Quaternion(Vector3(0,0,1),(3.14159))
+O.bodies.append(utils.facetBox((-12,-12,-6+0.9),(1,0.7,0.9),oriBody,**kwBoxes))
 
 # Example of utils.facetCylinder usage, RotationEngine example see below
-q1 = Quaternion(Vector3(0,0,1),(3.14159/2))
-rotateIDs=O.bodies.append(utils.facetCylinder((6.0,6.0,-4.0),2.0,4.0,q1,wallMask=4,segmentsNumber=10,**kwBoxes))
+oriBody = Quaternion(Vector3(0,0,1),(3.14159/2))
+rotateIDs=O.bodies.append(utils.facetCylinder((6.0,6.0,-4.0),2.0,4.0,oriBody,wallMask=4,segmentsNumber=10,**kwBoxes))
 
 # Import regular-sphere-pack.mesh into the YADE simulation
-O.bodies.append(ymport.gmsh('regular-sphere-pack.mesh',**kwMeshes))#generates facets from the mesh file
+oriBody = Quaternion(Vector3(0,0,1),(3.14159/2))
+O.bodies.append(ymport.gmsh('regular-sphere-pack.mesh',orientation=oriBody,**kwMeshes))#generates facets from the mesh file
 
 # Import regular-sphere-pack-LSMGenGeo.geo into the YADE simulation
-O.bodies.append(ymport.gengeoFile('regular-sphere-pack-LSMGenGeo.geo',shift=[-7.0,-7.0,-5.9],scale=1.0,color=(1,0,1),**kw))
+oriBody = Quaternion(Vector3(0,0,1),(3.14159/2))
+O.bodies.append(ymport.gengeoFile('regular-sphere-pack-LSMGenGeo.geo',shift=Vector3(-7.0,-7.0,-5.9),scale=1.0,orientation=oriBody,color=(1,0,1),**kw))
 
 # spheresToFile saves coordinates and radii of all spheres of the simulation into the text file
 #print "Saved into the OutFile " + str (export.text("OutFile")) + " spheres";

=== modified file 'py/ymport.py'
--- py/ymport.py	2010-06-12 20:39:00 +0000
+++ py/ymport.py	2010-06-29 21:36:43 +0000
@@ -6,7 +6,7 @@
 from miniEigen import *
 from yade import utils
 
-def textExt(fileName,format='x_y_z_r',shift=[0.0,0.0,0.0],scale=1.0,**kw):
+def textExt(fileName,format='x_y_z_r',shift=Vector3.Zero,scale=1.0,**kw):
 	"""Load sphere coordinates from file in specific format, create spheres, insert them to the simulation.
 	
 	:Parameters:
@@ -34,16 +34,18 @@
 		elif (data[0][0] == "#"): continue
 		
 		if (format=='x_y_z_r'):
-			ret.append(utils.sphere([shift[0]+scale*float(data[0]),shift[1]+scale*float(data[1]),shift[2]+scale*float(data[2])],scale*float(data[3]),**kw))
+			pos = Vector3(float(data[0],float(data[1],float(data[2])
+			ret.append(utils.sphere(shift+scale*pos,scale*float(data[3]),**kw))
 			
 		elif (format=='x_y_z_r_matId'):
-			ret.append(utils.sphere([shift[0]+scale*float(data[0]),shift[1]+scale*float(data[1]),shift[2]+scale*float(data[2])],scale*float(data[3]),material=int(data[4]),**kw))
+			pos = Vector3(float(data[0],float(data[1],float(data[2])
+			ret.append(utils.sphere(shift+scale*pos,scale*float(data[3]),material=int(data[4]),**kw))
 			
 		else:
 			raise RuntimeError("Please, specify a correct format output!");
 	return ret
 
-def text(fileName,shift=[0.0,0.0,0.0],scale=1.0,**kw):
+def text(fileName,shift=Vector3.Zero,scale=1.0,**kw):
 	"""Load sphere coordinates from file, create spheres, insert them to the simulation.
 
 	:Parameters:
@@ -96,7 +98,7 @@
 	surf.translate(shift) 
 	yade.pack.gtsSurface2Facets(surf,**kw)
 
-def gmsh(meshfile="file.mesh",shift=[0.0,0.0,0.0],scale=1.0,orientation=Quaternion().Identity,**kw):
+def gmsh(meshfile="file.mesh",shift=Vector3.Zero,scale=1.0,orientation=Quaternion.Identity,**kw):
 	""" Imports geometry from mesh file and creates facets.
 
 	:Parameters:
@@ -132,10 +134,9 @@
 		nodelistVector3.append(Vector3(0.0,0.0,0.0))
 	id = 0
 	
-	qTemp = Quaternion(Vector3(orientation[0],orientation[1],orientation[2]),orientation[3])
 	for line in lines[findVerticesString+1:numNodes+findVerticesString+1]:
 		data = line.split()
-		nodelistVector3[id] = qTemp.Rotate(Vector3(float(data[0])*scale,float(data[1])*scale,float(data[2])*scale))+Vector3(shift[0],shift[1],shift[2])
+		nodelistVector3[id] = orientation*Vector3(float(data[0])*scale,float(data[1])*scale,float(data[2])*scale)+shift
 		id += 1
 
 	
@@ -168,16 +169,18 @@
 		ret.append(utils.facet((nodelistVector3[i[1]],nodelistVector3[i[2]],nodelistVector3[i[3]]),**kw))
 	return ret
 
-def gengeoFile(fileName="file.geo",shift=[0.0,0.0,0.0],scale=1.0,**kw):
+def gengeoFile(fileName="file.geo",shift=Vector3.Zero,scale=1.0,orientation=Quaternion.Identity,**kw):
 	""" Imports geometry from LSMGenGeo .geo file and creates spheres.
 	
 	:Parameters:
 		`filename`: string
 			file which has 4 colums [x, y, z, radius].
-		`shift`: [float,float,float]
-			[X,Y,Z] parameter moves the specimen.
+		`shift`: Vector3
+			Vector3(X,Y,Z) parameter moves the specimen.
 		`scale`: float
 			factor scales the given data.
+		`orientation`: quaternion
+			orientation of the imported geometry
 		`**kw`: (unused keyword arguments)
 				is passed to :yref:`yade.utils.sphere`
 	:Returns: list of spheres.
@@ -201,10 +204,11 @@
 	ret=[]
 	for line in lines[7:numSpheres+7]:
 		data = line.split()
-		ret.append(utils.sphere([shift[0]+scale*float(data[0]),shift[1]+scale*float(data[1]),shift[2]+scale*float(data[2])],scale*float(data[3]),**kw))
+		pos = orientation*Vector3(float(data[0]),float(data[1]),float(data[2]))
+		ret.append(utils.sphere(shift+scale*pos,scale*float(data[3]),**kw))
 	return ret
 
-def gengeo(mntable,shift=Vector3().Zero,scale=1.0,**kw):
+def gengeo(mntable,shift=Vector3.Zero,scale=1.0,**kw):
 	""" Imports geometry from LSMGenGeo library and creates spheres.
 
 	:Parameters: