Exemplo n.º 1
0
        public void Test_InterceptList_MergeInterceptLists_MaximumListLength()
        {
            InterceptList list1 = new InterceptList();
            InterceptList list2 = new InterceptList();

            for (int i = 0; i < InterceptList.MaxIntercepts + 10; i++)
            {
                list1.AddPoint(new InterceptRec(i, i, i, i, i, i));
            }

            for (int i = 99; i < 199; i++)
            {
                list2.AddPoint(new InterceptRec(i, i, i, i, i + 0.5, i));
            }

            InterceptList mergedList = new InterceptList();

            mergedList.MergeInterceptLists(list1, list2);

            Assert.True(InterceptList.MaxIntercepts == mergedList.Count, $"Count not == MaxIntercepts after overfilling list ({InterceptList.MaxIntercepts } vs {mergedList.Count}");

            mergedList = new InterceptList();
            mergedList.MergeInterceptLists(list2, list1);

            Assert.True(InterceptList.MaxIntercepts == mergedList.Count, $"Count not == MaxIntercepts after overfilling list ({InterceptList.MaxIntercepts } vs {mergedList.Count}");
        }
Exemplo n.º 2
0
        public void Test_InterceptList_AddPoint_3D_Duplicate()
        {
            InterceptList list = new InterceptList();

            for (int i = 0; i < 5; i++)
            {
                list.AddPoint(1, 1, 1);
            }

            Assert.True(1 == list.Count, "List count incorrect after addition of duplicates");
        }
Exemplo n.º 3
0
        public void Test_InterceptList_AddPoint_3D_Resize()
        {
            InterceptList list = new InterceptList();

            for (int i = 0; i < InterceptList.ListInc + 5; i++)
            {
                list.AddPoint(i, i, i);
            }

            Assert.True(InterceptList.ListInc + 5 == list.Count, "List count incorrect after addition");
        }
Exemplo n.º 4
0
        public void Test_InterceptList_AddPoint2()
        {
            InterceptList list = new InterceptList();

            var newPoint = new InterceptRec(1, 2, 0, 0, 5, 0);

            list.AddPoint(newPoint);

            Assert.True(1 == list.Count, "List count not 1 after addition");
            Assert.True(list.Items[0].Equals(newPoint), "New point and list point not same after addition");
        }
Exemplo n.º 5
0
        public void Test_InterceptList_MaximumListLength()
        {
            InterceptList list = new InterceptList();

            for (int i = 0; i < InterceptList.MaxIntercepts + 10; i++)
            {
                list.AddPoint(new InterceptRec(i, i, i, i, i, i));
            }

            Assert.True(InterceptList.MaxIntercepts == list.Count, $"Count not == MaxIntercepts after overfilling list ({InterceptList.MaxIntercepts } vs {list.Count}");
        }
Exemplo n.º 6
0
        public void Test_InterceptList_MergeInterceptLists_SameItems()
        {
            InterceptList list1 = new InterceptList();
            InterceptList list2 = new InterceptList();

            var newPoint = new InterceptRec(1, 2, 3, 4, 5, 6);

            list1.AddPoint(newPoint);
            list2.AddPoint(newPoint);

            InterceptList mergedList = new InterceptList();

            mergedList.MergeInterceptLists(list1, list2);

            Assert.True(1 == mergedList.Count, $"merged list count != after merge, = {mergedList.Count}");
            Assert.Equal(newPoint, mergedList.Items[0]);
        }
Exemplo n.º 7
0
        public void Test_InterceptList_MergeInterceptLists_UniqueItems_InOrder()
        {
            InterceptList list1 = new InterceptList();
            InterceptList list2 = new InterceptList();

            var newPoint1 = new InterceptRec(1, 2, 3, 4, 5, 6);
            var newPoint2 = new InterceptRec(2, 3, 4, 5, 6, 7);

            list1.AddPoint(newPoint1);
            list2.AddPoint(newPoint2);

            InterceptList mergedList = new InterceptList();

            mergedList.MergeInterceptLists(list1, list2);

            Assert.True(2 == mergedList.Count, $"merged list count != after merge, = {mergedList.Count}");
            Assert.Equal(newPoint1, mergedList.Items[0]);
            Assert.Equal(newPoint2, mergedList.Items[1]);
        }
Exemplo n.º 8
0
        public void Test_InterceptList_MergeInterceptLists_SameItems_InExactOutOfOrder()
        {
            InterceptList list1 = new InterceptList();
            InterceptList list2 = new InterceptList();

            var newPoint1 = new InterceptRec(1.99995f, 2.99995f, 3, 4, 5.99995f, 6);
            var newPoint2 = new InterceptRec(2, 3, 4, 5, 6, 7);

            list1.AddPoint(newPoint2);
            list2.AddPoint(newPoint1);

            InterceptList mergedList = new InterceptList();

            mergedList.MergeInterceptLists(list1, list2);

            Assert.True(1 == mergedList.Count, $"merged list count != after merge, = {mergedList.Count}");
            Assert.Equal(newPoint1, mergedList.Items[0]);
            Assert.Equal(newPoint2, mergedList.Items[0]);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Calculates all intercepts between the profile line and horizontal lines separating rows of cells
        /// </summary>
        /// <param name="startStation"></param>
        private void CalculateHorizontalIntercepts(double startStation)
        {
            // Find intersections of all horizontal grid rows
            int VGridLineStartIndex = (int)Math.Truncate(StartY / CellSize);
            int VGridLineEndIndex   = (int)Math.Truncate(EndY / CellSize);
            int Increment           = Math.Sign(VGridLineEndIndex - VGridLineStartIndex);

            // To find a match, tell the intersection matching method that each
            // horizontal grid line starts 'before' the StartX parameter and 'ends'
            // after the EndX parameter - use the CellSize as an arbitrary value for this.
            // This gets around an issue where with a perfectly vertical profile line,
            // no intersections were being determined.
            double HGridStartX = StartX;
            double HGridEndX   = EndX;

            if (HGridStartX > HGridEndX)
            {
                MinMax.Swap(ref HGridEndX, ref HGridStartX);
            }

            HGridStartX = HGridStartX - CellSize;
            HGridEndX   = HGridEndX + CellSize;

            int IntersectionCount = Math.Abs(VGridLineEndIndex - VGridLineStartIndex) + 1;

            while (IntersectionCount > 0 && HzIntercepts.Count < kMaxHzVtGridInterceptsToCalculate)
            {
                if (LineIntersection.LinesIntersect(StartX, StartY, EndX, EndY,
                                                    HGridStartX, VGridLineStartIndex * CellSize,
                                                    HGridEndX, VGridLineStartIndex * CellSize,
                                                    out double IntersectX, out double IntersectY, true, out bool _))
                {
                    HzIntercepts.AddPoint(IntersectX, IntersectY,
                                          startStation + MathUtilities.Hypot(StartX - IntersectX, StartY - IntersectY));
                }

                VGridLineStartIndex += Increment;
                IntersectionCount--;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Constructs a vector of cells in profileCells along the path of the profile geometry containing in nEECoords
        /// </summary>
        public bool Build(XYZ[] nEECoords, List <T> profileCells)
        {
            NEECoords    = nEECoords;
            ProfileCells = profileCells;

            CellSize = SiteModel.CellSize;

            CurrStationPos = 0;

            CurrentSubgridOrigin  = new SubGridCellAddress(int.MaxValue, int.MaxValue);
            ReturnDesignElevation = CutFillDesignWrapper?.Design != null;
            DesignElevations      = null;

            // Obtain the primary partition map to allow this request to determine the elements it needs to process
            bool[] primaryPartitionMap = ImmutableSpatialAffinityPartitionMap.Instance().PrimaryPartitions();

            for (int loopBound = NEECoords.Length - 1, I = 0; I < loopBound; I++)
            {
                StartX       = NEECoords[I].X;
                StartY       = NEECoords[I].Y;
                StartStation = NEECoords[I].Z;

                EndX       = NEECoords[I + 1].X;
                EndY       = NEECoords[I + 1].Y;
                EndStation = NEECoords[I + 1].Z;

                if (I == 0)                                               // Add start point of profile line to intercept list
                {
                    CurrStationPos = SlicerToolUsed ? 0 : NEECoords[I].Z; // alignment profiles pass in station for more accuracy
                    VtHzIntercepts.AddPoint(StartX, StartY, CurrStationPos);
                }

                Distance = SlicerToolUsed
          ? MathUtilities.Hypot(EndX - StartX, EndY - StartY) // station is not passed so compute
          : EndStation - StartStation;                        // use precise station passed

                if (Distance == 0)                            // if we have two points the same
                {
                    continue;
                }

                // Get all intercepts between profile line and cell boundaries for this segment
                CalculateHorizontalIntercepts(CurrStationPos); // pass the distance down alignment this segment starts
                CalculateVerticalIntercepts(CurrStationPos);

                CurrStationPos += Distance; // add distance to current station
            }

            // Merge vertical and horizontal cell boundary/profile line intercepts
            VtHzIntercepts.MergeInterceptLists(VtIntercepts, HzIntercepts);

            // Add end point of profile line to intercept list
            VtHzIntercepts.AddPoint(EndX, EndY, CurrStationPos);

            // Update each intercept with it's midpoint and intercept length
            // i.e. the midpoint on the line between one intercept and the next one
            // and the length between those intercepts
            VtHzIntercepts.UpdateMergedListInterceptMidPoints();

            if (VtHzIntercepts.Count > ProfileCells.Capacity)
            {
                ProfileCells.Capacity = VtHzIntercepts.Count;
            }

            // Iterate over all intercepts calculating the results for each cell that lies in
            // a subgrid handled by this node
            for (int i = 0; i < VtHzIntercepts.Count; i++)
            {
                if (Aborted)
                {
                    return(false);
                }

                // Determine the on-the-ground cell underneath the midpoint of each intercept line
                SiteModel.Grid.CalculateIndexOfCellContainingPosition(VtHzIntercepts.Items[i].MidPointX,
                                                                      VtHzIntercepts.Items[i].MidPointY, out OTGCellX, out OTGCellY);

                ThisSubgridOrigin = new SubGridCellAddress(OTGCellX & ~SubGridTreeConsts.SubGridLocalKeyMask, OTGCellY & ~SubGridTreeConsts.SubGridLocalKeyMask);

                if (!CurrentSubgridOrigin.Equals(ThisSubgridOrigin))
                {
                    if (!primaryPartitionMap[ThisSubgridOrigin.ToSpatialPartitionDescriptor()])
                    {
                        continue;
                    }

                    CurrentSubgridOrigin = ThisSubgridOrigin;

                    if (!ProfileFilterMask.ConstructSubGridCellFilterMask(SiteModel, CurrentSubgridOrigin, VtHzIntercepts, i, FilterMask, CellFilter,
                                                                          SurfaceDesignMaskDesign))
                    {
                        continue;
                    }

                    if (ReturnDesignElevation && CutFillDesignWrapper?.Design != null) // cut fill profile request then get elevation at same spot along design
                    {
                        var getDesignHeightsResult = CutFillDesignWrapper.Design.GetDesignHeightsViaLocalCompute(SiteModel, CutFillDesignWrapper.Offset, new SubGridCellAddress(OTGCellX, OTGCellY), CellSize);

                        DesignElevations = getDesignHeightsResult.designHeights;
                        DesignResult     = getDesignHeightsResult.errorCode;

                        if (DesignResult != DesignProfilerRequestResult.OK &&
                            DesignResult != DesignProfilerRequestResult.NoElevationsInRequestedPatch)
                        {
                            continue;
                        }

                        if (DesignResult == DesignProfilerRequestResult.NoElevationsInRequestedPatch)
                        {
                            DesignElevations = null; // force a null height to be written
                        }
                    }
                }

                if (FilterMask.BitSet(OTGCellX & SubGridTreeConsts.SubGridLocalKeyMask, OTGCellY & SubGridTreeConsts.SubGridLocalKeyMask))
                {
                    AddCellPassesDataToList(OTGCellX, OTGCellY, VtHzIntercepts.Items[i].ProfileItemIndex, VtHzIntercepts.Items[i].InterceptLength);
                }
            }

            Log.LogInformation($"CellProfileBuilder constructed a vector of {VtHzIntercepts.Count} vertices");

            return(true);
        }