Esempio n. 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);
    }
  }