예제 #1
0
        public bool LoadAllGestureConfig()
        {
            if (!Directory.Exists(GESTURE_DATABASE_DIR))
            {
                return(false);
            }

            GESTURE_LIST.Clear();
            GESTURE_CONFIG.Clear();

            // look for config xml file under database root directory: XXX.xml
            IEnumerable <string> gesture_config_files = Directory.EnumerateFiles(GESTURE_DATABASE_DIR, "*.xml");
            int gid = 0;

            foreach (string g_cfile in gesture_config_files)
            {
                // get gesture name
                int    slash_id     = g_cfile.LastIndexOf('\\');
                string gesture_name = g_cfile.Substring(slash_id + 1, g_cfile.Length - slash_id - 5);

                // add to list
                GESTURE_LIST.Add(gid, gesture_name);

                // read configuration file
                GestureTemplateBase cur_basis = LoadGestureConfig(g_cfile, gid);

                GESTURE_CONFIG.Add(gid, cur_basis);

                gid++;
            }

            return(true);
        }
예제 #2
0
        public GestureTemplateBase LoadGestureConfig(string filename, int gid)
        {
            if (!File.Exists(filename))
            {
                return(null);
            }

            GestureTemplateBase basis = new GestureTemplateBase();

            XmlDocument doc = new XmlDocument();

            doc.Load(filename);

            XmlElement root = doc.DocumentElement;

            basis.name = root.Attributes["name"].Value;
            basis.id   = gid;
            for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                XmlElement joint_elem = root.ChildNodes[i] as XmlElement;
                int        jtype      = int.Parse(joint_elem.Attributes["typeid"].Value);
                JointType  type       = (JointType)jtype;
                float      weight     = float.Parse(joint_elem.Attributes["weight"].Value);
                basis.jointWeights[type] = weight;
            }

            return(basis);
        }
예제 #3
0
        public bool SaveGestureConfig(GestureTemplateBase config)
        {
            // write config file for each gesture model
            // format: <Gesture name = "">
            //              <Joint type="" weight=""></Joint>
            //         </Gesture>
            string filename = GESTURE_DATABASE_DIR + config.name + ".xml";

            XmlDocument    xmldoc = new XmlDocument();
            XmlDeclaration declar = xmldoc.CreateXmlDeclaration("1.0", null, null);

            xmldoc.AppendChild(declar);
            // create root element
            XmlElement root = xmldoc.CreateElement("Gesture");

            root.SetAttribute("name", config.name);
            xmldoc.AppendChild(root);

            #region output_joint_weights

            // add joints
            foreach (JointType joint_type in config.jointWeights.Keys)
            {
                XmlElement joint_elem = xmldoc.CreateElement("Joint");
                root.AppendChild(joint_elem);

                joint_elem.SetAttribute("type", joint_type.ToString());
                int jtype = (int)joint_type;
                joint_elem.SetAttribute("typeid", jtype.ToString());
                joint_elem.SetAttribute("weight", config.jointWeights[joint_type].ToString());
            }

            #endregion

            // save to disk
            xmldoc.Save(filename);

            return(true);
        }
예제 #4
0
        /// <summary>
        /// gesture config management
        /// </summary>
        public bool AddGestureConfig(GestureTemplateBase gbase)
        {
            string gdir = GESTURE_DATABASE_DIR + gbase.name;

            // save config file
            string gfilename = GESTURE_DATABASE_DIR + gbase.name + ".xml";

            SaveGestureConfig(gbase);

            // create new directory
            if (!Directory.Exists(gdir))
            {
                Directory.CreateDirectory(gdir);
            }

            int max_id = (GESTURE_LIST.Keys.Count > 0 ? GESTURE_LIST.Keys.Max() : -1);

            gbase.id = max_id + 1;
            GESTURE_LIST.Add(max_id + 1, gbase.name);
            GESTURE_CONFIG.Add(max_id + 1, gbase);

            return(true);
        }
예제 #5
0
        public bool SaveGestureConfig(GestureTemplateBase config)
        {
            // write config file for each gesture model
            // format: <Gesture name = "">
            //              <Joint type="" weight=""></Joint>
            //         </Gesture>
            string filename = GESTURE_DATABASE_DIR + config.name + ".xml";

            XmlDocument xmldoc = new XmlDocument();
            XmlDeclaration declar = xmldoc.CreateXmlDeclaration("1.0", null, null);
            xmldoc.AppendChild(declar);
            // create root element
            XmlElement root = xmldoc.CreateElement("Gesture");
            root.SetAttribute("name", config.name);
            xmldoc.AppendChild(root);

            #region output_joint_weights

            // add joints
            foreach (JointType joint_type in config.jointWeights.Keys)
            {
                XmlElement joint_elem = xmldoc.CreateElement("Joint");
                root.AppendChild(joint_elem);

                joint_elem.SetAttribute("type", joint_type.ToString());
                int jtype = (int)joint_type;
                joint_elem.SetAttribute("typeid", jtype.ToString());
                joint_elem.SetAttribute("weight", config.jointWeights[joint_type].ToString());
            }

            #endregion

            // save to disk
            xmldoc.Save(filename);

            return true;
        }
예제 #6
0
        public GestureTemplateBase LoadGestureConfig(string filename, int gid)
        {
            if (!File.Exists(filename))
                return null;

            GestureTemplateBase basis = new GestureTemplateBase();

            XmlDocument doc = new XmlDocument();
            doc.Load(filename);

            XmlElement root = doc.DocumentElement;
            basis.name = root.Attributes["name"].Value;
            basis.id = gid;
            for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                XmlElement joint_elem = root.ChildNodes[i] as XmlElement;
                int jtype = int.Parse(joint_elem.Attributes["typeid"].Value);
                JointType type = (JointType)jtype;
                float weight = float.Parse(joint_elem.Attributes["weight"].Value);
                basis.jointWeights[type] = weight;
            }

            return basis;
        }
예제 #7
0
        /// <summary>
        /// gesture config management
        /// </summary>
        public bool AddGestureConfig(GestureTemplateBase gbase)
        {
            string gdir = GESTURE_DATABASE_DIR + gbase.name;

            // save config file
            string gfilename = GESTURE_DATABASE_DIR + gbase.name + ".xml";
            SaveGestureConfig(gbase);

            // create new directory
            if (!Directory.Exists(gdir))
                Directory.CreateDirectory(gdir);

            int max_id = (GESTURE_LIST.Keys.Count > 0 ? GESTURE_LIST.Keys.Max() : -1);
            gbase.id = max_id + 1;
            GESTURE_LIST.Add(max_id+1, gbase.name);
            GESTURE_CONFIG.Add(max_id + 1, gbase);

            return true;
        }