Ejemplo n.º 1
0
  public synchronized void outputNewImage(String filename) {
    switch (layoutPolicy) {
      case COMPUTED_IN_LAYOUT_RUNNER:
        layoutPipeIn.pump();
        break;
      case COMPUTED_ONCE_AT_NEW_IMAGE:
        if (layout != null) layout.compute();
        break;
      case COMPUTED_FULLY_AT_NEW_IMAGE:
        stabilizeLayout(layout.getStabilizationLimit());
        break;
      default:
        break;
    }

    if (resolution.getWidth() != image.getWidth() || resolution.getHeight() != image.getHeight())
      initImage();

    if (clearImageBeforeOutput) {
      for (int x = 0; x < resolution.getWidth(); x++)
        for (int y = 0; y < resolution.getHeight(); y++) image.setRGB(x, y, 0x00000000);
    }

    if (gg.getNodeCount() > 0) {
      if (autofit) {
        gg.computeBounds();

        Point3 lo = gg.getMinPos();
        Point3 hi = gg.getMaxPos();

        renderer.getCamera().setBounds(lo.x, lo.y, lo.z, hi.x, hi.y, hi.z);
      }

      renderer.render(g2d, 0, 0, resolution.getWidth(), resolution.getHeight());
    }

    for (PostRenderer action : postRenderers) action.render(g2d);

    image.flush();

    try {
      File out = new File(filename);

      if (out.getParent() != null && !out.getParentFile().exists()) out.getParentFile().mkdirs();

      ImageIO.write(image, outputType.name(), out);

      printProgress();
    } catch (IOException e) {
      // ?
    }
  }
Ejemplo n.º 2
0
  public FileSinkImages(
      String prefix, OutputType type, Resolution resolution, OutputPolicy outputPolicy) {
    this.resolution = resolution;
    this.outputType = type;
    this.filePrefix = prefix;
    this.counter = 0;
    this.gg = new GraphicGraph(prefix);
    this.postRenderers = new LinkedList<PostRenderer>();
    this.layoutPolicy = LayoutPolicy.NO_LAYOUT;
    this.layout = null;
    this.optLayout = null;
    this.layoutPipeIn = null;
    this.sink = gg;

    setOutputPolicy(outputPolicy);
    setRenderer(RendererType.BASIC);

    initImage();
  }
Ejemplo n.º 3
0
  public FileSinkImages(
      String prefix, OutputType type, Resolution resolution, OutputPolicy outputPolicy) {
    this.resolution = resolution;
    this.outputType = type;
    this.filePrefix = prefix;
    this.counter = 0;
    this.gg = new GraphicGraph(prefix);
    this.outputPolicy = outputPolicy;
    this.postRenderers = new LinkedList<PostRenderer>();
    this.layoutPolicy = LayoutPolicy.NoLayout;
    this.layout = null;
    this.optLayout = null;
    this.layoutPipeIn = null;

    setRenderer(RendererType.Basic);

    initImage();

    this.renderer.open(gg, null);
  }
Ejemplo n.º 4
0
  /** Produce a new image. */
  protected synchronized void outputNewImage() {
    switch (layoutPolicy) {
      case ComputedAtNewImage:
        if (layout != null) layout.compute();
        break;
    }

    if (resolution.getWidth() != image.getWidth() || resolution.getHeight() != image.getHeight())
      initImage();

    if (gg.getNodeCount() > 0) {
      gg.computeBounds();

      Point3 lo = gg.getMinPos();
      Point3 hi = gg.getMaxPos();

      renderer.setBounds(lo.x, lo.y, lo.z, hi.x, hi.y, hi.z);
      renderer.render(g2d, resolution.getWidth(), resolution.getHeight());
    }

    for (PostRenderer action : postRenderers) action.render(g2d);

    image.flush();

    try {
      File out = new File(String.format("%s%06d.png", filePrefix, counter++));

      if (!out.getParentFile().exists()) out.getParentFile().mkdirs();

      ImageIO.write(image, outputType.name(), out);

      printProgress();
    } catch (IOException e) {
      // ?
    }
  }
Ejemplo n.º 5
0
 /**
  * Set a custom resolution.
  *
  * @param width
  * @param height
  */
 public void setResolution(int width, int height) {
   if (resolution == null || resolution.getWidth() != width || resolution.getHeight() != height) {
     resolution = new CustomResolution(width, height);
     initImage();
   }
 }
Ejemplo n.º 6
0
 /**
  * Set resolution of images.
  *
  * @param r resolution
  */
 public void setResolution(Resolution r) {
   if (r != resolution) {
     resolution = r;
     initImage();
   }
 }