Displays the specified stack image, where {@literal 1<=n<=stackSize}. Does nothing if this image is not a stack. @see #setPosition @see #setC @see #setZ @see #setT
(int n)
| 2074 | * @see #setT |
| 2075 | */ |
| 2076 | @AstroImageJ(reason = "Add reset if color type is RGB", modified = true) |
| 2077 | public synchronized void setSlice(int n) { |
| 2078 | if (getType()==ImagePlus.COLOR_RGB) ip.reset(); |
| 2079 | if (stack==null || (n==currentSlice&&ip!=null)) { |
| 2080 | if (!noUpdateMode) |
| 2081 | updateAndRepaintWindow(); |
| 2082 | return; |
| 2083 | } |
| 2084 | if (n>=1 && n<=stack.size()) { |
| 2085 | Roi roi = getRoi(); |
| 2086 | if (roi!=null) |
| 2087 | roi.endPaste(); |
| 2088 | if (isProcessor()) { |
| 2089 | if (currentSlice==0) currentSlice=1; |
| 2090 | stack.setPixels(ip.getPixels(),currentSlice); |
| 2091 | } |
| 2092 | setCurrentSlice(n); |
| 2093 | Object pixels = null; |
| 2094 | Overlay overlay2 = null; |
| 2095 | if (stack.isVirtual() && !((stack instanceof FileInfoVirtualStack)||(stack instanceof AVI_Reader))) { |
| 2096 | ImageProcessor ip2 = stack.getProcessor(currentSlice); |
| 2097 | overlay2 = ip2!=null?ip2.getOverlay():null; |
| 2098 | if (overlay2!=null) |
| 2099 | setOverlay(overlay2); |
| 2100 | if (stack instanceof VirtualStack) { |
| 2101 | Properties props = ((VirtualStack)stack).getProperties(); |
| 2102 | if (props!=null) |
| 2103 | setProperty("FHT", props.get("FHT")); |
| 2104 | } |
| 2105 | if (ip2!=null) pixels=ip2.getPixels(); |
| 2106 | } else |
| 2107 | pixels = stack.getPixels(currentSlice); |
| 2108 | if (ip!=null && pixels!=null) { |
| 2109 | try { |
| 2110 | ip.setPixels(pixels); |
| 2111 | ip.setSnapshotPixels(null); |
| 2112 | } catch(Exception e) {} |
| 2113 | } else { |
| 2114 | ImageProcessor ip2 = stack.getProcessor(n); |
| 2115 | if (ip2!=null) ip = ip2; |
| 2116 | } |
| 2117 | if (compositeImage && getCompositeMode()==IJ.COMPOSITE && ip!=null) { |
| 2118 | int channel = getC(); |
| 2119 | if (channel>0 && channel<=getNChannels()) |
| 2120 | ip.setLut(((CompositeImage)this).getChannelLut(channel)); |
| 2121 | } |
| 2122 | if (win!=null && win instanceof StackWindow) |
| 2123 | ((StackWindow)win).updateSliceSelector(); |
| 2124 | if (Prefs.autoContrast && nChannels==1 && imageType!=COLOR_RGB) { |
| 2125 | (new ContrastEnhancer()).stretchHistogram(ip,0.35,ip.getStats()); |
| 2126 | ContrastAdjuster.update(); |
| 2127 | //IJ.showStatus(n+": min="+ip.getMin()+", max="+ip.getMax()); |
| 2128 | } |
| 2129 | if (imageType==COLOR_RGB) |
| 2130 | ContrastAdjuster.update(); |
| 2131 | if (!noUpdateMode) |
| 2132 | updateAndRepaintWindow(); |
| 2133 | else |
no test coverage detected