private void ActionCompleteEffect() { Vector3 effectPosition1 = BoundUtils.GetMinMaxFromBoundVector(moveVector, myCollider.bounds, true, +0.2F); effectPosition1 += Vector3.down * Utils.PixelToWorldunits(4); Vector3 effectPosition2 = BoundUtils.GetMinMaxFromBoundVector(moveVector, myCollider.bounds, false, -0.2F); effectPosition2 += Vector3.down * Utils.PixelToWorldunits(4); InstantiateEffect(dustEffect, effectPosition1, BoundUtils.GetEffectRotation(moveVector, false)); InstantiateEffect(dustEffect, effectPosition2, BoundUtils.GetEffectRotation(moveVector, false)); actionCompleteEffectPlayed = true; }
public void Insert(GameObjData data) { if (!BoundUtils.Constains(bound, data.position)) { return; } if (gameObjs == null) { gameObjs = new List <GameObjData>(); } gameObjs.Add(data); }
public void Insert(GameObjData data) { if (!BoundUtils.Constains(bound, data.position)) { return; } if (childs == null) { CreateChild(); } foreach (var child in childs) { child.Insert(data); } }
public override void ReactToPassenger(Vector3 velocity, PassengerMovement passenger) { bool squisch = false; Vector3 hitSourcePosition = transform.position; if ((!passenger.standingOnPlatform && velocity.x < 0 && passengerDictionary[passenger.transform].IsLeft()) || (!passenger.standingOnPlatform && velocity.x > 0 && passengerDictionary[passenger.transform].IsRight())) { // sideways squisch! squisch = true; hitSourcePosition = new Vector3(transform.position.x, passenger.transform.position.y, transform.position.z); } if ((passenger.standingOnPlatform && velocity.y > 0 && passengerDictionary[passenger.transform].IsBelow() && passengerDictionary[passenger.transform].IsAbove()) || (!passenger.standingOnPlatform && passengerDictionary[passenger.transform].IsBelow() && velocity.y < 0)) { // vertical squisch! squisch = true; hitSourcePosition = new Vector3(passenger.transform.position.x, transform.position.y, transform.position.z); } if (squisch) { HurtBox hurtBox = passenger.transform.GetComponent <HurtBox>(); if (!hurtBox) { hurtBox = passenger.transform.GetComponentInChildren <HurtBox>(); } if (hurtBox) { hurtBox.ReceiveHit(true, 100, HitBox.DAMAGE_TYPE.SQUISH, hitSourcePosition); // create squish effect on platform Vector3 positionEffectPlatform = BoundUtils.GetPositionOnBounds(velocity, passenger.transform.position, myCollider.bounds, 26); InstantiateEffect(squishEffect, positionEffectPlatform, BoundUtils.GetEffectRotation(velocity, true), transform); // create squish effect on ground BoxCollider2D collider2D = passenger.transform.GetComponent <BoxCollider2D>(); if (collider2D) { Vector3 positionEffectGround = BoundUtils.GetPositionOnBounds(velocity, positionEffectPlatform, collider2D.bounds); InstantiateEffect(squishEffect, positionEffectGround, BoundUtils.GetEffectRotation(velocity, false)); } } } }
public void CreateChild() { childs = new List <INode>(); if (depth < QuadTree.TREE_DEPTH - 1) { for (int i = 0; i < QuadTree.CHILDS_COUNT; i++) { childs.Add(new QTNode(BoundUtils.GetChildBound(bound, (Quadrant)i), depth + 1)); } } else { for (int i = 0; i < QuadTree.CHILDS_COUNT; i++) { childs.Add(new QTLeaf(BoundUtils.GetChildBound(bound, (Quadrant)i))); } } }
private void ActionCompleteEffect() { if (shakeCam) { CameraFollow.GetInstance().ShakeSmall(); } Vector3 effectPosition1 = BoundUtils.GetMinMaxFromBoundVector(moveVector, myCollider.bounds, true, +0.2F); Vector3 effectPosition2 = BoundUtils.GetMinMaxFromBoundVector(moveVector, myCollider.bounds, false, -0.2F); InstantiateEffect(dustEffect, effectPosition1, BoundUtils.GetEffectRotation(moveVector, false)); InstantiateEffect(dustEffect, effectPosition2, BoundUtils.GetEffectRotation(moveVector, false)); if (moveVector.y > 0 || moveVector.x != 0) { Vector3 dustEffectPosition1 = BoundUtils.GetMinMaxFromBoundVector(moveVector, myCollider.bounds, false, +0.2F); InstantiateEffect(dustDownEffect, dustEffectPosition1); if (moveVector.y > 0) { Vector3 dustEffectPosition2 = BoundUtils.GetMinMaxFromBoundVector(moveVector, myCollider.bounds, true, +0.2F); InstantiateEffect(dustDownEffect, dustEffectPosition2); } } }
public void UpdateObjState(Bounds playerBound) { if (gameObjs == null) { return; } if (!BoundUtils.Intersects(bound, playerBound)) { if (isActive) { foreach (var gameObj in gameObjs) { gameObj.UnActiveObj(); } isActive = false; } } else { if (!isActive) { foreach (var gameObj in gameObjs) { if (gameObj.isUnInstantiate()) { gameObj.Instantiate(); } else { gameObj.ActiveObj(); } } isActive = true; } } }
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; }
public float DiscreteIoU(GameObject groundtruth, List <Vector3> corners, bool volumetric) { var gtRotation = groundtruth.transform.rotation; var gtPosition = groundtruth.transform.position; groundtruth.transform.rotation = Quaternion.Euler(0, 0, 0); groundtruth.transform.position = Vector3.zero; var bound = BoundUtils.GetBounds(groundtruth.GetComponentsInChildren <Transform>()); for (int i = 0; i < corners.Count; i++) { corners[i] -= gtPosition; corners[i] = RotatePointAroundPivot(corners[i], Vector3.zero, Quaternion.Inverse(gtRotation)); } groundtruth.transform.rotation = gtRotation; groundtruth.transform.position = gtPosition; float minZ = Mathf.Infinity; float maxZ = -Mathf.Infinity; for (int i = 1; i < corners.Count; i++) { if (corners[i].z < minZ) { minZ = corners[i].z; } if (corners[i].z > maxZ) { maxZ = corners[i].z; } } float inside = 0; float total = 0; float angle = Mathf.Atan2(corners[3].y - corners[0].y, corners[3].x - corners[0].x); float x, y; for (float d = 0; d <= Vector3.Distance(corners[0], corners[3]); d += m_geometricAccuracy) { for (float d2 = 0; d2 <= Vector3.Distance(corners[0], corners[1]); d2 += m_geometricAccuracy) { x = corners[0].x + d2 * Mathf.Cos(angle - Mathf.PI / 2) + d * Mathf.Cos(angle); y = corners[0].y + d2 * Mathf.Sin(angle - Mathf.PI / 2) + d * Mathf.Sin(angle); if (volumetric) { for (float z = minZ; z <= maxZ; z += m_geometricAccuracy) { if (bound.Contains(new Vector3(x, y, z))) { inside++; } total++; } } else { if (bound.Contains(new Vector3(x, y, 0))) { inside++; } total++; } } } float IoU; if (volumetric) { IoU = inside * Mathf.Pow(m_geometricAccuracy, 3) / ((total - inside) * Mathf.Pow(m_geometricAccuracy, 3) + bound.size.x * bound.size.y * bound.size.z); } else { IoU = inside * Mathf.Pow(m_geometricAccuracy, 2) / ((total - inside) * Mathf.Pow(m_geometricAccuracy, 2) + bound.size.x * bound.size.y); } return(IoU); }
private void OnDrawGizmos() { if (points != null && points.Count > 0) { Gizmos.color = Color.yellow; Vector3 temp = Vector3.zero; foreach (Vector3 t in points) { Gizmos.DrawSphere(t, 0.1f); if (temp != Vector3.zero) { Gizmos.DrawLine(temp, t); } temp = t; } } if (vob1 != null && vob2 != null) { List <SemanticObject.Corner> ref1 = vob1.semanticObject.Corners; List <SemanticObject.Corner> obs = vob2.semanticObject.Corners; for (int i = 0; i < ref1.Count; i++) { Gizmos.DrawLine(ref1[i].position, obs[i].position); } if (Mide) { Debug.Log(VirtualObjectSystem.CalculateMatchingScore(ref1, obs)); Mide = false; } if (Ordena) { vob2.semanticObject.SetNewCorners(YNN(vob1.semanticObject.Corners, vob2.semanticObject.Corners)); Debug.Log(VirtualObjectSystem.CalculateMatchingScore(ref1, obs)); Ordena = false; } } if (groundtruth != null) { var gtRotation = groundtruth.transform.rotation; var gtPosition = groundtruth.transform.position; groundtruth.transform.rotation = Quaternion.Euler(0, 0, 0); groundtruth.transform.position = Vector3.zero; var bound = BoundUtils.GetBounds(groundtruth.GetComponentsInChildren <Transform>()); Gizmos.DrawWireCube(bound.center, bound.size); List <Vector3> corners = new List <Vector3>(); corners.Add(detection.GetComponentInChildren <VirtualObjectBox>().semanticObject.Corners[0].position); corners.Add(detection.GetComponentInChildren <VirtualObjectBox>().semanticObject.Corners[1].position); corners.Add(detection.GetComponentInChildren <VirtualObjectBox>().semanticObject.Corners[2].position); corners.Add(detection.GetComponentInChildren <VirtualObjectBox>().semanticObject.Corners[3].position); if (sustituye) { corners = new List <Vector3>(points); } for (int i = 0; i < corners.Count; i++) { corners[i] -= gtPosition; corners[i] = RotatePointAroundPivot(corners[i], Vector3.zero, Quaternion.Inverse(gtRotation)); Gizmos.color = new Color(i % 2, i % 3, i % 4); Gizmos.DrawSphere(corners[i], 0.1f); } groundtruth.transform.rotation = gtRotation; groundtruth.transform.position = gtPosition; if (Mide) { Mide = false; StartCoroutine(IoU(corners, bound)); } Gizmos.DrawSphere(refPose, 0.01f); //groundtruth.transform.rotation = gtRotation; } }