예제 #1
0
  /**
   * Writes the contour data to the specified path for all images containing contours. The file
   * format is as follows: blank line, SOPInstanceUID, number of points, all of the (x, y) pairs for
   * the contour. a "-1" indicates the end of the list of contours for an image.
   *
   * @param SOPInstanceUIDToDICOMImage a hashmap containing all of the DICOM images with their
   *     SOPInstanceUIDs as keys
   * @param path the file path to which to create the text file
   */
  public static void writeContoursToFile(
      Map<String, DICOMImage> SOPInstanceUIDToDICOMImage, String path) {
    // TODO Categorize points based on location (i.e. LA, RA, Endo, Epi,
    // etc...
    // TODO merge with save() in SerializableManager
    Vector<Contour> contours;
    PrintWriter writer = null;

    File f = new File(path);

    try {
      writer = new PrintWriter(new BufferedWriter(new FileWriter(f, false)));
      for (DICOMImage image : SOPInstanceUIDToDICOMImage.values()) {
        contours = image.getContours();
        if (contours.size() < 1) {
          continue;
        } else {
          ContourUtilities.writeControurControlPointsToFile(writer, image, contours);
          ContourUtilities.writeContourGeneratedPointsToFile(writer, image, contours);
        }
      }
      writer.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
예제 #2
0
  public static void loadContour(File file, Map<String, DICOMImage> SOPInstanceUIDToDICOMImage) {
    Vector<Contour> contours;
    List<Vector3d> controlPoints;

    String sopInstanceUID;
    String[] line = new String[2];
    @SuppressWarnings("unused")
    String lineCheck;

    int contourType;
    try {
      BufferedReader reader = new BufferedReader(new FileReader(file));
      while (reader.readLine() != null) {
        contours = new Vector<Contour>();
        sopInstanceUID = reader.readLine();
        contourType = Integer.parseInt(reader.readLine());

        while ((lineCheck = reader.readLine()) != "-1") {
          controlPoints = new Vector<Vector3d>();
          while ((line = reader.readLine().split("\t")).length >= 2) {
            float x = Float.parseFloat(line[0]);
            float y = Float.parseFloat(line[1]);
            controlPoints.add(new Vector3d(x, y, 0));
          }

          // Only add contours to image if it is a control point contour
          if (Contour.isControlPointFromInt(contourType)) {
            Contour contour = new Contour(Contour.getTypeFromInt(contourType));

            contour.setControlPoints(controlPoints);
            contours.add(contour);
          }

          if (line[0].equals("-1")) {
            break;
          } else {
            contourType = Integer.parseInt(line[0]);
          }
        }
        DICOMImage image = SOPInstanceUIDToDICOMImage.get(sopInstanceUID);
        image.getContours().addAll(contours);
      }
      reader.close();
    } catch (IOException x) {
      System.err.format("IOException: %s%n", x);
    }
  }