private static synchronized void decrementAndReleasePixels(ImageTile<?> tile) {
   tile.decrementPixelDataReleaseCount();
   if (tile.getPixelDataReleaseCount() == 0) tile.releasePixels();
 }
  @Override
  public void run() {
    try {

      List<CorrelationTriple> multi_ccfs = new ArrayList<CorrelationTriple>();

      while (!this.isCancelled && (count < this.numNeighbors)) {
        multi_ccfs.clear();
        StitchingTask<T> task = this.ccfQueue.take();

        Debug.msg(
            DebugType.VERBOSE,
            "WP Task acquired: "
                + task.getTask()
                + "  size: "
                + this.ccfQueue.size()
                + " count: "
                + count);

        if (task.getTask() == TaskType.CCF_DONE) {
          break;
        } else if (task.getTask() == TaskType.CCF) {
          int[] indices = task.getIndices();
          ImageTile<T> tile = task.getTile();
          ImageTile<T> neighbor = task.getNeighbor();
          boolean north = false;
          boolean west = false;
          if (tile.isSameRowAs(neighbor)) west = true;
          else north = true;

          for (int index : indices) {
            int x = index % tile.getWidth();
            int y = index / tile.getWidth();

            if (west) multi_ccfs.add(Stitching.peakCrossCorrelationLR(neighbor, tile, x, y));
            else if (north) multi_ccfs.add(Stitching.peakCrossCorrelationUD(neighbor, tile, x, y));
          }

          CorrelationTriple corr = Collections.max(multi_ccfs);
          if (north) {
            tile.setNorthTranslation(corr);
            Log.msg(
                LogType.HELPFUL,
                "N: "
                    + tile.getFileName()
                    + " -> "
                    + neighbor.getFileName()
                    + " x: "
                    + tile.getNorthTranslation().getMatlabFormatStrX()
                    + " y: "
                    + tile.getNorthTranslation().getMatlabFormatStrY()
                    + " ccf: "
                    + tile.getNorthTranslation().getMatlatFormatStrCorr());
            incProgressBar();

            incCount();

            decrementAndReleasePixels(tile);
            decrementAndReleasePixels(neighbor);
          } else if (west) {
            tile.setWestTranslation(corr);
            Log.msg(
                LogType.HELPFUL,
                "W: "
                    + tile.getFileName()
                    + " -> "
                    + neighbor.getFileName()
                    + " x: "
                    + tile.getWestTranslation().getMatlabFormatStrX()
                    + " y: "
                    + tile.getWestTranslation().getMatlabFormatStrY()
                    + " ccf: "
                    + tile.getWestTranslation().getMatlatFormatStrCorr());

            incProgressBar();
            incCount();

            decrementAndReleasePixels(tile);
            decrementAndReleasePixels(neighbor);
          }

        } else if (task.getTask() == TaskType.CANCELLED) {
          this.isCancelled = true;
        }
      }

      Debug.msg(DebugType.HELPFUL, "CCF Done");

      // Signal other workers that may be waiting to finish
      this.ccfQueue.put(new StitchingTask<T>(null, null, TaskType.SENTINEL));

    } catch (InterruptedException e) {
      Log.msg(LogType.MANDATORY, "Interrupted CCF worker");
    }
  }
Example #3
0
 /**
  * Checks if the tile exists in the grid
  *
  * @param tile the tile to check
  * @return true if the tile exists, otherwise false
  */
 public boolean hasTile(ImageTile<?> tile) {
   return hasTile(tile.getRow(), tile.getCol());
 }