ShapeMaterial

This class provides shape materials.

Contents

classdef ShapeMaterial < handle
    % This defines the ShapeMaterial class.

    %   URL : $URL: $
    %   Log : $Id: ShapeMaterial.html,v 1.1 2008/07/23 12:51:20 jberg Exp $
    %   Copyright (c) 2008 The MathWorks, Inc.

Class Properties

    properties ( SetAccess = 'private', GetAccess = 'public' )
        ambientColor    = [0.6602 0.6719 0.7109];   % (RGB)
        density         = 2700;         % (double) (kg/m^3)
        diffuseColor    = [0 0 0];      % (RGB)
        emissiveColor   = [0.6602 0.6719 0.7109];  % (RGB)
        material_name   = 'Aluminum';   % (char)
        poissons_ratio  = 0.33;         % (double)
        shininess       = 100;          % (double) dull-to-shiny (1-128)
        specularColor   = [1 1 1];      % (RGB)
        transparency    = 0.25;         % (double)
        youngs_modulus  = 68;           % (double) MPa
        appearance;                     % (javax.media.j3d.Appearance)
    end
    properties ( SetAccess = 'private', GetAccess = 'private', Constant = true )
        PROPERTY_LIST = {
            'ambientColor'
            'density'
            'diffuseColor'
            'emissiveColor'
            'material_name'
            'poissons_ratio'
            'shininess'
            'specularColor'
            'transparency'
            'youngs_modulus'
            };
    end

    methods

Constructor

        function obj = ShapeMaterial(varargin)
            prop_list = eval([mfilename '.PROPERTY_LIST']);
            n_props = length(prop_list);
			Log.msg(sprintf('\n%s::%s',mfilename,mfilename));
			if(mod(nargin,2)~=0)
				error('Expecting inputs as property name-value pairs.')
			end
			error(nargchk(0, 2*n_props, nargin,'string'));

			% Property Name-Value pair matching
			for ii=1:2:nargin
				prop    = varargin{ii};
				val     = varargin{ii+1};
				idx     = strmatch(lower(prop),lower(prop_list),'exact');
				if isempty(idx)
					error('%s: This property is unknown',...
						'or cannot be set during the construction',...
						'of the object: %s ',prop,mfilename);
				else
					obj.(prop_list{idx}) = val;
				end
			end
			obj.attach_appearance();
		end

SAVEOBJ Method

       function A = saveobj(obj)
           A.ambientColor      = obj.ambientColor;     % (RGB)
           A.density           = obj.density;          % (double) (kg/m^3)
           A.diffuseColor      = obj.diffuseColor;     % (RGB)
           A.emissiveColor     = obj.emissiveColor;    % (RGB)
           A.material_name     = obj.material_name;    % (char)
           A.poissons_ratio    = obj.poissons_ratio;   % (double)
           A.shininess         = obj.shininess;        % (double) dull-to-shiny (1-128)
           A.specularColor     = obj.specularColor;    % (RGB)
           A.transparency      = obj.transparency;     % (double)
           A.youngs_modulus    = obj.youngs_modulus;   % (double) MPa
           A.appearance        = [];                   % (javax.media.j3d.Appearance)
       end

SET Methods

        function set.ambientColor(obj, in)
            prop_name = 'ambientColor';
            prop_type = 'double';
            [valid_flag in] = Validate.ARRAY(in,'type',prop_type,'minLen',3,'maxLen',3);
            if valid_flag
                obj.(prop_name) = in;
            end
        end
        function set.appearance(obj, in)
            prop_name = 'appearance';
			prop_type = 'javax.media.j3d.Appearance';
			% Validate and assign
			[valid_flag in] = Validate.SCALAR(in,'type',prop_type);
			if valid_flag
				obj.(prop_name) = in;
			end
        end
        function set.density(obj, in)
            prop_name = 'density';
            prop_type = 'double';
            [valid_flag in] = Validate.SCALAR(in,'type',prop_type);
            if valid_flag
                obj.(prop_name) = in;
            end
        end
        function set.diffuseColor(obj, in)
            prop_name = 'diffuseColor';
            prop_type = 'double';
            [valid_flag in] = Validate.ARRAY(in,'type',prop_type,'minLen',3,'maxLen',3);
            if valid_flag
                obj.(prop_name) = in;
            end
        end
        function set.emissiveColor(obj, in)
            prop_name = 'emissiveColor';
            prop_type = 'double';
            [valid_flag in] = Validate.ARRAY(in,'type',prop_type,'minLen',3,'maxLen',3);
            if valid_flag
                obj.(prop_name) = in;
            end
        end
        function set.material_name(obj, in)
            prop_name = 'material_name';
            prop_type = 'char';
            [valid_flag in] = Validate.ARRAY(in,'type',prop_type);
            if valid_flag
                obj.(prop_name) = in;
            end
        end
        function set.poissons_ratio(obj, in)
            prop_name = 'poissons_ratio';
            prop_type = 'double';
            [valid_flag in] = Validate.SCALAR(in,'type',prop_type);
            if valid_flag
                obj.(prop_name) = in;
            end
        end
        function set.shininess(obj, in)
            prop_name = 'shininess';
            prop_type = 'double';
            [valid_flag in] = Validate.SCALAR(in,'type',prop_type);
            if valid_flag
                obj.(prop_name) = in;
            end
        end
        function set.specularColor(obj, in)
            prop_name = 'specularColor';
            prop_type = 'double';
            [valid_flag in] = Validate.ARRAY(in,'type',prop_type,'minLen',3,'maxLen',3);
            if valid_flag
                obj.(prop_name) = in;
            end
        end
        function set.transparency(obj, in)
            prop_name = 'transparency';
            prop_type = 'double';
            [valid_flag in] = Validate.SCALAR(in,'type',prop_type);
            if valid_flag
                obj.(prop_name) = in;
            end
        end
        function set.youngs_modulus(obj, in)
            prop_name = 'youngs_modulus';
            prop_type = 'double';
            [valid_flag in] = Validate.SCALAR(in,'type',prop_type);
            if valid_flag
                obj.(prop_name) = in;
            end
        end
    end

    methods ( Static = true )

LOADOBJ Method

        function B = loadobj(A)
            % We use loadobj so that when a stored object is loaded, we can
            % perform necessary steps that are contained in the constructor. We
            % have to do this because the constructor is not executed when an
            % object is loaded.
            Log.msg(sprintf('\n%s::%s',mfilename,'loadobj (Entering)'));
            prop_list = eval([mfilename '.PROPERTY_LIST']);

            % Construct object using the stored properties
            storedFields = fieldnames(A);
            args = cell(0);
            for ii=1:length(storedFields)
                prop = storedFields{ii};
                idx     = strmatch(lower(prop),lower(prop_list),'exact');
                if ~isempty(idx)
                    args{end+1} = prop; %#ok<AGROW>
                    args{end+1} = A.(storedFields{ii}); %#ok<AGROW>
                end
            end
            B = ShapeMaterial(args{:});
            Log.msg(sprintf('%s::%s',mfilename,'loadobj (Exiting)'));
        end
    end

    methods ( Access = 'private' )

Private HELPER Methods

        function attach_appearance(obj)
            obj.appearance	= sv_Appearance.create_appearance(...
                obj.ambientColor,obj.emissiveColor,...
                obj.diffuseColor,obj.specularColor,...
                obj.shininess,obj.transparency);
        end
    end
end