<commit_before>/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2014, Open Source Geospatial Foundation (OSGeo)
 *    (C) 2014 TOPP - www.openplans.org.
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */
package org.geotools.process.raster;

import static org.junit.Assert.assertEquals;

import java.awt.Rectangle;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.media.jai.ROI;
import javax.media.jai.RenderedOp;
import javax.media.jai.operator.CropDescriptor;
import javax.media.jai.operator.MeanDescriptor;
import javax.media.jai.operator.SubtractDescriptor;
import javax.media.jai.operator.TranslateDescriptor;

import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.coverage.grid.io.GridFormatFinder;
import org.geotools.geometry.Envelope2D;
import org.geotools.geometry.jts.JTS;
import org.geotools.resources.coverage.CoverageUtilities;
import org.geotools.test.TestData;
import org.jaitools.imageutils.ROIGeometry;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opengis.coverage.grid.GridCoverageReader;
import org.opengis.geometry.MismatchedDimensionException;
import org.opengis.metadata.spatial.PixelOrientation;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.MathTransform2D;
import org.opengis.referencing.operation.TransformException;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Polygon;

/**
 * This class is used for testing the processes operating on the bands: BandMerge and BandSelect.
 * 
 * @author <NAME>, GeoSolutions S.A.S.
 * 
 */
public class BandProcessTest {

    /** Tolerance value for the double comparison */
    private static final double TOLERANCE = 0.1d;

    /** First coverage to use */
    private static GridCoverage2D coverage1;

    /** Second coverage to use, equal to the first coverage */
    private static GridCoverage2D coverage2;

    /** Third coverage to use, which equal to the first one but also translated on the X direction */
    private static GridCoverage2D coverage3;

    @BeforeClass
    public static void setup() throws FileNotFoundException, IOException,
            NoninvertibleTransformException {
        // First file selection
        File input = TestData.file(BandProcessTest.class, "sample.tif");
        AbstractGridFormat format = GridFormatFinder.findFormat(input);
        // Get a reader for the selected format
        GridCoverageReader reader = format.getReader(input);
        // Read the input Coverage
        coverage1 = (GridCoverage2D) reader.read(null);
        // Reader disposal
        reader.dispose();

        // Second File selection
        coverage2 = coverage1;

        // Third file selection (This file is similar to the first one but it is translated by 1 on the X direction)
        File input2 = TestData.file(BandProcessTest.class, "sample2.tif");
        format = GridFormatFinder.findFormat(input2);
        // Get a reader for the selected format
        reader = format.getReader(input2);
        // Read the input Coverage
        coverage3 = (GridCoverage2D) reader.read(null);
        // Reader disposal
        reader.dispose();
    }

    // Ensure that the merging and selecting two equal images returns the same images
    @Test
    public void testEqualImages() {
        // Creation of a GridCoverage List
        List<GridCoverage2D> coverages = new ArrayList<GridCoverage2D>();
        coverages.add(coverage1);
        coverages.add(coverage2);

        // ///////////////
        //
        // BANDMERGE STEP
        //
        // ///////////////

        // Call of the bandmerge process
        BandMergeProcess bandmerge = new BandMergeProcess();
        // Execution of the process (used Last coverage g2w transformation)
        GridCoverage2D merged = bandmerge.execute(coverages, null, "last", null);

        // Checks on the new Coverage<commit_msg>GEOT-4925 BandProcessTest.testROI fails with native JAI<commit_after>/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2014, Open Source Geospatial Foundation (OSGeo)
 *    (C) 2014 TOPP - www.openplans.org.
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */
package org.geotools.process.raster;

import static org.junit.Assert.assertEquals;

import java.awt.Rectangle;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.media.jai.JAI;
import javax.media.jai.ROI;
import javax.media.jai.RenderedOp;
import javax.media.jai.operator.BandMergeDescriptor;
import javax.media.jai.operator.CropDescriptor;
import javax.media.jai.operator.MeanDescriptor;
import javax.media.jai.operator.SubtractDescriptor;
import javax.media.jai.operator.TranslateDescriptor;
import javax.media.jai.registry.RenderedRegistryMode;

import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.coverage.grid.io.GridFormatFinder;
import org.geotools.factory.GeoTools;
import org.geotools.geometry.Envelope2D;
import org.geotools.geometry.jts.JTS;
import org.geotools.image.jai.Registry;
import org.geotools.resources.coverage.CoverageUtilities;
import org.geotools.test.TestData;
import org.jaitools.imageutils.ROIGeometry;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opengis.coverage.grid.GridCoverageReader;
import org.opengis.geometry.MismatchedDimensionException;
import org.opengis.metadata.spatial.PixelOrientation;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.MathTransform2D;
import org.opengis.referencing.operation.TransformException;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Polygon;

/**
 * This class is used for testing the processes operating on the bands: BandMerge and BandSelect.
 * 
 * @author <NAME>, GeoSolutions S.A.S.
 * 
 */
public class BandProcessTest {

    /** Tolerance value for the double comparison */
    private static final double TOLERANCE = 0.1d;

    /** First coverage to use */
    private static GridCoverage2D coverage1;

    /** Second coverage to use, equal to the first coverage */
    private static GridCoverage2D coverage2;

    /** Third coverage to use, which equal to the first one but also translated on the X direction */
    private static GridCoverage2D coverage3;

    @BeforeClass
    public static void setup() throws FileNotFoundException, IOException,
            NoninvertibleTransformException {
        // Disable medialib
        System.setProperty("com.sun.media.jai.disableMediaLib", "true");
        // Disable bandmerge and mosaic native operation
        Registry.setNativeAccelerationAllowed("BandMerge", false);
        Registry.setNativeAccelerationAllowed("Mosaic", false);
        // First file selection
        File input = TestData.file(BandProcessTest.class, "sample.tif");
        AbstractGridFormat format = GridFormatFinder.findFormat(input);
        // Get a reader for the selected format
        GridCoverageReader reader = format.getReader(input);
        // Read the input Coverage
        coverage1 = (GridCoverage2D) reader.read(null);
        // Reader disposal
        reader.dispose();

        // Second File selection
        coverage2 = coverage1;

        // Third file selection (This file is similar to the first one but it is translated by 1 on the X direction)
        File input2 = TestData.file(BandProcessTest.class, "sample2.tif");
        format = GridFormatFinder.findFormat(input2);
        // Get a reader for the selected format
        reader = format.getReader(input2);
        // Read the input Coverage
        coverage3 = (GridCoverage2D) reader.read(null);
        // Reader disposal
        reader.dispose();
    }

    @AfterClass
    public static void afterClass() {
        // Enable medialib
        System.setProperty("com.sun.media.jai.disableMediaLib", "false");
        // Enable bandmerge and mosaic native operation
        Registry.setNativeAccelerationAllowed("BandMerge", true);
        Registry.setNativeAccelerationAllowed("Mosaic", true);
    }

    // Ensure that the merging and selecting two equal images returns the same images
    @Test
    public void testEqualImages() {
        // Creation of a GridCoverage List
        List<GridCoverage2D> coverages = new ArrayList<GridCoverage2D>();
        coverages.add(coverage1);
        coverages.add(coverage2);

        // ///////////////
        //
        // BANDMERGE STEP
        //
        // ///////////////

        // Call of the bandmerge process
        BandMergeProcess bandmerge = new BandMergeProcess();
        // Execution of the process (used Last coverage g2w transformation)
        GridCoverage2D merged = bandmerge.execute(coverages, null, "last", null);

        // Checks on the new Coverage
{'fraction_non_alphanumeric': 0.09159216283051169, 'fraction_numerical': 0.007608902415826517, 'mean_word_length': 3.3165024630541873, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5665148', 'n_tokens_mistral': 3040, 'n_tokens_neox': 2950, 'n_words': 839}