Returns the ROI.
()
| 164 | |
| 165 | /** Returns the ROI. */ |
| 166 | public Roi getRoi() throws IOException { |
| 167 | if (path!=null) { |
| 168 | File f = new File(path); |
| 169 | size = (int)f.length(); |
| 170 | if (!path.endsWith(".roi") && size>5242880) |
| 171 | throw new IOException("This is not an ROI or file size>5MB)"); |
| 172 | name = f.getName(); |
| 173 | is = new FileInputStream(path); |
| 174 | } |
| 175 | data = new byte[size]; |
| 176 | |
| 177 | int total = 0; |
| 178 | while (total<size) |
| 179 | total += is.read(data, total, size-total); |
| 180 | is.close(); |
| 181 | if (getByte(0)!=73 || getByte(1)!=111) //"Iout" |
| 182 | throw new IOException("This is not an ImageJ ROI"); |
| 183 | int version = getShort(VERSION_OFFSET); |
| 184 | int type = getByte(TYPE); |
| 185 | int subtype = getShort(SUBTYPE); |
| 186 | int top= getShort(TOP); |
| 187 | int left = getShort(LEFT); |
| 188 | int bottom = getShort(BOTTOM); |
| 189 | int right = getShort(RIGHT); |
| 190 | int width = right-left; |
| 191 | int height = bottom-top; |
| 192 | int n = getUnsignedShort(N_COORDINATES); |
| 193 | if (n==0) |
| 194 | n = getInt(SIZE); |
| 195 | int options = getShort(OPTIONS); |
| 196 | int position = getInt(POSITION); |
| 197 | int hdr2Offset = getInt(HEADER2_OFFSET); |
| 198 | int channel=0, slice=0, frame=0; |
| 199 | int overlayLabelColor=0; |
| 200 | int overlayFontSize=0; |
| 201 | int group=0; |
| 202 | int imageOpacity=0; |
| 203 | int imageSize=0; |
| 204 | boolean subPixelResolution = (options&SUB_PIXEL_RESOLUTION)!=0 && version>=222; |
| 205 | boolean drawOffset = subPixelResolution && (options&DRAW_OFFSET)!=0; |
| 206 | boolean scaleStrokeWidth = true; |
| 207 | if (version>=228) |
| 208 | scaleStrokeWidth = (options&SCALE_STROKE_WIDTH)!=0; |
| 209 | |
| 210 | boolean subPixelRect = version>=223 && subPixelResolution && (type==rect||type==oval); |
| 211 | double xd=0.0, yd=0.0, widthd=0.0, heightd=0.0; |
| 212 | if (subPixelRect) { |
| 213 | xd = getFloat(XD); |
| 214 | yd = getFloat(YD); |
| 215 | widthd = getFloat(WIDTHD); |
| 216 | heightd = getFloat(HEIGHTD); |
| 217 | } |
| 218 | |
| 219 | if (hdr2Offset>0 && hdr2Offset+IMAGE_SIZE+4<=size) { |
| 220 | channel = getInt(hdr2Offset+C_POSITION); |
| 221 | slice = getInt(hdr2Offset+Z_POSITION); |
| 222 | frame = getInt(hdr2Offset+T_POSITION); |
| 223 | overlayLabelColor = getInt(hdr2Offset+OVERLAY_LABEL_COLOR); |
no test coverage detected