コード例 #1
0
    def _generate_sdf(self, path_to_sdfgen, dim, padding):
        """ Converts mesh to an sdf object """
        # write the mesh to file
        of = obj_file.ObjFile(self.obj_filename)
        of.write(self.mesh_)

        # if SDF already exists don't recompute it
        if os.path.exists(self.sdf_filename):
            sf = sdf_file.SdfFile(self.sdf_filename)
            self.sdf_ = sf.read()
            return self.sdf_

        # create the SDF using binary tools
        sdfgen_cmd = '%s \"%s\" %d %d' %(path_to_sdfgen, self.obj_filename, dim, padding)
        os.system(sdfgen_cmd)
        logging.info('SDF Command: %s' %(sdfgen_cmd))

        if not os.path.exists(self.sdf_filename):
            raise ValueError('SDF computation failed for %s' %(self.sdf_filename))
        os.system('chmod a+rwx \"%s\"' %(self.sdf_filename) )

        # read the generated sdf
        sf = sdf_file.SdfFile(self.sdf_filename)
        self.sdf_ = sf.read()
        return self.sdf_
コード例 #2
0
    def load(gripper_name, gripper_dir='data/grippers'):
        """ Load the gripper specified by gripper_name.

        Parameters
        ----------
        gripper_name : :obj:`str`
            name of the gripper to load
        gripper_dir : :obj:`str`
            directory where the gripper files are stored

        Returns
        -------
        :obj:`RobotGripper`
            loaded gripper objects
        """
        mesh_filename = os.path.join(gripper_dir, gripper_name,
                                     GRIPPER_MESH_FILENAME)
        mesh = obj_file.ObjFile(mesh_filename).read()

        f = open(
            os.path.join(
                os.path.join(gripper_dir, gripper_name,
                             GRIPPER_PARAMS_FILENAME)), 'r')
        params = json.load(f)

        T_mesh_gripper = RigidTransform.load(
            os.path.join(gripper_dir, gripper_name, T_MESH_GRIPPER_FILENAME))
        T_grasp_gripper = RigidTransform.load(
            os.path.join(gripper_dir, gripper_name, T_GRASP_GRIPPER_FILENAME))
        return RobotGripper(gripper_name, mesh, mesh_filename, params,
                            T_mesh_gripper, T_grasp_gripper)
コード例 #3
0
    def _load_mesh(self, script_to_apply=None):
        """ Loads the mesh from the file by first converting to an obj and then loading """        
        # convert to an obj file using meshlab
        if script_to_apply is None:
            meshlabserver_cmd = 'meshlabserver -i \"%s\" -o \"%s\"' %(self.filename, self.obj_filename)
        else:
            meshlabserver_cmd = 'meshlabserver -i \"%s\" -o \"%s\" -s \"%s\"' %(self.filename, self.obj_filename, script_to_apply) 
        os.system(meshlabserver_cmd)
        logging.info('MeshlabServer Command: %s' %(meshlabserver_cmd))

        if not os.path.exists(self.obj_filename):
            raise ValueError('Meshlab conversion failed for %s' %(self.obj_filename))
        
        # read mesh from obj file
        of = obj_file.ObjFile(self.obj_filename)
        self.mesh_ = of.read()
        return self.mesh_