Пример #1
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);
    }
  }
Пример #2
0
 public static void writeContourGeneratedPointsToFile(
     PrintWriter writer, DICOMImage image, Vector<Contour> contours) {
   writer.write("\n" + image.getSopInstanceUID() + "\n");
   for (Contour c : contours) {
     if (c.getControlPoints().size() > 0) {
       int numPoints = c.getGeneratedPoints().size();
       String header = c.getIntFromType() + "\n" + numPoints + "\n";
       writer.write(header);
       for (Vector3d point : c.getGeneratedPoints()) {
         writer.write(
             BigDecimal.valueOf(point.getX()).setScale(4, BigDecimal.ROUND_UP)
                 + "\t"
                 + BigDecimal.valueOf(point.getY()).setScale(4, BigDecimal.ROUND_UP)
                 + "\n");
       }
     }
   }
   writer.write((-1) + "\n");
 }