Exemplo n.º 1
0
    protected override void Process(SIGProcessingContext context)
    {
        if (!Assert(IsConnected(nameof(camera)), "A camera is required"))
        {
            return;
        }
        if (!Assert(IsConnected(nameof(image)), "An image is required"))
        {
            return;
        }

        var cam = camera.GetComponent <Camera>();

        if (!Assert(cam != null, "A camera is required"))
        {
            return;
        }


        var keypoints = scene.GetComponents <ISIGKeypoint>(true);

        imageKeypoints = new List <ImageKeypoint>();

        using (new CameraContext(cam, new CameraContext.CameraProps
        {
            aspect = image.Width / image.Height
        }))
        {
            foreach (var keypoint in keypoints)
            {
                var point = cam.WorldToViewportPoint(keypoint.Position);

                if (culling)
                {
                    if (point.x < 0 || point.x > 1 || point.y < 0 || point.y > 1)
                    {
                        continue;
                    }
                }

                imageKeypoints.Add(new ImageKeypoint <Keypoint>(
                                       Mathf.RoundToInt(point.x * image.Width),
                                       Mathf.RoundToInt(image.Height - point.y * image.Height),
                                       keypoint.Keypoint
                                       ));
            }
        }
    }