Home > bioelectromagnetism > SaveAVWObjectMap.m

SaveAVWObjectMap

PURPOSE ^

SaveAVWObjectMap ( Filename, objectmap )

SYNOPSIS ^

function SaveAVWObjectMap ( Filename, objectmap )

DESCRIPTION ^

 SaveAVWObjectMap ( Filename, objectmap )
 Save the objectmap in Filename

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function SaveAVWObjectMap ( Filename, objectmap )
0002 % SaveAVWObjectMap ( Filename, objectmap )
0003 % Save the objectmap in Filename
0004 
0005 fid = fopen ( Filename, 'w', 'b' );
0006 if fid < 0,
0007   error ( ['Can not open ' Filename ' for writing'] );
0008 end
0009 
0010 fwrite ( fid, objectmap.Version, 'int' );
0011 if objectmap.Version ~= 910926
0012   error ( ['Unknown ObjectMap version: ' int2str(objectmap.Version) ' expected 910926'] );
0013 end
0014 
0015 fwrite ( fid, objectmap.Width, 'int' );
0016 fwrite ( fid, objectmap.Height, 'int' );
0017 fwrite ( fid, objectmap.Depth, 'int' );
0018 fwrite ( fid, objectmap.NumberOfObjects, 'int' );
0019 
0020 for o = 1:objectmap.NumberOfObjects
0021   Object = objectmap.Objects(o);
0022   N = double ( Object.Name );
0023   N = [N zeros(1,32-length(N))];
0024   fwrite ( fid, N, 'uchar' );
0025   fwrite ( fid, Object.Display, 'int' );
0026   fwrite ( fid, Object.Copy, 'uchar' );
0027   fwrite ( fid, Object.Mirror, 'uchar' );
0028   fwrite ( fid, Object.Status, 'uchar' );
0029   fwrite ( fid, Object.NUsed, 'uchar' );
0030   fwrite ( fid, Object.Shades, 'int' );
0031   fwrite ( fid, Object.StartRed, 'int' );
0032   fwrite ( fid, Object.StartGreen, 'int' );
0033   fwrite ( fid, Object.StartBlue, 'int' );
0034   fwrite ( fid, Object.EndRed, 'int' );
0035   fwrite ( fid, Object.EndGreen, 'int' );
0036   fwrite ( fid, Object.EndBlue, 'int' );
0037   fwrite ( fid, Object.XRotation, 'int' );
0038   fwrite ( fid, Object.YRotation, 'int' );
0039   fwrite ( fid, Object.ZRotation, 'int' );
0040   fwrite ( fid, Object.XShift, 'int' );
0041   fwrite ( fid, Object.YShift, 'int' );
0042   fwrite ( fid, Object.ZShift, 'int' );
0043   fwrite ( fid, Object.XCenter, 'int' );
0044   fwrite ( fid, Object.YCenter, 'int' );
0045   fwrite ( fid, Object.ZCenter, 'int' );
0046   fwrite ( fid, Object.XRotationIncrement, 'int' );
0047   fwrite ( fid, Object.YRotationIncrement, 'int' );
0048   fwrite ( fid, Object.ZRotationIncrement, 'int' );
0049   fwrite ( fid, Object.XShiftIncrement, 'int' );
0050   fwrite ( fid, Object.YShiftIncrement, 'int' );
0051   fwrite ( fid, Object.ZShiftIncrement, 'int' );
0052   fwrite ( fid, Object.XMinimum, 'short' );
0053   fwrite ( fid, Object.YMinimum, 'short' );
0054   fwrite ( fid, Object.ZMinimum, 'short' );
0055   fwrite ( fid, Object.XMaximum, 'short' );
0056   fwrite ( fid, Object.YMaximum, 'short' );
0057   fwrite ( fid, Object.ZMaximum, 'short' );
0058   fwrite ( fid, Object.Opacity, 'float' );
0059   fwrite ( fid, Object.OpacityThickness, 'int' );
0060   % Dummy
0061   fwrite ( fid, 0, 'int' );
0062 end
0063 
0064 
0065 Output = 0;
0066 NOut = 0;
0067 
0068 % RLE is done image by image
0069 for slice = 1:size(objectmap.Image,3)
0070   X = squeeze(objectmap.Image(:,:,slice));
0071   % Write the volume run length encoded.
0072   % Rotate back
0073   % X = rot90 ( X, 2 );
0074   X = X(:)';
0075   Counts = diff([ 0 find(X(1:end-1) ~= X(2:end)) length(X) ]);
0076   Values = X([ find(X(1:end-1) ~= X(2:end)) length(X) ]);
0077 
0078   for idx = 1:length(Counts)
0079     Count = Counts(idx);
0080     Value = Values(idx) - 1;
0081     while Count >= 255
0082       fwrite ( fid, [255 Value], 'uchar' );
0083       Count = Count - 255;
0084       % Output = Output + 255;
0085       % NOut = NOut + 1;
0086     end
0087     fwrite ( fid, [Count Value], 'uchar' );
0088     % Output = Output + Count;
0089     % NOut = NOut + 1;
0090   end
0091 end
0092 fclose ( fid );

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003