
function obj = Make3DData(N, factor)
%------------------------
% This function makes a 3D data set, a noisy box in a ball.
% noisy ball ------------
% Input:  N - dyadic side of a cube (N=32,64,128 and if you have
%                                    good computer 512)
%         factor - level of noise, affects boundaries and the interiors 
%                  of 3D shapes (factor = 0.5 is reasonable).
% Usage:  > object =  Make3DData(64, 0.5)
%
% To view the object you may want to make MOVIE with frames taken
% along the third dimension.
%
% > for i = 1:N %N is the same as in the input of Make3DData
% > imagesc( obj(:,:,i) );
% >  axis equal
% >  axis off
% > M(:,i) = getframe;
% > end
%
%  To view: > movie(M)
%-----------------------------------
obj = factor.*randn(N,N,N);
 for i = -N/2+1:N/2
     for j = -N/2+1:N/2
         for k = -N/2+1:N/2
            if i^2 + j^2 + k^2 < (N/2 + factor*randn - 1)^2 
                obj(i+N/2,j+N/2,k+N/2) = 1 + factor*randn;
            end
            if  abs(i)+abs(j)+abs(k) < (N/2 + factor*randn - 1) 
                obj(i+N/2,j+N/2,k+N/2) = 4 + factor*randn;
            end
        end
    end
end
%
%     
%  Vicki Yang and Brani Vidakovic
%                  ISyE, GaTech 2002.
    
