示例#1
0
    def write(self):
        """
        Writes stable pose data for meshes in the input directory to an stp file.

        path -- path to directory containing meshes to be converted to .stp
        """

        min_prob_str = sys.argv[1]
        min_prob = float(min_prob_str)
        mesh_index = 1

        mesh_files = [filename for filename in os.listdir(sys.argv[2]) if filename[-4:] == ".obj"]
        for filename in mesh_files:
            print "Writing file: " + sys.argv[2] + "/" + filename
            ob = obj_file.ObjFile(sys.argv[2] + "/" + filename)
            mesh = ob.read()
            mesh.remove_unreferenced_vertices()

            prob_mapping, cv_hull = st.compute_stable_poses(mesh), mesh.convex_hull()
            R_list = []
            for face, p in prob_mapping.items():
                if p >= min_prob:
                    vertices = [cv_hull.vertices()[i] for i in face]
                    basis = st.compute_basis(vertices, cv_hull)
                    R_list.append([p, basis])
            self.write_mesh_stable_poses(mesh, filename, min_prob)
示例#2
0
def assign_components(path):
	"""
	Sets values for component attribute of all meshes in an input directory.
	Utilizes breadth first search to determine connected components and assign values accordingly.
	Returns a dictionary mapping component numbers to indexes of all the vertices contained in that component.

	path -- path to directory containing mesh objects as .obj
	"""
	mesh_files = [filename for filename in os.listdir(path) if filename[-4:] == ".obj"]
	mesh_components_list = []
	for filename in mesh_files:
		print "Assigning components: " + path + "/" + filename
		ob = obj_file.ObjFile(path + "/" + filename)
		mesh = ob.read()
		mesh.remove_unreferenced_vertices()

		# generate graph and connect nodes appropriately
		nodes = []
		for triangle in mesh.triangles():
			node_0 = Node(triangle[0])
			node_1 = Node(triangle[1])
			node_2 = Node(triangle[2])
			node_0.connect_nodes(node_1)
			node_1.connect_nodes(node_2)
			node_2.connect_nodes(node_0)
			nodes.append(node_0)
			nodes.append(node_1)
			nodes.append(node_2)

		# breadth-first-search to mark elements of each component
		component_counter = 0
		component_to_index = {}
		while nodes != []:
			q = Queue.Queue()
			q.put(nodes[0])
			while (q.qsize() != 0):
				curr = q.get()
				curr.visited = True;
				if curr in nodes:
					nodes.remove(curr)
				else:
					continue

				for child in curr.children:
					if not child.visited:
						q.put(child)

				if component_counter in component_to_index:
					if curr.index not in component_to_index[component_counter]:
						component_to_index[component_counter].append(curr.index)
				else:
					component_to_index[component_counter] = [curr.index]
			component_counter += 1
		mesh_components_list.append(component_to_index)
	return mesh_components_list
def transform_meshes(path):
    """
    Transforms meshes in the directory given by path based on their highest probability stable poses.

    path -- path leading to directory containing meshes
    num_poses -- variable denoting number of desired poses per object
    """
    f = open()

    # write header
    f.write('###########################################################\n')
    f.write('# POSE TRANSFORM DATA file generated by UC Berkeley Automation Sciences Lab\n')
    f.write('#\n')
    
    min_prob = sys.argv[1]
    for filename in os.listdir(path):
        if filename[-4:] == ".obj":
            ob = obj_file.ObjFile(path + "/" + filename)
            mesh = ob.read()
            mesh.remove_unreferenced_vertices()
            prob_mapping, cv_hull = compute_stable_poses(mesh), mesh.convex_hull()

            R_list = []
            for face, p in prob_mapping.items():
                if p >= min_prob:
                    R_list.append([p, compute_basis([cv_hull.vertices()[i] for i in face])])

            # write necessary data to compute each pose (R and pose probability)
            for i in range(len(R_list)):
                f.write('# Pose ' + str(i + 1) + ':\n')
                f.write('# Probability: ' + str(R_list[i][0]) + '\n')
                for p in range(3):
                    f.write(str(R_list[i][1][p][0]) + ' ' + str(R_list[i][1][p][1]) + ' ' + str(R_list[i][1][p][2]) + '\n')
                f.write('#\n')

    f.write('###########################################################\n')
    f.write('\n')
示例#4
0
def transform_meshes(path):
    """
    Transforms meshes in the directory given by path based on their highest probability stable poses.

    path -- path leading to directory containing meshes
    num_poses -- variable denoting number of desired poses per object
    """
    f = open()

    # write header
    f.write('###########################################################\n')
    f.write('# POSE TRANSFORM DATA file generated by UC Berkeley Automation Sciences Lab\n')
    f.write('#\n')
    
    min_prob = sys.argv[1]
    for filename in os.listdir(path):
        if filename[-4:] == ".obj":
            ob = obj_file.ObjFile(path + "/" + filename)
            mesh = ob.read()
            mesh.remove_unreferenced_vertices()
            prob_mapping, cv_hull = compute_stable_poses(mesh), mesh.convex_hull()

            R_list = []
            for face, p in prob_mapping.items():
                if p >= min_prob:
                    R_list.append([p, compute_basis([cv_hull.vertices()[i] for i in face])])

            # write necessary data to compute each pose (R and pose probability)
            for i in range(len(R_list)):
                f.write('# Pose ' + str(i + 1) + ':\n')
                f.write('# Probability: ' + str(R_list[i][0]) + '\n')
                for p in range(3):
                    f.write(str(R_list[i][1][p][0]) + ' ' + str(R_list[i][1][p][1]) + ' ' + str(R_list[i][1][p][2]) + '\n')
                f.write('#\n')

    f.write('###########################################################\n')
    f.write('\n')