throw new NullPointerException("The list of MosaicElements contains one element but it's null");
}
PAMDataset pamDataset = in.pamDataset;
// the roi is exactly equal to the image
ROI roi = in.roi;
if (roi != null) {
Rectangle bounds = Utils.toRectangle(roi.getAsShape());
if(bounds!=null){
RenderedImage mosaic = in.source;
Rectangle imageBounds = PlanarImage.wrapRenderedImage(mosaic).getBounds();
if (imageBounds.equals(bounds)) {
// do we need to crop? (image is bigger than requested?)
if (!rasterBounds.contains(imageBounds)) {
// we have to crop
XRectangle2D.intersect(imageBounds, rasterBounds, imageBounds);
if (imageBounds.isEmpty()) {
// return back a constant image
return null;
}
// crop
ImageWorker iw = new ImageWorker(mosaic);
iw.setRenderingHints(localHints);
iw.crop(imageBounds.x, imageBounds.y, imageBounds.width, imageBounds.height);
mosaic = iw.getRenderedImage();
imageBounds = PlanarImage.wrapRenderedImage(mosaic).getBounds();
}
// and, do we need to add a BORDER around the image?
if (!imageBounds.contains(rasterBounds)) {
mosaic = MergeBehavior.FLAT
.process(
new RenderedImage[] { mosaic },
backgroundValues,
sourceThreshold,
(hasAlpha || doInputTransparency) ? new PlanarImage[] { in.alphaChannel }: new PlanarImage[] { null },
new ROI[] { in.roi },
request.isBlend() ? MosaicDescriptor.MOSAIC_TYPE_BLEND: MosaicDescriptor.MOSAIC_TYPE_OVERLAY,
localHints);
roi=roi.add(new ROIGeometry(JTS.toGeometry(new ReferencedEnvelope(rasterBounds, null))));
if (footprintBehavior!=FootprintBehavior.None) {
// Adding globalRoi to the output
RenderedOp rop = (RenderedOp) mosaic;
rop.setProperty("ROI", in.roi);
}
}
// add to final list
return new MosaicElement(in.alphaChannel, roi, mosaic, pamDataset);
}
}
}
}
// === do the mosaic as usual
// prepare sources for the mosaic operation
final RenderedImage[] sources = new RenderedImage[size];
final PlanarImage[] alphas = new PlanarImage[size];
ROI[] rois = new ROI[size];
final PAMDataset[] pams = new PAMDataset[size];
int realROIs=0;
for (int i = 0; i < size; i++) {
final MosaicElement mosaicElement = inputs.get(i);
sources[i] = mosaicElement.source;
alphas[i] = mosaicElement.alphaChannel;
rois[i] = mosaicElement.roi;
pams[i] = mosaicElement.pamDataset;
// compose the overall ROI if needed
if (mosaicElement.roi != null) {
realROIs++;
}
}
if (realROIs == 0){
rois = null;
}
// execute mosaic
final RenderedImage mosaic =
mergeBehavior.process(
sources,
backgroundValues,
sourceThreshold,
(hasAlpha || doInputTransparency) ? alphas : null,
rois,
request.isBlend() ? MosaicDescriptor.MOSAIC_TYPE_BLEND: MosaicDescriptor.MOSAIC_TYPE_OVERLAY,
localHints);
ROI overallROI = mosaicROIs(rois);
if (footprintBehavior != FootprintBehavior.None) {
// Adding globalRoi to the output
RenderedOp rop = (RenderedOp) mosaic;
rop.setProperty("ROI", overallROI);
}