Пример #1
0
        public static void Zintegruj(Vector_Rectangle aObj1, Vector_Rectangle aObj2, MapFactory aMapFactory)
        {
            Vector_Rectangle obj1;
            Vector_Rectangle obj2;
            int delId;
            int colorGroupListIdx;
            ColorGroupList colorGroupList;

            if ((aObj2.parentVectorGroup == null) || (aObj1.parentVectorGroup.lpGroup < aObj2.parentVectorGroup.lpGroup))
            {
                obj1 = aObj1;
                obj2 = aObj2;
            }
            else
            {
                obj1 = aObj2;
                obj2 = aObj1;
            };

            //jeśli sąsiad jest niezintegrowany i ma taki sam kolor
            if ((obj2.parentVectorGroup == null) && (obj2.color == obj1.color))
            //dodajemy do grupy obj na którym jesteśmy
            {
                obj2.parentVectorGroup = obj1.parentVectorGroup;
                obj2.parentVectorGroupId = obj1.parentVectorGroupId;
                obj2.parentVectorGroup.lpGroup = obj1.parentVectorGroup.lpGroup;
                obj1.parentVectorGroup.Add(obj1.parentVectorGroup.Count, obj2);
            //jeśli sąsiad jest ma grupę, ale ta grupa ma takisam kolor, to
            }
            else if ((obj2.parentVectorGroup != obj1.parentVectorGroup) && (obj2.color == obj1.color))
            {
                //jeśli nasza grupa jest liczniejsza, to dodajemy grupę sąsiada do naszej
                if (obj1.parentVectorGroup.Count > obj2.parentVectorGroup.Count)
                {
                    delId = obj2.parentVectorGroupId;
                    obj1.DopiszGrupe(obj2.parentVectorGroup);
                    colorGroupListIdx = obj2.parentVectorGroup.sourceColor.ToArgb();
                }
                //jeśli grupa sąsiadaj est silniejsza, to dołączamy się do niej
                else
                {
                    delId = obj1.parentVectorGroupId;
                    obj2.DopiszGrupe(obj1.parentVectorGroup);
                    colorGroupListIdx = obj1.parentVectorGroup.sourceColor.ToArgb();
                };
                //usunięcie przepisanej grupy z listy grup
                //assert(aMapFactory.indexOf(delIdx) >== 0, 'Brak grupy do usunięcia: ' + intToStr(delIdx) + '.');
                aMapFactory.Remove(delId);

                colorGroupList = aMapFactory.vectRectGroupsByColor[colorGroupListIdx];
                colorGroupList.Remove(delId);
            };
        }
Пример #2
0
        private void btnMainThread_Click(object sender, EventArgs e)
        {
            RasterToVectorSettings rasterToVectorSettings = new RasterToVectorSettings();
            rasterToVectorSettings.ReadGeoCorners(windowSettings.leftXCoord,
                                                  windowSettings.leftYCoord,
                                                  windowSettings.rightXCoord,
                                                  windowSettings.rightYCoord);
            rasterToVectorSettings.sourceBmp = sourceBmp;
            rasterToVectorSettings.CalculateGeoPx();

            mapFactory = RasterToVectorRunner.RunRasterToVectorMainThread(rasterToVectorSettings);
            desinationImageCrooper = new VectorImageCrooper(new Size(sourcePanel.Width, sourcePanel.Height), mapFactory,
                                                            sourceImageCropper.centerX, sourceImageCropper.centerY, windowSettings);

            DrawCroppedScaledImage(float.Parse(ScaleTB.Text));
        }
Пример #3
0
        private void btnMainThread_Click(object sender, EventArgs e)
        {
            R2VSettings r2vSettings = new R2VSettings();
            r2vSettings.ReadGeoCorners(windowSettings.leftXCoord,
                                       windowSettings.leftYCoord,
                                       windowSettings.rightXCoord,
                                       windowSettings.rightYCoord);
            r2vSettings.sourceBmp = posterizedBmp;
            r2vSettings.CalculateGeoPx();
            r2vSettings.sliceWidth = windowSettings.sliceWidthVect;
            r2vSettings.sliceHeight = windowSettings.sliceHeightVect;
            r2vSettings.simplifyPhase1 = windowSettings.SimplifyPhase1();
            r2vSettings.simplifyPhase2 = windowSettings.SimplifyPhase2();
            r2vSettings.simplifyPhase3 = windowSettings.SimplifyPhase3();

            mapFactory = R2VRunner.RunR2VMainThread(r2vSettings, new UpdateInfoBoxTimeDelegate(UpdateInfoBoxTime));
            desinationImageCropper = new VectorImageCrooper(new Size(posterizedPanel.Width, posterizedPanel.Height), mapFactory,
                                                            posterizedImageCropper.centerX, posterizedImageCropper.centerY,
                                                            windowSettings, posterizedBmp);

            DrawCroppedScaledImage(float.Parse(txtScaleLvlVect.Text), UpdateInfoBoxTime);
        }
Пример #4
0
 public VectorImageCrooper(Size aPanelSize, MapFactory aMapFactory, int aCenterX, int aCenterY, MainWindowSettings aSettings)
     : base(aPanelSize, 0, 0)
 {
     mapFactory = aMapFactory;
     settings = aSettings;
     if (aMapFactory != null)
     {
         srcBmpWidth = aMapFactory.vectArr.Length;
         Debug.Assert(aMapFactory.vectArr[0] != null, "aMapFactory.vectArr[0] jest null");
         srcBmpHeight = aMapFactory.vectArr[0].Length;
     }
     centerX = aCenterX;
     centerY = aCenterY;
 }
Пример #5
0
 private void btnStartR2V_Click_1(object sender, EventArgs e)
 {
     Debug.Assert(sourceBmp != null, "Nie wgrano obrazu źródłowego.");
     RasterToVectorSettings rasterToVectorSettings = new RasterToVectorSettings{ sourceBmp = sourceBmp };
     rasterToVectorSettings.ReadGeoCorners(windowSettings.leftXCoord, windowSettings.leftYCoord, windowSettings.rightXCoord, windowSettings.rightYCoord);
     if (rbMainThread.Checked)
     {
         mapFactory = RasterToVectorRunner.RunRasterToVectorMainThread(rasterToVectorSettings);
        // Bitmap res = mapFactory.getBitmap(new Rectangle(0, 0, sourceBmp.Width, sourceBmp.Height));
     }
     else if (rbSeparateThread.Checked)
     {
         RasterToVectorRunner.RunRasterToVectorSeparateThread();
     }
     else
     {
         Debug.Assert(false, "Oba: Main i Separate = false");
     }
 }
Пример #6
0
        //HEY!  groups[index] = subexpression for regexpression.
        public static Map CreateMap(Game game, Texture2D spriteMap, String[] gameDesc)
        {
            Map ret = null;

            //int subMapCounter = 0;
            Regex tileRegex = new Regex(@"t (?:(\d+),(\d+)) (?:(\d+),(\d+)|null) (?:(\d+),(\d+)|null) (true)?");    //This is looking at specific locations in the original tile map.  The 2nd to last entry is a 'refernce' to be used for the submap, and the string is a reference to determine what the tile corresponds to.
            Regex subMapRegex = new Regex(@"(\d+)\-(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)  ?(\d+)"); //This is defined to be the tiles specified for a submap
            Regex mapDefine = new Regex(@"md (\d+) (\d+)"); //This is defined as the dimensions of the map.
            //Regex subMapModeRegex = new Regex(@"(?:(\d),(\d)|null) (?:(\d),(\d)|null) (?:(\d),(\d)|null) (true|false)");
            Regex mapSet = new Regex(@"ms (\d+) (\d+) (\d+)");
            //Regex mapCreate = new Regex(
            //Regex tileRegex = new Regex(@"(?:(\d),(\d)|null) (?:(\d),(\d)|null) (?:(\d),(\d)|null) (true|false)");
            MatchCollection matches;
            MapFactory mapFact = null;
            TileFactory tiles = new TileFactory(spriteMap);
            SubMapFactory subMaps = new SubMapFactory(tiles);

            //For each string of lines in the textual map
            foreach (String line in gameDesc)
            {
                //If this is defined to be a map,
                if (mapDefine.IsMatch(line))
                {
                    matches = mapDefine.Matches(line);
                    mapFact = new MapFactory(subMaps, int.Parse(matches[0].Groups[1].Value), int.Parse(matches[0].Groups[2].Value));
                }

                //If it is information for a tile,
                else if (tileRegex.IsMatch(line))
                {
                    matches = tileRegex.Matches(line);  //Collection of matches based on regex

                    //[1],[2] = first set of (\d+),(\d+)
                    tiles.SetBaseSprite(new Rectangle(int.Parse(matches[0].Groups[1].Value) * 32, int.Parse(matches[0].Groups[2].Value) * 32, 32, 32));

                    //[3] [4] = second set of (\d+),(\d+).  Most often, both are null.
                    if (matches[0].Groups[3].Success)
                    {
                        tiles.SetAccentSprite(new Rectangle(int.Parse(matches[0].Groups[3].Value) * 32, int.Parse(matches[0].Groups[4].Value) * 32, 32, 32));
                    }

                    //[5] = passability [6] = third set of (\d+),(\d+).  Most often, both are null.
                    if (matches[0].Groups[5].Success)
                    {
                        tiles.SetTopSprite(new Rectangle(int.Parse(matches[0].Groups[5].Value) * 32, int.Parse(matches[0].Groups[6].Value) * 32, 32, 32));
                    }

                    //[7] = Passability
                    tiles.SetPassible(matches[0].Groups[7].Success);
                    tiles.AddTile();
                }

                //Or if it is information for a submap,
                else if (subMapRegex.IsMatch(line))
                {
                    matches = subMapRegex.Matches(line);

                    //From the first tile entry onward...
                    for (int x = 0; x < 32; x++)
                    {
                        //[2] = row entry, [x+3] = col entry, [1] = sub-map
                        subMaps.setTile(x, int.Parse(matches[0].Groups[2].Value), int.Parse(matches[0].Groups[x + 3].Value), int.Parse(matches[0].Groups[1].Value));
                    }
                    if (int.Parse(matches[0].Groups[1].Value) == 31) subMaps.AddSubMap();
                }

                //If it is defined for a specific submap (Submap 1-2, Submap 2-2, etc...),
                else if (mapSet.IsMatch(line))
                {
                    matches = mapSet.Matches(line);
                    mapFact.setSubSector(int.Parse(matches[0].Groups[1].Value), int.Parse(matches[0].Groups[2].Value), int.Parse(matches[0].Groups[3].Value));
                }
                else
                {
                    throw new System.ArgumentException("Line does not match known regex lines", "line");
                }
            }

            //Generate the sprite map based on the map returned.  spriteMap is the 2D map used as a reference.
            ret = mapFact.generate(spriteMap);
            return ret;
        }