% % % Camera Manager Function for Imaris % % Copyright Bitplane AG 2006 % % % Installation: % % - Copy this file into the XTensions folder in the Imaris installation directory. % - You will find this function in the Image Processing menu % % % % % % Matlab::BPCameraManager(%i) % % % % % % % Description: % % Save/load/clear camera settings in .mat files. % Settings are: Position, orientation, perspective, ortographic, % focus and height. % % function BPCameraManager(aImarisApplicationID) global vImarisApplication vEditFileName; % button callbacks if aImarisApplicationID==-1 clear global vImarisApplication; return; elseif isa(aImarisApplicationID, 'numeric') && aImarisApplicationID==-5; Browse; return; elseif isa(aImarisApplicationID, 'numeric') && aImarisApplicationID<-1; Execute(-aImarisApplicationID-1); return; end % connect to Imaris Com interface if ~isa(aImarisApplicationID, 'COM.Imaris_Application') vImarisServer = actxserver('ImarisServer.Server'); vImarisApplication = vImarisServer.GetObject(aImarisApplicationID); else vImarisApplication = aImarisApplicationID; end % create the window uicontrol('Style', 'text', 'String', 'Imaris Camera Manager', ... 'FontName', 'Times New Roman', 'FontSize', 10, ... 'Position', [10,70,170,20], 'DeleteFcn', 'BPCameraManager(-1)'); uicontrol('Style', 'pushbutton', 'String', 'Browse...', ... 'Position', [210,70,80,20], 'Callback', 'BPCameraManager(-5)'); uicontrol('Style', 'text', 'String', 'File Name:', ... 'FontName', 'Times New Roman', 'FontSize', 10, ... 'Position', [10,50,70,20]); vEditFileName = uicontrol('Style', 'edit', 'String', 'ImarisCamera.mat', ... 'FontName', 'Times New Roman', 'FontSize', 10, ... 'Position', [80,50,210,20]); uicontrol('Style', 'pushbutton', 'String', 'Save', ... 'Position', [10,10,80,30], 'Callback', 'BPCameraManager(-2)'); uicontrol('Style', 'pushbutton', 'String', 'Load', ... 'Position', [110,10,80,30], 'Callback', 'BPCameraManager(-3)'); uicontrol('Style', 'pushbutton', 'String', 'Clear', ... 'Position', [210,10,80,30], 'Callback', 'BPCameraManager(-4)'); vWindow = get(vEditFileName, 'Parent'); vWindowPosition = get(vWindow, 'Position'); vWindowPosition(3:4) = [300, 100]; set(vWindow, 'Position', vWindowPosition); %----------------------------------------------% function Browse() global vEditFileName; vFileName = get(vEditFileName,'String'); [vFileName, vPathName] = uigetfile({'*.mat','MAT-files (*.mat)'}, ... 'Select the file', vFileName); if ~isequal(vFileName,0) set(vEditFileName,'String',fullfile(vPathName,vFileName)); end %----------------------------------------------% function Execute(aOperation) % aOperation = 1 save, 2 load, 3 clear global vImarisApplication vEditFileName; vStringOperations = {'save', 'load', 'clear'}; vFileName = get(vEditFileName,'String'); vCamera = vImarisApplication.mSurpassCamera; if aOperation==1 vName = inputdlg({'Please enter the camera settings name:'}, ... 'Imaris Object Manager', 1, {'Default'}); vName = char(vName); if isempty(vName) return; end else % load the list of the saved camera settings if exist(vFileName, 'file') load(vFileName,'vCameraNames'); vNumberOfObjects = length(vCameraNames); else vNumberOfObjects = 0; end if vNumberOfObjects==0 msgbox(['There is no object to ', char(vStringOperations(aOperation)), '!']); return; end [vSelectedObject, vOk] = listdlg('ListString', vCameraNames, ... 'SelectionMode','single',... 'ListSize',[250 150],... 'Name','Imaris Object Manager',... 'PromptString',{['Please select the object to ', ... char(vStringOperations(aOperation)), ':']}); if vOk<1, return; end; vName = char(vCameraNames(vSelectedObject)); end % remove invalid characters vName_ = vName; for vLetter = 1:length(vName) vChar = vName(vLetter); if (vChar<'0' || vChar>'9') && (vChar<'a' || vChar>'z') && (vChar<'A' || vChar>'Z') vName_(vLetter) = '_'; end end % names (that should be unique) of the variables in the file.mat vValidName = ['v',vName_]; if aOperation==1 % save if exist(vFileName, 'file') load(vFileName, 'vCameraNames'); % if the variable is already saved, their values are overwritten % but no new object is added vFound = false; vNumberOfObjects = length(vCameraNames); for vIndex = 1:vNumberOfObjects if strcmp(vName,char(vCameraNames(vIndex))) vFound = true; break; end end if vFound vAnswer = questdlg(['Overwrite ',vName,'?'], ... 'Imaris Object Manager', 'Yes', 'No', 'Yes'); if ~strcmp(vAnswer,'Yes') return; end else vCameraNames(vNumberOfObjects+1) = {vName}; save(vFileName, 'vCameraNames', '-append'); end else vCameraNames = {vName}; save(vFileName, 'vCameraNames'); end [vX, vY, vZ] = vCamera.GetPosition; [vAxisX, vAxisY, vAxisZ, vAngle] = vCamera.GetOrientationAxisAngle; eval([vValidName,' = [vX, vY, vZ, vAxisX, vAxisY, vAxisZ, vAngle, ', ... 'vCamera.mPerspective, vCamera.mFocus, vCamera.mHeight];']); save(vFileName, vValidName, '-append'); elseif aOperation==2 % load load(vFileName, vValidName); vSettings = eval(vValidName); vCamera.SetPosition(vSettings(1), vSettings(2), vSettings(3)); vCamera.SetOrientationAxisAngle(vSettings(4), vSettings(5), vSettings(6), vSettings(7)); vCamera.mPerspective = vSettings(8); vCamera.mFocus = vSettings(9); vCamera.mHeight = vSettings(10); else % clear % copy the data into a struct % deletes the original file % rebuild the right file vAnswer = questdlg(['Remove ',vName,' from the memory?'], ... 'Imaris Object Manager', 'Yes', 'No', 'Yes'); if ~strcmp(vAnswer,'Yes') return; end vFile = load(vFileName); vFields = fieldnames(vFile); % remove the name from the lists vRemaining = [1:vSelectedObject-1,vSelectedObject+1:vNumberOfObjects]; vCameraNames = vCameraNames(vRemaining); save(vFileName, 'vCameraNames'); vNumberOfLetters = length(vValidName); for vVariable = 1:length(vFields) vString = char(vFields(vVariable)); if ~strcmp(vString,'vCameraNames') && ... (length(vString)