Java Code Examples for java.awt.image.WritableRaster#getHeight()

The following examples show how to use java.awt.image.WritableRaster#getHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorPaintContext.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public synchronized Raster getRaster(int x, int y, int w, int h) {
    WritableRaster t = savedTile;

    if (t == null || w > t.getWidth() || h > t.getHeight()) {
        t = getColorModel().createCompatibleWritableRaster(w, h);
        IntegerComponentRaster icr = (IntegerComponentRaster) t;
        Arrays.fill(icr.getDataStorage(), color);
        // Note - markDirty is probably unnecessary since icr is brand new
        icr.markDirty();
        if (w <= 64 && h <= 64) {
            savedTile = t;
        }
    }

    return t;
}
 
Example 2
Source File: TexturePaintContext.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
synchronized static WritableRaster makeByteRaster(Raster srcRas,
                                                  int w, int h)
{
    if (byteRasRef != null) {
        WritableRaster wr = (WritableRaster) byteRasRef.get();
        if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
            byteRasRef = null;
            return wr;
        }
    }
    // If we are going to cache this Raster, make it non-tiny
    if (w <= 32 && h <= 32) {
        w = h = 32;
    }
    return srcRas.createCompatibleWritableRaster(w, h);
}
 
Example 3
Source File: TexturePaintContext.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
synchronized static WritableRaster makeByteRaster(Raster srcRas,
                                                  int w, int h)
{
    if (byteRasRef != null) {
        WritableRaster wr = (WritableRaster) byteRasRef.get();
        if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
            byteRasRef = null;
            return wr;
        }
    }
    // If we are going to cache this Raster, make it non-tiny
    if (w <= 32 && h <= 32) {
        w = h = 32;
    }
    return srcRas.createCompatibleWritableRaster(w, h);
}
 
Example 4
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Extracts pixel data as arrays of floats, one per channel. */
public static float[][] getFloats(final WritableRaster r, final int x,
	final int y, final int w, final int h)
{
	if (canUseBankDataDirectly(r, DataBuffer.TYPE_FLOAT,
		DataBufferFloat.class) && x == 0 && y == 0 && w == r.getWidth() && h == r
			.getHeight())
	{
		return ((DataBufferFloat) r.getDataBuffer()).getBankData();
	}
	// NB: an order of magnitude faster than the naive makeType solution
	final int c = r.getNumBands();
	final float[][] samples = new float[c][w * h];
	for (int i = 0; i < c; i++)
		r.getSamples(x, y, w, h, i, samples[i]);
	return samples;
}
 
Example 5
Source File: ImageProcessor.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
/** Hunts for the start or end of a sequence of split pixels. Begins searching at (startX, startY) then follows along the x or y
 * axis (depending on value of xAxis) for the first non-transparent pixel if startPoint is true, or the first transparent pixel
 * if startPoint is false. Returns 0 if none found, as 0 is considered an invalid split point being in the outer border which
 * will be stripped. */
static private int getSplitPoint (WritableRaster raster, String name, int startX, int startY, boolean startPoint, boolean xAxis) {
	int[] rgba = new int[4];

	int next = xAxis ? startX : startY;
	int end = xAxis ? raster.getWidth() : raster.getHeight();
	int breakA = startPoint ? 255 : 0;

	int x = startX;
	int y = startY;
	while (next != end) {
		if (xAxis)
			x = next;
		else
			y = next;

		raster.getPixel(x, y, rgba);
		if (rgba[3] == breakA) return next;

		if (!startPoint && (rgba[0] != 0 || rgba[1] != 0 || rgba[2] != 0 || rgba[3] != 255)) splitError(x, y, rgba, name);

		next++;
	}

	return 0;
}
 
Example 6
Source File: OmsSkyview.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculate the angle.
 * 
 * @param x the x index.
 * @param y the y index.
 * @param tmpWR the sky map.
 * @param pitWR the elevation map.
 * @param res the resolution of the map.
 * @param normalSunVector
 * @param inverseSunVector
 * @param sunVector
 */
protected WritableRaster shadow( int x, int y, WritableRaster tmpWR, WritableRaster pitWR, double res,
        double[] normalSunVector, double[] inverseSunVector, double[] sunVector ) {
    int n = 0;
    double zcompare = -Double.MAX_VALUE;
    double dx = (inverseSunVector[0] * n);
    double dy = (inverseSunVector[1] * n);
    int nCols = tmpWR.getWidth();
    int nRows = tmpWR.getHeight();
    int idx = (int) (x + dx);
    int jdy = (int) (y + dy);
    double vectorToOrigin[] = new double[3];
    while( idx >= 0 && idx <= nCols - 1 && jdy >= 0 && jdy <= nRows - 1 ) {
        vectorToOrigin[0] = dx * res;
        vectorToOrigin[1] = dy * res;
        vectorToOrigin[2] = pitWR.getSampleDouble(idx, jdy, 0);
        double zprojection = scalarProduct(vectorToOrigin, normalSunVector);
        double nGrad[] = normalVectorWR.getPixel(idx, jdy, new double[3]);
        double cosinc = scalarProduct(sunVector, nGrad);
        double elevRad = elevation;
        if ((cosinc >= 0) && (zprojection > zcompare)) {
            tmpWR.setSample(idx, jdy, 0, elevRad);
            zcompare = zprojection;
        }
        n = n + 1;
        dy = (inverseSunVector[1] * n);
        dx = (inverseSunVector[0] * n);
        idx = (int) Math.round(x + dx);
        jdy = (int) Math.round(y + dy);
    }
    return tmpWR;

}
 
Example 7
Source File: TexturePaintContext.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Any(WritableRaster srcRas, ColorModel cm,
           AffineTransform xform, int maxw, boolean filter)
{
    super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
    this.srcRas = srcRas;
    this.filter = filter;
}
 
Example 8
Source File: AdditiveCompositeDouble.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
@Override
public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
{
  int minX = dstOut.getMinX();
  int minY = dstOut.getMinY();
  int maxX = minX + dstOut.getWidth();
  int maxY = minY + dstOut.getHeight();

  //log.debug("minX,minY,maxX,maxY: " + minX + "," + minY + "," + maxX + "," + maxY);
  for (int y = minY; y < maxY; y++)
  {
    for (int x = minX; x < maxX; x++)
    {
      double d = dstIn.getSampleDouble(x, y, 0);
      if (isNodataNaN)
      {
        if (Double.isNaN(d))
        {
          d = 0;
        }
      }
      else
      {
        if (FloatUtils.isEqual(d, nodata))
        {
          d = 0;
        }
      }
      double sample = (src.getSampleDouble(x, y, 0) * weight) + d;

      dstOut.setSample(x, y, 0, sample);
    }
  }
}
 
Example 9
Source File: TexturePaintContext.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public Any(WritableRaster srcRas, ColorModel cm,
           AffineTransform xform, int maxw, boolean filter)
{
    super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
    this.srcRas = srcRas;
    this.filter = filter;
}
 
Example 10
Source File: PDDeviceRGB.java    From sambox with Apache License 2.0 5 votes vote down vote up
@Override
public BufferedImage toRGBImage(WritableRaster raster) throws IOException
{
    init();
    //
    // WARNING: this method is performance sensitive, modify with care!
    //
    // Please read PDFBOX-3854 and PDFBOX-2092 and look at the related commits first.
    // The current code returns TYPE_INT_RGB images which prevents slowness due to threads
    // blocking each other when TYPE_CUSTOM images are used.
    BufferedImage image = new BufferedImage(raster.getWidth(), raster.getHeight(),
            BufferedImage.TYPE_INT_RGB);
    image.setData(raster);
    return image;
}
 
Example 11
Source File: PDDeviceRGB.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public BufferedImage toRGBImage(WritableRaster raster) throws IOException
{
    init();

    //
    // WARNING: this method is performance sensitive, modify with care!
    //
    // Please read PDFBOX-3854 and PDFBOX-2092 and look at the related commits first.
    // The current code returns TYPE_INT_RGB images which prevents slowness due to threads
    // blocking each other when TYPE_CUSTOM images are used.
    BufferedImage image = new BufferedImage(raster.getWidth(), raster.getHeight(), BufferedImage.TYPE_INT_RGB);
    image.setData(raster);
    return image;
}
 
Example 12
Source File: DataRaster.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
void append(double x, double y) {
  if(Double.isNaN(x)||Double.isInfinite(x)||Double.isNaN(y)||Double.isInfinite(y)) {
    return; // do not append bad data
  }
  if(nextPoint>=data[0].length) {
    increaseCapacity(data[0].length*2);
  }
  data[0][nextPoint] = (float) x; // save value for later use
  data[1][nextPoint] = (float) y;
  nextPoint++;
  WritableRaster raster = image.getRaster();
  if(raster.getWidth()<2) {
    return; // image is too small
  }
  double xmin = Math.max(primaryDrawingPanel.getXMin(), DataRaster.this.xmin);
  double ymax = Math.min(primaryDrawingPanel.getYMax(), DataRaster.this.ymax);
  int i = (int) (primaryDrawingPanel.getXPixPerUnit()*(x-xmin)+0.5);
  int j = (int) (primaryDrawingPanel.getYPixPerUnit()*(ymax-y)+0.5);
  if((i<0)||(j<0)||(i>=raster.getWidth())||(j>=raster.getHeight())) {
    return; // outside the image
  }
  try {
    raster.setPixel(i, j, color);                                    // set the image pixel
  } catch(Exception ex) {
    System.out.println("Error setting raster in ImageData append."); //$NON-NLS-1$
  }
}
 
Example 13
Source File: MaskComposite.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
@Override
  public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
  {
    int minX = dstOut.getMinX();
    int minY = dstOut.getMinY();
    int maxX = minX + dstOut.getWidth();
    int maxY = minY + dstOut.getHeight();

    for (int y = minY; y < maxY; y++)
    {
      for (int x = minX; x < maxX; x++)
      {
        double srcValue = src.getSampleDouble(x, y, 0);
        // If the source value is set to the srcMaskedValue, then write out
        // the maskedValue. Otherwise, write out the unmaskedValue.
        if (((srcMaskedValue - EPSILON) <= srcValue) && (srcValue <= (srcMaskedValue + EPSILON)))
        {
//            dstOut.setSample(x, y, 0, maskedValue);
          dstOut.setSample(x, y, 0, maskedValue);
        }
        else
        {
          dstOut.setSample(x, y, 0, unmaskedValue);
        }
      }
    }
  }
 
Example 14
Source File: Screenshots.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static void convertScreenShot(ByteBuffer bgraBuf, BufferedImage out){
    WritableRaster wr = out.getRaster();
    DataBufferByte db = (DataBufferByte) wr.getDataBuffer();

    byte[] cpuArray = db.getData();

    // copy native memory to java memory
    bgraBuf.clear();
    bgraBuf.get(cpuArray);
    bgraBuf.clear();

    int width  = wr.getWidth();
    int height = wr.getHeight();

    // flip the components the way AWT likes them
    for (int y = 0; y < height / 2; y++){
        for (int x = 0; x < width; x++){
            int inPtr  = (y * width + x) * 4;
            int outPtr = ((height-y-1) * width + x) * 4;

            byte b1 = cpuArray[inPtr+0];
            byte g1 = cpuArray[inPtr+1];
            byte r1 = cpuArray[inPtr+2];
            byte a1 = cpuArray[inPtr+3];

            byte b2 = cpuArray[outPtr+0];
            byte g2 = cpuArray[outPtr+1];
            byte r2 = cpuArray[outPtr+2];
            byte a2 = cpuArray[outPtr+3];

            cpuArray[outPtr+0] = a1;
            cpuArray[outPtr+1] = b1;
            cpuArray[outPtr+2] = g1;
            cpuArray[outPtr+3] = r1;

            cpuArray[inPtr+0] = a2;
            cpuArray[inPtr+1] = b2;
            cpuArray[inPtr+2] = g2;
            cpuArray[inPtr+3] = r2;
        }
    }
}
 
Example 15
Source File: PDDeviceN.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
private BufferedImage toRGBWithAttributes(WritableRaster raster) throws IOException
{
    int width = raster.getWidth();
    int height = raster.getHeight();

    BufferedImage rgbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    WritableRaster rgbRaster = rgbImage.getRaster();

    // white background
    Graphics2D g = rgbImage.createGraphics();
    g.setBackground(Color.WHITE);
    g.clearRect(0, 0, width, height);
    g.dispose();

    // look up each colorant
    for (int c = 0; c < numColorants; c++)
    {
        PDColorSpace componentColorSpace;
        if (colorantToComponent[c] >= 0)
        {
            // process color
            componentColorSpace = processColorSpace;
        }
        else if (spotColorSpaces[c] == null)
        {
            // TODO this happens in the Altona Visual test, is there a better workaround?
            // missing spot color, fallback to using tintTransform
            return toRGBWithTintTransform(raster);
        }
        else
        {
            // spot color
            componentColorSpace = spotColorSpaces[c];
        }

        // copy single-component to its own raster in the component color space
        WritableRaster componentRaster = Raster.createBandedRaster(DataBuffer.TYPE_BYTE,
            width, height, componentColorSpace.getNumberOfComponents(), new Point(0, 0));

        int[] samples = new int[numColorants];
        int[] componentSamples = new int[componentColorSpace.getNumberOfComponents()];
        boolean isProcessColorant = colorantToComponent[c] >= 0;
        int componentIndex = colorantToComponent[c];
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                raster.getPixel(x, y, samples);
                if (isProcessColorant)
                {
                    // process color
                    componentSamples[componentIndex] = samples[c];
                }
                else
                {
                    // spot color
                    componentSamples[0] = samples[c];
                }
                componentRaster.setPixel(x, y, componentSamples);
            }
        }

        // convert single-component raster to RGB
        BufferedImage rgbComponentImage = componentColorSpace.toRGBImage(componentRaster);
        WritableRaster rgbComponentRaster = rgbComponentImage.getRaster();

        // combine the RGB component with the RGB composite raster
        int[] rgbChannel = new int[3];
        int[] rgbComposite = new int[3];
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                rgbComponentRaster.getPixel(x, y, rgbChannel);
                rgbRaster.getPixel(x, y, rgbComposite);

                // multiply (blend mode)
                rgbChannel[0] = rgbChannel[0] * rgbComposite[0] >> 8;
                rgbChannel[1] = rgbChannel[1] * rgbComposite[1] >> 8;
                rgbChannel[2] = rgbChannel[2] * rgbComposite[2] >> 8;

                rgbRaster.setPixel(x, y, rgbChannel);
            }
        }
    }

    return rgbImage;
}
 
Example 16
Source File: GaussianComposite.java    From mrgeo with Apache License 2.0 4 votes vote down vote up
@Override
public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
{
  int minX = dstOut.getMinX();
  int minY = dstOut.getMinY();
  int maxX = minX + dstOut.getWidth();
  int maxY = minY + dstOut.getHeight();

  //System.out.println(minX + ", " + minY + " - " + maxX + ", " + maxY);
  // calculate the area of the ellipse
  double area = Math.PI * (major / 2.0) * (minor / 2.0);

  // the final pixel multiplier, to be combined with the gaussian
  double multiplier = weight / area;

  for (int y = minY; y < maxY; y++)
  {
    for (int x = minX; x < maxX; x++)
    {
      double d = dstIn.getSampleDouble(x, y, 0);
      double s = src.getSampleDouble(x, y, 0);

      double sample;

      if (isNodataNaN)
      {
        if (Double.isNaN(s))
        {
          sample = d;
        }
        else
        {
          // do the gaussian...
          sample = calculateGaussian(s, x - dstIn.getSampleModelTranslateX(),
              y - dstIn.getSampleModelTranslateY(), multiplier);
        }
      }
      else
      {
        if (FloatUtils.isEqual(s, nodata))
        {
          sample = d;
        }
        else
        {
          // do the gaussian...
          sample = calculateGaussian(s, x - dstIn.getSampleModelTranslateX(),
              y - dstIn.getSampleModelTranslateY(), multiplier);
        }
      }

      dstOut.setSample(x, y, 0, sample);
    }
  }
}
 
Example 17
Source File: PDSeparation.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public BufferedImage toRGBImage(WritableRaster raster) throws IOException
{
    if (alternateColorSpace instanceof PDLab)
    {
        // PDFBOX-3622 - regular converter fails for Lab colorspaces
        return toRGBImage2(raster);
    }
    
    // use the tint transform to convert the sample into
    // the alternate color space (this is usually 1:many)
    WritableRaster altRaster = Raster.createBandedRaster(DataBuffer.TYPE_BYTE,
            raster.getWidth(), raster.getHeight(),
            alternateColorSpace.getNumberOfComponents(),
            new Point(0, 0));

    int numAltComponents = alternateColorSpace.getNumberOfComponents();
    int width = raster.getWidth();
    int height = raster.getHeight();
    float[] samples = new float[1];

    Map<Integer, int[]> calculatedValues = new HashMap<Integer, int[]>();
    Integer hash;
    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            raster.getPixel(x, y, samples);
            hash = Float.floatToIntBits(samples[0]);
            int[] alt = calculatedValues.get(hash);
            if (alt == null)
            {
                alt = new int[numAltComponents];
                tintTransform(samples, alt);
                calculatedValues.put(hash, alt);
            }                
            altRaster.setPixel(x, y, alt);
        }
    }

    // convert the alternate color space to RGB
    return alternateColorSpace.toRGBImage(altRaster);
}
 
Example 18
Source File: PDDeviceCMYK.java    From sambox with Apache License 2.0 4 votes vote down vote up
@Override
protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)
{
    if (usePureJavaCMYKConversion)
    {
        BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        ColorSpace destCS = dest.getColorModel().getColorSpace();
        WritableRaster destRaster = dest.getRaster();
        float[] srcValues = new float[4];
        float[] lastValues = new float[] { -1.0f, -1.0f, -1.0f, -1.0f };
        float[] destValues = new float[3];
        int width = raster.getWidth();
        int startX = raster.getMinX();
        int height = raster.getHeight();
        int startY = raster.getMinY();
        for (int x = startX; x < width + startX; x++)
        {
            for (int y = startY; y < height + startY; y++)
            {
                raster.getPixel(x, y, srcValues);
                // check if the last value can be reused
                if (!Arrays.equals(lastValues, srcValues))
                {
                    for (int k = 0; k < 4; k++)
                    {
                        lastValues[k] = srcValues[k];
                        srcValues[k] = srcValues[k] / 255f;
                    }
                    // use CIEXYZ as intermediate format to optimize the color conversion
                    destValues = destCS.fromCIEXYZ(colorSpace.toCIEXYZ(srcValues));
                    for (int k = 0; k < destValues.length; k++)
                    {
                        destValues[k] = destValues[k] * 255f;
                    }
                }
                destRaster.setPixel(x, y, destValues);
            }
        }
        return dest;
    }
    else
    {
        return super.toRGBImageAWT(raster, colorSpace);
    }
}
 
Example 19
Source File: GeomorphUtilities.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public void orizzonte6( double delta, int quadrata, double beta, double alfa, RandomIter elevImageIterator,
        WritableRaster curvatureImage, int[][] shadow ) {
    int rows = curvatureImage.getHeight();
    int cols = curvatureImage.getWidth();
    /*=====================*/

    int y, I, J;
    double zenith;

    /*======================*/

    if (beta != 0) {
        for( int i = 0; i < quadrata; i++ ) {
            I = -1;
            J = -1;
            y = 0;
            for( int ii = i; ii >= 0; ii-- ) {
                for( int j = (int) floor(1 / tan(beta) * (i - ii)); j <= (int) floor(1 / tan(beta) * (i - ii + 1)) - 1
                        && j < cols; j++ ) {
                    if (ii < rows && !isNovalue(elevImageIterator.getSampleDouble(j, ii, 0))) {
                        /*shadow.element[ii][j]=i;}}}}}*/
                        if (curvatureImage.getSampleDouble(j, ii, 0) == 1 && I == -1) {
                            I = ii;
                            J = j;
                            y = 1;
                        } else if (curvatureImage.getSampleDouble(j, ii, 0) == 1 && I != -1) {
                            zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator
                                    .getSampleDouble(j, ii, 0))
                                    / sqrt(pow((double) (I - ii) * (double) delta, (double) 2)
                                            + pow((double) (J - j) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[ii][j] = 0;
                                I = ii;
                                J = j;
                            } else {
                                shadow[ii][j] = 1;
                            }
                        } else if (curvatureImage.getSampleDouble(j, ii, 0) == 0 && y == 1) {
                            zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator
                                    .getSampleDouble(j, ii, 0))
                                    / sqrt((double) pow((I - ii) * (double) delta, (double) 2)
                                            + pow((double) (J - j) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[ii][j] = 0;
                                y = 0;
                            } else {
                                shadow[ii][j] = 1;
                            }
                        }
                    }
                }
            }
        }
    } else {
        for( int i = 0; i < rows; i++ ) {
            I = -1;
            J = -1;
            y = 0;
            for( int j = 0; j < cols; j++ ) {
                if (!isNovalue(elevImageIterator.getSampleDouble(j, i, 0))) {
                    if (curvatureImage.getSampleDouble(j, i, 0) == 1 && I == -1) {
                        I = i;
                        J = j;
                        y = 1;
                    } else if (curvatureImage.getSampleDouble(j, i, 0) == 1 && I != -1) {
                        zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(j, i, 0))
                                / sqrt(pow((double) (I - i) * (double) delta, (double) 2)
                                        + pow((double) (J - j) * (double) delta, (double) 2));
                        if (zenith <= tan(alfa)) {
                            shadow[i][j] = 0;
                            I = i;
                            J = j;
                        } else {
                            shadow[i][j] = 1;
                        }
                    } else if (curvatureImage.getSampleDouble(j, i, 0) == 0 && y == 1) {
                        zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(j, i, 0))
                                / sqrt(pow((double) (I - i) * (double) delta, (double) 2)
                                        + pow((double) (J - j) * (double) delta, (double) 2));
                        if (zenith <= tan(alfa)) {
                            shadow[i][j] = 0;
                            y = 0;
                        } else {
                            shadow[i][j] = 1;
                        }
                    }
                }
            }
        }
    }

}
 
Example 20
Source File: ModelsEngine.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Evaluate the shadow map.
 *
 * @param i
 *            the x axis index.
 * @param j
 *            the y axis index.
 * @param tmpWR
 *            the output shadow map.
 * @param demWR
 *            the elevation map.
 * @param res
 *            the resolution of the elevation map.
 * @param normalSunVector
 * @param inverseSunVector
 * @return
 */
private static WritableRaster shadow( int i, int j, WritableRaster tmpWR, WritableRaster demWR, double res,
        double[] normalSunVector, double[] inverseSunVector ) {
    int n = 0;
    double zcompare = -Double.MAX_VALUE;
    double dx = (inverseSunVector[0] * n);
    double dy = (inverseSunVector[1] * n);
    int nCols = tmpWR.getWidth();
    int nRows = tmpWR.getHeight();
    int idx = (int) Math.round(i + dx);
    int jdy = (int) Math.round(j + dy);
    double vectorToOrigin[] = new double[3];
    while( idx >= 0 && idx <= nCols - 1 && jdy >= 0 && jdy <= nRows - 1 ) {
        vectorToOrigin[0] = dx * res;
        vectorToOrigin[1] = dy * res;

        int tmpY = (int) (j + dy);
        if (tmpY < 0) {
            tmpY = 0;
        } else if (tmpY > nRows) {
            tmpY = nRows - 1;
        }
        int tmpX = (int) (i + dx);
        if (tmpX < 0) {
            tmpX = 0;
        } else if (tmpY > nCols) {
            tmpX = nCols - 1;
        }
        vectorToOrigin[2] = demWR.getSampleDouble(idx, jdy, 0);
        // vectorToOrigin[2] = (pitRandomIter.getSampleDouble(idx, jdy, 0) +
        // pitRandomIter
        // .getSampleDouble(tmpX, tmpY, 0)) / 2;
        double zprojection = scalarProduct(vectorToOrigin, normalSunVector);
        if ((zprojection < zcompare)) {
            tmpWR.setSample(idx, jdy, 0, 0);
        } else {
            zcompare = zprojection;
        }
        n = n + 1;
        dy = (inverseSunVector[1] * n);
        dx = (inverseSunVector[0] * n);
        idx = (int) Math.round(i + dx);
        jdy = (int) Math.round(j + dy);
    }
    return tmpWR;
}