public void LineSearchGridTestMethod() { LineSearchGrid<string> LineSearch = new LineSearchGrid<string>(new GridRectangle(-10, 10, -10, 10), 500); GridLineSegment lineA = new GridLineSegment(new GridVector2(-5, 3), new GridVector2(5, 3)); GridLineSegment lineB = new GridLineSegment(new GridVector2(3, -5), new GridVector2(3, 5)); GridLineSegment lineC = new GridLineSegment(new GridVector2(-6, -5), new GridVector2(-6, 5)); GridLineSegment lineD = new GridLineSegment(new GridVector2(-9, 8), new GridVector2(1, -8)); //Should be in seven grid cells GridLineSegment lineE = new GridLineSegment(new GridVector2(-9, 8), new GridVector2(1, -2)); LineSearch.Add(lineA, "A"); LineSearch.Add(lineB, "B"); LineSearch.Add(lineC, "C"); LineSearch.Add(lineD, "D"); LineSearch.Add(lineE, "E"); GridVector2 intersection; double distance; string value = LineSearch.GetNearest(new GridVector2(-5, 3), out intersection, out distance); Debug.Assert(value == "A"); value = LineSearch.GetNearest(new GridVector2(-10, -10), out intersection, out distance); Debug.Assert(value == "C"); value = LineSearch.GetNearest(new GridVector2(7, 4), out intersection, out distance); Debug.Assert(value == "A"); value = LineSearch.GetNearest(new GridVector2(3.5, 6), out intersection, out distance); Debug.Assert(value == "B"); }
public void LineSearchGridTestMethod() { LineSearchGrid<GridVector2> LineSearch = new LineSearchGrid<GridVector2>(new GridRectangle(-10, 10, -10, 10), 500); GridLineSegment lineA = new GridLineSegment(new GridVector2(-5, 3), new GridVector2(5, 3)); GridLineSegment lineB = new GridLineSegment(new GridVector2(3, -5), new GridVector2(3, 5)); GridLineSegment lineC = new GridLineSegment(new GridVector2(-6, -5), new GridVector2(-6, 5)); GridLineSegment lineD = new GridLineSegment(new GridVector2(-9, 8), new GridVector2(1, -8)); GridLineSegment lineE = new GridLineSegment(new GridVector2(-9, 8), new GridVector2(1, -2)); LineSearch.Add(lineA, lineA.A); LineSearch.Add(lineB, lineB.A); LineSearch.Add(lineC, lineC.A); LineSearch.Add(lineD, lineD.A); LineSearch.Add(lineE, lineE.B); GridVector2 intersection; double distance; GridVector2 value = LineSearch.GetNearest(new GridVector2(-5, 3), out intersection, out distance); Debug.Assert(value == lineA.A); value = LineSearch.GetNearest(new GridVector2(-10, -10), out intersection, out distance); Debug.Assert(value == lineC.A); }
public SectionLocationsViewModel(SectionViewModel section, Viking.UI.Controls.SectionViewerControl Parent) { this.parent = Parent; Trace.WriteLine("Create SectionLocationsViewModel for " + section.Number.ToString()); this.Section = section; GridRectangle bounds = AnnotationOverlay.SectionBounds(parent, parent.Section.Number); if (Locations == null) Locations = new QuadTree<Location_CanvasViewModel>(bounds); LocationsForStructure = new ConcurrentDictionary<long, ConcurrentDictionary<long, Location_CanvasViewModel>>(); StructureLinksSearch = new LineSearchGrid<StructureLink>(bounds, 10000); CollectionChangedEventManager.AddListener(Store.Structures, this); CollectionChangedEventManager.AddListener(Store.StructureLinks, this); }
protected void Dispose(bool freeManagedObjectsAlso) { if (freeManagedObjectsAlso) { if (StructureLinksSearch != null) { this.StructureLinksSearch.Dispose(); this.StructureLinksSearch = null; } if (this.Locations != null) { this.Locations.Dispose(); this.Locations = null; } } }
/// <summary> /// Load the annotations for the passed section and its reference sections /// </summary> /// <param name="section"></param> internal void LoadSectionAnnotations() { Trace.WriteLine("LoadSectionAnnotations: " + Section.Number.ToString(), "WebAnnotation"); // lock (LockObject) { /* if (LocationsForStructure != null) { LocationsForStructure.Clear(); } if (TransformedLocationPositionDict != null) { TransformedLocationPositionDict.Clear(); } if (TransformedRefLocationQuadTree != null) { TransformedRefLocationQuadTree = null; } if (TransformedLocationQuadTree != null) { TransformedLocationQuadTree = null; } if (LocationLinksSearch != null) { ClearLocationLinks(); LocationLinksSearch = null; } if (StructureLinksSearch != null) { ClearStructureLinks(); StructureLinksSearch = null; } */ //Create the datastructures /*PORT Concurrent Collections if (Locations == null) { Locations = new SortedList<long, LocationObj>(); } if (ReferenceLocations == null) { ReferenceLocations = new SortedList<long, LocationObj>(); } */ if (LocationsForStructure == null) { LocationsForStructure = new ConcurrentDictionary<long, ConcurrentDictionary<long, LocationObj>>(); } GridRectangle bounds = QuadTreeBounds(); bounds.Scale(.2); if(TransformedRefLocationQuadTree == null) TransformedRefLocationQuadTree = new QuadTree<long>(bounds); if(TransformedLocationQuadTree == null) TransformedLocationQuadTree = new QuadTree<long>(bounds); if (LocationLinksSearch == null) { LocationLinksSearch = new LineSearchGrid<LocationLinkObj>(bounds, 10000); StructureLinksSearch = new LineSearchGrid<StructureLinkObj>(bounds, 10000); } } //Have to let the Lock go before we call the location store or we can get a deadlock. Don't modify //data structures after this point. //Load reference locations /* PORT Concurrent Collections List<LocationObj> RefLocationArray = new List<LocationObj>(); if (section.ReferenceSectionBelow != null) RefLocationArray.AddRange(Store.Locations.GetLocationsForSection(section.ReferenceSectionBelow.Number)); if (section.ReferenceSectionAbove != null) RefLocationArray.AddRange(Store.Locations.GetLocationsForSection(section.ReferenceSectionAbove.Number)); // ReferenceLocations = new SortedList<long, LocationObj>(); */ LocationObj[] RefLocations = GetReferenceLocations(); foreach (LocationObj loc in RefLocations) { AddLocation(loc); } foreach (LocationObj loc in Locations.Values) { AddLocation(loc); } HaveLoadedSectionAnnotations = true; // PopulateLocationLinks(); }
public LineSearchGrid<LocationLink> GetOrAddSearchGrid(int SectionNumber, int EstimatedLinks) { LineSearchGrid<LocationLink> searchGrid; bool success = SectionLocationLinksSearch.TryGetValue(SectionNumber, out searchGrid); if(success) return searchGrid; searchGrid = new LineSearchGrid<LocationLink>(AnnotationOverlay.SectionBounds(parent, SectionNumber), EstimatedLinks); searchGrid = SectionLocationLinksSearch.GetOrAdd(SectionNumber, searchGrid); return searchGrid; }