parameters: (world,container,objects,container_wall_thickness=0.01,randomize_orientation=True,
      visualize=False,verbose=0)
return_statement: return (world,sim)
docstring: For a given container and a list of objects in the world, drops the objects inside the container and simulates until stable.
  
      Args:
          world (WorldModel): the world containing the objects and obstacles
          container: the container RigidObject / Terrain in world into which
              objects should be spawned.  Assumed axis-aligned.
          objects (list of RigidObject): a list of RigidObjects in the world,
              at arbitrary locations.  They are placed in order.
          container_wall_thickness (float, optional): a margin subtracted from
              the container's outer dimensions into which the objects are spawned.
          randomize_orientation (bool or str, optional): if True, the orientation
              of the objects are completely randomized.  If 'z', only the z
              orientation is randomized.  If False or None, the orientation is
              unchanged
          visualize (bool, optional): if True, pops up a visualization window to
              show the progress of the pile
          verbose (int, optional): if > 0, prints progress of the pile.
      
      Side effect: the positions of objects in world are modified
  
      Returns:
          (tuple): (world,sim), containing
  
              - world (WorldModel): the original world
              - sim (Simulator): the Simulator instance at the state used to obtain
                the stable placement of the objects.
  
      Note:
          Since world is modified in-place, if you wish to make multiple worlds with
          piles of the same objects, you should use world.copy() to store the
          configuration of the objects. You may also wish to randomize the object
          ordering using random.shuffle(objects) between instances.
docstring_summary: For a given container and a list of objects in the world, drops the objects inside the container and simulates until stable.
docstring_tokens: For a given container and a list of objects in the world drops the objects inside the container and simulates until stable .
function: def make_object_pile(world,container,objects,container_wall_thickness=0.01,randomize_orientation=True,
      visualize=False,verbose=0):
      """For a given container and a list of objects in the world, drops the objects inside the container and simulates until stable.
  
      Args:
          world (WorldModel): the world containing the objects and obstacles
          container: the container RigidObject / Terrain in world into which
              objects should be spawned.  Assumed axis-aligned.
          objects (list of RigidObject): a list of RigidObjects in the world,
              at arbitrary locations.  They are placed in order.
          container_wall_thickness (float, optional): a margin subtracted from
              the container's outer dimensions into which the objects are spawned.
          randomize_orientation (bool or str, optional): if True, the orientation
              of the objects are completely randomized.  If 'z', only the z
              orientation is randomized.  If False or None, the orientation is
              unchanged
          visualize (bool, optional): if True, pops up a visualization window to
              show the progress of the pile
          verbose (int, optional): if > 0, prints progress of the pile.
      
      Side effect: the positions of objects in world are modified
  
      Returns:
          (tuple): (world,sim), containing
  
              - world (WorldModel): the original world
              - sim (Simulator): the Simulator instance at the state used to obtain
                the stable placement of the objects.
  
      Note:
          Since world is modified in-place, if you wish to make multiple worlds with
          piles of the same objects, you should use world.copy() to store the
          configuration of the objects. You may also wish to randomize the object
          ordering using random.shuffle(objects) between instances.
      """
      container_outer_bb = _get_bound(container)
      container_inner_bb = (vectorops.add(container_outer_bb[0],[container_wall_thickness]*3),vectorops.sub(container_outer_bb[1],[container_wall_thickness]*3))
      spawn_area = (container_inner_bb[0][:],container_inner_bb[1][:])
      collision_margin = 0.0025
      if visualize:
          from klampt import vis
          from klampt.model import config
          import time
          oldwindow = vis.getWindow()
          newwindow = vis.createWindow("make_object_pile dynamic visualization")
          vis.setWindow(newwindow)
          vis.show()
          visworld = world.copy()
          vis.add("world",visworld)
  
      sim = Simulator(world)
      sim.setSetting("maxContacts","20")
      sim.setSetting("adaptiveTimeStepping","0")
      Tfar = (so3.identity(),[0,0,-100000])
      for object in objects:
          R,t = object.getTransform()
          object.setTransform(R,Tfar[1])
          sim.body(object).setTransform(*Tfar)
          sim.body(object).enable(False)
      if verbose: 
          print "Spawn area",spawn_area
      if visualize:
          vis.lock()
          config.setConfig(visworld,config.getConfig(world))
          vis.unlock()
      for index in xrange(len(objects)):
          #always spawn above the current height of the pile 
          if index > 0:
              objects_bound = _get_bound(objects[:index])
              if verbose: 
                  print "Existing objects bound:",objects_bound
              zshift = max(0.0,objects_bound[1][2] - spawn_area[0][2])
              spawn_area[0][2] += zshift
              spawn_area[1][2] += zshift
          object = objects[index]
          obb = _get_bound(object)
          zmin = obb[0][2]
          R0,t0 = object.getTransform()
          feasible = False
          for sample in xrange(1000):
              R,t = R0[:],t0[:]
              if randomize_orientation == True:
                  R = so3.sample()
              t[2] = spawn_area[1][2] - zmin + t0[2] + collision_margin
              object.setTransform(R,t)
              xy_randomize(object,spawn_area[0],spawn_area[1])
              if verbose: 
                  print "Sampled position of",object.getName(),object.getTransform()[1]
              if not randomize_orientation:
                  _,t = object.getTransform()
                  object.setTransform(R,t)
  
              #object spawned, now settle
              sobject = sim.body(object)
              sobject.enable(True)
              sobject.setTransform(*object.getTransform())
              res = sim.checkObjectOverlap()
              if len(res[0]) == 0:
                  feasible = True
                  #get it low as possible without overlapping
                  R,t = object.getTransform()
                  for lower in xrange(100):
                      sobject.setTransform(R,vectorops.add(t,[0,0,-(lower+1)*0.01]))
                      res = sim.checkObjectOverlap()
                      if len(res[0]) != 0:
                          if verbose: 
                              print "Terminated lowering at",lower,"cm lower"
                          sobject.setTransform(R,vectorops.add(t,[0,0,-lower*0.01]))
                          res = sim.checkObjectOverlap()
                          break
                  sim.updateWorld()
                  break
          if not feasible:
              if verbose: 
                  print "Failed to place object",object.getName()
              return None
          if visualize:
              vis.lock()
              config.setConfig(visworld,config.getConfig(world))
              vis.unlock()
              time.sleep(0.1)
      
      if verbose: 
          print "Beginning to simulate"
      #start letting everything  fall
      for firstfall in xrange(10):
          sim.simulate(0.01)
          if visualize:
              vis.lock()
              config.setConfig(visworld,config.getConfig(world))
              vis.unlock()
              time.sleep(0.01)
      maxT = 5.0
      dt = 0.01
      t = 0.0
      wdamping = -0.01
      vdamping = -0.1
      while t < maxT:
          settled = True
          for object in objects:
              sobject = sim.body(object)
              w,v = sobject.getVelocity()
              sobject.applyWrench(vectorops.mul(v,vdamping),vectorops.mul(w,wdamping))
              if vectorops.norm(w) + vectorops.norm(v) > 1e-4:
                  #settled
                  settled=False
                  break
          if settled:
              break
          if visualize:
              t0 = time.time()
          sim.simulate(dt)
          if visualize:
              vis.lock()
              config.setConfig(visworld,config.getConfig(world))
              vis.unlock()
              time.sleep(max(0.0,dt-(time.time()-t0)))
          t += dt
      if visualize:
          vis.show(False)
          vis.setWindow(oldwindow)
      return (world,sim)
function_tokens: def make_object_pile ( world , container , objects , container_wall_thickness = 0.01 , randomize_orientation = True , visualize = False , verbose = 0 ) : container_outer_bb = _get_bound ( container ) container_inner_bb = ( vectorops . add ( container_outer_bb [ 0 ] , [ container_wall_thickness ] * 3 ) , vectorops . sub ( container_outer_bb [ 1 ] , [ container_wall_thickness ] * 3 ) ) spawn_area = ( container_inner_bb [ 0 ] [ : ] , container_inner_bb [ 1 ] [ : ] ) collision_margin = 0.0025 if visualize : from klampt import vis from klampt . model import config import time oldwindow = vis . getWindow ( ) newwindow = vis . createWindow ( "make_object_pile dynamic visualization" ) vis . setWindow ( newwindow ) vis . show ( ) visworld = world . copy ( ) vis . add ( "world" , visworld ) sim = Simulator ( world ) sim . setSetting ( "maxContacts" , "20" ) sim . setSetting ( "adaptiveTimeStepping" , "0" ) Tfar = ( so3 . identity ( ) , [ 0 , 0 , - 100000 ] ) for object in objects : R , t = object . getTransform ( ) object . setTransform ( R , Tfar [ 1 ] ) sim . body ( object ) . setTransform ( * Tfar ) sim . body ( object ) . enable ( False ) if verbose : print "Spawn area" , spawn_area if visualize : vis . lock ( ) config . setConfig ( visworld , config . getConfig ( world ) ) vis . unlock ( ) for index in xrange ( len ( objects ) ) : #always spawn above the current height of the pile  if index > 0 : objects_bound = _get_bound ( objects [ : index ] ) if verbose : print "Existing objects bound:" , objects_bound zshift = max ( 0.0 , objects_bound [ 1 ] [ 2 ] - spawn_area [ 0 ] [ 2 ] ) spawn_area [ 0 ] [ 2 ] += zshift spawn_area [ 1 ] [ 2 ] += zshift object = objects [ index ] obb = _get_bound ( object ) zmin = obb [ 0 ] [ 2 ] R0 , t0 = object . getTransform ( ) feasible = False for sample in xrange ( 1000 ) : R , t = R0 [ : ] , t0 [ : ] if randomize_orientation == True : R = so3 . sample ( ) t [ 2 ] = spawn_area [ 1 ] [ 2 ] - zmin + t0 [ 2 ] + collision_margin object . setTransform ( R , t ) xy_randomize ( object , spawn_area [ 0 ] , spawn_area [ 1 ] ) if verbose : print "Sampled position of" , object . getName ( ) , object . getTransform ( ) [ 1 ] if not randomize_orientation : _ , t = object . getTransform ( ) object . setTransform ( R , t ) #object spawned, now settle sobject = sim . body ( object ) sobject . enable ( True ) sobject . setTransform ( * object . getTransform ( ) ) res = sim . checkObjectOverlap ( ) if len ( res [ 0 ] ) == 0 : feasible = True #get it low as possible without overlapping R , t = object . getTransform ( ) for lower in xrange ( 100 ) : sobject . setTransform ( R , vectorops . add ( t , [ 0 , 0 , - ( lower + 1 ) * 0.01 ] ) ) res = sim . checkObjectOverlap ( ) if len ( res [ 0 ] ) != 0 : if verbose : print "Terminated lowering at" , lower , "cm lower" sobject . setTransform ( R , vectorops . add ( t , [ 0 , 0 , - lower * 0.01 ] ) ) res = sim . checkObjectOverlap ( ) break sim . updateWorld ( ) break if not feasible : if verbose : print "Failed to place object" , object . getName ( ) return None if visualize : vis . lock ( ) config . setConfig ( visworld , config . getConfig ( world ) ) vis . unlock ( ) time . sleep ( 0.1 ) if verbose : print "Beginning to simulate" #start letting everything  fall for firstfall in xrange ( 10 ) : sim . simulate ( 0.01 ) if visualize : vis . lock ( ) config . setConfig ( visworld , config . getConfig ( world ) ) vis . unlock ( ) time . sleep ( 0.01 ) maxT = 5.0 dt = 0.01 t = 0.0 wdamping = - 0.01 vdamping = - 0.1 while t < maxT : settled = True for object in objects : sobject = sim . body ( object ) w , v = sobject . getVelocity ( ) sobject . applyWrench ( vectorops . mul ( v , vdamping ) , vectorops . mul ( w , wdamping ) ) if vectorops . norm ( w ) + vectorops . norm ( v ) > 1e-4 : #settled settled = False break if settled : break if visualize : t0 = time . time ( ) sim . simulate ( dt ) if visualize : vis . lock ( ) config . setConfig ( visworld , config . getConfig ( world ) ) vis . unlock ( ) time . sleep ( max ( 0.0 , dt - ( time . time ( ) - t0 ) ) ) t += dt if visualize : vis . show ( False ) vis . setWindow ( oldwindow ) return ( world , sim )