Exemplo n.º 1
0
        // -----------------------------------------------------------------
        public void TestDistanceCriteria()
        {
            var testPointList = new List <Tuple <int, int> >();

            var testFilter = new PathFilter(new PathFilter.Parameters {
                minimumDistanceBetweenPoints = 5, maximumAngleRadians = 0
            },
                                            (point) => { testPointList.Add(point); });

            testFilter.HandlePoint(new Tuple <int, int>(0, 0));                 // should be added
            testFilter.HandlePoint(new Tuple <int, int>(0, 10));                // should be added
            testFilter.HandlePoint(new Tuple <int, int>(10, 10));               // should be added
            testFilter.HandlePoint(new Tuple <int, int>(11, 11));               // should NOT be added

            // path should have added three points
            if (testPointList.Count == 3)
            {
                Console.WriteLine("PathFilter distance test passed.");
            }
            else
            {
                Console.WriteLine("PathFilter distance test FAILED.");
            }
        }
        // --------------------------------------------------------------
        private void generateSVG()
        {
            var totalPoints = 0;

            // -- quantize --
            var timer = new Timing.Timer(true);

            _data.Quantize(_contourHeights);

            timer.Stop();
            addTiming("quantization", timer.ElapsedMilliseconds);

            // ---- regions ----
            timer.ResetAndStart();

            var regionalizerSetup = new FLTDataRegionalizer.RegionalizerSetupData();

            regionalizerSetup.topoData    = _data;
            regionalizerSetup.RectIndices = this._rectIndices;

            var regionalizer = new FLTDataRegionalizer(regionalizerSetup);

            regionalizer.GenerateRegions();

            timer.Stop();
            addTiming("region discovery", timer.ElapsedMilliseconds);

            // ---- hulls ----
            Console.WriteLine("Discovering edges");

            timer.ResetAndStart();

            var regionsList = regionalizer.RegionList();

            var regionDataArray = new RegionData[regionsList.Count];

            Parallel.For(0, regionsList.Count, regionIndex =>
            {
                Boolean includeCurrentRegion = true;

                // get height of current region
                regionDataArray[regionIndex] = new RegionData {
                    height = regionsList[regionIndex].regionValue
                };

                if (regionsList[regionIndex].totalDataPoints <= _minimumRegionDataPoints)
                {
                    includeCurrentRegion = false;
                }

                if (includeCurrentRegion)
                {
                    // construct point pipeline for this region
                    regionDataArray[regionIndex].points = new List <Tuple <int, int> >();

                    RegionHullGenerator hullBuilder = null;
                    PathFilter pathFilter           = null;

                    if (_minimumDistanceBetweenPoints > 0 || _maximumAngleDeltaRadians > 0)
                    {
                        // if path options specified, put a path filter in the pipe
                        // hullBuilder -> pathFilter -> pointsListArray[regionIndex]
                        pathFilter = new PathFilter(new PathFilter.Parameters
                        {
                            minimumDistanceBetweenPoints = _minimumDistanceBetweenPoints,
                            maximumAngleRadians          = _maximumAngleDeltaRadians
                        },
                                                    (point) => { regionDataArray[regionIndex].points.Add(point); });

                        hullBuilder = new RegionHullGenerator((point) => { pathFilter.HandlePoint(point); });
                    }
                    else
                    {
                        // if no path options specified, generate straight to list
                        hullBuilder = new RegionHullGenerator((point) => { regionDataArray[regionIndex].points.Add(point); });
                    }

                    hullBuilder.generate(regionsList[regionIndex]);

                    totalPoints += regionDataArray[regionIndex].points.Count;
                }

                /*
                 * else
                 * {
                 *      regionDataArray[ regionIndex ].points = new List<Tuple<int,int>>();
                 * }
                 */
            });

            timer.Stop();
            addTiming("edge discovery", timer.ElapsedMilliseconds);

            Console.WriteLine("Generated total of " + totalPoints + " points.");

            Console.WriteLine("Building svg");

            // ---- svg ----
            timer.ResetAndStart();
            var svgBuilder = new SVGBuilder.Builder();

            // move to origin
            svgBuilder.SetTranslate(-rectLeft, -rectTop);
            // size to rect
            svgBuilder.SetWidthAndHeight(rectRight - rectLeft + 1, rectBottom - rectTop + 1);
            svgBuilder.SetBackgroundColor(_backgroundColor_Hex);

            foreach (var currentData in regionDataArray)
            {
                Int32 evenOdd = Convert.ToInt32(currentData.height / _contourHeights % 2);

                String currentPathColor = "#000000";

                if (evenOdd <= 0)
                {
                    currentPathColor = _color1_Hex;
                }
                else
                {
                    currentPathColor = _color2_Hex;
                }


                svgBuilder.addPath(currentData.points, currentPathColor);
            }

            svgBuilder.CreateFile(_outputFilename + ".svg");

            timer.Stop();
            addTiming("svg creation", timer.ElapsedMilliseconds);
        }