🔒 Locked
loading terrain data set *SOLVED
Advertisement
Original Post
ive downlaod the data set which can be found here http://www-static.cc.gatech.edu/projects/large_models/ps.html ive then converted the greyscale heightdata to a 24bit tga and loaded it into memory... but since each channel is loaded as 0-256... how can i get the values 0 to 65535 which it says in the text...? [Edited by - Dragon_Strike on September 19, 2006 1:47:18 PM]
I don't know if you should really convert the .png to a .tga before loading it into your program. You're probably losing height information since the png stores the height values as 16bit. If you can figure out which channels in the .png store the height information then you could combine like this:
Red and Green
unsigned short heightValue = Red | (Green << 8)
Red and Blue
unsigned short heightValue = Red | (Blue << 8)
etc...
Red and Green
unsigned short heightValue = Red | (Green << 8)
Red and Blue
unsigned short heightValue = Red | (Blue << 8)
etc...
but since the image is in a greyscale.. doesnt that men that the png image has the same RGB values at the same point? thats what i dont get...
ok so its a 16bit greyscale image which means it has 16bits per channel (48bit image)... how do i load a 16bit greyscale png into memory?
or is there a way/program which can convert this into a 24bit color image where it sets the 16bit value as two 8 bit color values...
or is there a way/program which can convert this into a 24bit color image where it sets the 16bit value as two 8 bit color values...
Quote:A grayscale png only has one channel per pixel (or two if it is grayscale with alpha). You load it using libpng or some general image loading library that uses libpng internally.
Original post by Dragon_Strike
ok so its a 16bit greyscale image which means it has 16bits per channel (48bit image)... how do i load a 16bit greyscale png into memory?
or is there a way/program which can convert this into a 24bit color image where it sets the 16bit value as two 8 bit color values...
Quote:
Original post by Kalidor Quote:A grayscale png only has one channel per pixel (or two if it is grayscale with alpha). You load it using libpng or some general image loading library that uses libpng internally.
Original post by Dragon_Strike
ok so its a 16bit greyscale image which means it has 16bits per channel (48bit image)... how do i load a 16bit greyscale png into memory?
or is there a way/program which can convert this into a 24bit color image where it sets the 16bit value as two 8 bit color values...
well ive looked at libpng... but i have NO CLUE how to use it... i havent found any tutorials or a base class for it either to hepl me out.. all i foun dwas the manuel which didnt help me much... if you have any uideas that might hlp me id be grateful...
i think it ould be a solution to convert it to a 16bit raw... which should be easier to load... but ive been unsuccessful with that so far..
the best solution for me i think would be to somehow convert the 16bit gray scale to a 24bit RGB where the first 8 bits = R and the last 8 bits = G and B = other... is there a good program to do this? this is the way im currently saving and loading my own generated heightmaps...
If you can't read a PNG image using the documentation for the library, then you probably need to step back from your current problem and work a little bit on that piece of the code. It's a fairly easy-to-use library, and comes with sample code.
To convert between image formats, I usually use Photoshop. There are free, downloadable trials on the Adobe web site. Another program (which is free) that can do it is The Gimp, but I don't know how well it supports 16 bits per pixel.
To convert between image formats, I usually use Photoshop. There are free, downloadable trials on the Adobe web site. Another program (which is free) that can do it is The Gimp, but I don't know how well it supports 16 bits per pixel.
Quote:
Original post by hplus0603
If you can't read a PNG image using the documentation for the library, then you probably need to step back from your current problem and work a little bit on that piece of the code. It's a fairly easy-to-use library, and comes with sample code.
To convert between image formats, I usually use Photoshop. There are free, downloadable trials on the Adobe web site. Another program (which is free) that can do it is The Gimp, but I don't know how well it supports 16 bits per pixel.
it migth be easy-to-use but i rly dont understand.. ive read the documentation and the example and i have a somewhat idea how it works but i cant use it... for me its jsut to much info at 1 place... if u know a tutorial or other manuel that breaks down the documentation in more piece to make it easier to read and understand that wold be very helpful... other than that i dont think i can get anywhere whit it... is there any other similar library that might be easier to use?
and a program to convert from one 16bit greyscale format to another wont help me much... the only decent information ive found on images formats are TGA and BMP which i know how to use without library (but with documentation).. and neither of them has 16 bit grayscale...
ive converted to a 16bit raw format using photoshop but im unsuccessful in loading it...
unsigned short* HeightMap; char* szFilename = "temp.raw"; FILE *fp = NULL; fp = fopen(szFilename, "rb"); HeightMap = new unsigned short[ m_iSize*m_iSize]; fread(HeightMap, m_iSize*m_iSize*sizeof(unsigned short), 1, fp); fclose(fp);//Getvalue function inline float GetHeight(int x, int z) { return HeightMap[x+z*m_iSize];//m_HeightMap.Get16RedColor(x, z); }
You should be okay with Photoshop's RAW output. A couple things spring to mind that might be affecting it. First off, if you're using an older Photoshop, bear in mind its PNG support is a bit buggy. Do a search for the SuperPNG plugin.
When you output a .RAW file to match the code you've supplied, make sure you're saving it out with a 0-sized header and in "IBM PC" byte order. I can't remember if it outputs signed shorts or not.
When you output a .RAW file to match the code you've supplied, make sure you're saving it out with a 0-sized header and in "IBM PC" byte order. I can't remember if it outputs signed shorts or not.
well the RAW option seems to be the fastest and simplest but for some reason the code i just posted doesnt work properly... ive saved the image in pghotoshop as 16bit, raw, 0 header and IBM PC formated file...
but when i load it in my program using either unsiged short or short it loads something similar to a heightmap but it offsets/changes all the values in some strange way...? waht might be causeing this?
but when i load it in my program using either unsiged short or short it loads something similar to a heightmap but it offsets/changes all the values in some strange way...? waht might be causeing this?
Quote:
Original post by PlayerX
That could be Photoshop's PNG bugs. I think its 16-bit grayscale handling is broken. Try the SuperPNG plugin and see if that improves things for you.
i removed the adobe png.lib form the adobe folder fileformat and replaced it with superpng.. i start photoshop and save the png file as i said before...
but no improvement.. its exaclty the same as before... somewhat right geometry but still offseted/changed/disorted...
Hmmm, well, hard to tell where the problem is without seeing your datasets and code.
Just to double check, did you put the SuperPNG.8bi file into the Plug-Ins\Adobe Photoshop Only\File Formats directory of Photoshop and are you seeing the option to save out SuperPNG(*.PNG) files?
Just to double check, did you put the SuperPNG.8bi file into the Plug-Ins\Adobe Photoshop Only\File Formats directory of Photoshop and are you seeing the option to save out SuperPNG(*.PNG) files?
Quote:
Original post by PlayerX
Hmmm, well, hard to tell where the problem is without seeing your datasets and code.
Just to double check, did you put the SuperPNG.8bi file into the Plug-Ins\Adobe Photoshop Only\File Formats directory of Photoshop and are you seeing the option to save out SuperPNG(*.PNG) files?
yeap thats where i put it and i can save as superpng.. but i just openg the png file and saved a raw...
here is the dataset...
http://www-static.cc.gatech.edu/projects/large_models/ps.html
and here is the code:
unsigned short* HeightMap; char* szFilename = "temp.raw"; FILE *fp = NULL; fp = fopen(szFilename, "rb"); HeightMap = new unsigned short[ m_iSize*m_iSize]; fread(HeightMap, m_iSize*m_iSize*sizeof(unsigned short), 1, fp); fclose(fp);//Getvalue function inline float GetHeight(int x, int z) { return HeightMap[x+z*m_iSize]; }EDIT:
i know it might be a bit much to sak... but maybe u could convert the 4096.png heightmap file to a raw.. that u know should work... soo that i know if its my code that is incorrrect or the file im loading from...
[Edited by - Dragon_Strike on September 16, 2006 5:50:11 PM]
Okay, I put aside a few minutes to check this for you. I grabbed the 1k x 1k dataset from that web-site and converted it to raw using Photoshop 6.0 and SuperPNG (file is here).
I then added this code to my development framework:
Which produced this screen-shot:

So the conversion is working okay. It would seem there is something wrong with your rendering code somewhere.
I then added this code to my development framework:
t_Buffer *Verts, *Indices;struct s_Sample { t_Vec3 Vertex; t_Vec3 Normal;} TerrainMap[1025*1025];ulong Index[1024 * 1024 * 6];void terrtest(void) { ushort * Heights; void * File; ulong FileSize; int x, y, i; float fx, fy; struct s_Sample * sm; ulong * ind; FileSize = FileLoad(&File, "ps_height_1k.raw"); if (!File) return; Heights = (ushort *) File; sm = TerrainMap; fy = 0; for (y=0; y<1025; y++) { fx = 0; for (x=0; x<1025; x++) { sm->Vertex.x = fx; sm->Vertex.y = fy; sm->Vertex.z = (float)*Heights++; sm++; fx += 1000.0f; } fy += 1000.0f; } MemFree(File); // Doesn't do edge normals properly, but this is just test code, so... for (y=1; y<1024; y++) { for (x=1; x<1024; x++) { sm = &TerrainMap[x + y * 1025]; sm->Normal.x = TerrainMap[(x - 1) + y * 1025].Vertex.z - TerrainMap[(x + 1) + y * 1025].Vertex.z; sm->Normal.y = TerrainMap[x + (y - 1) * 1025].Vertex.z - TerrainMap[x + (y + 1) * 1025].Vertex.z; sm->Normal.z = 2.0f * 1000.0f; VecNorm(&sm->Normal, &sm->Normal); } } Verts = BufferNew(TerrainMap, sizeof(TerrainMap), BUFFER_VERTEX, 0); ind = Index; for (y=0; y<1024; y++) { i = y * 1025; for (x=0; x<1024; x++) { *ind++ = i; *ind++ = i + 1; *ind++ = i + 1025; *ind++ = i + 1; *ind++ = i + 1026; *ind++ = i + 1025; i++; } } Indices = BufferNew(Index, sizeof(Index), BUFFER_INDEX, 0);}void terrrender(void) { if (!Verts || !Indices) return; glEnable(GL_LIGHTING); glColor4f(1, 1, 1, 1); glShadeModel(GL_SMOOTH); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, Verts->Buffer); glVertexPointer(3, GL_FLOAT, sizeof(struct s_Sample), 0); glNormalPointer(GL_FLOAT, sizeof(struct s_Sample), (void *)sizeof(t_Vec3)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Indices->Buffer); glDrawElements(GL_TRIANGLES, 1024*1024*6, GL_UNSIGNED_INT, 0);}Which produced this screen-shot:

So the conversion is working okay. It would seem there is something wrong with your rendering code somewhere.
thx alot... ill look at it... the way u open the file doest seem to work for me... u got ur own function? "FileLoad" ?
EDIT: and my render code works just fine with 8bit images... since shorts ar 65000 i think i divide the values i get form the file to a lower value.. but its still not right
i rewrote it to this.. but it just crashes..
[Edited by - Dragon_Strike on September 17, 2006 3:38:59 AM]
EDIT: and my render code works just fine with 8bit images... since shorts ar 65000 i think i divide the values i get form the file to a lower value.. but its still not right
i rewrote it to this.. but it just crashes..
HeightMap = new float [257*257]; //m_HeightMap.LoadData("../Data/256h.tga"); void *File = NULL; File = fopen("../Data/256h.raw", "rb"); if (!File) return; unsigned short* Heights; Heights = (unsigned short *) File; for (int y=0; y<257; y++) { for (int x=0; x<257; x++) { HeightMap[x+y*257] = (float)*Heights++; } } free(File);[Edited by - Dragon_Strike on September 17, 2006 3:38:59 AM]
ok i tired ur file.. and it still doesnt work.. well atleast i know my code isnt workin... how annoying :(
FILE *fp = NULL; fp = fopen("../Data/ps_height_1k.raw", "rb"); HeightMap = new unsigned short[ 1025*1025]; fread(HeightMap, 1025*1025*sizeof(unsigned short), 1, fp); fclose(fp); inline float GetHeight(int x, int z) { return HeightMap[x+z*1025]/650; }Quote:
Original post by Dragon_Strike
thx alot... ill look at it... te download an dpicture u posted doesnt work though... the way u open the file doest seem to work for me... u got ur own function? "FileLoad" ?
Yep. It just loads the file given in the second argument into memory and writes a pointer to it into the pointer given in the first argument and returns the total bytes read. BufferNew is also a custom function to load data into a VBO.
Mighty strange you can render 8-bit heightmaps okay but not 16-bit ones. What exactly is it doing when you try rendering the 16-bit heightmaps?
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement