Ejemplo n.º 1
0
        public static WangTile[] LoadDescriptionsFromFile(StreamReader sr)
        {
            ArrayList a     = new ArrayList();
            int       count = 0;

            try
            {
                while (true)
                {
                    string   s  = sr.ReadLine();
                    WangTile wt = new WangTile(
                        count,
                        Int32.Parse(s.Substring(0, 1)),
                        Int32.Parse(s.Substring(1, 1)),
                        Int32.Parse(s.Substring(2, 1)),
                        Int32.Parse(s.Substring(3, 1)),
                        -1,
                        -1,
                        -1,
                        -1
                        );
                    count++;
                    a.Add(wt);
                }
            }
            catch (Exception) { sr.Close(); }
            WangTile[] tiles = new WangTile[a.Count];
            for (int i = 0; i < a.Count; i++)
            {
                tiles[i] = a[i] as WangTile;
            }

            return(tiles);
        }
Ejemplo n.º 2
0
 private void button4_Click(object sender, System.EventArgs e)
 {
     if (!QuiltedTextureMapValid)
     {
         MessageBox.Show("Please load a valid quilt file first.");
         return;
     }
     if (QuiltedTextureMap.Width <= (int)numericUpDownWangTileSize.Value)
     {
         MessageBox.Show("Your Wang Tiles must be smaller than your quilted image texture.");
         return;
     }
     WangTile[] wangTiles = WangTile.LoadDescriptionsFromFile(new StreamReader(new MemoryStream(System.Text.Encoding.ASCII.GetBytes(this.textBoxWangSpecs.Text))));
     WangTiles = WangTiler.WangTile(wangTiles, new Size((int)numericUpDownWangTileSize.Value, (int)numericUpDownWangTileSize.Value),
                                    new Bitmap[] { QuiltedTextureMap }, (int)numericUpDownQuiltingBlockOverlap.Value,
                                    (int)numericUpDownMaxWangMatchAttempts.Value, (int)numericUpDownMaxWangMatchError.Value,
                                    checkBoxOnePixelOverlapBetweenTiles.Checked);
     Console.WriteLine("yeah");
 }
Ejemplo n.º 3
0
 public static WangTile SelectWangTileMatching(WangTile[] wangTiles, int colorN, int colorE, int colorS, int colorW, int cornerNW, int cornerNE, int cornerSE, int cornerSW)
 {
     ArrayList a = WangTilesMatching(wangTiles, colorN, colorE, colorS, colorW, cornerNW, cornerNE, cornerSE, cornerSW);
     if (a.Count == 0)
     {
         Console.WriteLine("Warning: no wang tile found matching request: N " + colorN + " E " + colorE + " S " + colorS + " W " + colorW+ " cornerNW " + cornerNW + " cornerNE " + cornerNE + " cornerSE " + cornerSE + " cornerSW " + cornerSW + "!!!");
         return null;
     }
     else return a[r.Next(a.Count)] as WangTile;
 }
Ejemplo n.º 4
0
        public static WangTile[] LoadDescriptionsFromFile(StreamReader sr)
        {
            ArrayList a = new ArrayList();
            int count = 0;
            try
            {
                while (true)
                {
                    string s = sr.ReadLine();
                    WangTile wt = new WangTile(
                        count,
                        Int32.Parse(s.Substring(0,1)),
                        Int32.Parse(s.Substring(1,1)),
                        Int32.Parse(s.Substring(2,1)),
                        Int32.Parse(s.Substring(3,1)),
                        -1,
                        -1,
                        -1,
                        -1
                        );
                    count++;
                    a.Add(wt);
                }
            }
            catch (Exception) { sr.Close(); }
            WangTile[] tiles = new WangTile[a.Count];
            for(int i = 0; i < a.Count; i++) tiles[i] = a[i] as WangTile;

            return tiles;
        }
Ejemplo n.º 5
0
 public WangTileWithBitmapInfo(WangTile wt)
 {
     WangTile = wt;
 }
Ejemplo n.º 6
0
 public WangTileSpecification(WangTile[] tiles, Bitmap[] sourceBitmaps, bool onePixelOverlap)
 {
     WangTilesInfo = new WangTileWithBitmapInfo[tiles.Length];
     SourceBitmaps = sourceBitmaps;
     OnePixelOverlap = onePixelOverlap;
     for (int i = 0; i < tiles.Length; i++) WangTilesInfo[i] = new WangTileWithBitmapInfo(tiles[i]);
 }
Ejemplo n.º 7
0
        public static WangTile[] WangTile(WangTile[] wangTiles, Size wangTileSize, 
			Bitmap[] sourceBitmaps, int sourceBitmapBorderWidth, 
			int maxAttempts, 
			long maximumMatchingError,
			bool onePixelOverlapBetweenTiles)
        {
            Size sampleTileSize = new Size(wangTileSize.Width*3/2 + (onePixelOverlapBetweenTiles ? 1 : 0),
                wangTileSize.Height*3/2 + (onePixelOverlapBetweenTiles ? 1 : 0));

            // determine the number of Sample Portions you'll need
            int numSamplePortions = 0;
            foreach (WangTile wt in wangTiles) numSamplePortions = Math.Max(numSamplePortions, wt.MaxColorNumber);
            numSamplePortions++;

            int numAttempts = 0;
            int numSourceBitmaps = sourceBitmaps.Length;

            WangTileSpecification bestSpecification = null;
            // while you haven't found an appropriate wang tiling..
            while (numAttempts < maxAttempts && (bestSpecification == null || bestSpecification.MatchingError > maximumMatchingError) )
            {
                Util.Spew("Generating Wang Tiles, attempt " + (numAttempts+1) + " of a maximum " + maxAttempts+"...");
                Application.DoEvents();

                WangTileSpecification wts = new WangTileSpecification(wangTiles, sourceBitmaps, onePixelOverlapBetweenTiles);
                numAttempts ++;

                wts.WangTileSize = wangTileSize;
                wts.SamplePortions = new Rectangle[numSourceBitmaps, numSamplePortions];
                // Randomly select new sample portions from each bitmap.
                for (int bmp = 0; bmp < numSourceBitmaps; bmp++)
                {
                    int maxX = sourceBitmaps[bmp].Width - sampleTileSize.Width - (2*sourceBitmapBorderWidth);
                    int maxY = sourceBitmaps[bmp].Height - sampleTileSize.Height - (2*sourceBitmapBorderWidth);
                    for (int i = 0; i < numSamplePortions; i++)
                    {
                        wts.SamplePortions[bmp, i] = new Rectangle(new Point(sourceBitmapBorderWidth+r.Next(maxX), sourceBitmapBorderWidth+r.Next(maxY)), sampleTileSize);
                    }
                }

                wts.RecalcScanLines();
                if (bestSpecification == null || wts.MatchingError < bestSpecification.MatchingError)
                {
                    bestSpecification = wts;
                }
            }

            Util.Spew("Synthesizing bitmaps for best Wang Tile specification...");
            Application.DoEvents();

            bestSpecification.SynthesizeBitmaps();

            Util.Spew("Finished generating Wang Tiles.");
            Application.DoEvents();

            return bestSpecification.WangTiles;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Returns a ArrayList of Wang Tiles matching the desired requirements from the list of wangTiles passed in.
 /// -1 can be used for any parameter to indicate "don't care."
 /// </summary>
 public static ArrayList WangTilesMatching(WangTile[] wangTiles, int colorN, int colorE, int colorS, int colorW, int cornerNW, int cornerNE, int cornerSW, int cornerSE)
 {
     ArrayList possibles = new ArrayList();
     foreach (WangTile wt in wangTiles)
     {
         bool ok = true;
         ok = ok && (colorN == wt.ColorN || colorN < 0);
         ok = ok && (colorS == wt.ColorS || colorS < 0);
         ok = ok && (colorE == wt.ColorE || colorE < 0);
         ok = ok && (colorW == wt.ColorW || colorW < 0);
         ok = ok && (cornerNE == wt.CornerSW || cornerNE < 0);
         ok = ok && (cornerNW == wt.CornerSE || cornerNW < 0);
         ok = ok && (cornerSE == wt.CornerNW || cornerSE < 0);
         ok = ok && (cornerSW == wt.CornerNE || cornerSW < 0);
         if (ok) possibles.Add(wt);
     }
     return possibles;
 }
Ejemplo n.º 9
0
 public WangTileWithBitmapInfo(WangTile wt)
 {
     WangTile = wt;
 }