BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Getting height elevation values from .bt terrain files...

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
Paul Nicholls
Guest





PostPosted: Tue Jun 22, 2004 4:01 am    Post subject: Getting height elevation values from .bt terrain files... Reply with quote



Hi all, I am making a .bt file reader for a certain type of terrain (see
http://www.vterrain.org/Implementation/Formats/BT.html)

Using the info at that page, I have come up with a unit to help me with this
so far:

unit BTTerrainUnit;

interface

type
TBTTerrainHeader = packed record
Version: array[0..9] of Char;
ColumnsWidth: LongWord;
RowsHeight: LongWord;
DataSize: Word;
FloatingPointFlag: Word;
HorizontalUnits: Word;
UTMZone: Smallint;
Datum: Word;
LeftExtent: Double;
RightExtent: Double;
BottomExtent: Double;
TopExtent: Double;
ExternalProj: Word;
Scale: Single;
Unused: array[0..190-1] of Byte;
end;

function GetHeightDataAt(BTHeader: TBTTerrainHeader; DataStart: Pointer;
x,z: Integer): Double;

implementation

type
PSmallIntArray = ^SmallIntArray;
SmallIntArray = packed array[0..(MaxInt div SizeOf(SmallInt)) - 1] of
Smallint;

PSingleArray = ^SingleArray;
SingleArray = packed array[0..(MaxInt div SizeOf(Single)) - 1] of Single;

PIntegerArray = ^IntegerArray;
IntegerArray = packed array[0..(MaxInt div SizeOf(Integer)) - 1] of
Integer;

PDoubleArray = ^DoubleArray;
DoubleArray = packed array[0..(MaxInt div SizeOf(Double)) - 1] of Double;

function GetHeightDataAt(BTHeader: TBTTerrainHeader; DataStart: Pointer;
x,z: Integer): Double;
begin
if(BTHeader.DataSize = 2)then
begin
if(BTHeader.FloatingPointFlag = 1)then
// single data type
Result := PSingleArray(DataStart)[x+z*BTHeader.ColumnsWidth]
else
// smallint data type
Result := PSmallIntArray(DataStart)[x+z*BTHeader.ColumnsWidth];
end
else
if(BTHeader.DataSize = 4)then
begin
if(BTHeader.FloatingPointFlag = 1)then
// double data type
Result := PDoubleArray(DataStart)[x+z*BTHeader.ColumnsWidth]
else
// integer data type
Result := PIntegerArray(DataStart)[x+z*BTHeader.ColumnsWidth];
end;
end;

end.


My problem is this:

I load a .bt file that I downloaded from here
(http://vterrain.org/data/crater_0513.zip)
into a TMemoryStream

I then do this

ms.Position := 0;
ms.Read(BTHeader,SizeOf(BTHeader));

ms.Position := 0;
DataStart := Pointer(Integer(ms.Memory)+ms.Position); //DataStart is
a pointer to the data straight after the header info...

but it appears that when I iterate through the width and height info I get
from the BTHeader, and call this function GetHeightDataAt(...), I am only
getting 0 values from it...

Can anyone see if I have made a mistake with the GetHeightDataAt(..)
function other defs in the short unit?

I can't see where the problem is :(

Thanks in advance,
Paul Nicholls (Delphi 5/6 Professional)
"The plastic veneer of civilization is easily melted in the heat of the
moment" - Paul Nicholls
[email]paul-nicholls (AT) hotmail (DOT) com[/email]

Replace '-' with '_' to reply


Back to top
Paul Nicholls
Guest





PostPosted: Tue Jun 22, 2004 11:10 pm    Post subject: Re: Getting height elevation values from .bt terrain files.. Reply with quote



Don't worry about it guys, I totally rewrote my little unit to do the
reading of the .bt info differently and return it in a 2d array, and it now
works fine :)

Here it is if anyone is interested...

<Unit Code Start>

unit BTTerrainUnit;

interface

uses
Classes,TerrainTypesUnit;

procedure ReadBTHeightDataFromStream(s: TStream; var HeightData:
TDoubleBuffer; var Columns,Rows: Integer);

implementation

const
BTVer11 = 'binterr1.1';
BTVer13 = 'binterr1.3';

type
TBTVersion = array[0..9] of Char; //10

procedure ReadBTHeightDataFromStream(s: TStream; var HeightData:
TDoubleBuffer; var Columns,Rows: Integer);
var
BTVersion: TBTVersion;
DataSize: Word;
FloatingPointFlag: Word;
x,z: Integer;
Value_Single: Single;
Value_Double: Double;
Value_SmallInt: SmallInt;
Value_Integer: Integer;
p: Integer;
begin
p := s.Position;

s.Read(BTVersion,SizeOf(BTVersion));
s.Read(Columns,SizeOf(Columns));
s.Read(Rows,SizeOf(Rows));
s.Read(DataSize,SizeOf(DataSize));
s.Position := p+256;

SetLength(HeightData,Rows,Columns);

for x := 0 to Columns - 1 do
for z := 0 to Rows - 1 do
begin
if(DataSize = 2)then
begin
if(FloatingPointFlag = 1)then
// single data type
begin
s.Read(Value_Single,SizeOf(Value_Single));
HeightData[(Columns - 1)-z,x] := Value_Single;
end
else
// smallint data type
begin
s.Read(Value_SmallInt,SizeOf(Value_SmallInt));
HeightData[(Columns - 1)-z,x] := 1.0*Value_SmallInt;
end;
end
else
if(DataSize = 4)then
begin
if(FloatingPointFlag = 1)then
// double data type
begin
s.Read(Value_Double,SizeOf(Value_Double));
HeightData[(Columns - 1)-z,x] := Value_Double;
end
else
// integer data type
begin
s.Read(Value_Integer,SizeOf(Value_Integer));
HeightData[(Columns - 1)-z,x] := 1.0*Value_Integer;
end;
end;
end;
end;

end.

<Unit Code Start/>

"Paul Nicholls" <.> wrote

Quote:
Hi all, I am making a .bt file reader for a certain type of terrain (see
http://www.vterrain.org/Implementation/Formats/BT.html)

SNIP
but it appears that when I iterate through the width and height info I get
from the BTHeader, and call this function GetHeightDataAt(...), I am only
getting 0 values from it...

Can anyone see if I have made a mistake with the GetHeightDataAt(..)
function other defs in the short unit?

I can't see where the problem is :(

Thanks in advance,
Paul Nicholls (Delphi 5/6 Professional)
"The plastic veneer of civilization is easily melted in the heat of the
moment" - Paul Nicholls
[email]paul-nicholls (AT) hotmail (DOT) com[/email]

Replace '-' with '_' to reply





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.