示例#1
0
    protected override void Process(SIGProcessingContext context)
    {
        if (!Assert(mask != null, "A bit mask is required"))
        {
            return;
        }
        if (keypoints == null)
        {
            keypoints = new List <ImageKeypoint>();
        }

#if UNITY_EDITOR
        var rawTexture = mask.ConvertTo(UTextureFormat.PNG).RawTexture;

        var pythonOutput = SIGPython.Services.ProcessNode(PYTHON_NODE, new Dictionary <string, object>
        {
            { "mask_texture", rawTexture.ToList() },
            { "id", DatasetItemId },
            { "category_id", Dataset.Category.id },
            { "image_id", DatasetItemId },
            { "is_crowd", false },
            { "keypoints", JsonConverter.ToJson(CocoAnnotation.GetCocoKeypoints(keypoints)) }
        }.ToPyDict());

        annotation = new CocoAnnotation(Dataset)
        {
            imageAnnotation = JsonConverter.FromJson <CocoJsonAnnotationData.Annotation>(pythonOutput.GetOutput <string>("json"))
        };
#else
        Error("SIGPython is not available at runtime");
        return;
#endif
    }
示例#2
0
 public virtual void Run(SIGGraphProcessor processor, SIGProcessingContext context)
 {
     OnPreProcess(context);
     processor.Run(context);
     OnPostProcess(context);
     Complete();
 }
示例#3
0
 protected override void Process(SIGProcessingContext context)
 {
     x = input.x;
     y = input.y;
     z = input.z;
     w = input.w;
 }
示例#4
0
    public override void Initialize(SIGProcessingContext context)
    {
        base.Initialize(context);
        ClearScene();

        this.context.onReset += ClearScene;
    }
    protected override RenderScene Apply(SIGProcessingContext context)
    {
        if (InputIsEmpty)
        {
            return(RenderScene.Empty);
        }

        int s = Mathf.RoundToInt(start);
        int c = Mathf.RoundToInt(count);

        if (!AssertIndex(s, "Start is out of range"))
        {
            return(null);
        }
        if (!Assert(c >= 0, "Count can not be less than 0"))
        {
            return(null);
        }
        if (!AssertIndex(s + c - 1, "End is out of range"))
        {
            return(null);
        }

        var objects = new GameObject[c];

        for (int i = s; i < s + c; i++)
        {
            objects[i - s] = input[i];
        }

        return(new RenderObjectCollection(objects));
    }
示例#6
0
    protected override void Process(SIGProcessingContext context)
    {
        string msg = JsonConvert.SerializeObject(message, ShouldIndent ? Formatting.Indented : Formatting.None);

        AddMessage(msg, NodeMessageType.Info);
        Debug.Log(msg);
    }
示例#7
0
    protected override RenderScene Apply(SIGProcessingContext context)
    {
        if (!Assert(count >= 0, "Count can not be less than 0"))
        {
            return(null);
        }
        if (count == 0)
        {
            return(RenderScene.Empty);
        }

        scene = Target;
        if (count == 1)
        {
            return((RenderObject)Instance);
        }

        var instances = new GameObject[count];

        for (int i = 0; i < count; i++)
        {
            instances[i] = Instance;
        }

        return(new RenderObjectCollection(instances));
    }
示例#8
0
 public virtual void OnPostProcess(SIGProcessingContext context)
 {
     if (context.HasError)
     {
         Debug.LogError("Error while processing graph. Open the graph for more details.");
     }
 }
示例#9
0
 public void InitializeComponents(SIGProcessingContext context)
 {
     foreach (var component in components.Values)
     {
         component.Initialize(context);
     }
 }
示例#10
0
 protected virtual void PostProcess(SIGProcessingContext context)
 {
     foreach (var component in components.Values)
     {
         component.Finalize();
     }
     components.Clear();
 }
示例#11
0
    protected override RenderScene Apply(SIGProcessingContext context)
    {
        component.focalLength           = focalLength;
        component.usePhysicalProperties = true;
        component.clearFlags            = clearFlags;
        component.backgroundColor       = clearColor;

        return(base.Apply(context));
    }
示例#12
0
    protected override RenderScene Apply(SIGProcessingContext context)
    {
        if (scene1 == null && scene2 == null)
        {
            return(RenderScene.Empty);
        }

        return(merge ? RenderScene.Merge(scene1, scene2) : scene1);
    }
示例#13
0
    protected override void Process(SIGProcessingContext context)
    {
#if UNITY_EDITOR
        var inputs = PullInputs();
        PushOutputs(SIGPython.Services.ProcessNode(PythonNodeClass, inputs.ToPyDict()));
#else
        context.Error();
        throw new PlatformNotSupportedException("SIGPython is only available in the Unity editor");
#endif
    }
示例#14
0
    protected override void Process(SIGProcessingContext context)
    {
        if (!Assert(ReplacementShader != null, "Replacement shader required"))
        {
            return;
        }

        base.Process(context);
        Target.ResetReplacementShader();
    }
示例#15
0
 protected override void Process(SIGProcessingContext context)
 {
     output = Apply(context);
     if (debug)
     {
         AddMessage("Output: " + output.ToString(), NodeMessageType.Info);
     }
     else
     {
         RemoveMessageContains("Output: ");
     }
 }
    protected override RenderScene Apply(SIGProcessingContext context)
    {
        foreach (var gameObject in input)
        {
            var transform = gameObject.transform;
            SetPosition(transform, positionIn);
            SetRotation(transform, Quaternion.Euler(rotationIn));
            transform.localScale = scaleIn;
        }

        return(input);
    }
    protected override RenderScene Apply(SIGProcessingContext context)
    {
        foreach (var gameObject in input)
        {
            var transform = gameObject.transform;
            SetPosition(transform, Position(transform) + offsetPos);
            SetRotation(transform, Quaternion.Euler(Rotation(transform).eulerAngles + offsetRot));
            transform.localScale += offsetScale;
        }

        return(input);
    }
    protected override RenderScene Apply(SIGProcessingContext context)
    {
        if (InputIsEmpty)
        {
            return(RenderScene.Empty);
        }

        int c = Mathf.RoundToInt(count);

        if (!Assert(c >= 0, "Count can not be less than 0"))
        {
            return(RenderScene.Empty);
        }
        if (!Assert(c <= input.Count || !selectUnique, "Input has not enough unique elements"))
        {
            return(input);
        }

        // Single random
        if (c == 1)
        {
            return(new RenderObject(input[Random.Range(0, input.Count)]));
        }

        GameObject[] gameObjects = new GameObject[c];

        // Unique random with count
        if (selectUnique)
        {
            List <int> used = new List <int>(c);
            for (int i = 0; i < c; i++)
            {
                var random = Random.Range(0, input.Count);;
                while (used.Contains(random))
                {
                    random = (random + 1) % c;
                }

                gameObjects[i] = input[random];
                used.Add(random);
            }
            return(new RenderObjectCollection(gameObjects));
        }

        // Random with count
        for (int i = 0; i < c; i++)
        {
            gameObjects[i] = input[Random.Range(0, input.Count)];
        }

        return(new RenderObjectCollection(gameObjects));
    }
示例#19
0
    protected override void Process(SIGProcessingContext context)
    {
        if (!Assert(Dataset != null, "No dataset provided") ||
            !Assert(Item != null, "No dataset item provided") ||
            !Assert(Annotation != null, "No annotation provided"))
        {
            return;
        }

        var id = Dataset.AddItem(Item);

        Dataset.AddAnnotation(id, Annotation);
    }
    protected override RenderScene Apply(SIGProcessingContext context)
    {
        if (!Assert(input.Count >= 1, "Scene needs at least one element"))
        {
            return(RenderScene.Empty);
        }
        var transform = input[0].transform;

        positionOut = Position(transform);
        rotationOut = Rotation(transform);
        scaleOut    = Scale(transform);

        return(input);
    }
示例#21
0
    public T AddSIGComponent <T>(SIGProcessingContext context) where T : SIGComponent
    {
        var type = typeof(T);

        Debug.Assert(!components.ContainsKey(type), "There should only be one instance of a SIGComponent");

        var go        = new GameObject(type.Name);
        var component = go.AddComponent <T>();

        component.Initialize(context);
        components.Add(type, component);

        return(component);
    }
示例#22
0
    protected override RenderScene Apply(SIGProcessingContext context)
    {
        List <GameObject> results = new List <GameObject>();

        foreach (var go in input)
        {
            var result = Find(go.transform, searchName, recurse);
            if (result != null)
            {
                results.Add(result.gameObject);
            }
        }

        return(RenderScene.FromList(results));
    }
示例#23
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
                                       ));
            }
        }
    }
    protected override RenderScene Apply(SIGProcessingContext context)
    {
        if (InputIsEmpty)
        {
            return(RenderScene.Empty);
        }

        int i = Mathf.RoundToInt(index);

        if (!AssertIndex(i, "Index is out of range"))
        {
            return(null);
        }

        return(new RenderObject(input[i]));
    }
示例#25
0
    protected override void Process(SIGProcessingContext context)
    {
        ProcessStartInfo start = new ProcessStartInfo();

        start.FileName               = ExecutablePath;
        start.Arguments              = Arguments;
        start.UseShellExecute        = false;
        start.RedirectStandardOutput = true;
        using (Process process = System.Diagnostics.Process.Start(start))
        {
            using (StreamReader reader = process.StandardOutput)
            {
                output = reader.ReadToEnd();
                onOutputChanged?.Invoke(output);
            }
        }
    }
    protected override RenderScene Apply(SIGProcessingContext context)
    {
        if (!Assert(!target.IsEmpty, "Target can not be empty"))
        {
            return(input);
        }

        var pos = target.Aggregate(Vector3.zero, (p, g) => p + g.transform.position) / target.Count;

        foreach (var gameObject in input)
        {
            var transform = gameObject.transform;
            transform.LookAt(pos, Vector3.up);
            transform.position += transform.forward * zoom;
        }

        return(input);
    }
示例#27
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();
    }
示例#28
0
    protected override void Process(SIGProcessingContext context)
    {
        if (!HasData)
        {
            return;
        }

        var data = Data;

        if (!Assert(data != null && data.Length > 0, "Empty data can not be saved"))
        {
            return;
        }

        using (var fs = new FileStream(Path, FileMode.OpenOrCreate))
        {
            fs.Write(data, 0, data.Length);
        }
        #if UNITY_EDITOR
        AssetDatabase.Refresh();
        #endif
    }
示例#29
0
    protected override void Process(SIGProcessingContext context)
    {
        var hasInputs =
            AssertInput(source, "Missing Source") &&
            AssertInput(destination, "Missing Destination");

        if (!hasInputs)
        {
            return;
        }

        if (material != null)
        {
            Graphics.Blit(source, destination, material);
        }
        else
        {
            Graphics.Blit(source, destination);
        }

        output = destination;
    }
示例#30
0
    public T GetSIGComponent <T>(SIGProcessingContext context) where T : SIGComponent
    {
        var type = typeof(T);

        if (components.ContainsKey(type))
        {
            return(components[type] as T);
        }

        var component = FindObjectOfType <T>();

        if (component == null)
        {
            component = AddSIGComponent <T>(context);
        }
        else
        {
            component.Initialize(context);
            components[type] = component;
        }

        return(component);
    }