Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Provides a single jar containing all JAITools modules which you can
use instead of including individual modules in your project. Note:
It does not include the Jiffle scripting language or Jiffle image
operator.
/*
* Copyright (c) 2010-2011, Michael Bedward. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jaitools.media.jai.contour;
import java.awt.image.RenderedImage;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.media.jai.PlanarImage;
import javax.media.jai.ROI;
import javax.media.jai.iterator.RectIter;
import javax.media.jai.iterator.RectIterFactory;
import com.vividsolutions.jts.geom.LineString;
import org.jaitools.CollectionFactory;
import org.jaitools.jts.LineSmoother;
import org.jaitools.jts.SmootherControl;
import org.jaitools.jts.Utils;
import org.jaitools.media.jai.AttributeOpImage;
import org.jaitools.numeric.CompareOp;
import org.jaitools.numeric.Range;
/**
* Generates contours for user-specified levels of values in the source image.
* The contours are returned as a {@code Collection} of
* {@link com.vividsolutions.jts.geom.LineString}s.
*
* The interpolation algorithm used is that of Paul Bourke: originally published
* in Byte magazine (1987) as the CONREC contouring subroutine written in
* FORTRAN. The implementation here was adapted from Paul Bourke's C code for the
* algorithm available at:
*
* http://local.wasp.uwa.edu.au/~pbourke/papers/conrec/
*
*
* @author Michael Bedward
* @since 1.1
* @version $Id$
*/
public class ContourOpImage extends AttributeOpImage {
/*
* Constants to identify vertices for each group of
* data points being processed, as per the diagram
* in the javadoc for getContourSegments method.
*/
private static final int BL_VERTEX1 = 0;
private static final int BR_VERTEX2 = 1;
private static final int TR_VERTEX3 = 2;
private static final int TL_VERTEX4 = 3;
/** The source image band to process */
private int band;
/** Values at which to generate contour intervals */
private List contourLevels;
/**
* Interval between contours. This is used if specific contour
* levels are not requested. Contours will be generated such that
* the value of each is an integer multiple of this value.
*/
private Double contourInterval;
/** List of Numbers to treat as NO_DATA */
private List noDataNumbers;
/** List of Ranges to treat as NO_DATA */
private List> noDataRanges;
/** Whether to use strict NODATA exclusion */
private final boolean strictNodata;
/** Output contour lines */
private SoftReference> cachedContours;
/** Whether to simplify contour lines by removing coincident vertices */
private final boolean simplify;
/** Whether to apply Bezier smoothing to the contour lines */
private final boolean smooth;
/**
* Alpha parameter controlling Bezier smoothing
* (see {@link LineSmoother})
*/
private double smoothAlpha = 0.0;
/**
* Control object for Bezier smoothing. Note that length units here
* are pixels.
*/
private final SmootherControl smootherControl = new SmootherControl() {
public double getMinLength() {
return 0.1;
}
public int getNumVertices(double length) {
return (int) Math.max(5, length * 10);
}
};
/**
* Constructor. Note that one of {@code levels} or {@code interval} must
* be supplied. If both are supplied {@code interval} is ignored.
*
* @param source the source image
*
* @param roi an optional {@code ROI} to constrain the areas for which
* contours are generated
*
* @param band the band of the source image to process
*
* @param levels values for which to generate contours
*
* @param interval interval between contour levels (ignored if {@code levels}
* is supplied)
*
* @param noDataValues an optional {@code Collection} of values and/or {@code Ranges}
* to treat as NO_DATA
*
* @param simplify whether to simplify contour lines by removing
* colinear vertices
*
* @param strictNodata if {@code true} any NO_DATA values in a 2x2 data window will
* cause that window to be skipped; if {@code false} a single NO_DATA value
* is permitted
*
* @param smooth whether contour lines should be smoothed using
* Bezier interpolation
*/
public ContourOpImage(RenderedImage source,
ROI roi,
int band,
Collection extends Number> levels,
Double interval,
Collection