예제 #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
                                       ));
            }
        }
    }
예제 #2
0
    protected override void Process(SIGProcessingContext context)
    {
        base.Process(context);

        if (resolution.x < 1 || resolution.y < 1 || resolution.x % 1f != 0f || resolution.y % 1f != 0f)
        {
            AddMessage("Invalid resolution", NodeMessageType.Error);
            context.Error();
            return;
        }

        if (!camera.IsEmpty)
        {
            var cam = camera.GetComponent <Camera>();
            Assert(cam != null, "Camera input does not contain a camera component");
            Target.SetCamera(cam);
        }

        image = Render();
    }