コード例 #1
0
        /// <inheritdoc />
        public IEnumerable <Character> GetCharacters()
        {
            lock (DocLib.Lock)
            {
                var width  = GetPageWidth();
                var height = GetPageHeight();

                var charCount = fpdf_text.FPDFTextCountChars(_text);

                for (var i = 0; i < charCount; i++)
                {
                    var charCode = (char)fpdf_text.FPDFTextGetUnicode(_text, i);

                    double left   = 0;
                    double top    = 0;
                    double right  = 0;
                    double bottom = 0;

                    var success = fpdf_text.FPDFTextGetCharBox(_text, i, ref left, ref right, ref bottom, ref top) == 1;

                    if (!success)
                    {
                        continue;
                    }

                    var(adjustedLeft, adjustedTop) = GetAdjustedCoords(width, height, left, top);
                    var(adjustRight, adjustBottom) = GetAdjustedCoords(width, height, right, bottom);

                    var box = new BoundBox(adjustedLeft, adjustedTop, adjustRight, adjustBottom);

                    yield return(new Character(charCode, box));
                }
            }
        }
コード例 #2
0
ファイル: MashTrigle.cs プロジェクト: ijrys/MiRaIRender
        /// <summary>
        /// 光线追踪测试
        /// </summary>
        /// <param name="ray"></param>
        /// <returns></returns>
        public override RayCastResult Intersection(Ray ray, float nowbest)
        {
            // 包围盒测试失败
            {
                (bool happened, float mint) = BoundBox.Intersection(ray);
                if (!happened || mint > nowbest)                   // 未相交 或 当前最小解已不是最优
                {
                    return(null);
                }
            }

            RayCastResult result = BVH.Intersection(ray, float.MaxValue);

            if (result != null)
            {
                result.material = Material;
                if (result.internalPoint)
                {
                    result.IOR = 1.0f;
                }
                else
                {
                    result.IOR = Material.Refraction.IOR;
                }
            }
            return(result);
        }
コード例 #3
0
 private void Awake()
 {
     selectionScript           = GetComponent <BoundBox>();
     selectionScript.enabled   = false;
     selectionScript.permanent = true;
     camScript = Camera.main.GetComponent <CameraController>();
     CameraController.UpdateSelection += CheckSelectionStatus;
 }
コード例 #4
0
ファイル: Octree.cs プロジェクト: hksonngan/sharptracing
 public Octree(BoundBox box, T[] acceleationUnits = null)
     : base(acceleationUnits)
 {
     this.box = box;
     if (acceleationUnits != null && acceleationUnits.Length < this.maxUnitsInBox)
     {
         this.maxUnitsInBox = acceleationUnits.Length;
     }
 }
コード例 #5
0
        public override BoundBox GetBoundBox()
        {
            base.Center = body.GetPosition();
            BoundBox bb = base.GetBoundBox();

            //base.drawBoundBox.SetBoundBoxInfor(bb);

            return(bb);
        }
コード例 #6
0
        public void Ctor_WhenCalledWithValidVersion_ShouldCreateInstance(int left, int top, int right, int bottom)
        {
            var sut = new BoundBox(left, top, right, bottom);

            Assert.Equal(left, sut.Left);
            Assert.Equal(top, sut.Top);
            Assert.Equal(right, sut.Right);
            Assert.Equal(bottom, sut.Bottom);
        }
コード例 #7
0
        private void generate_Click(object sender, EventArgs e)
        {
            //get total samples
            int totalSamples = (int)numericUpDown1.Value;

            //First get our background color
            Color c = listView1.SelectedItems[0].BackColor;
            int   indexBackground = getColorIndex(c);

            samplePoints = new List <Sample2D>();

            //now we need to find out our sampling technique
            if (comboBox1.SelectedIndex == 0) //Samples per Color
            {
                for (int i = 0; i < colors.Count; i++)
                {
                    if (i != indexBackground)
                    {
                        int countSamples = 0;

                        BoundBox bb = colorBounds[i];
                        while (countSamples < totalSamples)
                        {
                            //Generate a random Point
                            var point = bb.genPoint();
                            if (isInColor(point.Item1, point.Item2, i))
                            {
                                samplePoints.Add(new Sample2D(point.Item1, point.Item2, i));
                                countSamples++;
                            }
                        }
                    }
                }
            }
            else //Total Samples
            {
                BoundBox entireBound  = new BoundBox(selectedFile.Width - 1, selectedFile.Height - 1);
                int      countSamples = 0;
                while (countSamples < totalSamples)
                {
                    //Generate a random Point
                    var point  = entireBound.genPoint();
                    int cIndex = getColorIndex(point.Item1, point.Item2);
                    if (cIndex != indexBackground)
                    {
                        samplePoints.Add(new Sample2D(point.Item1, point.Item2, cIndex));
                        countSamples++;
                    }
                }
            }

            //Now we have our Samples! Time to do something with it
            samplePreview.Image = makePointImage();

            saveButton.Enabled = true;
        }
コード例 #8
0
ファイル: Sheep.cs プロジェクト: fib25/ResistJam
    public void SetInitialPosition()
    {
        localBounds = CalculateLocalBounds(_lean);

        Vector3 startPos = Vector3.zero;

        startPos.x = UnityEngine.Random.Range(localBounds.Left, localBounds.Right);
        startPos.y = UnityEngine.Random.Range(localBounds.Top, localBounds.Bottom);

        this.transform.position = startPos;
    }
コード例 #9
0
ファイル: TrigleFace.cs プロジェクト: ijrys/MiRaIRender
        public override RayCastResult Intersection(Ray ray, float nowbest)
        {
            if (ray.OriginObject == this)
            {
                return(null);
            }
            {
                (bool happened, Float mint) = BoundBox.Intersection(ray);
                if (!happened || mint > nowbest)                   // 未相交 或 当前最小解已不是最优
                {
                    return(null);
                }
            }
            Float    u, v, t_tmp = 0;
            Vector3f pvec = Vector3f.Cross(ray.Direction, e2);             // S1
            Float    det  = Vector3f.Dot(e1, pvec);

            Float    det_inv = 1.0f / det;
            Vector3f tvec    = ray.Origin - v0;          // S

            u = Vector3f.Dot(tvec, pvec) * det_inv;
            if (u < 0 || u > 1)
            {
                return(null);
            }
            Vector3f qvec = Vector3f.Cross(tvec, e1);             // S2

            v = Vector3f.Dot(ray.Direction, qvec) * det_inv;
            if (v < 0 || u + v > 1)
            {
                return(null);
            }
            t_tmp = Vector3f.Dot(e2, qvec) * det_inv;
            if (t_tmp < 0)
            {
                return(null);
            }

            RayCastResult result = new RayCastResult();

            result.distance      = t_tmp;
            result.obj           = this;
            result.coords        = ray.Origin + t_tmp * ray.Direction;
            result.uv            = new Vector2f(u, v);
            result.normal        = Tools.UVMerge(u, v, n0, n1, n2);
            result.internalPoint = (Vector3f.Dot(result.normal, ray.Direction) > 0);
            if (result.internalPoint)
            {
                result.normal = -result.normal;
            }
            return(result);
        }
コード例 #10
0
ファイル: Sheep.cs プロジェクト: fib25/ResistJam
    protected override void Start()
    {
        base.Start();

        // Target area.
        localBounds = CalculateLocalBounds(_lean);

        SetInitialPosition();
        prevLean = _lean;

        SetState(SheepState.Idle);
        idleTimer = UnityEngine.Random.Range(0f, settings.IdleTime);
        newspaperDisplay.SetActive(false);
    }
コード例 #11
0
 public virtual bool CollidesWith(ICollidable c2)
 {
     if (c2 is PartController)
     {
         c2 = (c2 as PartController).Hull;
     }
     if (c2 is Collidable)
     {
         if (BoundCircle.Intersects((c2 as Collidable).BoundCircle))
         {
             return(BoundBox.Intersects((c2 as Collidable).BoundBox));
         }
     }
     return(false);
 }
コード例 #12
0
ファイル: Sheep.cs プロジェクト: fib25/ResistJam
    protected override void Awake()
    {
        base.Awake();

        settings = GameSettings.Instance;

        RandomiseKeyIdeals();

        BoxCollider2D sheepArea = GameObject.Find("SheepArea").GetComponent <BoxCollider2D>();

        maxBounds   = new BoundBox(sheepArea.bounds.center, sheepArea.bounds.size);
        localBounds = CalculateLocalBounds(_lean);

        halfScreenHeight = Camera.main.orthographicSize;
    }
コード例 #13
0
        private Annotation ConvertAnnotationsToPascal(Image image)
        {
            List <Models.Pascal.Object> imageObjects = new List <Models.Pascal.Object>();
            var _xmlFileName = $"{image.Id}.xml";

            if (image.Regions != null)
            {
                foreach (ImageRegion region in image.Regions)
                {
                    BoundBox newBounds = new BoundBox
                    {
                        Xmin = region.Left * region.Width,
                        Ymin = region.Top * region.Height,
                        Xmax = region.Width * region.Width,
                        Ymax = region.Height * region.Height
                    };
                    imageObjects.Add(new Models.Pascal.Object
                    {
                        Name   = region.TagName,
                        Bndbox = newBounds
                    });
                }
            }

            // Create the Pascal Annotation
            var pascalAnnotationFile = new Annotation
            {
                Folder   = "",
                FileName = _xmlFileName,
                Source   = new Source {
                    Database = ""
                },
                Size = new Models.Pascal.Size
                {
                    Depth  = 3,
                    Width  = image.Width,
                    Height = image.Height,
                },
                Objects = imageObjects
            };

            return(pascalAnnotationFile);
        }
コード例 #14
0
        public Entity getClosestEntityToPointInBound(Vector2 point, BoundBox bound, Type type, bool select)
        {
            var entities = this.getEntitiesInBound(bound, type, select);

            var    minDistance = double.MaxValue;
            Entity picked      = null;

            foreach (var entity in entities)
            {
                var currDistance = Vector2.DistanceSquared(entity.Pos, point);
                if (currDistance <= minDistance)
                {
                    minDistance = currDistance;
                    picked      = entity;
                }
            }

            return(picked);
        }
コード例 #15
0
        private async Task <BoundBox> ParseBoundBoxAsync()
        {
            await reader.BeginReadMessageAsync();

            var result = new BoundBox();

            while (reader.State == ProtobufReaderState.Field)
            {
                switch (reader.FieldNumber)
                {
                case 1:
                    result.Left = await reader.ReadSInt64Async();

                    break;

                case 2:
                    result.Right = await reader.ReadSInt64Async();

                    break;

                case 3:
                    result.Top = await reader.ReadSInt64Async();

                    break;

                case 4:
                    result.Bottom = await reader.ReadSInt64Async();

                    break;

                default:
                    await reader.SkipAsync();

                    break;
                }
            }
            await reader.EndReadMessageAsync();

            return(result);
        }
コード例 #16
0
ファイル: VertScrollBar.cs プロジェクト: YogurtFP/YogUI
        public VertScrollBar(Vector2 topLeft, float height)
        {
            this.topLeft     = topLeft;
            this.bottomRight = new Vector2(topLeft.X + width, topLeft.Y + height);
            base.UIC_Initialize();
            InputManager.BindMouse(() =>
            {
                if (active)
                {
                    Point m = InputManager.GetMousePos();
                    if ((BoundBox.Contains(m) || selected) && !selectedOutside)
                    {
                        float dist    = ((m.Y - (BoundBoxPart.Bottom - BoundBoxPart.Top) / 2) - BoundBox.Top);
                        dist          = height - dist;
                        float percent = dist / height;
                        curValue      = maxValue * percent;
                        if (curValue < minValue)
                        {
                            curValue = minValue;
                        }
                        if (curValue > maxValue)
                        {
                            curValue = maxValue;
                        }
                        selected = true;
                    }
                    else
                    {
                        selectedOutside = true;
                    }
                }
            }, MouseButton.Left, true, true);

            InputManager.BindMouse(() =>
            {
                selectedOutside = false;
                selected        = false;
            }, MouseButton.Left, false, false);
        }
コード例 #17
0
ファイル: Sheep.cs プロジェクト: fib25/ResistJam
    protected BoundBox CalculateLocalBounds(float lean)
    {
        float yPos = Mathf.Lerp(maxBounds.Top, maxBounds.Bottom, Mathf.InverseLerp(-3f, 3f, lean));

        BoundBox newBounds = new BoundBox();

        newBounds.Center = new Vector3(maxBounds.Center.x, yPos, 0f);
        newBounds.Size   = new Vector3(maxBounds.Size.x, maxBounds.Size.y * 0.08f, 0f);

        // Keep the sheep walk area within the maxBounds by shift up or down slightly.
        if (newBounds.Center.y + newBounds.Extents.y > maxBounds.Top)
        {
            newBounds.Center = new Vector3(newBounds.Center.x, newBounds.Center.y - (newBounds.Extents.y * 0.5f), 0f);
            newBounds.Size   = new Vector3(newBounds.Size.x, newBounds.Size.y * 0.5f, 0f);
        }
        else if (newBounds.Center.y - newBounds.Extents.y < maxBounds.Bottom)
        {
            newBounds.Center = new Vector3(newBounds.Center.x, newBounds.Center.y + (newBounds.Extents.y * 0.5f), 0f);
            newBounds.Size   = new Vector3(newBounds.Size.x, newBounds.Size.y * 0.5f, 0f);
        }

        return(newBounds);
    }
コード例 #18
0
        public List <Entity> getEntitiesInBound(BoundBox rect, Type type, bool select)
        {
            var entities = new List <Entity>();

            var containedChunks = this.getChunksInChunkArea(toChunkCoord(MathHelp.ceil(rect.X)) - 1, toChunkCoord(MathHelp.ceil(rect.Y)) - 1, toChunkCoord(MathHelp.ceil(rect.X + rect.Width)) + 1, toChunkCoord(MathHelp.ceil(rect.Y + rect.Height)) + 1);

            foreach (var chunk in containedChunks)
            {
                for (var i = 0; i < chunk.Entities.Count; i++)
                {
                    var entity = chunk.Entities[i];
                    if (entity != null)
                    {
                        if ((type == null || entity.GetType() == type) && (select ? entity.MouseSelectBox : entity.BoundingBox).offset(entity.Pos).intersects(rect))
                        {
                            entities.Add(entity);
                        }
                    }
                }
            }

            return(entities);
        }
コード例 #19
0
ファイル: ListBox.cs プロジェクト: YogurtFP/YogUI
        public void computeSelected()
        {
            Point mousePos = InputManager.GetMousePos();

            if (BoundBox.Contains(mousePos))
            {
                if (mousePos.X - Position.X <= width)
                {
                    float off   = mousePos.Y - Position.Y;
                    float which = off / 15;
                    which = (float)Math.Floor(which);
                    int oldSel = selectedIndex;
                    selectedIndex = (int)(which + vertOffset);
                    if (selectedIndex >= dataSource.Count)
                    {
                        selectedIndex = -1;
                    }
                }
            }
            else
            {
                selectedIndex = -1;
            }
        }
コード例 #20
0
        public override BoundBox GetBoundBox()
        {
            if (NoContactTime > 0)
            {
                return(null);
            }

            BoundBox bb = null;

            base.Center = body.GetPosition();
            //爆炸后检测范围扩大
            if (isBomb == true)
            {
                bb = new BoundBox(Center.X, Center.Y, Width * 6f, Heigth * 6f);
            }
            else
            {
                bb = base.GetBoundBox();
            }
            bb.IsUseCircle = true;
            //base.drawBoundBox.SetBoundBoxInfor(bb);

            return(bb);
        }
コード例 #21
0
        public bool IsOverlap(BoundBox bb)
        {
            v0 = (this.Vertex1.Position - bb.Center);
            v1 = (this.Vertex2.Position - bb.Center);
            v2 = (this.Vertex3.Position - bb.Center);
            e0 = (this.Vertex2.Position - this.Vertex1.Position);
            e1 = (this.Vertex3.Position - this.Vertex2.Position);
            e2 = (this.Vertex1.Position - this.Vertex3.Position);
            //e0 = this.Edge1;
            //e1 = this.Edge3;
            //e2 = this.Edge2;
            float fex = Math.Abs(e0.X);
            float fey = Math.Abs(e0.Y);
            float fez = Math.Abs(e0.Z);

            if (!AXISTEST_X01(e0.Z, e0.Y, fez, fey, bb.HalfVector))
            {
                return(false);
            }
            if (!AXISTEST_Y02(e0.Z, e0.X, fez, fex, bb.HalfVector))
            {
                return(false);
            }
            if (!AXISTEST_Z12(e0.Y, e0.X, fey, fex, bb.HalfVector))
            {
                return(false);
            }
            fex = Math.Abs(e1.X);
            fey = Math.Abs(e1.Y);
            fez = Math.Abs(e1.Z);
            if (!AXISTEST_X01(e1.Z, e1.Y, fez, fey, bb.HalfVector))
            {
                return(false);
            }
            if (!AXISTEST_Y02(e1.Z, e1.X, fez, fex, bb.HalfVector))
            {
                return(false);
            }
            if (!AXISTEST_Z0(e1.Y, e1.X, fey, fex, bb.HalfVector))
            {
                return(false);
            }
            fex = Math.Abs(e2.X);
            fey = Math.Abs(e2.Y);
            fez = Math.Abs(e2.Z);
            if (!AXISTEST_X2(e2.Z, e2.Y, fez, fey, bb.HalfVector))
            {
                return(false);
            }
            if (!AXISTEST_Y1(e2.Z, e2.X, fez, fex, bb.HalfVector))
            {
                return(false);
            }
            if (!AXISTEST_Z12(e2.Y, e2.X, fey, fex, bb.HalfVector))
            {
                return(false);
            }
            /* test in X-direction */
            FindMinMax(v0.X, v1.X, v2.X);
            if (min > bb.HalfVector.X || max < -bb.HalfVector.X)
            {
                return(false);
            }
            /* test in Y-direction */
            FindMinMax(v0.Y, v1.Y, v2.Y);
            if (min > bb.HalfVector.Y || max < -bb.HalfVector.Y)
            {
                return(false);
            }
            /* test in Z-direction */
            FindMinMax(v0.Z, v1.Z, v2.Z);
            if (min > bb.HalfVector.Z || max < -bb.HalfVector.Z)
            {
                return(false);
            }
            /* test if the box intersects the plane of the triangle */
            //normal = (e0 ^ e1);
            float d = -this.Normal * v0;

            return(PlaneBoxOverlap(this.Normal, bb.HalfVector, d));
        }
コード例 #22
0
ファイル: Sheep.cs プロジェクト: fib25/ResistJam
    public void SetState(SheepState newState)
    {
        //Debug.Log("Set new state: " + newState.ToString());

        _prevState = _state;
        _state     = newState;

        if (goToNewspaperNext && _prevState == SheepState.MoveToLean)
        {
            SetState(SheepState.Newspaper);
            goToNewspaperNext = false;
            return;
        }

        if (_prevState == SheepState.Newspaper)
        {
            newspaperDisplay.SetActive(false);
        }

        if (newState == SheepState.Idle)
        {
            if (_prevState == SheepState.MoveToLean || _prevState == SheepState.Newspaper)
            {
                idleTimer = UnityEngine.Random.Range(0f, settings.IdleTime);
            }
            else
            {
                idleTimer = settings.IdleTime;
            }

            SetSheepSprite(SheepSprite.Happy);
        }
        else if (newState == SheepState.Wandering)
        {
            float x = UnityEngine.Random.Range(this.transform.position.x - settings.WanderRange, this.transform.position.x + settings.WanderRange);
            float y = UnityEngine.Random.Range(localBounds.Top, localBounds.Bottom);

            if (x > localBounds.Right)
            {
                x = UnityEngine.Random.Range(this.transform.position.x - settings.WanderRange, this.transform.position.x - (settings.WanderRange * 2f));
            }
            else if (x < localBounds.Left)
            {
                x = UnityEngine.Random.Range(this.transform.position.x + settings.WanderRange, this.transform.position.x + (settings.WanderRange * 2f));
            }

            targetPos = new Vector3(x, y, 0f);
        }
        else if (newState == SheepState.MoveToLean)
        {
            // Target area.
            localBounds = CalculateLocalBounds(_lean);

            targetPos = CalculateTargetPosition();

            if (_prevState == SheepState.Newspaper)
            {
                SetSheepSprite(SheepSprite.Rage);
            }
            else if (_lean > prevLean)
            {
                SetSheepSprite(SheepSprite.Ecstatic);
            }
            else if (_lean < prevLean)
            {
                SetSheepSprite(SheepSprite.Sad);
            }
        }
        else if (newState == SheepState.Newspaper)
        {
            // Change sprite to newspaper reading!
            if (!goToNewspaperNext && _prevState == SheepState.MoveToLean)
            {
                goToNewspaperNext = true;
                _state            = SheepState.MoveToLean;
                return;
            }

            newspaperDisplay.SetActive(true);
        }
    }
コード例 #23
0
 public Character(char character, BoundBox box)
 {
     Char = character;
     Box  = box;
 }
コード例 #24
0
 public override bool IsOverlap(BoundBox boundBox)
 {
     throw new NotImplementedException();
 }
コード例 #25
0
ファイル: Entity.cs プロジェクト: Ellpeck/Evolvinary
 public Entity()
 {
     this.BoundingBox    = this.getBoundBox();
     this.MouseSelectBox = this.getMouseSelectBox();
 }
コード例 #26
0
        private void ParserASCII(PlyObjectHeader header, Stream sr, ref MeshModel mesh)
        {
            MeshVertex[]     vertices = new MeshVertex[header.Elements["vertex"].Count];
            int[]            indices  = new int[header.Elements["face"].Count * 3];
            NumberFormatInfo nfi      = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";
            nfi.NumberGroupSeparator   = ",";
            //Initialize bound box calculation
            String[] str;
            //for number of vertices readed in header do...
            BoundBox boundBox = new BoundBox();

            for (int i = 0; i < vertices.Length; i++)
            {
                str = sr.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);


                vertices[i].Position = new Point3D(float.Parse(str[0], nfi), float.Parse(str[1], nfi),
                                                   float.Parse(str[2], nfi));
                //Adjusting BoundBox...
                boundBox.Include(vertices[i].Position);
                //Reporting progress
                int percent = (int)(((float)i / vertices.Length) * 100.0f);
                if ((percent % 20) == 0)
                {
                    this.OnElementLoaded(percent, ElementMesh.Vertex);
                }
            }

            //MeshModel mesh = new MeshModel(header.Elements["face"].Count);
            mesh.Triangles = new MeshTriangle[header.Elements["face"].Count];
            mesh.BoundBox  = boundBox;

            for (int i = 0, ptr = 0; i < mesh.Triangles.Length; i++)
            {
                str = sr.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                indices[ptr++]            = Int32.Parse(str[1], nfi);
                mesh.Triangles[i].Vertex1 = vertices[indices[ptr - 1]];
                indices[ptr++]            = Int32.Parse(str[2], nfi);
                mesh.Triangles[i].Vertex2 = vertices[indices[ptr - 1]];
                indices[ptr++]            = Int32.Parse(str[3], nfi);
                mesh.Triangles[i].Vertex3 = vertices[indices[ptr - 1]];

                int percent = (int)(((float)i / indices.Length) * 100.0f);
                if ((percent % 20) == 0)
                {
                    this.OnElementLoaded(percent, ElementMesh.VextexIndice);
                }
            }
            int verticesCount = vertices.Length;

            vertices = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            ProcessNormalsPerVertex(indices, ref mesh, verticesCount);
            indices = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
コード例 #27
0
 public override bool IsOverlap(BoundBox boundBox)
 {
     throw new NotImplementedException();
 }
コード例 #28
0
        private async void ImportAll()
        {
            Status = new AppStatusInfo()
            {
                Status = Enums.Status.Working
            };
            try
            {
                var openDig = new OpenFolderDialog()
                {
                    Title = "Choose a directory with xml annotations"
                };
                var dirName = await openDig.ShowAsync(new Window());

                if (string.IsNullOrEmpty(dirName) || !Directory.Exists(dirName))
                {
                    Status = new AppStatusInfo()
                    {
                        Status = Enums.Status.Ready
                    };
                    return;
                }

                var fileNames = Directory.GetFiles(dirName);
                _frameLoadProgressIndex = 0;
                Frames.Clear(); _frames.Clear(); GC.Collect();

                var loadingFrames = new List <Frame>();
                var annotations   = new List <Annotation>();
                foreach (var fileName in fileNames)
                {
                    if (Path.GetExtension(fileName).ToLower() != ".xml")
                    {
                        continue;
                    }
                    annotations.Add(Annotation.ParseFromXml(fileName));
                }

                foreach (var ann in annotations)
                {
                    var fileName = Path.Combine(dirName, ann.Filename);
                    // TODO: Проверка IsImage вне зависимости от расширений.
                    if (!File.Exists(fileName))
                    {
                        continue;
                    }
                    if (!Path.HasExtension(fileName))
                    {
                        continue;
                    }
                    if (Path.GetExtension(fileName).ToLower() != ".jpg" &&
                        Path.GetExtension(fileName).ToLower() != ".jpeg" &&
                        Path.GetExtension(fileName).ToLower() != ".png" &&
                        Path.GetExtension(fileName).ToLower() != ".bmp")
                    {
                        continue;
                    }

                    var frame = new Frame();
                    frame.OnLoad += FrameLoadingProgressUpdate;
                    frame.Load(fileName, Enums.ImageLoadMode.Miniature);
                    frame.Rectangles = new List <BoundBox>();
                    foreach (var obj in ann.Objects)
                    {
                        var bbox = new BoundBox(
                            x: obj.Box.Xmin,
                            y: obj.Box.Ymin,
                            height: obj.Box.Ymax - obj.Box.Ymin,
                            width: obj.Box.Xmax - obj.Box.Xmin
                            );
                        frame.Rectangles.Add(bbox);
                    }

                    if (frame.Rectangles.Count > 0)
                    {
                        frame.IsVisible = true;
                    }
                    loadingFrames.Add(frame);
                }

                if (loadingFrames.Count == 0)
                {
                    Status = new AppStatusInfo()
                    {
                        Status = Enums.Status.Ready
                    };
                    return;
                }


                Frames = loadingFrames;
                if (SelectedIndex < 0)
                {
                    SelectedIndex = 0;
                }
                UpdateFramesRepo();
                UpdateUi();
                _frames = new List <Frame>(Frames);
                Status  = new AppStatusInfo()
                {
                    Status = Enums.Status.Ready
                };
            }
            catch (Exception ex)
            {
                Status = new AppStatusInfo()
                {
                    Status       = Enums.Status.Error,
                    StringStatus = $"Error | {ex.Message.Replace('\n', ' ')}"
                };
            }
        }
コード例 #29
0
                // updating memory happens in LateUpdate after all visual perception happened in Update (See SyntheticVision)
                void Update()
                {
                    ShowMemory = _interactionPrefs.showVisualMemory;
                    if (!ShowMemory)
                    {
                        MemoryCanvas.SetActive(false);
                    }
                    else
                    {
                        MemoryCanvas.SetActive(true);
                    }

                    foreach (GameObject obj in _world.availableObjs)
                    {
                        Voxeme voxeme = obj.GetComponent <Voxeme>();
                        //				Debug.Log(voxeme + " is visible?");
                        List <GameObject> clones = null;
                        if (_vision.IsVisible(voxeme))
                        {
                            //					Debug.Log(voxeme + " is");
                            if (!_memorized.ContainsKey(voxeme))
                            {
                                clones = GetVisualClone(obj.gameObject);
                                _memorized.Add(voxeme, clones);

                                if (!_perceivingInitialConfiguration)
                                {
                                    // don't do this when you initially populate knownObjects
                                    // but otherwise
                                    // surprise!
                                    // todo _surpriseArgs can be plural
                                    _surpriseArgs = new VisionEventArgs(voxeme, InconsistencyType.Present);
                                    foreach (var clone in clones)
                                    {
                                        StartCoroutine(clone.GetComponent <BoundBox>().Flash(10));
                                    }

                                    Debug.Log(string.Format("{0} Surprise!", voxeme));
                                    _reactionTimer.Enabled = true;
                                }
                            }
                            else
                            {
                                clones = _memorized[voxeme];
                            }
                        }
                        // block is not visible
                        else
                        {
                            //					Debug.Log(voxeme + " is not ");
                            // but I know about it
                            if (_memorized.ContainsKey(voxeme))
                            {
                                clones = _memorized[voxeme];
                                // but I see it's not where it supposed to be!
                                if (clones.All(clone => _vision.IsVisible(clone)))
                                {
                                    // surprise!
                                    _surpriseArgs = new VisionEventArgs(voxeme, InconsistencyType.Missing);
                                    foreach (var clone in clones)
                                    {
                                        StartCoroutine(clone.GetComponent <BoundBox>().Flash(10));
                                        Destroy(clone, 3);
                                    }

                                    _memorized.Remove(voxeme);
                                    Debug.Log(string.Format("{0} Surprise!", voxeme));
                                    _reactionTimer.Enabled = true;
                                }
                            }
                        }

                        if (clones == null || clones.Count == 0)
                        {
                            continue;
                        }

                        foreach (var clone in clones)
                        {
                            if (_objectSelector.disabledObjects.Contains(voxeme.gameObject))
                            {
                                clone.transform.parent = null;
                                clone.SetActive(true);
                            }
                            else if (clone.transform.parent != null)
                            {
                                clone.transform.SetParent(voxeme.gameObject.transform);
                            }

                            BoundBox highlighter = clone.GetComponent <BoundBox>();
                            if (_vision.IsVisible(voxeme))
                            {
                                highlighter.lineColor = new Color(0.0f, 1.0f, 0.0f, 0.2f);
                            }
                            else
                            {
                                highlighter.lineColor = new Color(1.0f, 0.0f, 0.0f, 0.8f);
                            }
                        }
                    }

                    if (_memorized.Count > 0 && _perceivingInitialConfiguration)
                    {
                        // effectively this goes false after the first frame
                        _perceivingInitialConfiguration = false;
                    }

                    if (_surprise)
                    {
                        NewInformation(_surpriseArgs);
                        _surprise = false;
                    }
                }