Special Aircraft Service

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3   Go Down

Author Topic: Terrain height map generator for slibenli  (Read 8098 times)

0 Members and 1 Guest are viewing this topic.

Stainless

  • moderator
  • member
  • Offline Offline
  • Posts: 1534
Terrain height map generator for slibenli
« on: November 23, 2019, 08:45:01 AM »

As requested I am writing a new tool, this thread will be the documentation for it and hold the download link when it is finished.

So here we go....


1) Boot up the app.  It's windows wpf



2) The first time you run the app you need to set the directory you want to store all the SRTM data. So Options SRTM Directory
 You can either type in the directory or use the browse button.
 Note, WPF does not have a folder browser dialog, so I cheated and used the save file dialog.



3) Create a new project.
    You can either fill in the fields by hand or you can use the pick location button



The pick button will open a new window and display google maps.

Click on the map where you want the top left of the IL2 map to be. You will see the latitude and longitude popup in a little window.



Click on the latitude and longitude.



Then cut and paste the coordinates into the text boxes.



4) Save your project!!!

 The download can take a very long time, so save the project. The download will resume from where it left off as long as you delete any bad zip files.



5) Start the map generation. Actions Generate Map

The display will change and show a list of SRTM files needed for the project. Now SRTM files do not exist for areas of the world that are totally ocean, so some files will never be downloaded. Don't worry about it.
If the zip file already exists on the disk, it won't download it again.
If the download times out, it will retry. It will retry a lot. Hence saving your project is a good idea.
Once all the zip files are downloaded, the app will extract the contents into the directory.
 


Now the app will work through all the SRTM files loading in the height map data to form a virtual height map much bigger than IL2 can handle

SRTM data uses -32768 as a special value which means "we don't have any data for this region", so I scan all the data and if I find this value I sample a 3 by 3 area around it and put an average value in this data point.

Then it builds the requested image as signed 16 bit values in metres.

It have put a simple screen in so you know it hasn't crashed.



Finally it creates a false colour image to show you the region covered by the map.



I had to do this as most terrain we are interested in is a lot lower than 5000m , and hence damn near black.

You are then free to save the generated height map from the action menu.

I have PNG , TGA , and also IL2 format.

I.E. The height is mapped to 0-255 using the height equation used by IL2. This is basically you map_h


Created a repository for it.

https://github.com/PaulBlythe/IL2Tools

Logged

slibenli

  • member
  • Offline Offline
  • Posts: 619
    • IL-2 Graphics Extender
Re: Terrain height map generator for slibenli
« Reply #1 on: November 24, 2019, 05:56:17 PM »

Thank you for doing this!

There is one possible problem.
You're using wpf, which means the app will probably not run in linux (which I use for developing - actually I currently don't have a working windows installation). So I would need to setup a vm.
The question is whether that would be more productive (in the long run, as I would need to keep that vm running and updated - all drawing system resources) than porting the gui code to some other framework (which I would do, if you gave me the source).

BTW: I tried to load a 16000*16000 px height map in il2ge - unsuccessfully. At least for now the maximum size is 8000*8000 px.

Stainless

  • moderator
  • member
  • Offline Offline
  • Posts: 1534
Re: Terrain height map generator for slibenli
« Reply #2 on: November 25, 2019, 04:29:47 AM »

Linux..... man I have 7 machines set up here and the only one that runs Linux is the raspberry pi  :)

I work in C# for tools because you have so much already done for you.

Multithreading Trivial
Parrallel programmingTrivial
User interface Trivial
CollectionsTrivial
Image loadingTrivial

The list just goes on.

To convert this to Linux is a major task.

Let me think about what I can do. I have a laptop here I don't need, but it has a Swedish keyboard....
Logged

slibenli

  • member
  • Offline Offline
  • Posts: 619
    • IL-2 Graphics Extender
Re: Terrain height map generator for slibenli
« Reply #3 on: November 25, 2019, 06:58:21 AM »

C# as such shouldn't be a problem, as long as you don't use Windows-only stuff like Windows Forms or WPF.
I figure that the amount of GUI-specific code in the tool is relatively small(?)
With porting to another framework I meant porting that GUI-specific code to another (C# based) framework, like Qml.Net (https://qmlnet.github.io/introduction/) for example.

Hmm, I'll google what Swedish keyboard looks like ;)
Edit: OK it's a qwerty layout - that's good for me :)



Stainless

  • moderator
  • member
  • Offline Offline
  • Posts: 1534
Re: Terrain height map generator for slibenli
« Reply #4 on: November 26, 2019, 01:28:38 PM »

This is the map saved as an IL2 map_h file


Logged

slibenli

  • member
  • Offline Offline
  • Posts: 619
    • IL-2 Graphics Extender
Re: Terrain height map generator for slibenli
« Reply #5 on: November 27, 2019, 02:41:54 AM »

Those red areas are negative elevations?

Stainless

  • moderator
  • member
  • Offline Offline
  • Posts: 1534
Re: Terrain height map generator for slibenli
« Reply #6 on: November 27, 2019, 03:48:44 AM »

Yes.

I used a mapping table from a different thread.

There's a spreadsheet knocking about that defines height range and pixel colour.

I don't like it. It has errors in it which I have patched into this table

Code: [Select]
MapRecord[] map = new MapRecord[]
        {
            new MapRecord( -100  ,-1 ,255,   0,  0 ),
            new MapRecord(0 ,0  ,0  ,0  ,0),
            new MapRecord(1 ,1  ,1  ,1  ,1),
            new MapRecord(2 ,2  ,2  ,2  ,2),
            new MapRecord(3 ,3  ,3  ,3  ,3),
            new MapRecord(4 ,4  ,4  ,4  ,4),
            new MapRecord(5 ,5  ,5  ,5  ,5),
            new MapRecord(6 ,6  ,6  ,6  ,6),
            new MapRecord(7 ,7  ,7  ,7  ,7),
            new MapRecord(8 ,8  ,8  ,8  ,8),
            new MapRecord(9 ,9  ,9  ,9  ,9),
            new MapRecord(10 ,10 ,10 ,10 ,10 ),
            new MapRecord(11    ,11 ,11 ,11 ,11),
            new MapRecord(12    ,12 ,12 ,12 ,12),
            new MapRecord(13    ,13 ,13 ,13 ,13),
            new MapRecord(14    ,14 ,14 ,14 ,14),
            new MapRecord(15    ,15 ,15 ,15 ,15),
            new MapRecord(16    ,16 ,16 ,16 ,16),
            new MapRecord(17    ,17 ,17 ,17 ,17),
            new MapRecord(18    ,18 ,18 ,18 ,18),
            new MapRecord(19    ,19 ,19 ,19 ,19),
            new MapRecord(20    ,20 ,20 ,20 ,20),
            new MapRecord(21    ,21 ,21 ,21 ,21),
            new MapRecord(22    ,22 ,22 ,22 ,22),
            new MapRecord(23    ,23 ,23 ,23 ,23),
            new MapRecord(24    ,24 ,24 ,24 ,24),
            new MapRecord(25    ,25 ,25 ,25 ,25),
            new MapRecord(26    ,26 ,26 ,26 ,26),
            new MapRecord(27    ,27 ,27 ,27 ,27),
            new MapRecord(28    ,28 ,28 ,28 ,28),
            new MapRecord(29    ,29 ,29 ,29 ,29),
            new MapRecord(30    ,30 ,30 ,30 ,30),
            new MapRecord(31    ,31 ,31 ,31 ,31),
            new MapRecord(32    ,32 ,32 ,32 ,32),
            new MapRecord(33    ,33 ,33 ,33 ,33),
            new MapRecord(34    ,34 ,34 ,34 ,34),
            new MapRecord(35    ,35 ,35 ,35 ,35),
            new MapRecord(36    ,36 ,36 ,36 ,36),
            new MapRecord(37    ,37 ,37 ,37 ,37),
            new MapRecord(38    ,38 ,38 ,38 ,38),
            new MapRecord(39    ,39 ,39 ,39 ,39),
            new MapRecord(40    ,40 ,40 ,40 ,40),
            new MapRecord(41    ,41 ,41 ,41 ,41),
            new MapRecord(42    ,42 ,42 ,42 ,42),
            new MapRecord(43    ,43 ,43 ,43 ,43),
            new MapRecord(44    ,44 ,44 ,44 ,44),
            new MapRecord(45    ,45 ,45 ,45 ,45),
            new MapRecord(46    ,46 ,46 ,46 ,46),
            new MapRecord(47    ,47 ,47 ,47 ,47),
            new MapRecord(48    ,48 ,48 ,48 ,48),
            new MapRecord(49    ,49 ,49 ,49 ,49),
            new MapRecord(50    ,50 ,50 ,50 ,50),
            new MapRecord(51    ,51 ,51 ,51 ,51),
            new MapRecord(52    ,52 ,52 ,52 ,52),
            new MapRecord(53    ,53 ,53 ,53 ,53),
            new MapRecord(54    ,54 ,54 ,54 ,54),
            new MapRecord(55    ,55 ,55 ,55 ,55),
            new MapRecord(56    ,56 ,56 ,56 ,56),
            new MapRecord(57    ,57 ,57 ,57 ,57),
            new MapRecord(58    ,58 ,58 ,58 ,58),
            new MapRecord(59    ,59 ,59 ,59 ,59),
            new MapRecord(60    ,60 ,60 ,60 ,60),
            new MapRecord(61    ,61 ,61 ,61 ,61),
            new MapRecord(62    ,62 ,62 ,62 ,62),
            new MapRecord(63    ,63 ,63 ,63 ,63),
            new MapRecord(64    ,64 ,64 ,64 ,64),
            new MapRecord(65    ,66 ,65 ,65 ,65),
            new MapRecord(67    ,68 ,66 ,66 ,66),
            new MapRecord(69    ,70 ,67 ,67 ,67),
            new MapRecord(71    ,72 ,68 ,68 ,68),
            new MapRecord(73    ,74 ,69 ,69 ,69),
            new MapRecord(75    ,76 ,70 ,70 ,70),
            new MapRecord(77    ,78 ,71 ,71 ,71),
            new MapRecord(79    ,80 ,72 ,72 ,72),
            new MapRecord(81    ,82 ,73 ,73 ,73),
            new MapRecord(83    ,84 ,74 ,74 ,74),
            new MapRecord(85    ,86 ,75 ,75 ,75),
            new MapRecord(87    ,88 ,76 ,76 ,76),
            new MapRecord(89    ,90 ,77 ,77 ,77),
            new MapRecord(91    ,92 ,78 ,78 ,78),
            new MapRecord(93    ,94 ,79 ,79 ,79),
            new MapRecord(95    ,96 ,80 ,80 ,80),
            new MapRecord(97    ,98 ,81 ,81 ,81),
            new MapRecord(99    ,100,82 ,82 ,82),
            new MapRecord(101,  102 ,83 ,83 ,83),
            new MapRecord(103,  104 ,84 ,84 ,84),
            new MapRecord(105,  106 ,85 ,85 ,85),
            new MapRecord(107,  108 ,86 ,86 ,86),
            new MapRecord(109,  110 ,87 ,87 ,87),
            new MapRecord(111,  112 ,88 ,88 ,88),
            new MapRecord(113,  114 ,89 ,89 ,89),
            new MapRecord(115,  116 ,90 ,90 ,90),
            new MapRecord(117,  118 ,91 ,91 ,91),
            new MapRecord(119,  120 ,92 ,92 ,92),
            new MapRecord(121,  122 ,93 ,93 ,93),
            new MapRecord(123,  124 ,94 ,94 ,94),
            new MapRecord(125,  126 ,95 ,95 ,95),
            new MapRecord(127,  128 ,96 ,96 ,96),
            new MapRecord(129,  132 ,97 ,97 ,97),
            new MapRecord(133,  136 ,98 ,98 ,98),
            new MapRecord(137,   140 ,99 ,99 ,99),
            new MapRecord(141,  144 ,100,   100 ,100),
            new MapRecord(145,  148 ,101,   101 ,101),
            new MapRecord(149,  152 ,102,   102 ,102),
            new MapRecord(153,  156 ,103,   103 ,103),
            new MapRecord(157,  160 ,104,   104 ,104),
            new MapRecord(161,  164 ,105,   105 ,105),
            new MapRecord(165,  168 ,106,   106 ,106),
            new MapRecord(169,  172 ,107,   107 ,107),
            new MapRecord(173,  176 ,108,   108 ,108),
            new MapRecord(177,  180 ,109,   109 ,109),
            new MapRecord(181,  184 ,110,   110 ,110),
            new MapRecord(185,  188 ,111,   111 ,111),
            new MapRecord(189,  192 ,112,   112 ,112),
            new MapRecord(193,  196 ,113,   113 ,113),
            new MapRecord(197,  200 ,114,   114 ,114),
            new MapRecord(201,  204 ,115,   115 ,115),
            new MapRecord(205,  208 ,116,   116 ,116),
            new MapRecord(209,  212 ,117,   117 ,117),
            new MapRecord(213,  216 ,118,   118 ,118),
            new MapRecord(217,  220 ,119,   119 ,119),
            new MapRecord(221,  224 ,120,   120 ,120),
            new MapRecord(225,  228 ,121,   121 ,121),
            new MapRecord(229,  232 ,122,   122 ,122),
            new MapRecord(233,  236 ,123,   123 ,123),
            new MapRecord(237,  240 ,124,   124 ,124),
            new MapRecord(241,  244 ,125,   125 ,125),
            new MapRecord(245,  248 ,126,   126 ,126),
            new MapRecord(249,  252 ,127,   127 ,127),
            new MapRecord(253,  256 ,128,   128 ,128),
            new MapRecord(257,  264 ,129,   129 ,129),
            new MapRecord(265,  272 ,130,   130 ,130),
            new MapRecord(273,  280 ,131,   131 ,131),
            new MapRecord(281,  288 ,132,   132 ,132),
            new MapRecord(289,  296 ,133,   133 ,133),
            new MapRecord(297,  304 ,134,   134 ,134),
            new MapRecord(305,  312 ,135,   135 ,135),
            new MapRecord(313,  320 ,136,   136 ,136),
            new MapRecord(321,  328 ,137,   137 ,137),
            new MapRecord(329,  336 ,138,   138 ,138),
            new MapRecord(337,  344 ,139,   139 ,139),
            new MapRecord(345,  352 ,140,   140 ,140),
            new MapRecord(353,  360 ,141,   141 ,141),
            new MapRecord(361,  368 ,142,   142 ,142),
            new MapRecord(369,  376 ,143,   143 ,143),
            new MapRecord(377,  384 ,144,   144 ,144),
            new MapRecord(385,  392 ,145,   145 ,145),
            new MapRecord(393,  400 ,146,   146 ,146),
            new MapRecord(401,  408 ,147,   147 ,147),
            new MapRecord(409,  416 ,148,   148 ,148),
            new MapRecord(417,  424 ,149,   149 ,149),
            new MapRecord(425,  432 ,150,   150 ,150),
            new MapRecord(433,  440 ,151,   151 ,151),
            new MapRecord(441,  448 ,152,   152 ,152),
            new MapRecord(449,  456 ,153,   153 ,153),
            new MapRecord(457,  464 ,154,   154 ,154),
            new MapRecord(465,  472 ,155,   155 ,155),
            new MapRecord(473,  480 ,156,   156 ,156),
            new MapRecord(481,  488 ,157,   157 ,157),
            new MapRecord(489,  496 ,158,   158 ,158),
            new MapRecord(497,  504 ,159,   159 ,159),
            new MapRecord(505,  512 ,160,   160 ,160),
            new MapRecord(513,  528 ,161,   161 ,161),
            new MapRecord(529,  554 ,162,   162 ,162),
            new MapRecord(555,  560 ,163,   163 ,162),
            new MapRecord(561,  576 ,164,   164 ,164),
            new MapRecord(577,  592 ,165,   165 ,165),
            new MapRecord(593,  608 ,166,   166 ,166),
            new MapRecord(609,  624 ,167,   167 ,167),
            new MapRecord(625,  640 ,168,   168 ,168),
            new MapRecord(641,  656 ,169,   169 ,169),
            new MapRecord(657,  672 ,170,   170 ,170),
            new MapRecord(673,  688 ,171,   171 ,171),
            new MapRecord(689,  704 ,172,   172 ,172),
            new MapRecord(705,  720 ,173,   173 ,173),
            new MapRecord(721,  736 ,174,   174 ,174),
            new MapRecord(737,  752 ,175,   175 ,175),
            new MapRecord(753,  768 ,176,   176 ,176),
            new MapRecord(769,  784 ,177,   177 ,177),
            new MapRecord(785,  800 ,178,   178 ,178),
            new MapRecord(801,  816 ,179,   179 ,179),
            new MapRecord(817,  832 ,180,   180 ,180),
            new MapRecord(833,  848 ,181,   181 ,181),
            new MapRecord(849,  864 ,182,   182 ,182),
            new MapRecord(865,  880 ,183,   183 ,183),
            new MapRecord(881,  896 ,184,   184 ,184),
            new MapRecord(897,  912 ,185,   185 ,185),
            new MapRecord(913,  928 ,186,   186 ,186),
            new MapRecord(929,  944 ,187,   187 ,187),
            new MapRecord(945,  960 ,188,   188 ,188),
            new MapRecord(961,  976 ,189,   189 ,189),
            new MapRecord(977,  992 ,190,   190 ,190),
            new MapRecord(993,  1008,191,   191, 191),
            new MapRecord(1009, 1024,   192,192,    192),
            new MapRecord(1025, 1056,   193,193,    193),
            new MapRecord(1057, 1088,   194,194,    194),
            new MapRecord(1089, 1120,   195,195,    195),
            new MapRecord(1121, 1152,   196,196,    196),
            new MapRecord(1153, 1184,   197,197,    197),
            new MapRecord(1185, 1216,   198,198,    198),
            new MapRecord(1217, 1248,   199,199,    199),
            new MapRecord(1249, 1280,   200,200,    200),
            new MapRecord(1281, 1312,   201,201,    201),
            new MapRecord(1313, 1344,   202,202,    202),
            new MapRecord(1345, 1376,   203,203,    203),
            new MapRecord(1377, 1408,   204,204,    204),
            new MapRecord(1409, 1440,   205,205,    205),
            new MapRecord(1441, 1472,   206,206,    206),
            new MapRecord(1473, 1504,   207,207,    207),
            new MapRecord(1505, 1536,   208,208,    208),
            new MapRecord(1537, 1568,   209,209,    209),
            new MapRecord(1569, 1600,   210,210,    210),
            new MapRecord(1601, 1632,   211,211,    211),
            new MapRecord(1633, 1664,   212,212,    212),
            new MapRecord(1665, 1696,   213,213,    213),
            new MapRecord(1697, 1728,   214,214,    214),
            new MapRecord(1729, 1760,   215,215,    215),
            new MapRecord(1761, 1792,   216,216,    216),
            new MapRecord(1793, 1824,   217,217,    217),
            new MapRecord(1825, 1856,   218,218,    218),
            new MapRecord(1857, 1888,   219,219,    219),
            new MapRecord(1889, 1920,   220,220,    220),
            new MapRecord(1921, 1952,   221,221,    221),
            new MapRecord(1953, 1984,   222,222,    222),
            new MapRecord(1985, 2016,   223,223,    223),
            new MapRecord(2017, 2048,   224,224,    224),
            new MapRecord(2049, 2112,   225,225,    225),
            new MapRecord(2113, 2176,   226,226,    226),
            new MapRecord(2177, 2240,   227,227,    227),
            new MapRecord(2241, 2304,   228,228,    228),
            new MapRecord(2305, 2368,   229,229,    229),
            new MapRecord(2369, 2432,   230,230,    230),
            new MapRecord(2433, 2496,   231,231,    231),
            new MapRecord(2497, 2560,   232,232,    232),
            new MapRecord(2561, 2624,   233,233,    233),
            new MapRecord(2625, 2688,   234,234,    234),
            new MapRecord(2689, 2752,   235,235,    235),
            new MapRecord(2753, 2816,   236,236,    236),
            new MapRecord(2817, 2880,   237,237,    237),
            new MapRecord(2881, 2944,   238,238,    238),
            new MapRecord(2945, 3008,   239,239,    239),
            new MapRecord(3009, 3072,   240,240,    240),
            new MapRecord(3073, 3136,   241,241,    241),
            new MapRecord(3137, 3200,   242,242,    242),
            new MapRecord(3201, 3264,   243,243,    243),
            new MapRecord(3265, 3328,   244,244,    244),
            new MapRecord(3329, 3392,   245,245,    245),
            new MapRecord(3393, 3456,   246,246,    246),
            new MapRecord(2347, 3520,   247,247,    247),
            new MapRecord(3521, 3584,   248,248,    248),
            new MapRecord(3585, 3648,   249,249,    249),
            new MapRecord(3649, 3712,   250,250,    250),
            new MapRecord(3713, 3776,   251,251,    251),
            new MapRecord(3777, 3840,   252,252,    252),
            new MapRecord(3841, 3904,   253,253,    253),
            new MapRecord(3905, 3968,   254,254,    254),
            new MapRecord(3969, 4032,   255,255,    255),
            new MapRecord(4033, 8806,   255,255,    255),
        };
Logged

Stainless

  • moderator
  • member
  • Offline Offline
  • Posts: 1534
Re: Terrain height map generator for slibenli
« Reply #7 on: November 27, 2019, 04:16:12 AM »

Added option to edit a loaded project

Logged

Stainless

  • moderator
  • member
  • Offline Offline
  • Posts: 1534
Re: Terrain height map generator for slibenli
« Reply #8 on: November 28, 2019, 01:13:47 AM »

Started code to generate map_t

So far I have got a map that is 0.1 degrees of latitude and longitude and contains the types ....

Code: [Select]
LandTypeRecord[] LandTypes = new LandTypeRecord[]
        {
            new LandTypeRecord(24, 24, 128, "water"),
            new LandTypeRecord(50, 205, 49, "jungle"),
            new LandTypeRecord(33, 138, 33, "forest"),
            new LandTypeRecord(255, 255, 249, "snow"),
            new LandTypeRecord(189, 189, 189, "desert"),
            new LandTypeRecord(245, 222, 180, "dryscrub"),
            new LandTypeRecord(254, 0, 0, "city"),
            new LandTypeRecord(249, 237, 115, "grassland"),
            new LandTypeRecord(144, 187, 142, "hill"),
            new LandTypeRecord(240, 183, 104, "farmland"),
            new LandTypeRecord(255, 214, 0, "tropical savana"),
            new LandTypeRecord(70, 131, 178, "lake"),
            new LandTypeRecord(255, 214, 0, "swamp"),
            new LandTypeRecord(154, 205, 50, "steppe"),
            new LandTypeRecord(153, 249, 151, "mixed scrub"),
            new LandTypeRecord(218, 235, 157, "desert scrub"),
            new LandTypeRecord(151, 147, 84, "mountain"),
            new LandTypeRecord(188, 142, 144, "sand scrub")

        };

I sample this to create a type map that matches the height map



You can see the limits of accuracy in the image.

Next stage is to combine height values and this type map to generate a base map_t


Logged

Stainless

  • moderator
  • member
  • Offline Offline
  • Posts: 1534
Re: Terrain height map generator for slibenli
« Reply #9 on: November 28, 2019, 02:18:53 AM »

Okay looking a bit better,




I have used my own texture mapping which is not very good but will do for now

Code: [Select]
// My mapping
    // 0    Lowland near water
    // 1    Desert
    // 2    Dry scrub
    // 3    Grass
    // 4    Hill
    // 5    Farmland
    // 6    Tropical savannah
    // 7    Swamp
    // 8    Snow
    // 9    Mountain
    // 10
    // 11
    // 12   Steppe
    // 13   Mixed scrub
    // 14   Desert scrub
    // 15   Sand scrub
    // 16   City
    // 17
    // 18
    // 19
    // 20
    // 21
    // 22
    // 23
    // 24   Forest
    // 25
    // 26
    // 27   Jungle
    // 28   Sea
    // 29   Water in land
    // 30   Lake
    // 31
    //

Logged

Stainless

  • moderator
  • member
  • Offline Offline
  • Posts: 1534
Re: Terrain height map generator for slibenli
« Reply #10 on: November 28, 2019, 05:38:22 AM »

Seems to work, though you may have to invert the TGA file in an art package.

Sometimes it is upside down, not every time... don't know why

Checked into github
Logged

slibenli

  • member
  • Offline Offline
  • Posts: 619
    • IL-2 Graphics Extender
Re: Terrain height map generator for slibenli
« Reply #11 on: November 28, 2019, 02:46:37 PM »

Cloned :)
Pages: [1] 2 3   Go Up
 

Page created in 0.047 seconds with 27 queries.