Exemple #1
0
        private void FTopicChanged(IDiffSpread <string> spread)
        {
            foreach (var address in WorkingSockets.ToArray())
            {
                Subscribe(false, Sockets[address], Topic);
            }

            Topic.Clear();
            Topic = FTopic.ToList();

            foreach (var address in WorkingSockets.ToArray())
            {
                Subscribe(true, Sockets[address], Topic);
            }
        }
Exemple #2
0
        public void Evaluate(int SpreadMax)
        {
            FOutOnData.SliceCount       = FOutElementCount.SliceCount = 1;
            FOutMemoryStream.SliceCount = FOutActiveChunkIndex.SliceCount = 0;

            if (FChunkManager.IsConnected && FChunkManager.SliceCount > 0 && FChunkManager[0] != null)
            {
                ChunkManager chunkManager = FChunkManager[0];

                // create chunkaccessdata list for all requested chunks
                if (FIndex.IsChanged || FDownsampling.IsChanged || FDownsamplingOffset.IsChanged)
                {
                    IEnumerable <int>      currentChunks    = FIndex;
                    List <int>             currentChunkList = FIndex.ToList();
                    List <ChunkAccessData> chunksToAdd      = new List <ChunkAccessData>();
                    for (int i = 0; i < FIndex.SliceCount; i++)
                    {
                        int    streamLimit              = FLimit[i];
                        int    streamDownsampling       = FDownsampling[i];
                        int    streamDownsamplingOffset = FDownsamplingOffset[i];
                        double streamLocktime           = FLockTime[i];
                        chunksToAdd.Add(new ChunkAccessData(FIndex[i], streamLimit, streamDownsampling, streamDownsamplingOffset, streamLocktime));
                    }

                    // now remove chunks that are already active (with the same LOD)
                    chunksToAdd.RemoveAll(chunkToAdd => ActiveChunks.Exists(activeChunk => chunkToAdd.chunkId == activeChunk.chunkId &&
                                                                            chunkToAdd.streamDownsampling == activeChunk.streamDownsampling &&
                                                                            chunkToAdd.streamDownsamplingOffset == activeChunk.streamDownsamplingOffset
                                                                            ));
                    // remove chunks that are locked
                    chunksToAdd.RemoveAll(chunkToAdd => LockedChunks.Exists(lockedChunk => chunkToAdd.chunkId == lockedChunk.chunkId));

                    // create list of chunks wo dont need anymore
                    var chunksToRemove = ActiveChunks.Select(activeChunk => activeChunk.chunkId).Except(currentChunks).ToList();

                    // update list of locked chunks
                    var chunksToLock = ActiveChunks.Where(activeChunk => chunksToRemove.Contains(activeChunk.chunkId) && activeChunk.streamFinished).ToList();
                    chunksToLock.ForEach(activeChunk => activeChunk.StartLock());
                    LockedChunks.AddRange(chunksToLock);
                    LockedChunks.RemoveAll(lockedChunk => lockedChunk.isLocked == false);

                    // finally add remaining chunkaccessdata items to active list ..
                    ActiveChunks.AddRange(chunksToAdd);
                    // and remove chunkaccessdata items we dont need anymore
                    ActiveChunks.RemoveAll(activeChunk => chunksToRemove.Contains(activeChunk.chunkId));

                    // start reading process for new chunks (if not already happened)
                    if (chunkManager.ChunkReader != null)
                    {
                        foreach (ChunkAccessData chunkAccessData in chunksToAdd)
                        {
                            Chunk chunk = chunkManager.GetChunk(chunkAccessData.chunkId);
                            chunkManager.ChunkReader.Read(chunk);
                        }
                    }
                }

                // add chunkdata streams to a list
                FOutElementCount[0] = 0;
                List <Stream> streams = new List <Stream>();
                foreach (ChunkAccessData activeChunk in ActiveChunks)
                {
                    Chunk chunk = chunkManager.GetChunk(activeChunk.chunkId);

                    if (!activeChunk.streamFinished && chunk.finishedLoading)
                    {
                        Stream stream = chunk.MemoryStream;

                        // logic for limited stream output
                        if (activeChunk.streamLimit > -1)
                        {
                            int bytesToRead = chunkManager.BytesPerElement * activeChunk.streamLimit;
                            stream = new SkipStream(stream, activeChunk.streamPosition);
                            stream = new TakeStream(stream, bytesToRead * activeChunk.streamDownsampling);
                        }

                        // logic for picking every nth element
                        if (activeChunk.streamDownsampling > 1)
                        {
                            stream = new ModuloStream(stream, chunkManager.BytesPerElement, activeChunk.streamDownsampling, activeChunk.streamDownsamplingOffset);
                        }

                        // calculate number of appended elements
                        int bytesRead = (int)stream.Length;
                        FOutElementCount[0] += (bytesRead / chunkManager.BytesPerElement);

                        // update streamposition and set flag if position is at end
                        activeChunk.streamPosition += bytesRead * activeChunk.streamDownsampling;
                        if (activeChunk.streamPosition >= chunk.MemoryStream.Length)
                        {
                            activeChunk.streamFinished = true;
                        }

                        // add stream to list
                        streams.Add(stream);
                    }
                }

                // aggregate streams if needed
                if (streams.Count > 1)
                {
                    FOutMemoryStream.Add(new AggregatedStream(streams));
                }
                else if (streams.Count == 1)
                {
                    FOutMemoryStream.Add(streams[0]);
                }

                // bang on data
                FOutOnData[0] = (FOutElementCount[0] > 0) ? true : false;

                // output active chunk ids
                FOutActiveChunkIndex.AddRange(ActiveChunks.Select(activeChunk => activeChunk.chunkId));
            }
            else
            {
                FOutMemoryStream.Add(new MemoryComStream(new byte[sizeof(Single)]));   // workaround to prevent DynamicBufer (raw) from throwing exceptions
            }
        }
// ReSharper restore UnassignedField.Global
// ReSharper restore MemberCanBePrivate.Global


        public void Evaluate(int SpreadMax)
        {
            if (OnClickOut.Contains(true))
            {
                for (var i = 0; i < OnClickOut.SliceCount; i++)
                {
                    OnClickOut[i] = false;
                }
            }

            if (_onClick.ContainsValue(true))
            {
                (from item in _onClick where item.Value select item).ToList().ForEach(item =>
                {
                    OnClickOut[item.Key] = true;
                    _onClick[item.Key]   = false;
                });
            }

            //if (ControlOut.SliceCount == SpreadMax && !TransformIn.IsChanged && !EnabledIn.IsChanged) return;

            if (!(from path in PathIn.ToList() where File.Exists(path) select path).Any())
            {
                ControlOut.SliceCount = 0;
                return;
            }

            if (ControlOut.SliceCount != SpreadMax)
            {
                if (ControlOut.SliceCount > SpreadMax)
                {
                    for (var i = ControlOut.SliceCount; i > SpreadMax; i--)
                    {
                        ControlOut[i].Dispose();
                        _onClick.Remove(i);
                    }
                    OnClickOut.SliceCount = SpreadMax;
                    ControlOut.SliceCount = SpreadMax;
                }
                else
                {
                    var i = ControlOut.SliceCount;
                    for (ControlOut.SliceCount = SpreadMax; i < SpreadMax; i++)
                    {
                        if (File.Exists(PathIn[i]))
                        {
                            ControlOut[i] = new PictureBox {
                                Tag = i, Image = new Bitmap(PathIn[i]), SizeMode = PictureBoxSizeMode.Zoom
                            };
                            ControlOut[i].Click += (sender, args) => _onClick[(int)((Control)sender).Tag] = true;
                        }
                        OnClickOut.SliceCount = SpreadMax;
                    }
                }
            }

            for (var i = 0; i < SpreadMax; i++)
            {
                if (ControlOut[i] == null)
                {
                    if (File.Exists(PathIn[i]))
                    {
                        ControlOut[i] = new PictureBox {
                            Tag = i, Image = new Bitmap(PathIn[i]), SizeMode = PictureBoxSizeMode.Zoom
                        };
                        ControlOut[i].Click += (sender, args) => _onClick[(int)((Control)sender).Tag] = true;
                    }
                }

                if (!(ControlOut[i] is PictureBox))
                {
                    continue;
                }

                if (EnabledIn.IsChanged)
                {
                    ControlOut[i].Enabled = EnabledIn[i];
                }

                if (PathIn.IsChanged)
                {
                    if (File.Exists(PathIn[i]))
                    {
                        ((PictureBox)ControlOut[i]).Image = new Bitmap(PathIn[i]);
                    }
                }

                if (TransformIn.IsChanged)
                {
                    Vector3D scale;
                    Vector3D rotation;
                    Vector3D translation;
                    if (TransformIn[i].Decompose(out scale, out rotation, out translation))
                    {
                        ControlOut[i].Bounds = new Rectangle((int)(translation.x * 100.0), (int)(translation.y * 100.0), (int)(scale.x * ((PictureBox)ControlOut[i]).Image.Width), (int)(scale.y * ((PictureBox)ControlOut[i]).Image.Height));
                    }
                }
            }
        }