www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@calibrationdata/@visionv2matinterface/pRead.m
function calibration = pRead(obj, calibration, filename) %PREAD Private method. % PREAD reads a calibration from a Vision 2.x MAT file. % % See also ROLLBACK, PWRITE. % Copyright 2000-2011 The MathWorks, Inc. narginchk(3,3); nargoutchk(1,1); pm = obj.ProgressManager; pm.reset; pm.notify('Performing startup tasks') % Load structure pm.notify('Loading file from disk'); dataStructure = load(filename); dataStructure = dataStructure.ATICALParameterList; valueStructure = dataStructure.Scalar(:); curveStructure = dataStructure.Table2D(:); mapStructure = dataStructure.Table3D(:); % Further process items to discover their types (axis or curve) % Store codes: 1 = value, 2 = axis, 3 = curve, 4 = map, 0 = unknown t = zeros(size(curveStructure)); for i = 1:numel(curveStructure), thisS = curveStructure(i); if ~any(diff(thisS.XAxis)==0) && all(diff(sign(diff(thisS.XAxis)))==0) % Distinguish axes from curves by looking at monotonicity and rem if all(rem(thisS.YAxis,1)==0) && ~any(diff(thisS.YAxis)==0) && all(diff(sign(diff(thisS.YAxis)))==0) % Axis t(i) = 2; else % Curve t(i) = 3; end else % Unknown t(i) = 4; end end axisStructure = curveStructure(t==2); curveStructure = curveStructure(t==3); % Store lengths for convenience nValues = numel(valueStructure); nAxes = numel(axisStructure); nCurves = numel(curveStructure); nMaps = numel(mapStructure); % Process values if nValues > 0 pm.notify(sprintf('Processing %d values', nValues)); value = mbcutils.handleArray(nValues, 1); % preallocate for i = 1:nValues, thisValueS = valueStructure(i); try % Value thisValue = calibrationdata.value; thisValue.Identifier = calibrationdata.getVisionShortIdentifier(thisValueS.Name); thisValue.Name = thisValueS.Name; thisValue.Value = thisValueS.XAxis; catch ME fprintf('Could not read value: %s\n%s\n', thisValueS.Name, ME.message); continue end % Store value(i) = thisValue; pm.update(i/(nValues+nAxes+nCurves+nMaps)); end % Remove invalid value = value(ishandle(value)); % Add to calibration if numel(value) > 0 pm.notify(sprintf('Storing %d values', nValues)); calibration.addValue(value); end end % Process axes if nAxes > 0 pm.notify(sprintf('Processing %d axes', nAxes)); axis = mbcutils.handleArray(nAxes, 1); % preallocate for i = 1:nAxes, thisAxisS = axisStructure(i); try % Axis thisAxis = calibrationdata.axis; thisAxis.Identifier = calibrationdata.getVisionShortIdentifier(thisAxisS.Name); thisAxis.Name = thisAxisS.Name; thisAxis.Value = thisAxisS.XAxis; thisAxis.Index = thisAxisS.YAxis; catch ME fprintf('Could not read axis: %s\n%s\n', thisAxisS.Name, ME.message); continue end % Store axis(i) = thisAxis; pm.update((i+nValues)/(nValues+nAxes+nCurves+nMaps)); end % Remove invalid axis = axis(ishandle(axis)); % Add to calibration if numel(axis) > 0 pm.notify(sprintf('Storing %d axes', nAxes)); calibration.addAxis(axis); end end % Process curves if nCurves > 0 pm.notify(sprintf('Processing %d curves', nCurves)); curve = mbcutils.handleArray(nCurves, 1); % preallocate xAxis = mbcutils.handleArray(nCurves, 1); % preallocate for i = 1:nCurves, thisCurveS = curveStructure(i); try % Curve thisCurve = calibrationdata.curve; thisCurve.Identifier = calibrationdata.getVisionShortIdentifier(thisCurveS.Name); thisCurve.Name = thisCurveS.Name; thisCurve.Value = thisCurveS.YAxis; catch ME fprintf('Could not read curve: %s\n%s\n', thisCurveS.Name, ME.message); continue end try % X axis thisXAxis = calibrationdata.axis; thisXAxis.Identifier = thisCurve.XAxisIdentifier; thisXAxis.Value = thisCurveS.XAxis; catch ME fprintf('Could not read X axis of curve: %s\n%s\n', thisCurveS.Name, ME.message); continue end % Store curve(i) = thisCurve; xAxis(i) = thisXAxis; pm.update((i+nValues+nAxes)/(nValues+nAxes+nCurves+nMaps)); end % Remove invalid curve = curve(ishandle(curve)); xAxis = xAxis(ishandle(xAxis)); % Add to calibration if numel(curve) > 0 && numel(xAxis) > 0 pm.notify(sprintf('Storing %d curves', nCurves)); calibration.addCurve(curve); calibration.setAxis(xAxis); end end % Process maps if nMaps > 0 pm.notify(sprintf('Processing %d maps', nMaps)); map = mbcutils.handleArray(nMaps, 1); % preallocate xAxis = mbcutils.handleArray(nMaps, 1); % preallocate yAxis = mbcutils.handleArray(nMaps, 1); % preallocate for i = 1:nMaps, thisMapS = mapStructure(i); try % Map thisMap = calibrationdata.map; thisMap.Identifier = calibrationdata.getVisionShortIdentifier(thisMapS.Name); thisMap.Name = thisMapS.Name; thisMap.Value = transpose(thisMapS.ZAxis); catch ME fprintf('Could not read map: %s\n%s\n', thisMapS.Name, ME.message); continue end try % X axis thisXAxis = calibrationdata.axis; thisXAxis.Identifier = thisMap.XAxisIdentifier; thisXAxis.Value = thisMapS.XAxis; catch ME fprintf('Could not read X axis of map: %s\n%s\n', thisMapS.Name, ME.message); continue end try % Y axis thisYAxis = calibrationdata.axis; thisYAxis.Identifier = thisMap.YAxisIdentifier; thisYAxis.Value = thisMapS.YAxis; catch ME fprintf('Could not read Y axis of map: %s\n%s\n', thisMapS.Name, ME.message); continue end % Store map(i) = thisMap; xAxis(i) = thisXAxis; yAxis(i) = thisYAxis; pm.update((i+nValues+nAxes+nCurves)/(nValues+nAxes+nCurves+nMaps)); end % Remove invalid map = map(ishandle(map)); xAxis = xAxis(ishandle(xAxis)); yAxis = yAxis(ishandle(yAxis)); % Add to calibration if numel(map) > 0 && numel(xAxis) > 0 && numel(yAxis) > 0 pm.notify(sprintf('Storing %d maps', nMaps)); calibration.addMap(map); calibration.setAxis(xAxis); calibration.setAxis(yAxis); end end pm.update(1); pm.notify('Cleaning up');