Representation for a collection of rigidbodies that together represent a single semantic idea of an object. The simple version of this is just a single rigidbody and it's children colliders. The more complex version includes several other SemanticObject's that are wholly contained as part of this SemanticObject.
Inheritance: MonoBehaviour
コード例 #1
0
ファイル: XvForm.cs プロジェクト: odys-z/Anclient
        private void btnUpload_Click(object sender, EventArgs e)
        {
            foreach (string fn in ExApp.currentFiles)
            {
                if (string.IsNullOrEmpty(fn) || !File.Exists(fn))
                {
                    MessageBox.Show("File not found: " + fn, "Upload");
                    return;
                }
            }

            //if (onlyGlb.Checked)
            //{
            //    string glb = Core.ConvertGlb(ExApp.currentFiles[0]);
            //    ExApp.currentFiles.Clear();
            //    ExApp.currentFiles.Add(glb);
            //}

            string uid = client.ssInf.uid;

            Core.UploadUi(client, null, uid, ExApp.currentFiles,
                          (resulved) =>
            {
                SemanticObject attId0 = (SemanticObject)resulved.Get("a_attaches");     // some Id losted when resulving
                lbAttachId.Invoke((MethodInvoker) delegate
                {
                    lbAttachId.Text = "last file recId: " + attId0.Get("attId");
                });
            });
        }
コード例 #2
0
ファイル: XvForm.cs プロジェクト: odys-z/Anclient
        private void btnUpload_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtFile.Text))
            {
                onOpen(null, null);
            }
            if (currentFiles == null)
            {
                return;
            }

            foreach (string fn in currentFiles)
            {
                if (string.IsNullOrEmpty(fn) || !File.Exists(fn))
                {
                    MessageBox.Show("File not found: " + fn, "Upload");
                    return;
                }
            }

            string busic = cbbBusic.SelectedItem?.ToString();

            Core.UploadUi(client, busic, uid, currentFiles,
                          (resulved) =>
            {
                SemanticObject attId0 = (SemanticObject)resulved.Get("a_attaches");     // some Id losted when resulving
                lbAttachId.Invoke((MethodInvoker) delegate
                {
                    lbAttachId.Text = "last file recId: " + attId0.Get("attId");
                });
            });
        }
コード例 #3
0
ファイル: OnRelation.cs プロジェクト: dicarlolab/ThreeDWorld
 private List<SemanticObject> PerformTest(SemanticObject obj1, HashSet<SemanticObject> allObservedObjects)
 {
     List<SemanticObject> retList = new List<SemanticObject>();
     foreach(Collision col in obj1.GetActiveCollisions())
     {
         SemanticObjectSimple hitObj = (col.rigidbody == null) ? null : col.rigidbody.GetComponent<SemanticObjectSimple>();
         // Ensures sufficiently low vertical relative velocity to be treated as "at rest"
         if (hitObj != null && Mathf.Abs(col.relativeVelocity.y) < 0.1f && !retList.Contains(hitObj) && !hitObj.IsChildObjectOf(obj1))
         {
             // Check to see if there exists a contact where this object is above the other object
             foreach(ContactPoint pt in col.contacts)
             {
                 if (pt.normal.y > 0.1f)
                 {
                     retList.Add(hitObj);
                     foreach(SemanticObjectComplex parentObj in hitObj.GetParentObjects())
                     {
                         // Add parent objects, unless we are also a child object of that parent
                         if (!retList.Contains(parentObj) && !obj1.IsChildObjectOf(parentObj))
                             retList.Add(parentObj);
                     }
                     break;
                 }
             }
         }
     }
     if (retList.Count > 0)
         return retList;
     return null;
 }
コード例 #4
0
 private List<SemanticObject> PerformTest(SemanticObject obj1, HashSet<SemanticObject> allObservedObjects)
 {
     List<SemanticObject> retList = new List<SemanticObject>();
     foreach(Collision col in obj1.GetActiveCollisions())
     {
         SemanticObjectSimple hitObj = col.rigidbody.GetComponent<SemanticObjectSimple>();
         // Tests that the force in collision goes into target
         RaycastHit targetObj;
         foreach (ContactPoint contact in col.contacts) {
             if (hitObj != null && col.impulse != Vector3.zero && Physics.Raycast(new Ray(contact.point, col.impulse.normalized), out targetObj, 4f) && targetObj.collider == contact.otherCollider && col.impulse.magnitude / Time.fixedDeltaTime > 5f && !retList.Contains(hitObj) && !hitObj.IsChildObjectOf(obj1))
             {
                 retList.Add(hitObj);
                 foreach(SemanticObjectComplex parentObj in hitObj.GetParentObjects())
                     {
                         // Add parent objects, unless we are also a child object of that parent
                         if (!retList.Contains(parentObj) && !obj1.IsChildObjectOf(parentObj))
                             retList.Add(parentObj);
                     }
             }
             break;
         }
     }
     if (retList.Count > 0)
         return retList;
     return null;
 }
コード例 #5
0
 public virtual bool IsChildObjectOf(SemanticObject other)
 {
     if (other is SemanticObjectComplex)
     {
         return (other as SemanticObjectComplex).mySubObjects.Contains(this);
     }
     return false;
 }
コード例 #6
0
ファイル: JProtocol.cs プロジェクト: chenlinming/Anclient
        public static SemanticObject ok(IPort
                                        port, object data)
        {
            SemanticObject obj = new SemanticObject();

            obj.put("code", MsgCode.ok.ToString());
            obj.put("data", data);
            obj.put("port", port.name);
            return(obj);
        }
コード例 #7
0
ファイル: JProtocol.cs プロジェクト: chenlinming/Anclient
        public static SemanticObject err(IPort
                                         port, string code, string err)
        {
            SemanticObject obj = new SemanticObject();

            obj.put("code", code);
            obj.put("error", err);
            obj.put("port", port.name);
            return(obj);
        }
コード例 #8
0
 private List<SemanticObject> PerformTest(SemanticObject obj1, HashSet<SemanticObject> allObservedObjects)
 {
     List<SemanticObject> retList = new List<SemanticObject> ();
     foreach (Collision col in obj1.GetActiveCollisions()) {
         SemanticObjectSimple hitObj = col.rigidbody.GetComponent<SemanticObjectSimple> ();
         if (!retList.Contains(hitObj))
             retList.Add (hitObj);
     }
     if (retList.Count > 0) {
         return retList;
     }
     return null;
 }
コード例 #9
0
 private List<SemanticObject> PerformTest(SemanticObject obj1, HashSet<SemanticObject> allObservedObjects)
 {
     List<SemanticObject> retList = new List<SemanticObject> ();
     foreach (Collision col in obj1.GetActiveCollisions()) {
         SemanticObjectSimple hitObj = col.rigidbody.GetComponent<SemanticObjectSimple> ();
         retList.Add (hitObj);
         foreach (SemanticObjectComplex parentObj in hitObj.GetParentObjects()) {
             // Add parent objects, unless we are also a child object of that parent
             if (!retList.Contains (parentObj) && !obj1.IsChildObjectOf (parentObj))
                 retList.Add (parentObj);
         }
     }
     if (retList.Count > 0) {
         return retList;
     }
     return null;
 }
コード例 #10
0
 public static void UploadUi(AnsonClient client, string busic, string uid, List <string> fullpaths, Action <SemanticObject> onOk = null)
 {
     // upload to a_attaches
     if (client == null)
     {
         MessageBox.Show("Please connect first.", "Upload With UI");
     }
     else
     {
         client.AttachFiles(fullpaths, busic ?? "a_users", uid, (c, d) => {
             SemanticObject resulved = (SemanticObject)((AnsonResp)d).Map("resulved");
             if (onOk != null)
             {
                 onOk(resulved);
             }
         });
     }
 }
コード例 #11
0
ファイル: JProtocolTest.cs プロジェクト: odys-z/antson
        public void TestAnsonResp()
        {
            AnsonMsg respmsg = (AnsonMsg)Anson.FromJson(respjson);

            Assert.AreEqual("ok", respmsg.code.Name());
            Assert.AreEqual(Port.update, respmsg.port.port());

            AnsonResp resp = (AnsonResp)respmsg.Body(0);

            Assert.IsNotNull(resp);
            Assert.IsNotNull(resp.map);
            SemanticObject resulved = (SemanticObject)resp.map["resulved"];

            Assert.IsNotNull(resulved);

            IDictionary    props  = resulved.props;
            SemanticObject attach = (SemanticObject)props["a_attaches"];

            Assert.IsNotNull(attach.props);
            Assert.AreEqual("00000D", attach.props["attId"]);
        }
コード例 #12
0
        /// <summary>
        /// Получение семантического элемента из его описателя в виде XML
        /// </summary>
        /// <param name="source">XML-элемент, содержащий описатель семантического элемента</param>
        /// <returns>Объект или свойство</returns>
        private static SemanticElement GetSemanticElement(XElement source)
        {
            string internalName = source.Name.LocalName;

            if (source.HasElements)
            {
                SemanticObject output = new SemanticObject(internalName)
                {
                    RdfNamespace = source.Name.NamespaceName.TrimEnd('/')
                };
                foreach (XElement element in source.Elements())
                {
                    output.Elements.Add(GetSemanticElement(element));
                }
                return(output);
            }
            else
            {
                SemanticProperty output = new SemanticProperty(internalName, source.Value);
                return(output);
            }
        }
コード例 #13
0
ファイル: OnRelation.cs プロジェクト: dicarlolab/ThreeDWorld
 public override bool Evaluate(SemanticObject subject, SemanticObject obj)
 {
     return foundObjs.ContainsKey(subject) && foundObjs[subject].Contains(obj) && !subject.IsChildObjectOf(obj);
 }
コード例 #14
0
        private IEnumerator Compare()
        {
            detectionsProcessed_vimantic  = new Dictionary <VirtualObject, DetectionMatch>();
            detectionsProcessed_semapping = new Dictionary <VirtualObject, DetectionMatch>();

            int TP_vimantic = 0, FP_vimantic = 0, FN_vimantic = 0;
            int TP_semapping = 0, FP_semapping = 0, FN_semapping = 0;

            float averageIoU_vimantic = 0, averageVIoU_vimantic = 0, averageDistance_vimantic = 0;
            float averageIoU_semapping = 0, averageDistance_semapping = 0;

            ObjectTag      objectTag;
            ClassMatching  classMatching;
            VirtualObject  bestMatch;
            DetectionMatch match;
            float          distance, iou;
            List <Vector3> corners;


            //Calculate TP, FP and FN _vimantic
            foreach (VirtualObjectBox vob in  FindObjectsOfType(typeof(VirtualObjectBox)).Cast <VirtualObjectBox>())
            {
                SemanticObject so = vob.semanticObject;
                if (so.NDetections >= m_minDetections)
                {
                    bestMatch = null;
                    match     = new DetectionMatch();

                    corners = new List <Vector3>();
                    corners.Add(so.Corners[0].position);
                    corners.Add(so.Corners[1].position);
                    corners.Add(so.Corners[2].position);
                    corners.Add(so.Corners[3].position);

                    try
                    {
                        classMatching = m_classMatching.Find(match => match.ClassInOntology.Equals(so.ObjectClass));
                        objectTag     = (classMatching.ClassInOntology == null) ? (ObjectTag)Enum.Parse(typeof(ObjectTag), so.ObjectClass) : classMatching.ClassInVirtualEnvironment;

                        foreach (VirtualObject virtualObject in m_detectableObjects)
                        {
                            if (virtualObject.tags.Contains(objectTag))
                            {
                                distance = Vector3.Distance(BoundUtils.GetBounds(virtualObject.GetComponentsInChildren <Transform>()).center, so.Position);
                                if (distance <= 5)
                                {
                                    iou = DiscreteIoU(virtualObject.gameObject, new List <Vector3>(corners), false);
                                    if (iou > 0 && iou >= match.iou)
                                    {
                                        bestMatch      = virtualObject;
                                        match.iou      = iou;
                                        match.distance = distance;
                                    }
                                }
                            }
                        }

                        if (bestMatch != null)
                        {
                            if (detectionsProcessed_vimantic.ContainsKey(bestMatch))
                            {
                                if (detectionsProcessed_vimantic[bestMatch].iou < match.iou)
                                {
                                    averageDistance_vimantic -= detectionsProcessed_vimantic[bestMatch].distance;
                                    averageDistance_vimantic += match.distance;
                                    averageIoU_vimantic      -= detectionsProcessed_vimantic[bestMatch].iou;
                                    averageIoU_vimantic      += match.iou;
                                    averageVIoU_vimantic     -= detectionsProcessed_vimantic[bestMatch].viou;

                                    match.viou            = DiscreteIoU(bestMatch.gameObject, corners, true);
                                    averageVIoU_vimantic += match.viou;
                                    detectionsProcessed_vimantic[bestMatch] = match;
                                }
                                FP_vimantic++;
                            }
                            else
                            {
                                match.viou = DiscreteIoU(bestMatch.gameObject, corners, true);
                                detectionsProcessed_vimantic.Add(bestMatch, match);
                                TP_vimantic++;
                                averageIoU_vimantic      += match.iou;
                                averageVIoU_vimantic     += match.viou;
                                averageDistance_vimantic += match.distance;
                            }
                        }
                        else
                        {
                            FP_vimantic++;
                        }
                    }
                    catch (ArgumentException)
                    {
                        Log(so.ObjectClass + " failed to convert to ObjectTag", LogLevel.Developer);
                    }
                }

                //yield return null;
            }

            //Calculate TP, FP and FN _semapping
            foreach (semappingTest.detection detection in m_semappingTest.detections)
            {
                if (detection.exist_certainty >= m_minCertainty)
                {
                    bestMatch = null;
                    match     = new DetectionMatch();

                    corners = detection.oriented_box.ToList();
                    try
                    {
                        classMatching = m_classMatching.Find(match => match.ClassInOntology.Equals(detection.name));
                        objectTag     = (classMatching.ClassInOntology == null) ? (ObjectTag)Enum.Parse(typeof(ObjectTag), detection.name) : classMatching.ClassInVirtualEnvironment;

                        foreach (VirtualObject virtualObject in m_detectableObjects)
                        {
                            if (virtualObject.tags.Contains(objectTag))
                            {
                                distance = Vector3.Distance(BoundUtils.GetBounds(virtualObject.GetComponentsInChildren <Transform>()).center, detection.oriented_box_cen);
                                if (distance <= 5)
                                {
                                    iou = DiscreteIoU(virtualObject.gameObject, corners, false);
                                    if (iou > 0 && iou >= match.iou)
                                    {
                                        bestMatch      = virtualObject;
                                        match.iou      = iou;
                                        match.distance = distance;
                                    }
                                }
                            }
                        }

                        if (bestMatch != null)
                        {
                            if (detectionsProcessed_semapping.ContainsKey(bestMatch))
                            {
                                if (detectionsProcessed_semapping[bestMatch].iou < match.iou)
                                {
                                    averageDistance_semapping -= detectionsProcessed_semapping[bestMatch].distance;
                                    averageDistance_semapping += match.distance;
                                    averageIoU_semapping      -= detectionsProcessed_semapping[bestMatch].iou;
                                    averageIoU_semapping      += match.iou;
                                    detectionsProcessed_semapping[bestMatch] = match;
                                }
                                FP_semapping++;
                            }
                            else
                            {
                                detectionsProcessed_semapping.Add(bestMatch, match);
                                TP_semapping++;
                                averageIoU_semapping      += match.iou;
                                averageDistance_semapping += match.distance;
                            }
                        }
                        else
                        {
                            FP_semapping++;
                        }
                    }
                    catch (ArgumentException)
                    {
                        Log(detection.name + " failed to convert to ObjectTag", LogLevel.Developer);
                    }
                }
                yield return(null);
            }

            FN_vimantic  = m_detectableObjects.Count - detectionsProcessed_vimantic.Keys.Count;
            FN_semapping = m_detectableObjects.Count - detectionsProcessed_semapping.Keys.Count;

            float accuracy_vimantic = (float)TP_vimantic / (TP_vimantic + FP_vimantic);
            float recall_vimantic   = (float)TP_vimantic / (TP_vimantic + FN_vimantic);
            float f1_vimantic       = 2 * accuracy_vimantic * recall_vimantic / (accuracy_vimantic + recall_vimantic);

            averageIoU_vimantic      /= TP_vimantic;
            averageVIoU_vimantic     /= TP_vimantic;
            averageDistance_vimantic /= TP_vimantic;

            float accuracy_semapping = (float)TP_semapping / (TP_semapping + FP_semapping);
            float recall_semapping   = (float)TP_semapping / (TP_semapping + FN_semapping);
            float f1_semapping       = 2 * accuracy_semapping * recall_semapping / (accuracy_semapping + recall_semapping);

            averageIoU_semapping      /= TP_semapping;
            averageDistance_semapping /= TP_semapping;

            Log("TP_vimantic: " + TP_vimantic.ToString(), LogLevel.Normal);
            Log("FP_vimantic: " + FP_vimantic.ToString(), LogLevel.Normal);
            Log("FN_vimantic: " + FN_vimantic.ToString(), LogLevel.Normal);
            Log("Accuracy_vimantic: " + accuracy_vimantic.ToString(), LogLevel.Normal);
            Log("Recall_vimantic: " + recall_vimantic.ToString(), LogLevel.Normal);
            Log("F1_vimantic: " + f1_vimantic.ToString("f"), LogLevel.Normal);
            Log("Average IoU vimantic: " + averageIoU_vimantic, LogLevel.Normal);
            Log("Average VIoU vimantic: " + averageVIoU_vimantic, LogLevel.Normal);
            Log("Average Distance vimantic: " + averageDistance_vimantic.ToString(), LogLevel.Normal);


            Log("TP_semapping: " + TP_semapping.ToString(), LogLevel.Normal);
            Log("FP_semapping: " + FP_semapping.ToString(), LogLevel.Normal);
            Log("FN_semapping: " + FN_semapping.ToString(), LogLevel.Normal);
            Log("Accuracy_semapping: " + accuracy_semapping.ToString(), LogLevel.Normal);
            Log("Recall_semapping: " + recall_semapping.ToString(), LogLevel.Normal);
            Log("F1_semapping: " + f1_semapping.ToString("f"), LogLevel.Normal);
            Log("Average IoU semapping: " + averageIoU_semapping, LogLevel.Normal);
            Log("Average Distance semapping: " + averageDistance_semapping.ToString(), LogLevel.Normal);

            if (recordResults)
            {
                writer = new StreamWriter(m_enviromentManager.path + "/Results.csv", true);
                writer.WriteLine("--------------");
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Vimantic;Time;" + Time.realtimeSinceStartup.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Vimantic;TP;" + TP_vimantic.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Vimantic;FP;" + FP_vimantic.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Vimantic;FN;" + FN_vimantic.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Vimantic;Accuracy;" + accuracy_vimantic.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Vimantic;Recall;" + recall_vimantic.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Vimantic;F1;" + f1_vimantic.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Vimantic;IoU;" + averageIoU_vimantic.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Vimantic;VIoU;" + averageVIoU_vimantic.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Vimantic;Distance;" + averageDistance_vimantic.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine("--------------");
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Semapping;Time;" + Time.realtimeSinceStartup.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Semapping;TP;" + TP_semapping.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Semapping;FP;" + FP_semapping.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Semapping;FN;" + FN_semapping.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Semapping;Accuracy;" + accuracy_semapping.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Semapping;Recall;" + recall_semapping.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Semapping;F1;" + f1_semapping.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Semapping;IoU;" + averageIoU_semapping.ToString(CultureInfo.InvariantCulture));
                writer.WriteLine(m_enviromentManager.house.ToString() + ";Semapping;Distance;" + averageDistance_semapping.ToString(CultureInfo.InvariantCulture));

                writer.Close();
            }


            //yield return null;
        }
コード例 #15
0
 public abstract bool Evaluate(SemanticObject subject, SemanticObject obj);