← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2758: 1. yade.shop module is renamed to yade.bodiesHandling to get more adequate name

 

------------------------------------------------------------
revno: 2758
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
branch nick: yade
timestamp: Wed 2011-02-23 16:15:29 +0100
message:
  1. yade.shop module is renamed to yade.bodiesHandling to get more adequate name
  2. added bodiesHandling.spheresModify to modify a pack of spheres. Corresponding example is in examples/packs/packs.py
  3. added bodiesHandling.sphereDuplicate to make a copy of sphere
removed:
  doc/sphinx/yade.shop.rst
added:
  doc/sphinx/yade.bodiesHandling.rst
modified:
  doc/sphinx/yadeSphinx.py
  examples/packs/packs.py
  py/SConscript
  py/shop.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
=== added file 'doc/sphinx/yade.bodiesHandling.rst'
--- doc/sphinx/yade.bodiesHandling.rst	1970-01-01 00:00:00 +0000
+++ doc/sphinx/yade.bodiesHandling.rst	2011-02-23 15:15:29 +0000
@@ -0,0 +1,9 @@
+.. _yade.bodiesHandling:
+
+yade.bodiesHandling module
+==========================================
+
+.. automodule:: yade.bodiesHandling
+	:members:
+	:undoc-members:
+

=== removed file 'doc/sphinx/yade.shop.rst'
--- doc/sphinx/yade.shop.rst	2011-02-17 11:32:00 +0000
+++ doc/sphinx/yade.shop.rst	1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
-.. _yade.shop:
-
-yade.shop module
-==========================================
-
-.. automodule:: yade.shop
-	:members:
-	:undoc-members:
-

=== modified file 'doc/sphinx/yadeSphinx.py'
--- doc/sphinx/yadeSphinx.py	2011-02-17 11:32:00 +0000
+++ doc/sphinx/yadeSphinx.py	2011-02-23 15:15:29 +0000
@@ -33,7 +33,7 @@
 #
 # don't forget to put the module in index.rst as well!
 #
-mods={'export':[],'eudoxos':['_eudoxos'],'log':[],'post2d':[],'pack':['_packSpheres','_packPredicates','_packObb','_packSpherePadder'],'plot':[],'timing':[],'utils':['_utils'],'ymport':[],'geom':[],'shop':[],'qt':['_qt','qt._GLViewer'],'linterpolation':[]}
+mods={'export':[],'eudoxos':['_eudoxos'],'log':[],'post2d':[],'pack':['_packSpheres','_packPredicates','_packObb','_packSpherePadder'],'plot':[],'timing':[],'utils':['_utils'],'ymport':[],'geom':[],'bodiesHandling':[],'qt':['_qt','qt._GLViewer'],'linterpolation':[]}
 #
 # generate documentation, in alphabetical order
 mm=mods.keys(); mm.sort()

=== modified file 'examples/packs/packs.py'
--- examples/packs/packs.py	2011-02-17 11:32:00 +0000
+++ examples/packs/packs.py	2011-02-23 15:15:29 +0000
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
-from yade import pack,ymport,export,log,geom,shop
+from yade import pack,ymport,export,log,geom,bodiesHandling
 import math
 
 """ This script demonstrates how to use 2 components of creating packings:
@@ -71,11 +71,20 @@
 SpheresID+=O.bodies.append(ymport.gengeoFile('LSMGenGeo.geo',shift=Vector3(-7.0,-7.0,0.0),scale=1.0,orientation=oriBody,color=(1,0,1),**kw))
 
 #Demonstration of spheresPackDimensions function. The "Edge" particles are colored with blue color
-geometryParameters = shop.spheresPackDimensions(SpheresID)
+geometryParameters = bodiesHandling.spheresPackDimensions(SpheresID)
 for v in [geometryParameters['minId'],geometryParameters['maxId']]:
 	for i in v:
 		O.bodies[int(i)].shape.color = Vector3(0,0,1)
 
+#Example of bodiesHandling.spheresModify()
+hat=O.bodies.append(pack.regularOrtho(pack.inCylinder((0,0,6),(0,0,7),20*rad),radius=0.2,gap=0,color=(1,0,0))) # hat
+oriBody = Quaternion(Vector3(0,1,0),(math.pi/8))
+hat_upper=O.bodies.append(bodiesHandling.spheresModify(hat,shift=(0.0,0.0,1.4),scale=0.7,orientation=oriBody,copy=True))		#Duplicate the "heart", shifting, scaling and rotating it
+
+#change the color of upper part of the hat
+for hatTmp in hat_upper:
+	O.bodies[hatTmp].shape.color=(0.9,0.5,0.59)
+
 
 #facetBunker Demonstration
 #Demonstration of HarmonicMotionEngine

=== modified file 'py/SConscript'
--- py/SConscript	2011-02-17 11:32:00 +0000
+++ py/SConscript	2011-02-23 15:15:29 +0000
@@ -27,7 +27,7 @@
 	env.File('utils.py'),
 	env.File('ymport.py'),
 	env.File('geom.py'),
-	env.File('shop.py'),
+	env.File('bodiesHandling.py'),
 	env.File('export.py'),
 	env.File('eudoxos.py'),
 	env.File('plot.py'),

=== modified file 'py/shop.py'
--- py/shop.py	2011-02-23 10:28:42 +0000
+++ py/shop.py	2011-02-23 15:15:29 +0000
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # encoding: utf-8
 """
-Miscillaneous functions, which are can be useful for simulation.
+Miscellaneous functions, which are useful for handling bodies.
 """
 
 from yade.wrapper import *
@@ -10,20 +10,17 @@
 
 #spheresPackDimensions==================================================
 def spheresPackDimensions(idSpheres):
-	"""The function accepts the list of spheres id's or list of bodies, and calculates max and min dimensions.
+	"""The function accepts the list of spheres id's or list of bodies and calculates max and min dimensions, geometrical center.
 
 	:param list idSpheres: list of spheres
 	
-	:return: dictionary with keys ``min`` (minimal dimension, Vector3), ``max`` (maximal dimension, Vector3), ``minId`` (minimal dimension sphere Id, Vector3), ``miaxnId`` (maximal dimension sphere Id, Vector3), ``center`` (central point of bounding box, Vector3), ``extends`` (sizes of bounding box, Vector3)
+	:return: dictionary with keys ``min`` (minimal dimension, Vector3), ``max`` (maximal dimension, Vector3), ``minId`` (minimal dimension sphere Id, Vector3), ``maxId`` (maximal dimension sphere Id, Vector3), ``center`` (central point of bounding box, Vector3), ``extends`` (sizes of bounding box, Vector3)
 	
 	"""
 	
-	try:
-		if (len(idSpheres)<2):
-			raise RuntimeError("Only a list of particles with length > 1 can be analyzed")
-	except TypeError:
-			raise TypeError("There should be list if ints")
-		
+	if (len(idSpheres)<2):
+		raise RuntimeError("Only a list of particles with length > 1 can be analyzed")
+	
 	min = Vector3.Zero
 	max = Vector3.Zero
 	
@@ -34,14 +31,14 @@
 	
 		
 	for i in idSpheres:
-		
-		try:
+		if (type(i).__name__=='int'):
 			b = O.bodies[i]			#We have received a list of ID's
-		except TypeError: 
+		elif (type(i).__name__=='Body'):
 			b = i								#We have recevied a list of bodies
+		else:
+			raise TypeError("Unknow type of data, should be list of int's or bodies's")
 		
 		spherePosition=b.state.pos
-		
 		try:
 			sphereRadius=b.shape.radius	#skip non-spheres
 		except AttributeError: continue
@@ -65,4 +62,70 @@
 	
 	dimensions = {'max':max,'min':min,'maxId':maxId,'minId':minId,'center':center, 'extends':extends}
 	return dimensions
-	
+
+#spheresPackDimensions==================================================
+def spheresModify(idSpheres,shift=Vector3.Zero,scale=1.0,orientation=Quaternion.Identity,copy=False):
+	"""The function accepts the list of spheres id's or list of bodies and modifies them: rotating, scaling, shifting.
+	if copy=True copies bodies and modifies them.
+	
+	:Parameters:
+	`shift`: Vector3
+		Vector3(X,Y,Z) parameter moves spheres.
+	`scale`: float
+		factor scales given spheres.
+	`orientation`: quaternion
+		orientation of spheres
+	:Returns: list of bodies if copy=True, and Boolean value if copy=False
+	"""
+	dims = spheresPackDimensions(idSpheres)
+	
+	ret=[]
+	for i in idSpheres:
+		if (type(i).__name__=='int'):
+			b = O.bodies[i]			#We have received a list of ID's
+		elif (type(i).__name__=='Body'):
+			b = i								#We have recevied a list of bodies
+		else:
+			raise TypeError("Unknown type of data, should be list of int's or bodies")
+		
+		try:
+			sphereRadius=b.shape.radius	#skip non-spheres
+		except AttributeError: continue
+		
+		if (copy): b=sphereDuplicate(b)
+		
+		b.state.pos=orientation*(b.state.pos-dims['center'])+dims['center']
+		b.shape.radius*=scale
+		b.state.pos=(b.state.pos-dims['center'])*scale + dims['center']
+		
+		b.state.pos+=shift
+		
+		if (copy): ret.append(b)
+		
+	if (copy): 
+		return ret
+	else:
+		return True
+
+#spheresDublicate=======================================================
+def sphereDuplicate(idSphere):
+	"""The functions makes a copy of sphere"""
+	
+	i=idSphere
+	if (type(i).__name__=='int'):
+		b = O.bodies[i]			#We have received a list of ID's
+	elif (type(i).__name__=='Body'):
+		b = i								#We have recevied a list of bodies
+	else:
+		raise TypeError("Unknown type of data, should be list of int's or bodies")
+	
+	try:
+		sphereRadius=b.shape.radius	#skip non-spheres
+	except AttributeError: 
+		return False
+	
+	addedBody = utils.sphere(center=b.state.pos,radius=b.shape.radius,fixed=not(b.dynamic),wire=b.shape.wire,color=b.shape.color,highlight=b.shape.highlight,material=b.material,mask=b.mask)
+	
+	return addedBody
+	
+