VOIUtils { public static DicomObject selectVoiObject(DicomObject img, DicomObject pr, int frame) { String iuid = img.getString(Tag.SOPInstanceUID); DicomObject voi = selectVoiItemFromPr(iuid, pr, frame); if (voi != null) { return voi; } if (pr != null) { return pr; } DicomElement framed = img.get(Tag.PerFrameFunctionalGroupsSequence); if (framed != null) { int size = framed.countItems(); if (frame >= 1 && frame <= size) { DicomObject frameObj = framed.getDicomObject(frame - 1); if (frameObj != null) { DicomObject voiObj = frameObj.getNestedDicomObject(Tag.FrameVOILUTSequence); if (voiObj != null && containsVOIAttributes(voiObj)) { return voiObj; } } } } DicomObject shared = img.getNestedDicomObject(Tag.SharedFunctionalGroupsSequence); if (shared != null) { DicomObject voiObj = shared.getNestedDicomObject(Tag.FrameVOILUTSequence); if (voiObj != null && containsVOIAttributes(voiObj)) { return voiObj; } } if (containsVOIAttributes(img)) return img; return null; }  static boolean containsVOIAttributes(DicomObject dobj); static DicomObject getLUT(DicomObject dobj, int sqTag); static boolean isModalityLUTcontainsPixelIntensityRelationshipLUT(
            DicomObject img); static boolean isModalityLUTcontainsPixelIntensityRelationshipLUT(
            String uid); static DicomObject selectModalityLUTObject(DicomObject img,
            DicomObject pr, int frame); static DicomObject selectVoiObject(DicomObject img, DicomObject pr, int frame); static DicomObject selectVoiItemFromPr(String iuid, DicomObject pr,
            int frame); static float[] getMinMaxWindowCenterWidth(DicomObject img,
            DicomObject pr, int frame, Raster raster); static int[] calcMinMax(DicomObject img, Raster raster);  }
@Test public void testSelectVOIObjectShouldReturnImageIfOnlyWindowWidthAndCenter() { DicomObject obj = createWindowCenterObject(); assertSame(obj, VOIUtils.selectVoiObject(obj, null, 1)); }
@Test public void testSelectVOIObjectShouldReturnNullIfWindowWidthWithoutCenter() { DicomObject obj = new BasicDicomObject(); obj.putFloat(Tag.WindowWidth, VR.DS, 10.0f); assertNull(VOIUtils.selectVoiObject(obj, null, 1)); }
@Test public void testSelectVOIObjectShouldReturnNullIfWindowCenterWithoutWidth() { DicomObject obj = new BasicDicomObject(); obj.putFloat(Tag.WindowWidth, VR.DS, 10.0f); assertNull(VOIUtils.selectVoiObject(obj, null, 1)); }
@Test public void testSelectVOIObjectShouldReturnImageIfValidVoiLutSequence() { DicomObject obj = new BasicDicomObject(); DicomElement sq = obj.putSequence(Tag.VOILUTSequence); DicomObject item = new BasicDicomObject(); item.putInts(Tag.LUTDescriptor, VR.US, new int[] { 1, 0, 8 }); item.putInts(Tag.LUTData, VR.US, new int[] { 255 }); sq.addDicomObject(item); assertSame(obj, VOIUtils.selectVoiObject(obj, null, 1)); }
@Test public void testSelectVOIObjectShouldReturnFrameIfPresentWithWindowCenterWidth() { DicomObject frameVoiLut = createWindowCenterObject(); DicomObject perFrameGroup = createFrameGroups(frameVoiLut); DicomObject obj = new BasicDicomObject(); obj.putNestedDicomObject(Tag.PerFrameFunctionalGroupsSequence, perFrameGroup); assertSame(frameVoiLut, VOIUtils.selectVoiObject(obj, null, 1)); }
@Test public void testSelectVOIObjectShouldReturnSecondFrameWhenAskedFor() { DicomObject frameVoiLut1 = createWindowCenterObject(); DicomObject frameVoiLut2 = createWindowCenterObject(); DicomObject obj = new BasicDicomObject(); DicomElement frameGroupSequence = obj.putSequence(Tag.PerFrameFunctionalGroupsSequence); addFrame(frameGroupSequence, frameVoiLut1); addFrame(frameGroupSequence, frameVoiLut2); assertSame(frameVoiLut2, VOIUtils.selectVoiObject(obj, null, 2)); }
@Test public void testSelectVOIObjectShouldReturnSharedFrameDataIfPerFrameDataIsNotPresent() { DicomObject sharedVoiLut = createWindowCenterObject(); DicomObject obj = new BasicDicomObject(); DicomElement frameGroupSequence = obj.putSequence(Tag.PerFrameFunctionalGroupsSequence); addFrame(frameGroupSequence, null); addFrame(frameGroupSequence, null); obj.putNestedDicomObject(Tag.SharedFunctionalGroupsSequence, createFrameGroups(sharedVoiLut)); assertSame(sharedVoiLut, VOIUtils.selectVoiObject(obj, null, 2)); }
@Test public void testSelectVOIObjectShouldReturnNullIfNoVoiDataIsFound() { assertNull(VOIUtils.selectVoiObject(new BasicDicomObject(), null, 1)); }