Java Array Normalize normalizeHeightMapCopy(float heightMap[])

Here you can find the source of normalizeHeightMapCopy(float heightMap[])

Description

normalize Height Map Copy

License

Open Source License

Declaration

public static float[] normalizeHeightMapCopy(float heightMap[]) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static float[] normalizeHeightMapCopy(float heightMap[]) {
        float tmpHM[] = new float[heightMap.length];
        System.arraycopy(heightMap, 0, tmpHM, 0, heightMap.length);
        normalizeHeightMap(tmpHM);/*www  .ja v  a  2  s  .  c  om*/
        return tmpHM;
    }

    public static void normalizeHeightMap(float heightMap[]) {
        int mapArea = heightMap.length;
        float minHeight = heightMap[0], maxHeight = heightMap[0];
        for (int i = 1; i < mapArea; i++) {
            if (heightMap[i] < minHeight)
                minHeight = heightMap[i];
            if (heightMap[i] > maxHeight)
                maxHeight = heightMap[i];
        }

        float scaleFactor = maxHeight - minHeight;
        //if (min != 0.0f) minHeight -= min;
        //if (min != 0.0f || max != 1.0f) scaleFactor /= (max - min);

        for (int i = 0; i < mapArea; i++) {
            heightMap[i] = (heightMap[i] - minHeight) / scaleFactor;
        }
    }
}

Related

  1. normalizeFromLog10(double[] array)
  2. normalizeFromLog10(double[] array, boolean takeLog10OfOutput)
  3. normalizeFromLog10(final double[] array, final boolean takeLog10OfOutput, final boolean keepInLogSpace)
  4. normalizeFromRealSpace(final double[] array)
  5. normalizeHeightMap(float heightMap[])
  6. normalizeHistogram(int[] h)
  7. normalizeHistogram(int[] hist)
  8. normalizeHistogramToBase(int[] hist, double base)
  9. normalizeInnerPointDistanceMax(double[][] distances, double maxDist)