コード例 #1
0
        private Tuple <GridPt[, ], double, int, int> CreateGridPts(Curve BOUNDARY, BoundingBox boundaryBox,
                                                                   bool BOUNDARY_IS_RECT, int FIDELITY,
                                                                   double zRange)
        {
            // Determine boundary dimensions
            var corners   = boundaryBox.GetCorners();
            var xLength   = corners[1][0] - corners[0][0];
            var yLength   = corners[2][1] - corners[0][1];
            var BOUNDARYZ = corners[0][2];
            var maxLength = Math.Sqrt(Math.Pow(xLength, 2) + Math.Pow(yLength, 2));

            // Use these to determine the number of grid points
            var gridSpacing  = Math.Max(xLength, yLength) / FIDELITY;
            var xGridExtents = (int)Math.Floor(xLength / gridSpacing);
            var yGridExtents = (int)Math.Floor(yLength / gridSpacing);

            var middlePt = new Point3d(
                corners[0][0] + xLength / 2,
                corners[0][1] + yLength / 2,
                BOUNDARYZ);

            // Start bottom left (as measured from center point)
            var startPt = new Point3d(
                middlePt[0] - gridSpacing * (xGridExtents / 2),
                middlePt[1] - gridSpacing * (yGridExtents / 2),
                BOUNDARYZ);

            double xSpacingBump;

            if (xGridExtents % 2 == 0)
            {
                xSpacingBump = gridSpacing / 2;
            }
            else
            {
                xSpacingBump = 0;
            }

            double ySpacingBump;

            if (yGridExtents % 2 == 0)
            {
                ySpacingBump = gridSpacing / 2;
            }
            else
            {
                ySpacingBump = 0;
            }

            if (zRange == 0)
            {
                zRange = Math.Max(xLength, yLength) * 0.05;
            }
            //Print("createGridPts: with a Z range of {0}", zRange);

            // Make grid points
            var gridPts = new GridPt[xGridExtents, yGridExtents];

            var i = 0;

            for (var x = 0; x < xGridExtents; x++)
            {
                for (var y = 0; y < yGridExtents; y++)
                {
                    gridPts[x, y] = new GridPt
                    {
                        Location = new Point3d(
                            startPt[0] + gridSpacing * x + xSpacingBump,
                            startPt[1] + gridSpacing * y + ySpacingBump,
                            BOUNDARYZ),
                        GridIndex            = i,
                        BaseOverlaps         = 0,
                        InterpolatedOverlaps = 0,
                        InsideBoundary       = true
                    };
                    i++;
                }
            }

            //Print("createGridPts: Making {0} columns", gridPts.GetLength(0));
            //Print("createGridPts: Making {0} rows", gridPts.GetLength(1));

            // If out boundary is not rectangular cull the points outside of it
            if (!BOUNDARY_IS_RECT)
            {
                var isOutside = PointContainment.Outside;
                for (var x = 0; x < gridPts.GetLength(0); x++)
                {
                    for (var y = 0; y < gridPts.GetLength(1); y++)
                    {
                        if (BOUNDARY.Contains(gridPts[x, y].Location) == isOutside)
                        {
                            gridPts[x, y].InsideBoundary = false;
                        }
                    }
                }
            }

            return(Tuple.Create(gridPts, zRange, xGridExtents, yGridExtents));
        }
コード例 #2
0
        private double InterpolateOverlaps(int x, int y, GridPt fromPt, GridPt[,] searchPts)
        {
            var    xExtents             = searchPts.GetLength(0);
            var    yExtents             = searchPts.GetLength(1);
            double maximumProximity     = Math.Max(xExtents, yExtents); // Farthest distance possible
            double maximumOverlaps      = 0;                            // The number of overlaps for the closest neighbour
            double interpolatedOverlaps = 0;                            // The inerpolated overlap value

            // Here i is the offset from the base position
            for (var i = 1; i < maximumProximity; i++)
            {
                //Print("#[{0},{1} iteration {2}]_______", x, y, i);

                var travelDistance  = i * 2 + 1;                // The length of the rows to find
                var offset          = (travelDistance - 1) / 2; // The amount to go in x/y directions from centerpts
                var totalNeighbours = travelDistance * 4 - 4;

                var neighbourIndices = new List <Point>();

                for (var u = 0; u < travelDistance; u++)
                {
                    neighbourIndices.Add(new Point(x - offset + u, y + offset)); // Tops
                }
                for (var u = 0; u < travelDistance; u++)
                {
                    neighbourIndices.Add(new Point(x - offset + u, y - offset)); // Bottoms
                }
                for (var u = 0; u < travelDistance - 2; u++)
                {
                    neighbourIndices.Add(new Point(x - offset, y - offset + u + 1)); // Lefts
                }
                for (var u = 0; u < travelDistance - 2; u++)
                {
                    neighbourIndices.Add(new Point(x + offset, y - offset + u + 1)); // Rights
                }
                //neighbourIndices.RemoveAll(pt => pt.X < 0);
                //neighbourIndices.RemoveAll(pt => pt.Y < 0);
                //neighbourIndices.RemoveAll(pt => pt.X > xExtents);
                //neighbourIndices.RemoveAll(pt => pt.Y > yExtents);


                // Find the maximum hit value
                for (var j = 0; j < neighbourIndices.Count; j++)
                {
                    var pt = neighbourIndices[j];
                    //Print("{0},{1}", pt.X, pt.Y);
                    // TODO: index out of range here; why?
                    //double searchPtOverlaps = searchPts[pt.X, pt.Y].BaseOverlaps;
                    //if (searchPtOverlaps > maximumOverlaps) {
                    //  maximumOverlaps = searchPtOverlaps;
                    //  Print("    Found a maximum overlap of {0} at position {1}", maximumOverlaps, neighbourIndices[j]);
                    //}
                }

                if (maximumOverlaps > 0)
                {
                    interpolatedOverlaps = (maximumProximity - i) / maximumProximity * maximumOverlaps;
                    //Print("    Setting max overlap to {0}", interpolatedOverlaps);
                    break; // Found the closest neighbour so we break
                }
            }
            return(interpolatedOverlaps);
        }