Ejemplo n.º 1
0
 def slot_export_graph_(self):
     item = self.graphListWidget.currentItem()
     if item is not None:
         name = str(item.text())
         graph_id = str(item.data(Qt.UserRole))
         graph_data = download_graph_from_remote_db(self.db_url, graph_id)
         if graph_data is not None:
             if type(graph_data) == str:
                 graph_data = json.loads(graph_data)
         filename = QFileDialog.getSaveFileName(self, 'Save To File',
                                                '.')[0]
         filename = str(filename)
         if os.path.isfile(filename):
             save_json_file(graph_data, filename)
 def slot_download(self):
     skeleton_list = self.get_selected_db_skeletons()
     for skeleton_name in skeleton_list:
         skeleton = get_skeleton_from_remote_db(self.db_url, skeleton_name, self.session)
         skeleton_model = get_skeleton_model_from_remote_db(self.db_url, skeleton_name, self.session)
         if not os.path.isdir(self.local_skeleton_dir):
             os.makedirs(self.local_skeleton_dir)
         filename = self.local_skeleton_dir +os.sep + skeleton_name + ".json"
         data =dict()
         data["name"] = skeleton_name
         data["skeleton"] = skeleton
         data["model"] = skeleton_model
         save_json_file(data, filename)
     self.close()
 def logout(self):
     SessionManager.session = None
     save_json_file({}, SESSION_FILE)
 def login(self, user, password):
     result = authenticate(DB_URL, user, password)
     if "token" in result:
         print("authenticated", user, result["token"])
         SessionManager.session = {"user": user, "token": result["token"]}
         save_json_file(SessionManager.session, SESSION_FILE)
Ejemplo n.º 5
0
def save_local_skeleton(local_skeleton_dir, name, data):
    filename = local_skeleton_dir + os.sep + name + ".json"
    data = save_json_file(data, filename)
Ejemplo n.º 6
0
    def slot_export_graph(self):
        skeleton_name = str(self.skeletonListComboBox.currentText())
        item = self.graphListWidget.currentItem()
        if item is None:
            return

        out_dir = QFileDialog.getExistingDirectory(self, "Select Directory")
        print("directory", out_dir)
        if not os.path.isdir(out_dir):
            return

        name = str(item.text())
        graph_id = str(item.data(Qt.UserRole))
        graph_data = download_graph_from_remote_db(self.db_url, graph_id)
        if graph_data is not None:
            if type(graph_data) == str:
                graph_data = json.loads(graph_data)
        save_json_file(graph_data, out_dir + os.sep + "graph.json")

        skeleton_data = get_skeleton_from_remote_db(self.db_url, skeleton_name)
        skeleton = SkeletonBuilder().load_from_custom_unity_format(
            skeleton_data)
        mgrd_skeleton = convert_to_mgrd_skeleton(skeleton)
        skeleton.skeleton_model = get_skeleton_model_from_remote_db(
            self.db_url, skeleton_name)
        save_json_file(skeleton.to_json(), out_dir + os.sep + "skeleton.json")

        graph_def = dict()
        graph_def["formatVersion"] = "5.0"
        graph_def["usePickle"] = False
        graph_def["transitions"] = dict()
        graph_def["actionDefinitions"] = dict()
        if "start_node" in graph_data:
            graph_def["startNode"] = graph_data["start_node"]
        ea_dir = out_dir + os.sep + "elementary_action_models"
        for a in graph_data["nodes"]:
            action_def = dict()
            action_def["nodes"] = []
            action_def["constraint_slots"] = dict()
            action_data = graph_data["nodes"][a]
            action_dir = ea_dir + os.sep + "elementary_action_" + a
            if not os.path.isdir(action_dir):
                os.makedirs(action_dir)
            meta_info = dict()
            meta_info["stats"] = dict()
            start_states = []
            end_states = []
            idle_states = []
            single_states = []
            for model_id in action_data:
                mp_name = action_data[model_id]["name"]
                if mp_name.startswith("walk"):
                    mp_name = mp_name[5:]

                mp_type = action_data[model_id]["type"]
                action_def["nodes"].append(mp_name)
                transitions = list(action_data[model_id]["transitions"].keys())
                #transitions = [key.replace(":","_") for key in transitions]
                transitions = [
                    key if not key[5:].startswith("walk") else key[:5] +
                    key[10:] for key in transitions
                ]
                graph_def["transitions"][a + ":" + mp_name] = transitions

                if mp_type == "start":
                    start_states.append(mp_name)
                elif mp_type == "end":
                    end_states.append(mp_name)
                elif mp_type == "idle":
                    idle_states.append(mp_name)
                elif mp_type == "single":
                    single_states.append(mp_name)
                meta_info["stats"][mp_name] = dict()
                print("export motion primitive", mp_name)
                model_data_str = download_motion_model_from_remote_db(
                    self.db_url, model_id)
                #if not mp_name.startswith("walk"):
                mp_filename = a + "_" + mp_name
                #else:
                #    mp_filename = mp_name
                with open(
                        action_dir + os.sep + mp_filename +
                        "_quaternion_mm.json", "w+") as out_file:
                    out_file.write(model_data_str)
                cluster_tree_data_str = download_cluster_tree_from_remote_db(
                    self.db_url, model_id)
                if cluster_tree_data_str is not None and len(
                        cluster_tree_data_str) > 0:
                    with open(
                            action_dir + os.sep + mp_filename +
                            "_quaternion_cluster_tree.json", "w+") as out_file:
                        out_file.write(cluster_tree_data_str)

                model_data = json.loads(model_data_str)
                model = MotionPrimitiveModelWrapper()
                model._initialize_from_json(mgrd_skeleton, model_data)
                n_standard_transitions = 1
                n_samples = 5
                meta_info["stats"][mp_name][
                    "average_step_length"] = get_avg_step_length(
                        model, n_samples)
                meta_info["stats"][mp_name][
                    "n_standard_transitions"] = n_standard_transitions
                if "keyframes" in model_data:
                    for key in model_data["keyframes"]:
                        action_def["constraint_slots"][key] = {
                            "node": mp_name,
                            "joint": "left_wrist"
                        }

            # set node sequence
            action_def["node_sequence"] = []
            if len(action_data) == 1:
                mp_id = list(action_data.keys())[0]
                mp_name = action_data[mp_id]["name"]
                action_def["node_sequence"] = [[mp_name, "single_primitive"]]

            meta_info["start_states"] = start_states
            meta_info["end_states"] = end_states
            meta_info["idle_states"] = idle_states
            meta_info["single_states"] = single_states

            action_def["start_states"] = start_states
            action_def["end_states"] = end_states
            action_def["idle_states"] = idle_states
            graph_def["actionDefinitions"][a] = action_def

            save_json_file(meta_info,
                           action_dir + os.sep + "meta_information.json")
        print("export graph definition",
              out_dir + os.sep + "graph_definition.json")
        save_json_file(graph_def, out_dir + os.sep + "graph_definition.json")
 def slot_export_command_history(self):
     filename = QFileDialog.getSaveFileName(self, 'Save To File', '.')[0]
     save_json_file(self._animation_editor.command_history, filename)