Exemplo n.º 1
0
        public void UpdateProperties()
        {
            Position = new Vector3(Corners.Average(p => p.position.x), Corners.Average(p => p.position.y), Corners.Average(p => p.position.z));

            float heightAv = (Vector3.Distance(Corners[0].position, Corners[2].position) +
                              Vector3.Distance(Corners[1].position, Corners[7].position) +
                              Vector3.Distance(Corners[6].position, Corners[4].position) +
                              Vector3.Distance(Corners[3].position, Corners[5].position)) / 4;

            float widthAv = (Vector3.Distance(Corners[0].position, Corners[1].position) +
                             Vector3.Distance(Corners[3].position, Corners[6].position) +
                             Vector3.Distance(Corners[2].position, Corners[7].position) +
                             Vector3.Distance(Corners[4].position, Corners[5].position)) / 4;

            float deepAv = (Vector3.Distance(Corners[0].position, Corners[3].position) +
                            Vector3.Distance(Corners[1].position, Corners[6].position) +
                            Vector3.Distance(Corners[7].position, Corners[4].position) +
                            Vector3.Distance(Corners[2].position, Corners[5].position)) / 4;

            Size = new Vector3(deepAv, heightAv, widthAv);

            float angleAv = Mathf.Atan2(Corners[1].position.x - Corners[0].position.x, Corners[1].position.z - Corners[0].position.z) * Mathf.Rad2Deg +
                            Mathf.Atan2(Corners[6].position.x - Corners[3].position.x, Corners[6].position.z - Corners[3].position.z) * Mathf.Rad2Deg +
                            Mathf.Atan2(Corners[7].position.x - Corners[2].position.x, Corners[7].position.z - Corners[2].position.z) * Mathf.Rad2Deg +
                            Mathf.Atan2(Corners[4].position.x - Corners[5].position.x, Corners[4].position.z - Corners[5].position.z) * Mathf.Rad2Deg;


            Rotation = Quaternion.Euler(0, angleAv / 4, 0);


            // Update ObjectClass
            ObjectClass = Scores.OrderByDescending(x => x.Value).FirstOrDefault().Key;
            Score       = Scores[ObjectClass] / NDetections;

            Defined = (!Corners[0].occluded &&
                       !Corners[1].occluded &&
                       (!Corners[7].occluded || !Corners[2].occluded || !Corners[4].occluded || !Corners[5].occluded) &&
                       (!Corners[4].occluded || !Corners[5].occluded || !Corners[6].occluded || !Corners[3].occluded)) || Defined;

            if (Defined)
            {
                Corners.ForEach(c => c.SetOccluded(false));
            }
        }