Beispiel #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)
Beispiel #2
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)
                    R_list.append([p, basis])
            self.write_mesh_stable_poses(mesh, filename, min_prob)
Beispiel #3
0
    def write_mesh_stable_poses(self, mesh, filename, min_prob=0, vis=False):
        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:
                x0 = np.array(cv_hull.vertices()[face[0]])
                R_list.append([p, st.compute_basis([cv_hull.vertices()[i] for i in face], cv_hull), x0])

        if vis:
            print 'P', R_list[0][0]
            mv.figure()
            mesh.visualize()
            mv.axes()

            mv.figure()
            cv_hull_tf = cv_hull.transform(stf.SimilarityTransform3D(tfx.transform(R_list[0][1], np.zeros(3))))
            cv_hull_tf.visualize()
            mv.axes()
            mv.show()

        f = open(filename[:-4] + ".stp", "w")
        f.write("#############################################################\n")
        f.write("# STP file generated by UC Berkeley Automation Sciences Lab #\n")
        f.write("#                                                           #\n")
        f.write("# Num Poses: %d" %len(R_list))
        for _ in range(46 - len(str(len(R_list)))):
            f.write(" ")
        f.write(" #\n")
        f.write("# Min Probability: %s" %str(min_prob))
        for _ in range(40 - len(str(min_prob))):
            f.write(" ")
        f.write(" #\n")
        f.write("#                                                           #\n")
        f.write("#############################################################\n")
        f.write("\n")

        # adding R matrices to .stp file
        pose_index = 1
        for i in range(len(R_list)):
            f.write("p %f\n" %R_list[i][0])
            f.write("r %f %f %f\n" %(R_list[i][1][0][0], R_list[i][1][0][1], R_list[i][1][0][2]))
            f.write("  %f %f %f\n" %(R_list[i][1][1][0], R_list[i][1][1][1], R_list[i][1][1][2]))
            f.write("  %f %f %f\n" %(R_list[i][1][2][0], R_list[i][1][2][1], R_list[i][1][2][2]))
            f.write("x0 %f %f %f\n" %(R_list[i][2][0], R_list[i][2][1], R_list[i][2][2]))
        f.write("\n\n")
Beispiel #4
0
    def write_mesh_stable_poses(self, mesh, filename, min_prob=0, vis=False):
        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:
                R_list.append([p, st.compute_basis([cv_hull.vertices()[i] for i in face])])

        if vis:
            print 'P', R_list[0][0]
            mv.figure()
            mesh.visualize()
            mv.axes()

            mv.figure()
            cv_hull_tf = cv_hull.transform(stf.SimilarityTransform3D(tfx.transform(R_list[0][1], np.zeros(3))))
            cv_hull_tf.visualize()
            mv.axes()
            mv.show()

        f = open(filename[:-4] + ".stp", "w")
        f.write("#############################################################\n")
        f.write("# STP file generated by UC Berkeley Automation Sciences Lab #\n")
        f.write("#                                                           #\n")
        f.write("# Num Poses: %d" %len(R_list))
        for _ in range(46 - len(str(len(R_list)))):
            f.write(" ")
        f.write(" #\n")
        f.write("# Min Probability: %s" %str(min_prob))
        for _ in range(40 - len(str(min_prob))):
            f.write(" ")
        f.write(" #\n")
        f.write("#                                                           #\n")
        f.write("#############################################################\n")
        f.write("\n")

        # adding R matrices to .stp file
        pose_index = 1
        for i in range(len(R_list)):
            f.write("p %f\n" %R_list[i][0])
            f.write("r %f %f %f\n" %(R_list[i][1][0][0], R_list[i][1][0][1], R_list[i][1][0][2]))
            f.write("  %f %f %f\n" %(R_list[i][1][1][0], R_list[i][1][1][1], R_list[i][1][1][2]))
            f.write("  %f %f %f\n" %(R_list[i][1][2][0], R_list[i][1][2][1], R_list[i][1][2][2]))
        f.write("\n\n")