Example #1
0
        public PathPersistor(IPathContainer container, string path)
        {
            LOGGER.Debug($"Creating path persistor for path '{path}'");

            Path      = path;
            Container = container;
        }
        public void TestSetNewFrameNullContainer()
        {
            Bitmap         bitmap    = MockRepository.GenerateMock <Bitmap>();
            IPathContainer container = null;

            Assert.Throws <ArgumentNullException>(() => host.SetNewFrame(bitmap, container));
        }
 public void InputStateSetup()
 {
     editorState       = new EditorState();
     renderState       = new RenderState();
     projectState      = MockRepository.GenerateMock <ProjectState>();
     container         = MockRepository.GenerateMock <IPathContainer>();
     inputstateControl = new EditorStateControl(editorState, projectState, renderState);
     inputstateControl.SetPathsContainer(container);
 }
Example #4
0
        /// <summary>
        /// Constructor for Frame.
        /// </summary>
        /// <param name="imageurl"></param>
        public Frame(string imageurl)
        {
            #region Initialize private fields

            this.imageurl = imageurl;
            this.curves   = new PathContainer();

            #endregion
        }
        public void TestSetPathContainerNewPath()
        {
            IPathContainer container = MockRepository.GenerateMock <IPathContainer>();

            container.Stub(x => x.Count).Return(0);

            inputstateControl.SetPathsContainer(container);

            Assert.IsNull(editorState.SelectedPoint);
            Assert.IsNotNull(editorState.SelectedPath);
            container.AssertWasCalled(x => x.AddPath(Arg <Path> .Is.Anything));
        }
Example #6
0
        public PathForm(IPathContainer pathContainer, ITemplateContainer templateContainer, IYoutubeJobContainer queueContainer, IYoutubeJobContainer archiveContainer, IYoutubeAccountContainer accountContainer)
        {
            LOGGER.Info($"Initializing new instance of PathForm");

            InitializeComponent();

            this.pathContainer     = pathContainer;
            this.templateContainer = templateContainer;

            this.queueContainer   = queueContainer;
            this.archiveContainer = archiveContainer;
            this.accountContainer = accountContainer;
        }
        public void TestSetNewFrame()
        {
            Bitmap         bitmap    = MockRepository.GenerateMock <Bitmap>();
            IPathContainer container = MockRepository.GenerateMock <IPathContainer>();

            host.SetNewFrame(bitmap, container);

            stateControl.AssertWasCalled(x => x.SetPathsContainer(container));
            stateControl.AssertWasCalled(x => x.SetIdle());

            renderer.AssertWasCalled(x => x.SetFrame(bitmap, container));

            glControl.AssertWasCalled(x => x.Invalidate());
        }
        public void TestSetPathContainerExistingPath()
        {
            IPathContainer container  = MockRepository.GenerateMock <IPathContainer>();
            Path           simplePath = new Path();

            container.Stub(x => x.Count).Return(1);
            container.Stub(x => x.GetLastPath()).Return(simplePath);

            inputstateControl.SetPathsContainer(container);

            Assert.IsNull(editorState.SelectedPoint);
            Assert.IsNotNull(editorState.SelectedPath);
            Assert.That(editorState.SelectedPath, Is.EqualTo(simplePath));
            container.AssertWasNotCalled(x => x.AddPath(Arg <Path> .Is.Anything));
        }
        /// <summary>
        /// Set a new bitmap and paths for the editor.
        /// </summary>
        /// <param name="bitmap">Bitmap for the new frame, can be null if no image is required</param>
        /// <param name="container">The container for the new frame</param>
        public void SetNewFrame(Bitmap bitmap, IPathContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("PathsContainer cannot be null");
            }

            editorStateControl.SetPathsContainer(container);
            editorStateControl.SetIdle();

            bufferControl.SetContainer(container);

            renderer.SetFrame(bitmap, container);

            glControl.Invalidate();
        }
Example #10
0
        public void CloneTest()
        {
            IPathContainer container1 = new PathContainer();
            Path           dummyPath1 = MockRepository.GenerateMock <Path>();
            Path           dummyPath2 = MockRepository.GenerateMock <Path>();

            dummyPath1.Stub(x => x.Equals(Arg <Path> .Is.Anything)).Return(true);
            dummyPath2.Stub(x => x.Equals(Arg <Path> .Is.Anything)).Return(true);
            container1.AddPath(dummyPath1);
            container1.AddPath(dummyPath2);

            IPathContainer container2 = container1.Clone();

            Assert.True(container1.Equals(container2));
            Assert.False(container1 == container2);
        }
Example #11
0
        /// <summary>
        /// Sets the paths in the container.
        /// </summary>
        /// <param name="container"></param>
        public void SetPathsContainer(IPathContainer container)
        {
            if (container != null)
            {
                pathsContainer            = container;
                editorState.SelectedPoint = null;

                if (pathsContainer.Count == 0)
                {
                    SetNewSelectedPath();
                }
                else
                {
                    editorState.SelectedPath = pathsContainer.GetLastPath();
                }
            }
        }
        /// <summary>
        /// Sets the bitmap for the new frame
        /// </summary>
        /// <param name="bitmap">the new bitmap, can be null if no bitmap is required for this frame</param>
        public void SetFrame(Bitmap bitmap, IPathContainer container)
        {
            this.container = container;

            if (bitmap == null)
            {
                backgroundTextureID = -1;
            }
            else
            {
                if (!loaded)
                {
                    imageToLoad = bitmap;
                }
                else
                {
                    SetBitmap(bitmap);
                }
            }
        }
Example #13
0
        public ChooseStartTimesForm(IPathContainer pathContainer, ITemplateContainer templateContainer)
        {
            LOGGER.Info($"Initializing new instance of ChooseStartTimesForm");

            InitializeComponent();

            this.pathContainer     = pathContainer;
            this.templateContainer = templateContainer;

            foreach (var path in pathContainer.ActivePaths)
            {
                LOGGER.Info($"Adding active path '{path}'");

                publishSettings.Add(new ObservationConfiguration(path, templateContainer.RegisteredTemplates.FirstOrDefault(t => t.Id == path.SelectedTemplateId)));
            }

            chooseCustomTimesControl.AddRange(publishSettings);

            LOGGER.Debug($"Should publish controls be visible: {publishSettings.Any(i => i.Template.ShouldPublishAt)}");
            globalSettingsControl.SetPublishControlsVisibility(publishSettings.Any(i => i.Template.ShouldPublishAt), false);
        }
Example #14
0
        private void RecreateSaved()
        {
            LOGGER.Debug($"Recreating cache of saved paths");
            Saved = new PathContainer();
            foreach (var path in Container.RegisteredPaths)
            {
                LOGGER.Debug($"Recreating cache for path '{path.Fullname}'");
                var newPath = new Automation.Paths.Path()
                {
                    Filter             = path.Filter,
                    Fullname           = path.Fullname,
                    Inactive           = path.Inactive,
                    SearchHidden       = path.SearchHidden,
                    SearchRecursively  = path.SearchRecursively,
                    SelectedTemplateId = path.SelectedTemplateId,
                    MoveAfterUpload    = path.MoveAfterUpload,
                    MoveDirectoryPath  = path.MoveDirectoryPath,
                    SearchOrder        = path.SearchOrder
                };

                Saved.RegisterPath(newPath);
            }
        }
        /// <summary>
        /// Determines the error.
        /// </summary>
        /// <param name="oldPaths"></param>
        /// <param name="newPaths"></param>
        /// <param name="errors"></param>
        /// <returns></returns>
        double DetermineError(IPathContainer oldPaths, IPathContainer newPaths, byte[] errors)
        {
            int sum = 0;

            foreach (byte b in errors)
            {
                sum += b;
            }
            if (sum == 0)
            {
                return(double.MaxValue);
            }

            double      totalError   = 0;
            List <Path> oldPathsList = oldPaths.Paths;
            List <Path> newPathsList = newPaths.Paths;

            for (int i = 0; i < oldPathsList.Count; i++)
            {
                totalError += DeterminePathError(oldPathsList[i], newPathsList[i]);
            }

            return(totalError);
        }
Example #16
0
        private static PeakMatch GetPeakMatch(SrmDocument doc, ChromatogramSet chromSet, IPathContainer fileInfo, TransitionGroupDocNode nodeTranGroup,
                                              PeakMatchData referenceTarget, IEnumerable <PeakMatchData> referenceMatchData)
        {
            if (referenceTarget == null)
            {
                return(new PeakMatch(0, 0));
            }

            var mzMatchTolerance = (float)doc.Settings.TransitionSettings.Instrument.MzMatchTolerance;

            ChromatogramGroupInfo[] loadInfos;
            if (!nodeTranGroup.HasResults || !doc.Settings.MeasuredResults.TryLoadChromatogram(chromSet, null, nodeTranGroup, mzMatchTolerance, true, out loadInfos))
            {
                return(null);
            }

            var chromGroupInfo = loadInfos.FirstOrDefault(info => Equals(info.FilePath, fileInfo.FilePath));

            if (chromGroupInfo == null || chromGroupInfo.NumPeaks == 0 || !chromGroupInfo.TimeIntensitiesGroup.HasAnyPoints)
            {
                return(null);
            }

            var    matchData = new List <PeakMatchData>();
            double totalArea = chromGroupInfo.TransitionPointSets.Sum(chromInfo => chromInfo.Peaks.Sum(peak => peak.Area));

            for (int i = 0; i < chromGroupInfo.NumPeaks; i++)
            {
                matchData.Add(new PeakMatchData(nodeTranGroup, chromGroupInfo, mzMatchTolerance, i, totalArea, chromSet.OptimizationFunction));
            }

            // TODO: Try to improve this. Align peaks in area descending order until peaks do not match
            var  alignments       = new List <PeakAlignment>();
            bool referenceAligned = false;

            using (var referenceIter = referenceMatchData.OrderByDescending(d => d.PercentArea).GetEnumerator())
                using (var curIter = matchData.OrderByDescending(d => d.PercentArea).GetEnumerator())
                {
                    while (referenceIter.MoveNext() && curIter.MoveNext())
                    {
                        var alignAttempt = new PeakAlignment(referenceIter.Current, curIter.Current);
                        if (!TryInsertPeakAlignment(alignments, alignAttempt))
                        {
                            break;
                        }

                        if (referenceTarget == alignAttempt.ReferencePeak)
                        {
                            // Reference target aligned
                            referenceAligned = true;
                            matchData        = new List <PeakMatchData> {
                                alignAttempt.AlignedPeak
                            };
                            break;
                        }
                    }
                }

            PeakMatch manualMatch = null;

            if (!referenceAligned)
            {
                PeakAlignment prev, next;
                GetSurroundingAlignments(alignments, referenceTarget, out prev, out next);
                if (prev != null || next != null)
                {
                    // At least one alignment occurred
                    var chromGroupMinTime = chromGroupInfo.TimeIntensitiesGroup.MinTime;
                    var chromGroupMaxTime = chromGroupInfo.TimeIntensitiesGroup.MaxTime;

                    float scale = (chromGroupMaxTime - chromGroupMinTime) / (referenceTarget.MaxTime - referenceTarget.MinTime);
                    manualMatch = MakePeakMatchBetween(scale, referenceTarget, prev, next);
                    if (chromGroupMinTime >= manualMatch.EndTime || manualMatch.StartTime >= chromGroupMaxTime)
                    {
                        manualMatch = null;
                    }

                    float curMinTime = prev == null ? chromGroupMinTime : prev.AlignedPeak.RetentionTime;
                    float curMaxTime = next == null ? chromGroupMaxTime : next.AlignedPeak.RetentionTime;

                    matchData = matchData.Where(d => curMinTime < d.RetentionTime && d.RetentionTime < curMaxTime).ToList();
                }
            }

            PeakMatchData bestMatch = null;
            double        bestScore = double.MinValue;

            foreach (var other in matchData)
            {
                var score = referenceTarget.GetMatchScore(other);
                if (bestMatch == null || score > bestScore)
                {
                    bestScore = score;
                    bestMatch = other;
                }
            }

            // If no matching peak with high enough score was found, but there is a matching
            // peak or some peak with a low score.
            if (bestMatch == null || (!referenceAligned && bestScore < INTEGRATE_SCORE_THRESHOLD && manualMatch != null))
            {
                return(manualMatch);
            }

            if (referenceTarget.ShiftLeft == 0 && referenceTarget.ShiftRight == 0)
            {
                return(new PeakMatch(bestMatch.RetentionTime));
            }

            var range     = bestMatch.EndTime - bestMatch.StartTime;
            var startTime = bestMatch.StartTime + (referenceTarget.ShiftLeft * range);
            var endTime   = bestMatch.EndTime + (referenceTarget.ShiftRight * range);

            return(startTime <= bestMatch.RetentionTime && bestMatch.RetentionTime <= endTime
                ? new PeakMatch(startTime, endTime)
                : new PeakMatch(bestMatch.RetentionTime)); // If the shifted boundaries exclude the peak itself, don't change the boundaries
        }
Example #17
0
 /// <summary>
 /// Interpolates on give paths.
 /// </summary>
 /// <param name="previousPath"></param>
 /// <param name="nextPath"></param>
 /// <param name="previousImage"></param>
 /// <param name="nextImage"></param>
 /// <returns></returns>
 protected abstract double Interpolate(IPathContainer previousPath, IPathContainer nextPath, Image <Bgr, Byte> previousImage, Image <Bgr, Byte> nextImage);
Example #18
0
        /// <summary>
        /// Interpolates the paths.
        /// </summary>
        /// <param name="previousPath"></param>
        /// <param name="nextPath"></param>
        /// <param name="previousImage"></param>
        /// <param name="nextImage"></param>
        /// <returns></returns>
        public double InterpolatePaths(IPathContainer previousPath, IPathContainer nextPath, Image <Bgr, Byte> previousImage, Image <Bgr, Byte> nextImage)
        {
            bitmapSize = previousImage.Size;

            return(Interpolate(previousPath, nextPath, previousImage, nextImage));
        }
Example #19
0
        private static PeakMatch GetPeakMatch(SrmDocument doc, ChromatogramSet chromSet, IPathContainer fileInfo, TransitionGroupDocNode nodeTranGroup,
            PeakMatchData referenceTarget, IEnumerable<PeakMatchData> referenceMatchData)
        {
            if (referenceTarget == null)
                return new PeakMatch(0, 0);

            var mzMatchTolerance = (float) doc.Settings.TransitionSettings.Instrument.MzMatchTolerance;

            ChromatogramGroupInfo[] loadInfos;
            if (!nodeTranGroup.HasResults || !doc.Settings.MeasuredResults.TryLoadChromatogram(chromSet, null, nodeTranGroup, mzMatchTolerance, true, out loadInfos))
                return null;

            var chromGroupInfo = loadInfos.FirstOrDefault(info => Equals(info.FilePath, fileInfo.FilePath));
            if (chromGroupInfo == null || chromGroupInfo.NumPeaks == 0 || !chromGroupInfo.Times.Any())
                return null;

            var matchData = new List<PeakMatchData>();
            double totalArea = chromGroupInfo.TransitionPointSets.Sum(chromInfo => chromInfo.Peaks.Sum(peak => peak.Area));
            for (int i = 0; i < chromGroupInfo.NumPeaks; i++)
                matchData.Add(new PeakMatchData(nodeTranGroup, chromGroupInfo, mzMatchTolerance, i, totalArea));

            // TODO: Try to improve this. Align peaks in area descending order until peaks do not match
            var alignments = new List<PeakAlignment>();
            bool referenceAligned = false;
            var referenceIter = referenceMatchData.OrderByDescending(d => d.PercentArea).GetEnumerator();
            var curIter = matchData.OrderByDescending(d => d.PercentArea).GetEnumerator();
            while (referenceIter.MoveNext() && curIter.MoveNext())
            {
                var alignAttempt = new PeakAlignment(referenceIter.Current, curIter.Current);
                if (!TryInsertPeakAlignment(alignments, alignAttempt))
                    break;

                if (referenceTarget == alignAttempt.ReferencePeak)
                {
                    // Reference target aligned
                    referenceAligned = true;
                    matchData = new List<PeakMatchData> {alignAttempt.AlignedPeak};
                    break;
                }
            }

            PeakMatch manualMatch = null;

            if (!referenceAligned)
            {
                PeakAlignment prev, next;
                GetSurroundingAlignments(alignments, referenceTarget, out prev, out next);
                if (prev != null || next != null)
                {
                    // At least one alignment occurred
                    var chromGroupMinTime = chromGroupInfo.Times.First();
                    var chromGroupMaxTime = chromGroupInfo.Times.Last();

                    float scale = (chromGroupMaxTime - chromGroupMinTime)/(referenceTarget.MaxTime - referenceTarget.MinTime);
                    manualMatch = MakePeakMatchBetween(scale, referenceTarget, prev, next);
                    if (chromGroupMinTime >= manualMatch.EndTime || manualMatch.StartTime >= chromGroupMaxTime)
                        manualMatch = null;

                    float curMinTime = prev == null ? chromGroupMinTime : prev.AlignedPeak.RetentionTime;
                    float curMaxTime = next == null ? chromGroupMaxTime : next.AlignedPeak.RetentionTime;

                    matchData = matchData.Where(d => curMinTime < d.RetentionTime && d.RetentionTime < curMaxTime).ToList();
                }
            }

            PeakMatchData bestMatch = null;
            double bestScore = double.MinValue;
            foreach (var other in matchData)
            {
                var score = referenceTarget.GetMatchScore(other);
                if (bestMatch == null || score > bestScore)
                {
                    bestScore = score;
                    bestMatch = other;
                }
            }

            // If no matching peak with high enough score was found, but there is a matching
            // peak or some peak with a low score.
            if (bestMatch == null || (!referenceAligned && bestScore < INTEGRATE_SCORE_THRESHOLD && manualMatch != null))
                return manualMatch;

            if (referenceTarget.ShiftLeft == 0 && referenceTarget.ShiftRight == 0)
                return new PeakMatch(bestMatch.RetentionTime);

            var range = bestMatch.EndTime - bestMatch.StartTime;
            var startTime = bestMatch.StartTime + (referenceTarget.ShiftLeft*range);
            var endTime = bestMatch.EndTime + (referenceTarget.ShiftRight*range);
            return startTime <= bestMatch.RetentionTime && bestMatch.RetentionTime <= endTime
                ? new PeakMatch(startTime, endTime)
                : new PeakMatch(bestMatch.RetentionTime); // If the shifted boundaries exclude the peak itself, don't change the boundaries
        }
        /// <summary>
        /// Interpolates the path using the iterative Lucas-Kanade method for each point in the path as a feature
        /// </summary>
        /// <param name="previousPath">The path of the previous frame</param>
        /// <param name="nextPath">The empty path of the to be interpolated frame</param>
        /// <param name="previousImage">The previous image</param>
        /// <param name="nextImage">The next image to interpolate to</param>
        /// <returns>A value between 0 and 1 indicating the accuracy of the interpolation</returns>
        protected override double Interpolate(Model.IPathContainer previousPath, Model.IPathContainer nextPath, Image <Bgr, Byte> previousImage, Image <Bgr, Byte> nextImage)
        {
            List <PointF> featureList = new List <PointF>();
            List <Path>   activePaths = new List <Path>();

            for (int i = 0; i < previousPath.LayerIndices[previousPath.ActivePathsLayer].Count; i++)
            {
                activePaths.Add(previousPath.Paths[previousPath.LayerIndices[previousPath.ActivePathsLayer][i]]);
            }

            IEnumerator <Path> pathEnumerator = activePaths.GetEnumerator();

            while (pathEnumerator.MoveNext())
            {
                LinkedList <BezierPoint> .Enumerator pointEnumerator = pathEnumerator.Current.GetEnumerator();
                while (pointEnumerator.MoveNext())
                {
                    featureList.Add(GetImagePoint(pointEnumerator.Current));
                }
            }

            Image <Gray, Byte> prevGray = previousImage.Convert <Gray, Byte>();
            Image <Gray, Byte> nextGray = nextImage.Convert <Gray, Byte>();

            PointF[] featureArray = featureList.ToArray();
            PointF[] newFeatures;
            byte[]   errors;
            float[]  trackErrors;
            Emgu.CV.Structure.MCvTermCriteria criteria = new Emgu.CV.Structure.MCvTermCriteria(10);

            OpticalFlow.PyrLK(prevGray, nextGray, featureArray, new Size(10, 10), 5, criteria, out newFeatures, out errors, out trackErrors);

            IPathContainer     tempPathContainer  = previousPath.Clone();
            IEnumerator <Path> tempPathEnumerator = tempPathContainer.GetPathsEnumerator();
            int index = 0;

            for (int j = 0; j < previousPath.Count; j++)
            {
                if (previousPath.LayerIndices[previousPath.ActivePathsLayer].Contains(j))
                {
                    LinkedList <BezierPoint> .Enumerator pointEnumerator = tempPathContainer.Paths[j].GetEnumerator();
                    while (pointEnumerator.MoveNext())
                    {
                        Translate(pointEnumerator.Current, featureArray[index], newFeatures[index++]);
                    }
                }
            }

            IEnumerator <Path> nextPathEnumerator = tempPathContainer.GetPathsEnumerator();

            while (nextPathEnumerator.MoveNext())
            {
                nextPath.AddPath(nextPathEnumerator.Current);
            }

            nextPath.ActivePathsLayer = tempPathContainer.ActivePathsLayer;
            nextPath.LayerIndices     = tempPathContainer.LayerIndices;

            double error = DetermineError(previousPath, nextPath, errors);

            return(error);
        }
Example #21
0
 /// <summary>
 /// Sets container.
 /// </summary>
 /// <param name="container"></param>
 public void SetContainer(IPathContainer container)
 {
     this.container = container;
     Rebuild();
 }