⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 v3d_getcolormap.m

📁 Matlab显式三维地震数据的源代码
💻 M
字号:
function varargout = v3d_getcolormap(varargin)
% Select/import colormaps
%
% Adaptation of function "v3d_getcolormap" by Robert Barsch; the original
% version is available at The Matlab Central File Exchange, File ID 2255.
% http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=2255&objectType=file
%
% Modified by E. Rietsch: October 15, 2006
%
% v3d_getcolormap
%   Provides a list of all available standard colormaps, all user-defined
%   colormaps in folder "Color", and all user-defined colormap functions
%
%   Known user-specific formats
% 
%       Programm    | file extension | subfunction
%       ------------+----------------+-----------
%       Slicer      | .cmp           | importcmp
%       Pulse Ekko  | .tbl           | importtbl
%
% 
% v3d_getcolormap(filename) 
%   Farbpalettenwerte werden aus filename importiert und zur點kgeben 
%
% v3d_getcolormap(function) 
%   Farbpalettenwerte werden generiert und zur點kgeben 


%	User-defined colormaps
% Format: 'path/*.extension'
usrmap={'color/*.cmp';...
        'color/*.tbl';};

% Benutzerdefinierte Funktionen
% Format: 'name' 'function'
fctmap={'hotgray' 'hot.*gray';...
        'hotjet'  'hot.*jet';};

% Standard colormaps
% Format: 'Name' 'Funktion'
stdmap={'autumn' 'autumn';...
        'bone'   'bone';...
        'cool'   'cool';...
        'copper' 'copper';...
        'gray'   'gray';...
        'hot'    'hot';...
        'hsv'    'hsv';...
        'jet'    'jet';...
        'pink'   'pink';...
        'spring' 'spring';...
        'summer' 'summer';...
        'winter' 'winter';};

% Separator
% Format: 'Name' Funktion
delimiter={'---' 'jet'};


% Wenn Parameter vorhanden -> Dateiname oder Funktion wurde angegeben
if nargin==1
    % Testen ob Standartfarbpalette
    if any(strcmp(stdmap(:,1),varargin{1}))
        pos=strmatch(varargin{1},stdmap,'exact');
        varargout={stdmap{pos(1),2}};
    else
        % Testen ob Benutzerdefinierte Funktion
        if any(strcmp(fctmap(:,1),varargin{1}))
            pos=strmatch(varargin{1},fctmap,'exact');
            varargout={fctmap{pos(1),2}};
        else
            % Testen ob Trennlinie ausgew鋒lt
            if any(strcmp(delimiter(1,1),varargin{1}))
                varargout=delimiter(1,2);
            else
                % Ansonsten Benutzerdefinierte Farbpalette importieren
                % 躡ergabe des Dateinamens filename und R點kgabe der Farbpalette
                varargout={num2str(v3d_importcolormap(varargin{1}))};
            end
        end
    end
else
    % Kein Parameter -> Auflisten aller verf黦baren Farbpaletten
    % Namen der Standardpaletten und Funktionen zusammenf黦en
    cmaplist=[  stdmap(:,1);...
                delimiter(:,1);...
                fctmap(:,1);...
                delimiter(:,1);];

    % Dateinamen der Benutzerdefinierten Farbpaletten finden
    % und zur Farbpalettenliste hinzuf黦en
    for k=1:length(usrmap)
        path = fileparts(usrmap{k});
        files=dir(usrmap{k});
        for i=1:length(files)
            cmaplist(length(cmaplist)+1)={strcat(path,'/',files(i).name)};    
        end
    end
    
    % R點kgabe der Zeichenkettenliste aller verf黦baren Farbpaletten 
    varargout={cmaplist(:)};
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function cmap = v3d_importcolormap(filename)
% Farbpalette importieren
% --------------------------------------------------------------------
%   bekannte benutzerspezifische Formate:
% 
%       Programm    | Dateiendung   | Unterfunktion
%       ------------+---------------+--------------
%       Slicer      | .cmp          | importcmp
%       Pulse Ekko  | .tbl          | importtbl
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Test ob angegebene Datei vorhanden
fid = fopen(filename,'rt');
if fid ~= -1  &&  length(filename) >4 
    endung=filename(length(filename)-3:length(filename));
    switch (endung)
        case '.cmp'
            cmap=importcmp(filename);
        case '.tbl'
            cmap=importtbl(filename);
        otherwise
            error(['Fehler: Dateityp ' filename ' wird nicht unterst黷zt!']);
    end    
else
    error(['Fehler: Konnte Datei ' filename ' nicht 鰂fnen!']);
end
fclose(fid);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function cmap = importcmp(filename)
% Slicer Farbpalette importieren
% --------------------------------------------------------------------
%
% Format of a .cmp file:
%
% 10 lines: comments 
% n  lines: Alpha R G B ; n  
%
% Color values range from 0 to 1

% Einlesen 
[r g b] = textread(filename,'%*f %f %f %f ; %*d','headerlines',10);

% m鰃licherweise Testen ob < 128 -> Performancegr黱de

% R點kgabe an Hauptfunktion
cmap=[r g b];


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function cmap = importtbl(filename)
% Pulse Ekko Farbpalette importieren
% --------------------------------------------------------------------
%
% Format of a .tbl file:
%
% 1 line : Comment
% n lines: black cyan magenta tellow 
%
%   Color values range from 0 bis 255

%   Einlesen und 躡ergabe an Hauptfunktion
[c m y] = textread(filename,'%*f %f %f %f','headerlines',1);

%   Convert to RGB
r=((m(:)+y(:))/2)/255;
g=((c(:)+y(:))/2)/255;
b=((c(:)+m(:))/2)/255;

%   Return to calling function
cmap=[r(:),g(:),b(:)];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -