Ejemplo n.º 1
0
def doSphereOpt(stlFile, stlScale, minR, numAtoms):
    with open(stlFile,'r') as f:
        triangles = np.array([X for X, N in stlparser.load(f)])
    stlTri = stlScale*triangles
    opt = sphereOptimization(stlTri, minR, numAtoms)
    opt.doOpt()
    return 0
Ejemplo n.º 2
0
def main():
	# Command line parsing
	parser = argparse.ArgumentParser(description = 'Compute and show a blue noise sampling of a triangul mesh')
	parser.add_argument('-n', '--sample-count', type = int, default = 2048, help = 'number of sample to compute')
	args = parser.parse_args()

	# Load the input mesh as a list of triplets (ie. triangles) of 3d vertices
	try:
		triangle_list = numpy.array([X for X, N in stlparser.load(sys.stdin)])
	except stlparser.ParseError as e:
		sys.stderr.write('%s\n' % e)
		sys.exit(0)

	# Compute surface area of each triangle
	tri_area = mesh_area(triangle_list)

	# Compute an uniform sampling of the input mesh
	point_list = uniform_sample_mesh(triangle_list, tri_area, 4 * args.sample_count)

	# Compute a blue noise sampling of the input mesh, seeded by the previous sampling
	point_list = blue_noise_sample_elimination(point_list, numpy.sum(tri_area), args.sample_count)

	# Display
	fig = plot.figure()
	ax = fig.gca(projection = '3d')
	ax._axis3don = False
	ax.set_aspect('equal')
	ax.scatter(point_list[:,0], point_list[:,1], point_list[:,2], lw = 0., c = 'k')
	plot.show()
Ejemplo n.º 3
0
def main():
	# Load the input mesh as a list of triplets (ie. triangles) of 3d vertices
	try:
		triangles = numpy.array([X for X, N in stlparser.load(sys.stdin)])
	except stlparser.ParseError as e:
		sys.stderr.write(f'{e}\n')
		sys.exit(0)

	# Compute uniform distribution within the axis-aligned bound box for the mesh
	min_corner = numpy.amin(numpy.amin(triangles, axis = 0), axis = 0)
	max_corner = numpy.amax(numpy.amax(triangles, axis = 0), axis = 0)
	P = (max_corner - min_corner) * numpy.random.random((8198, 3)) + min_corner

	# Filter out points which are not inside the mesh
	P = P[is_inside(triangles, P)]

	# Display
	fig = plot.figure()
	ax = fig.gca(projection = '3d')
	ax.scatter(P[:,0], P[:,1], P[:,2], lw = 0., c = 'k')
	plot.show()