コード例 #1
0
 /**
  * Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the
  * combination of the DA and TM values of the specified pair of attributes.
  *
  * <p>Will use the TimezoneOffsetFromUTC if present in the AttributeList, else will assume UTC
  * (not whatever the local time zone happens to be).
  *
  * @param list the list containing the attributes
  * @param dateTag the tag of the DA attribute
  * @param timeTag the tag of the TM attribute
  * @return the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date
  * @throws java.text.ParseException if incorrectly encoded
  * @throws DicomException if date attribute is missing or empty
  */
 public static long getTimeInMilliSecondsSinceEpoch(
     AttributeList list, AttributeTag dateTag, AttributeTag timeTag)
     throws java.text.ParseException, DicomException {
   String dateValue = Attribute.getSingleStringValueOrEmptyString(list, dateTag);
   String timeValue = Attribute.getSingleStringValueOrEmptyString(list, timeTag);
   if (dateValue.length() == 0) {
     throw new DicomException("Missing date attribute or value for " + dateTag);
   }
   // missing or empty time is OK
   return getTimeInMilliSecondsSinceEpoch(
       dateValue
           + timeValue
           + Attribute.getSingleStringValueOrDefault(
               list, TagFromName.TimezoneOffsetFromUTC, "+0000"));
 }
 /**
  * Read a DICOM dataset and write an XML representation of it to the standard output, or vice
  * versa.
  *
  * @param arg either one filename of the file containing the DICOM dataset, or a direction
  *     argument (toDICOM or toXML, case insensitive) and an input filename
  */
 public static void main(String arg[]) {
   try {
     boolean bad = true;
     boolean toXML = true;
     String filename = null;
     if (arg.length == 1) {
       bad = false;
       toXML = true;
       filename = arg[0];
     } else if (arg.length == 2) {
       filename = arg[1];
       if (arg[0].toLowerCase(java.util.Locale.US).equals("toxml")) {
         bad = false;
         toXML = true;
       } else if (arg[0].toLowerCase(java.util.Locale.US).equals("todicom")
           || arg[0].toLowerCase(java.util.Locale.US).equals("todcm")) {
         bad = false;
         toXML = false;
       }
     }
     if (bad) {
       System.err.println(
           "usage: XMLRepresentationOfDicomObjectFactory [toDICOM|toXML] inputfile");
     } else {
       if (toXML) {
         AttributeList list = new AttributeList();
         // System.err.println("reading list");
         list.read(filename, null, true, true);
         // System.err.println("making document");
         Document document = new XMLRepresentationOfDicomObjectFactory().getDocument(list);
         // System.err.println(toString(document));
         write(System.out, document);
       } else {
         // long startReadTime = System.currentTimeMillis();
         AttributeList list =
             new XMLRepresentationOfDicomObjectFactory().getAttributeList(filename);
         // System.err.println("AttributeList.main(): read XML and create DICOM AttributeList -
         // done in "+(System.currentTimeMillis()-startReadTime)+" ms");
         String sourceApplicationEntityTitle =
             Attribute.getSingleStringValueOrEmptyString(
                 list, TagFromName.SourceApplicationEntityTitle);
         list.removeMetaInformationHeaderAttributes();
         FileMetaInformation.addFileMetaInformation(
             list, TransferSyntax.ExplicitVRLittleEndian, sourceApplicationEntityTitle);
         list.write(
             System.out,
             TransferSyntax.ExplicitVRLittleEndian,
             true /*useMeta*/,
             true /*useBufferedStream*/);
       }
     }
   } catch (Exception e) {
     e.printStackTrace(System.err);
   }
 }
コード例 #3
0
ファイル: ChestImageViewer.java プロジェクト: kullen/MRI
  /**
   * @param filenames
   * @exception Exception if internal error
   */
  public void loadMultiPanelFromSpecifiedFiles(String filenames[]) throws Exception {

    int nFiles = filenames.length;

    SingleImagePanel imagePanels[] = new SingleImagePanel[nFiles];

    String orientations[][] = new String[nFiles][];
    String views[] = new String[nFiles];
    String lateralityViewAndModifiers[] = new String[nFiles];
    String lateralities[] = new String[nFiles];
    int widths[] = new int[nFiles];
    int heights[] = new int[nFiles];
    PixelSpacing spacing[] = new PixelSpacing[nFiles];

    String rowOrientations[] = new String[nFiles];
    String columnOrientations[] = new String[nFiles];

    HashMap eventContexts = new HashMap();

    double maximumHorizontalExtentInMm = 0;
    double maximumVerticalExtentInMm = 0;

    StructuredReport sr[] = new StructuredReport[nFiles];

    int nImages = 0;
    int nCAD = 0;
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    for (int f = 0; f < nFiles; ++f) {
      try {
        String filename = filenames[f];
        DicomInputStream distream = null;
        InputStream in = classLoader.getResourceAsStream(filename);
        if (in != null) {
          distream = new DicomInputStream(in);
        } else {
          distream = new DicomInputStream(new File(filename));
        }
        AttributeList list = new AttributeList();
        list.read(distream);
        if (list.isImage()) {
          int i = nImages++;
          System.err.println("IMAGE [" + i + "] is file " + f + " (" + filenames[f] + ")");

          orientations[i] = getPatientOrientation(list);
          // System.err.println("IMAGE ["+i+"] orientation="+(orientations[i] == null &&
          // orientations[i].length == 2 ? "" : (orientations[i][0] + " " + orientations[i][1])));
          views[i] = getView(list);
          // System.err.println("IMAGE ["+i+"] view="+views[i]);
          lateralityViewAndModifiers[i] = getImageLateralityViewModifierAndViewModifier(list);
          // System.err.println("IMAGE ["+i+"]
          // lateralityViewAndModifiers="+lateralityViewAndModifiers[i]);
          // System.err.println("File "+filenames[f]+": "+lateralityViewAndModifiers[i]);
          lateralities[i] = getLaterality(list);
          // System.err.println("IMAGE ["+i+"] laterality="+lateralities[i]);
          spacing[i] = new PixelSpacing(list);
          // System.err.println("IMAGE ["+i+"] spacing="+spacing[i]);

          SourceImage sImg = new SourceImage(list);
          BufferedImage img = sImg.getBufferedImage();

          widths[i] = sImg.getWidth();
          heights[i] = sImg.getHeight();

          boolean shareVOIEventsInStudy =
              false; // does not seem to work anyway, since adding VOITransform to panel constructor
                     // :(

          EventContext eventContext = new EventContext(Integer.toString(i));

          SingleImagePanel imagePanel = makeNewImagePanel(sImg, eventContext);
          imagePanel.setDemographicAndTechniqueAnnotations(
              new DemographicAndTechniqueAnnotations(list),
              "SansSerif",
              Font.PLAIN,
              10,
              Color.pink);
          imagePanel.setOrientationAnnotations(
              new OrientationAnnotations(rowOrientations[i], columnOrientations[i]),
              "SansSerif",
              Font.PLAIN,
              20,
              Color.pink);
          imagePanel.setPixelSpacingInSourceImage(
              spacing[i].getSpacing(), spacing[i].getDescription());
          if (Attribute.getSingleStringValueOrEmptyString(list, TagFromName.VOILUTFunction)
              .equals("SIGMOID")) {
            imagePanel.setVOIFunctionToLogistic();
          }
          imagePanels[i] = imagePanel;
        } else {
          throw new DicomException("Unsupported SOP Class in file " + filenames[f]);
        }
      } catch (Exception e) { // FileNotFoundException,IOException,DicomException
        e.printStackTrace(System.err);
      }
    }

    // int imagesPerRow = nImages;			// i.e., 1 -> 1, 2 -> 1, 4 -> 4, 5 -> 4, 8 -> 4
    // int imagesPerCol = 1;

    int imagesPerRow = nImages >= 8 ? 8 : nImages; // i.e., 1 -> 1, 2 -> 1, 4 -> 4, 5 -> 4, 8 -> 4
    int imagesPerCol =
        (nImages - 1) / imagesPerRow + 1; // i.e., 1 -> 1, 2 -> 2, 4 -> 1, 5 -> 2, 8 -> 2

    int singleWidth = frameWidth / imagesPerRow;
    int singleHeight = frameHeight / imagesPerCol;

    if (nImages == 1 && singleWidth > singleHeight) {
      singleWidth =
          singleWidth / 2; // use only half the screen for a single view and a landscape monitor
    }

    for (int i = 0; i < nImages; ++i) {
      DisplayedAreaSelection displayedAreaSelection = null;
      displayedAreaSelection =
          new DisplayedAreaSelection(
              widths[i],
              heights[i],
              0,
              0,
              widths[i],
              heights[i],
              true, // in case spacing was not supplied
              0,
              0,
              0,
              0,
              0,
              false /*crop*/);
      imagePanels[i].setDisplayedAreaSelection(displayedAreaSelection);
      imagePanels[i].setPreTransformImageRelativeCoordinates(null);
    }

    SingleImagePanel.deconstructAllSingleImagePanelsInContainer(multiPanel);
    multiPanel.removeAll();
    multiPanel.setLayout(new GridLayout(imagesPerCol, imagesPerRow));
    multiPanel.setBackground(Color.black);

    for (int x = 0; x < imagesPerCol; ++x) {
      for (int y = 0; y < imagesPerRow; ++y) {
        int i = x * imagesPerRow + y;
        if (i < nImages) {
          imagePanels[i].setPreferredSize(new Dimension(singleWidth, singleHeight));
          multiPanel.add(imagePanels[i]);
        }
      }
    }
    frame.getContentPane().validate();
    frame.getContentPane().repaint();
  }
コード例 #4
0
 public static void main(String arg[]) {
   System.err.println("Test IntegerString.addValue(double):");
   for (int i = 0; i < testValues.length; ++i) {
     IntegerStringAttribute a = new IntegerStringAttribute(TagFromName.InstanceNumber);
     String sv = "";
     try {
       a.addValue(testValues[i]);
       sv = Attribute.getSingleStringValueOrEmptyString(a);
     } catch (DicomException e) {
       // System.err.println(e);
       sv = "exception";
     }
     int svl = sv.length();
     System.err.println(
         "\t"
             + (sv.equals(testStringExpected[i]) && svl <= 12 ? "PASS" : "FAIL")
             + ": Supplied <"
             + testStringSupplied[i]
             + ">\t Got <"
             + sv
             + "> (length="
             + svl
             + ")\t Expected <"
             + testStringExpected[i]
             + ">\t Double.toString() <"
             + Double.toString(testValues[i])
             + ">");
   }
   System.err.println("Test IntegerString.addValue(float):");
   for (int i = 0; i < testValues.length; ++i) {
     IntegerStringAttribute a = new IntegerStringAttribute(TagFromName.InstanceNumber);
     String sv = "";
     try {
       a.addValue((float) testValues[i]);
       sv = Attribute.getSingleStringValueOrEmptyString(a);
     } catch (DicomException e) {
       // System.err.println(e);
       sv = "exception";
     }
     int svl = sv.length();
     System.err.println(
         "\t"
             + (sv.equals(testStringExpected[i]) && svl <= 12 ? "PASS" : "FAIL")
             + ": Supplied <"
             + testStringSupplied[i]
             + ">\t Got <"
             + sv
             + "> (length="
             + svl
             + ")\t Expected <"
             + testStringExpected[i]
             + ">\t Double.toString() <"
             + Double.toString(testValues[i])
             + ">");
   }
   System.err.println("Test IntegerString.addValue(long):");
   for (int i = 0; i < testValues.length; ++i) {
     IntegerStringAttribute a = new IntegerStringAttribute(TagFromName.InstanceNumber);
     String sv = "";
     try {
       a.addValue((long) testValues[i]);
       sv = Attribute.getSingleStringValueOrEmptyString(a);
     } catch (DicomException e) {
       // System.err.println(e);
       sv = "exception";
     }
     int svl = sv.length();
     System.err.println(
         "\t"
             + (sv.equals(testStringExpected[i]) && svl <= 12 ? "PASS" : "FAIL")
             + ": Supplied <"
             + testStringSupplied[i]
             + ">\t Got <"
             + sv
             + "> (length="
             + svl
             + ")\t Expected <"
             + testStringExpected[i]
             + ">\t Double.toString() <"
             + Double.toString(testValues[i])
             + ">");
   }
 }