0001 function objectmap = LoadAVWObjectMap ( Filename )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 objectmap = struct ( 'Version', -1 );
0015
0016 fid = fopen ( Filename, 'r', 'b');
0017 if fid < 0,
0018 error ( ['Can not open ' Filename ' for reading'] );
0019 end
0020
0021 objectmap.Version = fread ( fid, 1, 'int' );
0022 if objectmap.Version ~= 910926
0023 error ( ['Unknown ObjectMap version: ' int2str(objectmap.Version) ' expected 910926'] );
0024 end
0025
0026 objectmap.Width = fread ( fid, 1, 'int' );
0027 objectmap.Height = fread ( fid, 1, 'int' );
0028 objectmap.Depth = fread ( fid, 1, 'int' );
0029 objectmap.NumberOfObjects = fread ( fid, 1, 'int' );
0030
0031 for o = 1:objectmap.NumberOfObjects
0032 Object = struct ( 'Name', 'Foo' );
0033 Object.Name = char(fread ( fid, 32, 'uchar' ));
0034 Object.Name = sscanf ( Object.Name, '%s' );
0035 Object.Display = fread ( fid, 1, 'int' );
0036 Object.Copy = fread ( fid, 1, 'uchar' );
0037 Object.Mirror = fread ( fid, 1, 'uchar' );
0038 Object.Status = fread ( fid, 1, 'uchar' );
0039 Object.NUsed = fread ( fid, 1, 'uchar' );
0040 Object.Shades = fread ( fid, 1, 'int' );
0041 Object.StartRed = fread ( fid, 1, 'int' );
0042 Object.StartGreen = fread ( fid, 1, 'int' );
0043 Object.StartBlue = fread ( fid, 1, 'int' );
0044 Object.EndRed = fread ( fid, 1, 'int' );
0045 Object.EndGreen = fread ( fid, 1, 'int' );
0046 Object.EndBlue = fread ( fid, 1, 'int' );
0047 Object.XRotation = fread ( fid, 1, 'int' );
0048 Object.YRotation = fread ( fid, 1, 'int' );
0049 Object.ZRotation = fread ( fid, 1, 'int' );
0050 Object.XShift = fread ( fid, 1, 'int' );
0051 Object.YShift = fread ( fid, 1, 'int' );
0052 Object.ZShift = fread ( fid, 1, 'int' );
0053 Object.XCenter = fread ( fid, 1, 'int' );
0054 Object.YCenter = fread ( fid, 1, 'int' );
0055 Object.ZCenter = fread ( fid, 1, 'int' );
0056 Object.XRotationIncrement = fread ( fid, 1, 'int' );
0057 Object.YRotationIncrement = fread ( fid, 1, 'int' );
0058 Object.ZRotationIncrement = fread ( fid, 1, 'int' );
0059 Object.XShiftIncrement = fread ( fid, 1, 'int' );
0060 Object.YShiftIncrement = fread ( fid, 1, 'int' );
0061 Object.ZShiftIncrement = fread ( fid, 1, 'int' );
0062 Object.XMinimum = fread ( fid, 1, 'short' );
0063 Object.YMinimum = fread ( fid, 1, 'short' );
0064 Object.ZMinimum = fread ( fid, 1, 'short' );
0065 Object.XMaximum = fread ( fid, 1, 'short' );
0066 Object.YMaximum = fread ( fid, 1, 'short' );
0067 Object.ZMaximum = fread ( fid, 1, 'short' );
0068 Object.Opacity = fread ( fid, 1, 'float' );
0069 Object.OpacityThickness = fread ( fid, 1, 'int' );
0070 Dummy = fread ( fid, 1, 'int' );
0071 objectmap.Objects(o) = Object;
0072 end
0073
0074
0075 Map = fread ( fid, inf, 'uchar' );
0076
0077
0078 T = zeros ( objectmap.Width, objectmap.Height, objectmap.Depth );
0079
0080 ImageIndex = 1;
0081 Counts = Map(1:2:end);
0082 Values = Map(2:2:end);
0083
0084 for idx = 1:length(Counts)
0085 T(ImageIndex:ImageIndex+Counts(idx)-1) = Values(idx) + 1;
0086 ImageIndex = ImageIndex + Counts(idx);
0087 end
0088
0089 objectmap.Image = zeros ( objectmap.Height, objectmap.Width, objectmap.Depth );
0090 yy = objectmap.Height:-1:1;
0091 for dd = 1:objectmap.Depth
0092 t = T(:,:,dd)';
0093 objectmap.Image(:,:,dd) = t(yy,:);
0094 end
0095
0096 fclose ( fid );
0097