Esempio n. 1
0
  private void calcViewPort(ViewPort viewPort) throws NoninvertibleTransformException {
    viewPortList = new ViewPort[numCols * numRows];

    /*
     * if(viewPort.getImageWidth() < width && viewPort.getImageHeight() <
     * height){ viewPortList[0] = viewPort; return; }
     */

    int vpCnt = 0;

    double imgPxX = viewPort.getImageWidth();
    double dWcX = viewPort.getAdjustedExtent().getWidth();
    double tileWcW = (getTile(vpCnt).getSize().getWidth() * dWcX) / imgPxX;

    double imgPxY = viewPort.getImageHeight();
    double dWcY = viewPort.getAdjustedExtent().getHeight();
    double tileWcH = (getTile(vpCnt).getSize().getHeight() * dWcY) / imgPxY;

    viewPortList[0] = viewPort.cloneViewPort();
    viewPortList[0].setImageSize(getTile(vpCnt).getSize());
    viewPortList[0].setExtent(
        new Rectangle2D.Double(
            viewPort.getAdjustedExtent().getMinX(),
            viewPort.getAdjustedExtent().getMaxY() - tileWcH,
            tileWcW,
            tileWcH));
    viewPortList[0].setAffineTransform(mat);

    double wt = tileWcW;
    double ht = tileWcH;
    double xt = viewPort.getAdjustedExtent().getMinX();
    double yt = viewPort.getAdjustedExtent().getMaxY() - tileWcH;

    for (int stepY = 0; stepY < numRows; stepY++) {
      wt = tileWcW;
      xt = viewPort.getAdjustedExtent().getMinX();
      for (int stepX = 0; stepX < numCols; stepX++) {
        vpCnt = stepY * numCols + stepX;
        if (vpCnt > 0) {
          if (stepX > 0) xt += wt;
          if ((xt + wt) > viewPort.getAdjustedExtent().getMaxX())
            wt = Math.abs(viewPort.getAdjustedExtent().getMaxX() - xt);

          viewPortList[vpCnt] = viewPort.cloneViewPort();
          viewPortList[vpCnt].setImageSize(getTile(vpCnt).getSize());
          viewPortList[vpCnt].setExtent(new Rectangle2D.Double(xt, yt, wt, ht));
          viewPortList[vpCnt].setAffineTransform(mat);
        }
        // System.out.println("ViewPort: "+vpCnt+" "+viewPortList[vpCnt].getAdjustedExtent()+"
        // "+getTile(vpCnt).getSize());
      }
      if ((yt - ht) < viewPort.getAdjustedExtent().getMinY()) {
        ht = Math.abs(yt - viewPort.getAdjustedExtent().getMinY());
        yt = viewPort.getAdjustedExtent().getMinY();
      } else yt -= ht;
    }
  }
Esempio n. 2
0
  public ViewPort getTileViewPort(ViewPort viewPort, int tileNr)
      throws NoninvertibleTransformException {
    /*
     * if(viewPortList == null) this.calcViewPort(viewPort); return
     * viewPortList[tileNr];
     */

    if (tile.length == 1) return viewPort;

    double[] dstPts = new double[8];
    double[] srcPts = getTilePts(tileNr);
    Rectangle tile = getTile(tileNr);
    // Rectangle newRect = new Rectangle((int)srcPts[0], (int)srcPts[1],
    // tileSz[0], tileSz[1]);

    mat.inverseTransform(srcPts, 0, dstPts, 0, 4);
    double x = dstPts[0], w = dstPts[2] - dstPts[0];
    double y = dstPts[1], h = dstPts[5] - dstPts[3];
    if (w < 0) {
      x = dstPts[2];
      w = dstPts[0] - dstPts[2];
    }
    if (h < 0) {
      y = dstPts[5];
      h = dstPts[3] - dstPts[5];
    }
    Rectangle2D.Double rectCuadricula = new Rectangle2D.Double(x, y, w, h);
    // Extent extent = new Extent(rectCuadricula);

    ViewPort vp = viewPort.cloneViewPort();
    vp.setImageSize(tile.getSize());
    // vp.setOffset(tile.getLocation());
    vp.setExtent(rectCuadricula);
    vp.setAffineTransform(mat);

    if (debug)
      System.out.println(
          "Tiling.print(): tile "
              + tileNr
              + " de "
              + getNumTiles()
              + "\n, Extent = "
              + vp.getAdjustedExtent()
              + " tile: "
              + tile);

    return vp;
  }