Ejemplo n.º 1
0
        // --------------------------------------------------------------------------------
        private void Test_SingleColumnRegionIsIgnoredByHullBuilder()
        {
            Console.WriteLine("Testing single column region is ignored");

            if (false == _data.isQuantized)
            {
                _data.Quantize(_contourHeights);
            }

            _data.SetRegionToHeight(0, 0, 100, 0, 100.0f);

            var regionalizerSetup = new FLTDataRegionalizer.RegionalizerSetupData();

            regionalizerSetup.topoData = _data;

            var testRectIndices = new int[4];

            testRectIndices[RectLeftIndex]   = 0;
            testRectIndices[RectTopIndex]    = 0;
            testRectIndices[RectRightIndex]  = 0;
            testRectIndices[RectBottomIndex] = 100;
            regionalizerSetup.RectIndices    = testRectIndices;

            var regionalizer = new FLTDataRegionalizer(regionalizerSetup);

            regionalizer.GenerateRegions();

            var regionList = regionalizer.RegionList();

            // expect 1 region here (not really the test, I know, should make a test for this)
            // there's actually a bug in this
            if (regionList.Count != 1)
            {
                Console.WriteLine("FAILED (unexpected number of regions (" + regionList.Count + ") in test data)");
                return;
            }
            else
            {
                /*
                 * var hullBuilder = new RegionHullBuilder();
                 *
                 * var pointsList = hullBuilder.generate(regionList[0]);
                 *
                 * if (pointsList.Count == 0)
                 * {
                 *      Console.WriteLine("PASSED");
                 * }
                 * else
                 * {
                 *      Console.WriteLine("FAILED (unexpected number of regions ("+ pointsList.Count +") in test data");
                 * }
                 */
            }
        }
        // --------------------------------------------------------------
        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);
        }