Exemple #1
0
 private void UpdateListView(BoxTree visualTree)
 {
     m_nodesForTreeCollection = new ObservableCollection <NodeViewModel>();
     m_nodesForTreeCollection.Add(new NodeViewModel {
         Node = visualTree.Root
     });
     LvBoxes.ItemsSource = m_nodesForTreeCollection;
 }
 private IEnumerable <SegmentProxyNeighborhood> GetNeighborhoods(
     BoxTree <SegmentProxy> neighborBoxTree, double searchDistance, IBox commonBox)
 {
     return(_boxTree.EnumerateNeighborhoods(neighborBoxTree, searchDistance, commonBox)
            .Select(boxPairs => new SegmentProxyNeighborhood
     {
         SegmentProxy = boxPairs.Entry.Value,
         Neighbours = GetSegments(boxPairs.Neighbours)
     }));
 }
        public IndexedPolycurve([NotNull] IPointCollection4 baseGeometry)
        {
            Assert.ArgumentNotNull(baseGeometry, nameof(baseGeometry));

            const bool @dynamic  = true;
            const int  dimension = 2;
            const int  maxElementCountPerTile = 4;            //  was: 64;

            _boxTree = new BoxTree <SegmentProxy>(dimension, maxElementCountPerTile, @dynamic);

            var geometry = (IGeometry)baseGeometry;

            _envelope = geometry.Envelope;
            double tolerance = GeometryUtils.GetXyTolerance(geometry);

            Box extent = QaGeometryUtils.CreateBox(_envelope);

            Expand(extent, tolerance);

            _boxTree.InitSize(new IGmtry[] { extent });

            var geometryCollection = baseGeometry as IGeometryCollection;

            if (geometryCollection != null)
            {
                int partCount = geometryCollection.GeometryCount;

                if (partCount > 1)
                {
                    // unpack and add individual parts
                    _partProxies = new List <PartProxy>(partCount);

                    for (int partIndex = 0; partIndex < partCount; partIndex++)
                    {
                        var part = (IPointCollection4)geometryCollection.Geometry[partIndex];

                        var partProxy = new PartProxy(_boxTree, partIndex, part);

                        _partProxies.Add(partProxy);

                        Marshal.ReleaseComObject(part);
                    }
                }
                else
                {
                    // single part in collection
                    _partProxies = AddSinglePartProxy(baseGeometry);
                }
            }
            else
            {
                // no geometry collection
                _partProxies = AddSinglePartProxy(baseGeometry);
            }
        }
Exemple #4
0
            public VertexSearcher([NotNull] IEnvelope envelope, double tolerance)
            {
                Assert.ArgumentNotNull(envelope, nameof(envelope));

                _tolerance        = tolerance;
                _toleranceSquared = tolerance * tolerance;

                _boxTree = BoxTreeUtils.CreateBoxTree <Vertex>(envelope.XMin, envelope.YMin,
                                                               envelope.XMax, envelope.YMax,
                                                               maxElementsPerTile: 16);
            }
 private IEnumerable <SegmentProxyNeighborhood> GetNeighborhoods(
     BoxTree <SegmentProxy> neighborBoxTree, double searchDistance, IBox commonBox)
 {
     foreach (BoxTree <SegmentProxy> .Neighborhood <SegmentProxy> boxPairs in
              _boxTree.EnumerateNeighborhoods(neighborBoxTree, searchDistance, commonBox))
     {
         SegmentProxyNeighborhood neighborhood =
             new SegmentProxyNeighborhood
         {
             SegmentProxy = boxPairs.Entry.Value,
             Neighbours   = GetSegments(boxPairs.Neighbours)
         };
         yield return(neighborhood);
     }
 }
Exemple #6
0
 private void FireListViewPropertyChanged(BoxTree visualTree)
 {
     if (m_nodesForTreeCollection != null)
     {
         foreach (var item in m_nodesForTreeCollection)
         {
             item.Changed();
         }
     }
     m_nodesForTreeCollection = new ObservableCollection <NodeViewModel>();
     m_nodesForTreeCollection.Add(new NodeViewModel {
         Node = visualTree.Root
     });
     LvBoxes.ItemsSource = m_nodesForTreeCollection;
 }
        public bool TryGetSegmentNeighborhoods(
            IIndexedSegments neighborSegments, IBox commonBox, double searchDistance,
            out IEnumerable <SegmentProxyNeighborhood> neighborhoods)
        {
            IndexedPolycurve neighbor = neighborSegments as IndexedPolycurve;

            if (neighbor == null)
            {
                neighborhoods = null;
                return(false);
            }

            BoxTree <SegmentProxy> neighborBoxTree = neighbor._boxTree;

            neighborhoods = GetNeighborhoods(neighborBoxTree, searchDistance, commonBox);
            return(true);
        }
Exemple #8
0
        private List <BoxTree <CachedRow> .TileEntry> SearchList(
            [NotNull] IGeometry searchGeometry, int tableIndex)
        {
            Assert.ArgumentNotNull(searchGeometry, nameof(searchGeometry));

            IBox searchGeometryBox = QaGeometryUtils.CreateBox(searchGeometry,
                                                               GetXYTolerance(tableIndex));

            BoxTree <CachedRow> boxTree = _rowBoxTrees[tableIndex];

            if (_currentRowNeighbors == null)
            {
                _currentRowNeighbors = new BoxSelection[_cachedTableCount];
            }

            BoxSelection currentRowBoxSelection = _currentRowNeighbors[tableIndex];

            if (currentRowBoxSelection == null)
            {
                currentRowBoxSelection = CreateCurrentRowToleranceSelection(tableIndex);

                _currentRowNeighbors[tableIndex] = currentRowBoxSelection;
            }

            IBox searchBox = null;
            var  isWithin  = false;

            if (currentRowBoxSelection != null)
            {
                isWithin = currentRowBoxSelection.Box.Contains(searchGeometryBox);
            }

            if (!isWithin)
            {
                searchBox = searchGeometryBox;
            }
            else if (currentRowBoxSelection.Selection == null)
            {
                searchBox = currentRowBoxSelection.Box;
            }

            List <BoxTree <CachedRow> .TileEntry> tileEntries;

            if (searchBox != null)
            {
                tileEntries = new List <BoxTree <CachedRow> .TileEntry>();

                foreach (
                    BoxTree <CachedRow> .TileEntry tileEntry in boxTree.Search(searchBox))
                {
                    tileEntries.Add(tileEntry);
                }

                if (isWithin)
                {
                    currentRowBoxSelection.Selection = tileEntries;
                }
            }
            else
            {
                tileEntries = currentRowBoxSelection.Selection;
            }

            if (!isWithin || searchGeometryBox.Contains(currentRowBoxSelection.Box))
            {
                return(tileEntries);
            }

            // drop non intersection lines
            Assert.NotNull(tileEntries, "tileEntries");

            var reducedList
                = new List <BoxTree <CachedRow> .TileEntry>(tileEntries.Count);

            foreach (BoxTree <CachedRow> .TileEntry tileEntry in tileEntries)
            {
                if (tileEntry.Box.Intersects(searchGeometryBox))
                {
                    reducedList.Add(tileEntry);
                }
            }

            return(reducedList);
        }
Exemple #9
0
        private void RenderBoxes(BoxTree visualTree, Canvas drawCanvas)
        {
            drawCanvas.Children.Clear();

            var boundingRect = LayoutAlgorithm.ComputeBranchVisualBoundingRect(visualTree);

            drawCanvas.Width           = boundingRect.Size.Width;
            drawCanvas.Height          = boundingRect.Size.Height;
            drawCanvas.RenderTransform = new TranslateTransform
            {
                X = -boundingRect.Left,
                Y = -boundingRect.Top
            };

            Func <BoxTree.Node, bool> renderBox = node =>
            {
                if (node.Level == 0)
                {
                    return(true);
                }

                if (node.State.IsHidden)
                {
                    return(true);
                }


                var box   = node.Element;
                var frame = node.State;

                var branchFrameRectangle = new Rectangle
                {
                    RenderTransform =
                        new TranslateTransform {
                        X = node.State.BranchExterior.Left, Y = node.State.BranchExterior.Top
                    },
                    Width  = node.State.BranchExterior.Size.Width,
                    Height = node.State.BranchExterior.Size.Height,
                    Stroke = new SolidColorBrush(Colors.Blue)
                    {
                        Opacity = 0.6
                    },
                    StrokeThickness = 0.5,
                    DataContext     = box
                };

                var boxRectangle = new Rectangle
                {
                    RenderTransform =
                        new TranslateTransform {
                        X = frame.Left, Y = frame.Top
                    },
                    Width  = frame.Size.Width,
                    Height = frame.Size.Height,
                    Fill   = new SolidColorBrush(GetBoxFillColor(node))
                    {
                        Opacity = box.IsSpecial ? 0.1 : 1
                    },
                    Stroke = new SolidColorBrush(GetBoxStroke(box))
                    {
                        Opacity = box.IsSpecial ? 0.1 : 1
                    },
                    IsHitTestVisible = !box.IsSpecial,
                    StrokeThickness  = 1,
                    DataContext      = box
                };

                boxRectangle.DoubleTapped += BoxOnDoubleTapped;

                drawCanvas.Children.Add(boxRectangle);
                drawCanvas.Children.Add(branchFrameRectangle);

                drawCanvas.Children.Add(new TextBlock
                {
                    RenderTransform =
                        new TranslateTransform {
                        X = frame.Left + 5, Y = frame.Top + 5
                    },
                    Width            = double.NaN,
                    Height           = double.NaN,
                    Text             = box.IsSpecial ? "" : TrimText($"{box.Id} ({box.DataId})"),
                    IsHitTestVisible = false
                });

                if (!box.IsCollapsed && node.State.Connector != null)
                {
                    var solidBrush = new SolidColorBrush(Colors.Black);
                    foreach (var edge in node.State.Connector.Segments)
                    {
                        var line = new Line
                        {
                            X1               = edge.From.X,
                            Y1               = edge.From.Y,
                            X2               = edge.To.X,
                            Y2               = edge.To.Y,
                            Stroke           = solidBrush,
                            StrokeEndLineCap = PenLineCap.Round,
                            StrokeThickness  = 1,
                            IsHitTestVisible = false
                        };
                        if (box.IsSpecial)
                        {
                            var len = Math.Max(Math.Abs(line.X2 - line.X1), Math.Abs(line.Y2 - line.Y1));
                            if (len > 2)
                            {
                                line.StrokeDashArray = new DoubleCollection {
                                    2
                                };
                            }
                        }
                        drawCanvas.Children.Add(line);
                    }
                }

                return(true);
            };

            visualTree.IterateChildFirst(renderBox);
        }
Exemple #10
0
        public PartProxy([NotNull] BoxTree <SegmentProxy> boxTree,
                         int partIndex,
                         [NotNull] IPointCollection4 baseGeometry)
        {
            _partIndex       = partIndex;
            SpatialReference = ((IGeometry)baseGeometry).SpatialReference;

            _points = new WKSPointZ[baseGeometry.PointCount];
            GeometryUtils.QueryWKSPointZs(baseGeometry, _points);

            var segmentCollection = baseGeometry as ISegmentCollection;

            if (segmentCollection == null)
            {
                return;
            }

            SegmentCount = segmentCollection.SegmentCount;
            IsClosed     = ((ICurve)segmentCollection).IsClosed;

            segmentCollection.HasNonLinearSegments(ref _hasNonLinearSegs);

            if (_hasNonLinearSegs)
            {
                _nonLinearSegments = new Dictionary <int, AoSegmentProxy>();

                IEnumSegment enumSeg   = segmentCollection.EnumSegments;
                bool         recycling = enumSeg.IsRecycling;

                ISegment segment;
                int      outPartIndex    = 0;
                int      outSegmentIndex = 0;

                enumSeg.Next(out segment, ref outPartIndex, ref outSegmentIndex);

                while (segment != null)
                {
                    var          line = segment as ILine;
                    SegmentProxy segmentProxy;
                    if (line != null)
                    {
                        segmentProxy = new WksSegmentProxy(this, _partIndex, outSegmentIndex);
                    }
                    else
                    {
                        var aoSegmentProxy = new AoSegmentProxy(recycling
                                                                                                ? GeometryFactory.Clone(segment)
                                                                                                : segment,
                                                                _partIndex, outSegmentIndex);

                        _nonLinearSegments.Add(outSegmentIndex, aoSegmentProxy);
                        segmentProxy = aoSegmentProxy;
                    }

                    boxTree.Add(segmentProxy.Extent, segmentProxy);

                    if (recycling)
                    {
                        Marshal.ReleaseComObject(segment);
                    }

                    enumSeg.Next(out segment, ref outPartIndex, ref outSegmentIndex);
                }
            }
            else
            {
                int segmentCount = segmentCollection.SegmentCount;
                for (int segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++)
                {
                    var wksSegmentProxy = new WksSegmentProxy(this, _partIndex, segmentIndex);

                    boxTree.Add(wksSegmentProxy.Extent, wksSegmentProxy);
                }
            }
        }
Exemple #11
0
 public int Compare(BoxTree <TopologicalLine> .TileEntry x,
                    BoxTree <TopologicalLine> .TileEntry y)
 {
     return(CompareCore(x, y));
 }