% % % Surface Merge 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::BPSurfaceMerge(%i) % % % % % % % Matlab::BPSurfaceMerge(%i) % % % % % % % Description: % % Merge all the surface objects that are in the same folder in a single % surface object. % % function BPSurfaceMerge(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 spots vSurface = vImarisApplication.mFactory.ToSurface(vImarisApplication.mSurpassSelection); if ~vImarisApplication.mFactory.IsSurface(vSurface) msgbox('Please select a surface!'); return; end vMergedVertices = []; vMergedTriangles = []; vMergedNormals = []; vNumberOfSurfaces = 0; vProgressDisplay = waitbar(0,'Merging surfaces'); vTime = vSurface.GetTimeIndex; vParentGroup = vSurface.GetParent; vNumberOfChildren = vParentGroup.GetNumberOfChildren; for vChildIndex = 1:vNumberOfChildren vDataItem = vParentGroup.GetChild(vChildIndex - 1); if vImarisApplication.mFactory.IsSurface(vDataItem) && vDataItem.GetTimeIndex==vTime vVertices = vDataItem.GetVertices; vTriangles = vDataItem.GetTriangles; vNormals = vDataItem.GetNormals; vDelta = size(vMergedVertices,1); vMergedVertices = [vMergedVertices; vVertices]; vMergedTriangles = [vMergedTriangles; vTriangles+vDelta]; vMergedNormals = [vMergedNormals; vNormals]; vDataItem.mVisible = false; vNumberOfSurfaces = vNumberOfSurfaces+1; end waitbar(vChildIndex/vNumberOfChildren) end close(vProgressDisplay); vMergedSurface = vImarisApplication.mFactory.CreateSurface; vMergedSurface.SetSurface(vMergedVertices, vMergedTriangles, vMergedNormals, vTime); vMergedSurface.mName = sprintf('Surfaces merged [%i items]', vNumberOfSurfaces); vMergedSurface.SetColor(0.0, 1.0, 0.0, 0.0); vParentGroup.AddChild(vMergedSurface);