def use_bounding_box(self): bbox = get_boundingbox(self._shape, EPSILON) xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get() dx, dy, dz = xmax - xmin, ymax - ymin, zmax - zmin self._collision_geometry = ode.GeomBox(self._space, lengths=(dx, dy, dz)) self._collision_geometry.setBody(self)
def use_sphere(self): """ Connect a ode.GeomSphere to the body The sphere radius is computed as the mean of the bounding box dimensions. As a consequence, if the TopoDS_Shape is a sphere, then the radius of the ode.GeomSphere will be the radius of the sphere """ xmin, ymin, zmin, xmax, ymax, zmax = get_boundingbox(self._shape, EPSILON) dx, dy, dz = xmax - xmin, ymax - ymin, zmax - zmin r = (dx + dy + dz) / 6.0 # /3 gives the mean diameter, so divide by 2 for the radius self._collision_geometry = ode.GeomSphere(self._space, radius=r) self._collision_geometry.setBody(self)
def use_sphere(self): ''' Connect a ode.GeomSphere to the body The sphere radius is computed as the mean of the bounding box dimensions. As a consequence, if the TopoDS_Shape is a sphere, then the radius of the ode.GeomSphere will be the radius of the sphere ''' bbox = get_boundingbox(self._shape, EPSILON) xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get() dx, dy, dz = xmax - xmin, ymax - ymin, zmax - zmin r = ( dx + dy + dz ) / 6. # /3 gives the mean diameter, so divide by 2 for the radius self._collision_geometry = ode.GeomSphere(self._space, radius=r) self._collision_geometry.setBody(self)
def run( n_procs, compare_by_number_of_processors=False ): shape = get_brep() x_min, y_min, z_min, x_max, y_max, z_max = get_boundingbox(shape) z_delta = abs( z_min - z_max ) # compute bounding box! init_time = time.time() # for total time computation def get_z_coords_for_n_procs(n_slices, n_procs): z_slices = numpy.arange( z_min, z_max, z_delta/n_slices ) slices = [] n = z_slices.shape[0] / n_procs _str_slices = [] for i in range(1, n_procs+1): if i == 1: slices.append(z_slices[ :i*n ].tolist()) _str_slices.append(':'+str(i*n)+' ') elif i == n_procs: # does a little extra work if the number of slices isnt divisible by n_procs slices.append(z_slices[ (i-1)*n: ].tolist()) _str_slices.append(str((i-1)*n)+': ') print 'last slice',len(z_slices[ (i-1)*n: ]) else: slices.append(z_slices[ (i-1)*n:i*n ].tolist()) _str_slices.append(' %s:%s ' % ( (i-1)*n, i*n) ) print 'the z-index array is sliced over %s processors like this: \n %s' % ( n_procs, _str_slices ) print 'number of slices:', z_slices[-1] return slices def arguments(n_slices, n_procs): _tmp = [] slices = get_z_coords_for_n_procs(n_slices, n_procs) for i in slices: _tmp.append([i, shape]) return _tmp n_slice = 200 if not compare_by_number_of_processors: _results = [] P = processing.Pool( n_procs ) _results = P.map(vectorized_slicer, arguments(n_slice, n_procs)) else: arr = [[i, shape] for i in numpy.arange( z_min, z_max, z_delta/n_slice ).tolist()] for i in range(1,9): tA = time.time() _results = [] if i == 1: _results = vectorized_slicer([numpy.arange( z_min, z_max, z_delta/n_slice ).tolist(), shape]) else: P = processing.Pool( n_procs ) _results = P.map(vectorized_slicer, arguments(n_slice, i)) print 'slicing took %s seconds for %s processors ' % ( time.time()-tA, i) sys.exit() print '\n\n\n DONE SLICING ON %i CORES \n\n\n'%nprocs time.sleep(3) # Display result display, start_display, add_menu, add_function_to_menu = init_display() print 'displaying original shape' display.DisplayShape(shape) for n, result_shp in enumerate(_results): print 'displaying results from process {0}'.format(n) display.DisplayShape(result_shp, update=True) # update viewer when all is added: display.Repaint() total_time = time.time() - init_time print "%s necessary to perform slice with %s processor(s)." % ( total_time, n_procs ) start_display()
def use_bounding_box(self): bbox = get_boundingbox(self._shape, EPSILON) xmin,ymin,zmin, xmax,ymax,zmax = bbox.Get() dx,dy,dz = xmax-xmin, ymax-ymin, zmax-zmin self._collision_geometry = ode.GeomBox(self._space, lengths=(dx,dy,dz)) self._collision_geometry.setBody(self)
def run(n_procs, compare_by_number_of_processors=False): shape = get_brep() x_min, y_min, z_min, x_max, y_max, z_max = get_boundingbox(shape) z_delta = abs(z_min - z_max) # compute bounding box! init_time = time.time() # for total time computation def get_z_coords_for_n_procs(n_slices, n_procs): z_slices = numpy.arange(z_min, z_max, z_delta / n_slices) slices = [] n = z_slices.shape[0] / n_procs _str_slices = [] for i in range(1, n_procs + 1): if i == 1: slices.append(z_slices[:i * n].tolist()) _str_slices.append(':' + str(i * n) + ' ') elif i == n_procs: # does a little extra work if the number of slices isnt divisible by n_procs slices.append(z_slices[(i - 1) * n:].tolist()) _str_slices.append(str((i - 1) * n) + ': ') print 'last slice', len(z_slices[(i - 1) * n:]) else: slices.append(z_slices[(i - 1) * n:i * n].tolist()) _str_slices.append(' %s:%s ' % ((i - 1) * n, i * n)) print 'the z-index array is sliced over %s processors like this: \n %s' % ( n_procs, _str_slices) print 'number of slices:', z_slices[-1] return slices def arguments(n_slices, n_procs): _tmp = [] slices = get_z_coords_for_n_procs(n_slices, n_procs) for i in slices: _tmp.append([i, shape]) return _tmp n_slice = 200 if not compare_by_number_of_processors: _results = [] P = processing.Pool(n_procs) _results = P.map(vectorized_slicer, arguments(n_slice, n_procs)) else: arr = [[i, shape] for i in numpy.arange(z_min, z_max, z_delta / n_slice).tolist()] for i in range(1, 9): tA = time.time() _results = [] if i == 1: _results = vectorized_slicer([ numpy.arange(z_min, z_max, z_delta / n_slice).tolist(), shape ]) else: P = processing.Pool(n_procs) _results = P.map(vectorized_slicer, arguments(n_slice, i)) print 'slicing took %s seconds for %s processors ' % (time.time() - tA, i) sys.exit() print '\n\n\n DONE SLICING ON %i CORES \n\n\n' % nprocs time.sleep(3) # Display result display, start_display, add_menu, add_function_to_menu = init_display() print 'displaying original shape' display.DisplayShape(shape) for n, result_shp in enumerate(_results): print 'displaying results from process {0}'.format(n) display.DisplayShape(result_shp, update=True) # update viewer when all is added: display.Repaint() total_time = time.time() - init_time print "%s necessary to perform slice with %s processor(s)." % (total_time, n_procs) start_display()