function vrep = obtainVrep3d(choice, param)
% This is a subfunction.
%
% See also: obtainVRep, obtainHRep

% The elk-library: convex geometry applied to crystallization modeling.
%   Copyright (C) 2012 Alexander Reinhold
%
% This program is free software: you can redistribute it and/or modify it 
%   under the terms of the GNU General Public License as published by the 
%   Free Software Foundation, either version 3 of the License, or (at your 
%   option) any later version.
%
% This program is distributed in the hope that it will be useful, but 
%   WITHOUT ANY WARRANTY; without even the implied warranty of 
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
%   General Public License for more details.
%
% You should have received a copy of the GNU General Public License along 
%   with this program.  If not, see <http://www.gnu.org/licenses/>.

switch choice
    % common bodies
    case 'cube'
        vrep.V = [0 0 0;0 0 1;0 1 0;0 1 1;...
               1 0 0;1 0 1;1 1 0;1 1 1;];
    case 'sphere'
        if isempty(param), param=20;end
        vrep = obtainSphere(param);
    case 'ball'
        vrep = obtainSphere(param);
    case 'cone'
        if isempty(param), param=20;end
        vrep = obtainCircle(param);
        vrep.V(:,3) = 0; % extend dimension of base
        vrep.V(end+1,:) = [0 0 1];
    case 'pyramid'
        % As a polygon is a bad approximation of a circle, a pyramid is a
        % bad approximation of a cone:
        vrep = obtainVrep3d('cone', param);
    case 'bicone'
        if isempty(param), param=20;end
        vrep = obtainCircle(param);
        vrep.V(:,3) = 0; % extend dimension of base
        vrep.V(end+1,:) = [0 0 1];  % upper tip
        vrep.V(end+1,:) = [0 0 -1]; % add lower tip
    case 'bipyramid'
        % As a polygon is a bad approximation of a circle, a pyramid is a
        % bad approximation of a cone:
        vrep = obtainVrep3d('bicone', param);
    case 'prism'
        vrep = obtainVrep2d('polygon', param);
        vrep.V(:,3) = 0; % extend dimension of base
        vrepMoved = moveVrep(vrep, [0 0 1]); % duplicate base
        vrep.V((end+1):(2*end),:) = vrepMoved.V;
    case 'antiprism'
        vrepBottom = obtainVrep2d('polygon', param);
        vrepTop = rotateVrep2d(vrepBottom, pi/param);
        vrepBottom.V(:,3) = 0; % extend dimension
        vrepTop.V(:,3) = 1; 
        vrep.V = [vrepBottom.V; vrepTop.V]; % duplicate base
        
    % special bodies
    case 'ikosaprism'
        vrep = [1 0 0;-1 0 0;0 sqrt(3) 0;...
            0 0 1;-1 sqrt(3) 1;1 sqrt(3) 1];
    case 'mixCubeOctahedron'
        CUB = obtainVrep3d('prism',4);
        CUB = moveVrep(CUB, [0 0 -0.5]);
        CUB = stretchVrep(CUB, [1/sqrt(2) 1/sqrt(2) sqrt(2)], [0 0 0]);
        POLY = stretchVrep(obtainVrep2d('polygon',4), [1 1], [0 0]);
        POLY.V(:,3) = 0;
        POLY = rotateVrep3d(POLY, 'z', pi/4, [0 0 0]);
        vrep.V = [CUB.V;POLY.V];
        
    % recursion into lower dimension
    otherwise
        vrep = obtainVrep2d(choice, param);
        % extend dimension
        vrep.V(:,3) = 0;
end
