% % % Camera Fit To Selected Object 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::BPCameraFitToSelectedObject(%i) % % % % % % Matlab::BPCameraFitToSelectedObject(%i) % % % % % % Description: % % Move the camera so that the selected object is centered in the window. % Camera orientation is not modified. % Apply to Spots, Surface, Track and Filament. % % function BPCameraFitToSelectedObject(aImarisApplicationID) % connect to Imaris Com interface if ~isa(aImarisApplicationID, 'COM.Imaris_Application') vImarisServer = actxserver('ImarisServer.Server'); vImarisApplication = vImarisServer.GetObject(aImarisApplicationID); else vImarisApplication = aImarisApplicationID; end % get the selected item vSelectedObject = vImarisApplication.mSurpassSelection; % is Spots, Surface, Track or Filament? vObjectType = 0; vObject = vImarisApplication.mFactory.ToSpots(vSelectedObject); if vImarisApplication.mFactory.IsSpots(vObject) vObjectType = 1; % take the spots visible at the current time point [vSpotsXYZ, vSpotsTime] = vObject.Get; vSpotsIndex = vSpotsTime==vImarisApplication.mVisibleIndexT; vKeyPoints = vSpotsXYZ(vSpotsIndex,:); end vObject = vImarisApplication.mFactory.ToSurface(vSelectedObject); if vImarisApplication.mFactory.IsSurface(vObject) vObjectType = 2; vKeyPoints = vObject.GetVertices; end vObject = vImarisApplication.mFactory.ToTrack(vSelectedObject); if vImarisApplication.mFactory.IsTrack(vObject) vObjectType = 3; [vSpotsXYZ, vSpotsTime] = vObject.GetSpots.Get; vSpotsIndex = vSpotsTime==vImarisApplication.mVisibleIndexT; vKeyPoints = vSpotsXYZ(vSpotsIndex,:); end vObject = vImarisApplication.mFactory.ToFilament(vSelectedObject); if vImarisApplication.mFactory.IsFilament(vObject) vObjectType = 4; vKeyPoints = vObject.GetPositionsXYZ; end if vObjectType==0 || size(vKeyPoints,1)==0 msgbox('Please select some spots, surface, track or filament!'); return; end % how the points are viewed by the camera? vCamera = vImarisApplication.mSurpassCamera; % [vPositionX, vPositionY, vPositionZ] = vCamera.GetPosition; [vOrientationX, vOrientationY, vOrientationZ, vAngle] = vCamera.GetOrientationAxisAngle; vAxis = [vOrientationX; vOrientationY; vOrientationZ]; vAxis = vAxis/norm(vAxis); % vFocus = vCamera.mFocus; % get the box containing the object and computes the focus distance if size(vKeyPoints,1)==1 vCenter = vKeyPoints; vFocus = 30; else vCenter = (min(vKeyPoints)+max(vKeyPoints))/2; vPoints = zeros(size(vKeyPoints,1),3); for vPoint = 1:size(vPoints,1) vPoints(vPoint,:) = RotateVA(vKeyPoints(vPoint,:)',vAxis,vAngle)'; end vMin = min(vPoints); vMax = max(vPoints); vFocus = max([15,vMax(1:2)-vMin(1:2)])*2; end % set the camera vDirection = RotateVA([0;0;1],vAxis,vAngle); vCamera.SetPosition(vCenter(1)+vFocus*vDirection(1), vCenter(2)+vFocus*vDirection(2), ... vCenter(3)+vFocus*vDirection(3)); vCamera.mFocus = vFocus; function aResult = RotateVA(aVector, aAxis, aAngle) % rotate aVector around aAxis by aAngle aResult = aVector .* cos(aAngle) + aAxis.*dot(aAxis,aVector) .* (1-cos(aAngle)) + ... cross(aAxis,aVector) .* sin(aAngle);