source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/qtfm/read.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 2.2 KB
Line 
1function A = read(filename, format)
2% READ    Input a quaternion array from a text file. The format
3% of the file is defined by the matching function WRITE (q.v.).
4%
5% A = read(filename, format) returns an array A of either full
6% or pure quaternions dependent on what was in the file.  The
7% format parameter may be omitted, in which case a default is
8% supplied compatible with the function write. Otherwise, the
9% format parameter is as for the Matlab function scanf (q.v.).
10
11% Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan.
12% See the file : Copyright.m for further details.
13
14error(nargchk(1, 2, nargin)), error(nargoutchk(0, 1, nargout))
15
16if nargin == 1
17   
18    % Only one parameter has been supplied. The missing one must
19    % be the format, so supply the default value, to match the
20    % default value used in the function write. Note that the
21    % strings differ slightly because of the differences between
22    % printf and scanf.
23
24    format = '%24e';   
25end
26
27fid = fopen(filename, 'r');
28
29r = fscanf(fid, ' %8u', 1);
30c = fscanf(fid, ' %8u', 1);
31n = r .* c;
32
33% Now read in the data into a real matrix, which we then re-arrange
34% to produce a quaternion matrix A. Note that we can deduce whether
35% the file contains pure or full quaternions from the number of
36% floating-point values read: it will be either 3 or 4 times the
37% number of quaternions indicated by n.
38
39[R, count] = fscanf(fid, [' ', format], inf);
40fclose(fid);
41
42inc = count ./ n; % This value is either 3 or 4, depending on whether
43                  % the file contained pure or full quaternions.
44
45if inc ~= 3 & inc ~= 4
46    error('The number of values read from the file is incorrect.');
47end
48
49if inc == 4
50    A = quaternion(transpose(reshape(R(1 : inc : count - 3), c, r)), ...
51                   transpose(reshape(R(2 : inc : count - 2), c, r)), ...
52                   transpose(reshape(R(3 : inc : count - 1), c, r)), ...
53                   transpose(reshape(R(4 : inc : count    ), c, r)));
54else
55    A = quaternion(transpose(reshape(R(1 : inc : count - 2), c, r)), ...
56                   transpose(reshape(R(2 : inc : count - 1), c, r)), ...
57                   transpose(reshape(R(3 : inc : count    ), c, r)));
58end
Note: See TracBrowser for help on using the repository browser.