%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % function ColorPerVertex() : Creates an RGB color matrix based on height % values. % % % INPUT : m x n matrix, name of file to write to,'filename'. % OUTPUT: m x 3n matrix of RGB colors, also writes as text to 'filename'. % % MODIFY: level height values, # of levels, colors, & # of colors to fit % your problem. If you change the number of levels don't forget to % add or remove if/elseif statements below. % % Author: Jason Tate June 10, 1998 % tate@edcenter.sdsu.edu % % Educational Center for Computational Science & Engineering % http://www.edcenter.sdsu.edu % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [ColorMatrix] = ColorPerVertex(ElevationMatrix,filename) % DEFINE COLOR HEIGHT BOUNDARIES %less than 732 level_1 = 732; % 732 to 785 level_2 = 785; % 785 to 840 level_3 = 840; % 840 to 910 level_4 = 910; % 910 or greater % INITIALIZE RGB COLORS color_0 = [0.1 0.3 0.9]; % Blue color_1 = [0.2 0.8 0.2]; % Green color_2 = [0.4 0.6 0.5]; % Darker Green color_3 = [0.75 0.75 0.75]; % Gray color_4 = [1.0 1.0 1.0]; % White % INITIALIZE COLORS FOR TEXT OUTPUT TO FILE color_0_string = '0.1 0.3 0.9'; color_1_string = '0.2 0.8 0.2,'; color_2_string = '0.4 0.6 0.5,'; color_3_string = '0.75 0.75 0.75,'; color_4_string = '1.0 1.0 1.0,'; % CHECK # OF ARGUMENTS if nargin > 2 error('too many arguments') end; if nargin < 2 error('too few arguments') end; % DETERMINE DIMENSIONS OF MATRIX Dimensions = size(ElevationMatrix); numRows = Dimensions(1); numColumns = Dimensions(2); % INITIALIZE COLORMATRIX ColorMatrix = ones(numRows,3 * numColumns); % OPEN FILE TO WRITE MATRIX TO fp = fopen(filename,'w'); for i = 1:numRows for j = 1:numColumns if ElevationMatrix(i,j) >= level_4 % SAVE TO MATRIX FOR FURTHER PROCESSING ColorMatrix(i,j*3-2) = color_4(1); ColorMatrix(i,j*3-1) = color_4(2); ColorMatrix(i,j*3) = color_4(3); % WRITE TO FILE FORMATTED FOR VRML COLOR NODE fprintf(fp,'%s',color_4_string); elseif ElevationMatrix(i,j) >= level_3 % SAVE TO MATRIX FOR FURTHER PROCESSING ColorMatrix(i,j*3-2) = color_3(1); ColorMatrix(i,j*3-1) = color_3(2); ColorMatrix(i,j*3) = color_3(3); % WRITE TO FILE FORMATTED FOR VRML COLOR NODE fprintf(fp,'%s',color_3_string); elseif ElevationMatrix(i,j) >= level_2 % SAVE TO MATRIX FOR FURTHER PROCESSING ColorMatrix(i,j*3-2) = color_2(1); ColorMatrix(i,j*3-1) = color_2(2); ColorMatrix(i,j*3) = color_2(3); % WRITE TO FILE FORMATTED FOR VRML COLOR NODE fprintf(fp,'%s',color_2_string); elseif ElevationMatrix(i,j) >= level_1 % SAVE TO MATRIX FOR FURTHER PROCESSING ColorMatrix(i,j*3-2) = color_1(1); ColorMatrix(i,j*3-1) = color_1(2); ColorMatrix(i,j*3) = color_1(3); % WRITE TO FILE FORMATTED FOR VRML COLOR NODE fprintf(fp,'%s',color_1_string); else % SAVE TO MATRIX FOR FURTHER PROCESSING ColorMatrix(i,j*3-2) = color_0(1); ColorMatrix(i,j*3-1) = color_0(2); ColorMatrix(i,j*3) = color_0(3); % WRITE TO FILE FORMATTED FOR VRML COLOR NODE fprintf(fp,'%s',color_0_string); end; end fprintf(fp,'\n'); end fclose(fp);