コード例 #1
0
        private static ThreadGroup StartCPU(DataType type, HeadsetModel headset, ElectrodePattern pattern, ElectrodeLayout layout, string path)
        {
            // declare colour matrix and electrodes (if needed)
            var matrix     = new Color[headset.GetWidth(), headset.GetHeight()];
            var electrodes = type == DataType.Phosphene ? pattern.GetElectrodePositions(layout)
                                                                                                                : default;

            // setup threadGroup
            var threadGroup = new ThreadGroup();

            threadGroup.OnAllThreadsFinished += () =>
            {
                EditorCallback.InvokeOnMainThread(() =>
                {
                    var asset = headset.CreateTexture();
                    asset.SetPixels(matrix.Flatten(false, true, true));
                    asset.Apply();
                    SaveAsset(asset, path);
                });
            };

            // generate the texture asynchronously
            threadGroup.ProcessArray(headset.GetWidth(), (i) =>
            {
                var n = headset.GetHeight();
                for (int j = 0; j < n; j++)
                {
                    switch (type)
                    {
                    case DataType.Phosphene:
                        matrix[i, j] = PhospheneMatrix.CalculatePoint(i, j, headset, electrodes).ToColour();
                        matrix[i, j] = AddRandomSeeds(matrix[i, j]);
                        break;

                    case DataType.Axon:
                        matrix[i, j] = AxonMatrix.CalculatePoint(i, j, headset).Colour;
                        break;
                    }
                }
            });

            // provide caller with threadGroup for completion statistics
            return(threadGroup);
        }