]> marstr Code Repo - orthographic/commitdiff
Made forest lines look much more natural, adjusted coloring of some roads and streets...
authormarstr <marcus@marstr.online>
Thu, 29 Aug 2024 20:46:49 +0000 (22:46 +0200)
committermarstr <marcus@marstr.online>
Thu, 29 Aug 2024 20:46:49 +0000 (22:46 +0200)
16 files changed:
Textures/landuse/grass/brd/b5.png [new file with mode: 0644]
Textures/landuse/grass/ptc/b5_p1.png [new file with mode: 0644]
Textures/landuse/grass/ptc/b5_p2.png [new file with mode: 0644]
Textures/tile/completion/p1.png [new file with mode: 0644]
Textures/tile/completion/p2.png [new file with mode: 0644]
Textures/tile/completion/p3.png [new file with mode: 0644]
Textures/tile/completion/p4.png [new file with mode: 0644]
Textures/tile/completion/p5.png [new file with mode: 0644]
Textures/tile/completion/p6.png [new file with mode: 0644]
Textures/tile/completion/p7.png [new file with mode: 0644]
defines.py
functions.py
layergen.py
maskgen.py
orthographic.py
photogen.py

diff --git a/Textures/landuse/grass/brd/b5.png b/Textures/landuse/grass/brd/b5.png
new file mode 100644 (file)
index 0000000..31bb2b1
Binary files /dev/null and b/Textures/landuse/grass/brd/b5.png differ
diff --git a/Textures/landuse/grass/ptc/b5_p1.png b/Textures/landuse/grass/ptc/b5_p1.png
new file mode 100644 (file)
index 0000000..841c7f2
Binary files /dev/null and b/Textures/landuse/grass/ptc/b5_p1.png differ
diff --git a/Textures/landuse/grass/ptc/b5_p2.png b/Textures/landuse/grass/ptc/b5_p2.png
new file mode 100644 (file)
index 0000000..5c52a3f
Binary files /dev/null and b/Textures/landuse/grass/ptc/b5_p2.png differ
diff --git a/Textures/tile/completion/p1.png b/Textures/tile/completion/p1.png
new file mode 100644 (file)
index 0000000..c104aba
Binary files /dev/null and b/Textures/tile/completion/p1.png differ
diff --git a/Textures/tile/completion/p2.png b/Textures/tile/completion/p2.png
new file mode 100644 (file)
index 0000000..25ed556
Binary files /dev/null and b/Textures/tile/completion/p2.png differ
diff --git a/Textures/tile/completion/p3.png b/Textures/tile/completion/p3.png
new file mode 100644 (file)
index 0000000..8058fbd
Binary files /dev/null and b/Textures/tile/completion/p3.png differ
diff --git a/Textures/tile/completion/p4.png b/Textures/tile/completion/p4.png
new file mode 100644 (file)
index 0000000..4915bab
Binary files /dev/null and b/Textures/tile/completion/p4.png differ
diff --git a/Textures/tile/completion/p5.png b/Textures/tile/completion/p5.png
new file mode 100644 (file)
index 0000000..4ab4b7f
Binary files /dev/null and b/Textures/tile/completion/p5.png differ
diff --git a/Textures/tile/completion/p6.png b/Textures/tile/completion/p6.png
new file mode 100644 (file)
index 0000000..24d18d4
Binary files /dev/null and b/Textures/tile/completion/p6.png differ
diff --git a/Textures/tile/completion/p7.png b/Textures/tile/completion/p7.png
new file mode 100644 (file)
index 0000000..295f0fd
Binary files /dev/null and b/Textures/tile/completion/p7.png differ
index 22c8909ff3f96bf39c276f2d58d66f0058da1fcb..4050009dbe4e9a91fcaca02a84a888e00751d5aa 100644 (file)
@@ -95,6 +95,7 @@ mstr_ortho_layers = [
     ("landuse", "farmyard", "landuse", "farmland"),
     ("landuse", "military", "landuse", "residential-boundary"),
     # Z-Order 2
+    ("highway", "service", 6),
     ("waterway", "river", 10),
     ("waterway", "stream", 10),
     ("leisure", "nature_reserve", "landuse", "forest"),
@@ -113,10 +114,9 @@ mstr_ortho_layers = [
     ("highway", "primary", 25),
     ("highway", "secondary", 13),
     ("highway", "tertiary", 20),
-    ("highway", "unclassified", 12),
+    ("highway", "unclassified", 17),
     ("highway", "living_street", 12),
     ("highway", "residential", 12),
-    ("highway", "service", 6),
     ("highway", "footway", 4),
     ("railway", "rail", 5),
     # Z-Order 5
@@ -176,11 +176,11 @@ mstr_mask_blur = [
     ("highway", "primary", 5),
     ("highway", "secondary", 5),
     ("highway", "tertiary", 5),
-    ("highway", "unclassified", 10),
-    ("highway", "living_street", 10),
-    ("highway", "residential", 10),
-    ("highway", "service", 5),
-    ("highway", "footway", 5),
+    ("highway", "unclassified", 5),
+    ("highway", "living_street", 5),
+    ("highway", "residential", 5),
+    ("highway", "service", 3),
+    ("highway", "footway", 3),
     ("highway", "track", 3),
     ("highway", "path", 3),
     ("railway", "rail", 4),
index cc89aeba37e8d67f4cf6900f692326a1f2da6973..b731d4ed62c3b8aadbe24591119c1ca293c841ac 100644 (file)
@@ -58,4 +58,11 @@ def findZL16tiles(v, h):
             tr.append(tl)
         tiles.append(tr)
     
-    return tiles
\ No newline at end of file
+    return tiles
+
+
+
+# Testing
+def in_circle(center_x, center_y, radius, x, y):
+    square_dist = (center_x - x) ** 2 + (center_y - y) ** 2
+    return square_dist <= radius ** 2
\ No newline at end of file
index da6d32a73bc3a3064ba95ef6d39ca21d9b62832d..db1774d4502b3f2af11b860bace3a7f4a4d9417d 100644 (file)
@@ -16,11 +16,12 @@ import glob
 import os
 from random import randrange
 import random
-from PIL import Image, ImageFilter
+from PIL import Image, ImageFilter, ImageDraw, ImagePath
 from defines import *
 from log import *
 from tiledb import *
 from osmxml import *
+from functions import *
 
 class mstr_layergen:
 
@@ -204,6 +205,27 @@ class mstr_layergen:
             osm_edge = osm_edge.filter(ImageFilter.MaxFilter)
             mstr_msg("mstr_layergen", "Edge mask generated")
 
+            # This adds some natural looking shapes to these types of features
+            if self._value == "forest" or self._value == "nature_reserve":
+                epx = osm_edge.load()
+                imgd = ImageDraw.Draw(osm_mask)
+
+                # Walk through a grid of 200x200 - on the edge image
+                for y in range(0, osm_mask.height, int(osm_mask.height/200)):
+                    for x in range(0, osm_mask.width, int(osm_mask.width/200)):
+                        px = epx[x,y]
+                        if px[3] == 255:
+                            rx = randrange(30,60)
+                            ry = randrange(30,60)
+                            f = randrange(1,10)
+                            
+                            # Do some magic
+                            if f != 5:
+                                imgd.ellipse((x-int(rx/2), y-int(ry/2), x+rx, y+ry), fill="black")
+                            if f == 3 or f == 7:
+                                imgd.ellipse((x-int(rx/2), y-int(ry/2), x+rx, y+ry), fill=(0,0,0,0))
+
+
             # We need to change the image in certain conditions
             if self._value == "hedge" and self._tag == "barrier":
                 osm_mask = osm_edge
@@ -229,6 +251,18 @@ class mstr_layergen:
                 layer.alpha_composite( ptc_src[imgid], ( randrange(l, r), randrange(t, b) ) )
             mstr_msg("mstr_layergen", "Layer image generated")
 
+
+            # Here we need to do some magic to make some features look more natural
+            if (self._tag == "landuse" and self._value == "meadow") or (self._tag == "natural" and self._value == "grassland") or (self._tag == "natural" and self._value == "heath"):
+                amt = randrange(1,3)
+                for i in range(1, amt):
+                    ptc = randrange(1, 7)
+                    img = Image.open(mstr_datafolder + "Textures\\tile\\completion\\p" + str(ptc)+".png")
+                    lx = randrange( int(layer.width/20), layer.width - (int(layer.width/20)) - img.width ) 
+                    ly = randrange( int(layer.width/20), layer.width - (int(layer.width/20)) - img.width )
+                    layer.alpha_composite( img, (lx, ly) ) 
+
+
             # We now need to add the seamless border
             layer.alpha_composite( brd_src )
             mstr_msg("mstr_layergen", "Layer image completed")
@@ -259,17 +293,6 @@ class mstr_layergen:
                     layer_border = self.genborder(osm_edge, "landuse", "meadow")
                     layer_comp.alpha_composite(layer_border)
 
-            # If this is the completion layer, we may add some aditional patches to the image
-            # for more realism
-            if self._is_completion == True:
-                cl = randrange(1, 10)
-                for i in range(1, cl):
-                    p = randrange(1, 2)
-                    ptc = Image.open(mstr_datafolder + "Textures\\tile\\completion\\p"+str(p)+".png")
-                    rdx = randrange(1, self._imgsize-1-ptc.width)
-                    rdy = randrange(1, self._imgsize-1-ptc.height)
-                    layer_comp.alpha_composite(ptc, (rdx, rdy))
-
 
             # Store layer
             if self._is_completion == False:
@@ -403,9 +426,15 @@ class mstr_layergen:
                         if self._tag == "railway":
                             d = randrange(41, 61)
                             layer_comp_pix[x, y] = ( d,d,d,a[3] )
-                        if self._tag == "highway":
-                            d = randrange(160,180)
+                        if self._tag == "highway" and self._value != "motorway":
+                            d = randrange(140,160)
                             layer_comp_pix[x, y] = ( d,d,d,a[3] )
+                        if self._tag == "highway" and self._value == "motorway":
+                            d = randrange(1,20)
+                            r = 86-d
+                            g = 97-d
+                            b = 106-d
+                            layer_comp_pix[x, y] = ( r,g,b,a[3] )
                         if self._tag == "waterway" and (self._value == "stream" or self._value == "river"):
                             d = randrange(1, 15)
                             layer_comp_pix[x, y] = ( 129-d, 148-d, 159-d, a[3] )
@@ -462,7 +491,7 @@ class mstr_layergen:
                     mstr_msg("mstr_layergen", "Shadow layer completed")
             
             # Highways and runways of any kind get some special treatment
-            if (self._tag == "highway" and self._value == "motorway") or (self._tag == "aeroway" and self._value == "runway"):
+            if (self._tag == "highway" and self._value == "motorway") or (self._tag == "highway" and self._value == "unclassified") or (self._tag == "aeroway" and self._value == "runway"):
                 # We will now add some white lines for coolness
                 mask_pix = osm_edge.load()
                 layer_comp_pix = layer_comp.load()
index 4c4a97a4751ebf86733f15e158a3f668367db13b..c762778a48baeab6b55b7be4acb02c88a716773e 100644 (file)
@@ -26,6 +26,8 @@ from osmxml import *
 from defines import *
 from log import *
 from PIL import Image, ImageFilter, ImageDraw, ImagePath
+from random import randrange
+import random
 
 class mstr_maskgen:
 
@@ -174,7 +176,7 @@ class mstr_maskgen:
                         if mstr_ortho_layers[i][0] == self._tag and mstr_ortho_layers[i][1] == self._value:
                             idx = i
                             break
-                    imgd.line(pts, fill="#000000", width=mstr_ortho_layers[idx][2])
+                    imgd.line(pts, fill="#000000", width=mstr_ortho_layers[idx][2], joint="curve")
         
         # Save image
         mask_img.save(mstr_datafolder + "_cache\\" + fstr + "_" + self._tag + "-" + self._value + ".png")
@@ -184,7 +186,7 @@ class mstr_maskgen:
 
 #mg = mstr_maskgen([51, 1, 7, 1], 0.0100691262567974, "natural", "bare_rock")
 #mg = mstr_maskgen([51, 1, 7, 1], 0.0100691262567974, "highway", "track")
-#mg = mstr_maskgen([51, 1, 7, 1], 0.0100691262567974, "landuse", "forest")
+#mg = mstr_maskgen([51, 1, 7, 1], 0.0100691262567974, "landuse", "forest", False)
 #mg = mstr_maskgen([51, 1, 7, 1], 0.0100691262567974, "natural", "water")
 #mg = mstr_maskgen([51, 1, 7, 1], 0.0100691262567974, "leisure", "golf_course")
 #mg = mstr_maskgen([51, 2, 7, 5], 0.0100691262567974, "boundary", "administrative", "admin_level", ["6"])
index 42c904a93c6935532bc42cf8393f0b4ed463bf2b..65b1959d42a21a5fe7785d2aba119115949201b5 100644 (file)
@@ -118,7 +118,11 @@ class mstr_orthographic:
                         os.makedirs(self._output + "/Tiles/"+str(self._lat)+"_"+str(self._long)+"\\terrain")
                         mstr_msg("mstr_orthographic", "Created tile terrain folder")
 
+                    curlyr = 1
                     for layer in layers:
+                        # Let the user know
+                        mstr_msg("mstr_orthographic", "Processing layer " + str(curlyr) + " of " + str(len(layers)))
+
                         # Generate the mask
                         mg = mstr_maskgen( [self._lat, cur_tile_y, self._long, cur_tile_x], self._vstep, layer[0], layer[1], layer[2] )
                         mg._build_mask()
@@ -126,6 +130,7 @@ class mstr_orthographic:
                         # Generate the layer
                         lg = mstr_layergen(layer[0], layer[1], self._lat, cur_tile_y, self._long, cur_tile_x, layer[2])
                         lg.genlayer()
+                        curlyr = curlyr+1
                     mstr_msg("mstr_orthographic", "All layers created")
 
                     # We should have all layers now.
index 5e1995191a1b5184c35c81aa67290f2041cd8b63..870ca7c183502e09ea6459826e7fe8e0371d1ad0 100644 (file)
@@ -73,7 +73,7 @@ class mstr_photogen:
         # aforementioned fix:
         if emptyspace == True:
             # Choose a suitable layer type
-            lt = [5,14,15]
+            lt = [6,14,17]
             pick = randrange(0,len(lt)-1)
             ltp = lt[pick]
             tag   = mstr_ortho_layers[ltp][0]