%kirotate 'Rotate Object by Arbitrary Angle '
% This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros irotate.pane file
%
% Parameters: 
% InputFile: i 'Input ', required: 'Input data object'
% Toggle: resize 'Resize to fit', default: 0: 'resize to fit rotated image'
% Toggle: planes 'Process by planes', default: 0: 'Process data by WxH planes (fast, but only good for smaller objects) instead of small prisms down D (slow, but works for huge objects)'
% OutputFile: o 'Output', required: 'Output data object'
% Toggle: wctr 'W center', default: 0: 'center of rotation in center of W coordinate span'
% Toggle: hctr 'H center', default: 0: 'center of rotation in center of H coordinate span'
%
% Example: o = kirotate(i, {'i','';'resize',0;'planes',0;'o','';'wctr',0;'hctr',0})
%
% Khoros helpfile follows below:
%
%  PROGRAM
% irotate - Rotate Object by Arbitrary Angle
%
%  DESCRIPTION
% .I irotate
% is used to apply a rotation operation to each WxH plane in the value segment 
% of a data object. The is equivalent to rotating the data about an axis
% that lies parallel to the DEPTH axis.
% 
% Interpolation of output data from the input data is bilinear.
% 
% Each of the (DxE) WxH planes is rotated before being stored in the output
% object.
% 
% If rotation about an axis parallel to an axis other than DEPTH is desired, 
% it is necessary to use the kaxis
% program to reorient the data such that the desired axis becomes the DEPTH axis 
% before applying irotate. This limitation is due to computational complexity and
% performance issues, particularly when dealing with large data sets.
% 
% If the input object has a map, the data is pulled through the map prior to
% rotation, and the output object will have no map.
% 
% The arbitrary (floating point) rotation angle is CW for a positive angle, and 
% should be specified in degrees.
% 
% The center of rotation is used to specify that WxH point in the input object
% about which the rotation is to take place. The -wctr and -hctr flags can be used
% to ask irotate to automatically place the center of rotation at the center 
% of the WxH plane.
% 
% The -resize flag will causes the output object dimensions to be increased or
% decreased sufficiently to just contain all of the input data even after 
% rotation. 
% When this flag is used, the W and H dimensions may increase or decrease by a 
% factor of up to sqrt(2).  If -resize is selected and the center of rotation is
% not in the center of the WxH plane, the resulting rotated data will not
% be centered in the output data. 
% 
% The -planes flag is used to change the way the data is accessed for processing.
% If the data set is small enough that individual WxH planes of data
% will fit in memory, then use of the -planes 
% flag will cause processing to be done on a plane-by-plane basis; this is
% generally "much faster\fR than the default method (orders of magnitude). 
% If -planes is "not\fR specified, then
% processing will occur in prisms down the D axis, which is much slower but will
% work on data sets of any size. If you have lots of memory, you may be able to
% get away with using -planes even for quite large data sets, say around 2Kx2K
% or more points per plane.
% 
% The value given to those data points in the output that do not map to
% data in the input object is controlled by the padding behavior. If padding by
% zero is selected, then those areas will be set to zero. If padding by a
% specific pad value is selected, then that value will appear in areas that
% don't map to the input data. If padding by the pad value attribute of the
% input object is selected, then the pad value from the input object
% attribute KPDS_VALUE_PAD_VALUE is retrieved and is placed in areas that
% don't map to the input data.
% 
% If the input object has a mask, a new mask will be computed for the output
% object indicating which data points contain reliable data. 
% If a mask is present, then the output mask will be computed
% with value 1 if there was a full set of valid data points in the input from
% which to compute the output value. If any of the needed input points was 
% marked as invalid,
% then the output mask value is set to 0, marking that output point as invalid. 
% For regions of the output that do not map to data in the input object, the
% mask can be set to valid or invalid, depending on the setting of the
% -padvalid argument.
% 
% If the input object has a location data segment and the location data is
% anything other than KUNIFORM, then
% .I irotate
% will complain and ask you to use klocxform instead.
%
%  
%
%  EXAMPLES
%
%  "SEE ALSO"
% igeowarp(1,) klocxform(1)
%
%  RESTRICTIONS 
% 
% If 
% .I irotate
% is too slow for your application, be sure to read about the -planes option
% to see if it can be used. If so, processing may occur several orders of 
% magnitude faster.
%
%  REFERENCES 
%
%  COPYRIGHT
% Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI")  All rights reserved.
% 


function varargout = kirotate(varargin)
if nargin ==0
  Inputs={};arglist={'',''};
elseif nargin ==1
  Inputs=varargin{1};arglist={'',''};
elseif nargin ==2
  Inputs=varargin{1}; arglist=varargin{2};
else error('Usage: [out1,..] = kirotate(Inputs,arglist).');
end
if size(arglist,2)~=2
  error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
 end
narglist={'i', '__input';'resize', 0;'planes', 0;'o', '__output';'wctr', 0;'hctr', 0};
maxval={0,0,0,0,0,0};
minval={0,0,0,0,0,0};
istoggle=[0,1,1,0,1,1];
was_set=istoggle * 0;
paramtype={'InputFile','Toggle','Toggle','OutputFile','Toggle','Toggle'};
% identify the input arrays and assign them to the arguments as stated by the user
if ~iscell(Inputs)
Inputs = {Inputs};
end
NumReqOutputs=1; nextinput=1; nextoutput=1;
  for ii=1:size(arglist,1)
  wasmatched=0;
  for jj=1:size(narglist,1)
   if strcmp(arglist{ii,1},narglist{jj,1})  % a given argument was matched to the possible arguments
     wasmatched = 1;
     was_set(jj) = 1;
     if strcmp(narglist{jj,2}, '__input')
      if (nextinput > length(Inputs)) 
        error(['Input ' narglist{jj,1} ' has no corresponding input!']); 
      end
      narglist{jj,2} = 'OK_in';
      nextinput = nextinput + 1;
     elseif strcmp(narglist{jj,2}, '__output')
      if (nextoutput > nargout) 
        error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']); 
      end
      if (isempty(arglist{ii,2}))
        narglist{jj,2} = 'OK_out';
      else
        narglist{jj,2} = arglist{ii,2};
      end

      nextoutput = nextoutput + 1;
      if (minval{jj} == 0)  
         NumReqOutputs = NumReqOutputs - 1;
      end
     elseif isstr(arglist{ii,2})
      narglist{jj,2} = arglist{ii,2};
     else
        if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
            error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
        end
        if (minval{jj} ~= 0 | maxval{jj} ~= 0)
          if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
            error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
          elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
            error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
          elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
            error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
          elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
            error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
          elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
            error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
          elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
            error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
          end
        end
     end
     if ~strcmp(narglist{jj,2},'OK_out') &  ~strcmp(narglist{jj,2},'OK_in') 
       narglist{jj,2} = arglist{ii,2};
     end
   end
   end
   if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
        error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
   end
end
% match the remaining inputs/outputs to the unused arguments and test for missing required inputs
 for jj=1:size(narglist,1)
     if  strcmp(paramtype{jj}, 'Toggle')
        if (narglist{jj,2} ==0)
          narglist{jj,1} = ''; 
        end;
        narglist{jj,2} = ''; 
     end;
     if  ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
          narglist{jj,1} = ''; 
          narglist{jj,2} = ''; 
     end;
     if strcmp(narglist{jj,2}, '__input')
      if (minval{jj} == 0)  % meaning this input is required
        if (nextinput > size(Inputs)) 
           error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']); 
        else
          narglist{jj,2} = 'OK_in';
          nextinput = nextinput + 1;
        end
      else  % this is an optional input
        if (nextinput <= length(Inputs)) 
          narglist{jj,2} = 'OK_in';
          nextinput = nextinput + 1;
        else 
          narglist{jj,1} = '';
          narglist{jj,2} = '';
        end;
      end;
     else 
     if strcmp(narglist{jj,2}, '__output')
      if (minval{jj} == 0) % this is a required output
        if (nextoutput > nargout & nargout > 1) 
           error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']); 
        else
          narglist{jj,2} = 'OK_out';
          nextoutput = nextoutput + 1;
          NumReqOutputs = NumReqOutputs-1;
        end
      else % this is an optional output
        if (nargout - nextoutput >= NumReqOutputs) 
          narglist{jj,2} = 'OK_out';
          nextoutput = nextoutput + 1;
        else 
          narglist{jj,1} = '';
          narglist{jj,2} = '';
        end;
      end
     end
  end
end
if nargout
   varargout = cell(1,nargout);
else
  varargout = cell(1,1);
end
global KhorosRoot
if exist('KhorosRoot') && ~isempty(KhorosRoot)
w=['"' KhorosRoot];
else
if ispc
  w='"C:\Program Files\dip\khorosBin\';
else
[s,w] = system('which cantata');
w=['"' w(1:end-8)];
end
end
[varargout{:}]=callKhoros([w 'irotate"  '],Inputs,narglist);
