Moved interpolation, filtering packages to math.

Dieser Commit ist enthalten in:
sk89q 2014-03-30 12:13:45 -07:00
Ursprung 75bee27610
Commit b07fd594e9
12 geänderte Dateien mit 234 neuen und 234 gelöschten Zeilen

Datei anzeigen

@ -44,9 +44,9 @@ import com.sk89q.worldedit.function.visitor.DownwardVisitor;
import com.sk89q.worldedit.function.visitor.LayerVisitor;
import com.sk89q.worldedit.function.visitor.RecursiveVisitor;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.interpolation.Interpolation;
import com.sk89q.worldedit.interpolation.KochanekBartelsInterpolation;
import com.sk89q.worldedit.interpolation.Node;
import com.sk89q.worldedit.math.interpolation.Interpolation;
import com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation;
import com.sk89q.worldedit.math.interpolation.Node;
import com.sk89q.worldedit.masks.Mask;
import com.sk89q.worldedit.math.noise.RandomNoise;
import com.sk89q.worldedit.math.transform.AffineTransform;

Datei anzeigen

@ -21,7 +21,7 @@ package com.sk89q.worldedit;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.filtering.HeightMapFilter;
import com.sk89q.worldedit.math.convolution.HeightMapFilter;
import com.sk89q.worldedit.regions.Region;
/**

Datei anzeigen

@ -27,8 +27,8 @@ import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.expression.ExpressionException;
import com.sk89q.worldedit.filtering.GaussianKernel;
import com.sk89q.worldedit.filtering.HeightMapFilter;
import com.sk89q.worldedit.math.convolution.GaussianKernel;
import com.sk89q.worldedit.math.convolution.HeightMapFilter;
import com.sk89q.worldedit.function.GroundFunction;
import com.sk89q.worldedit.function.generator.FloraGenerator;
import com.sk89q.worldedit.function.generator.ForestGenerator;

Datei anzeigen

@ -1,57 +1,57 @@
// $Id$
/*
* WorldEditLibrary
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.filtering;
import java.awt.image.Kernel;
/**
* A Gaussian Kernel generator (2D bellcurve)
*
* @author Grum
*/
public class GaussianKernel extends Kernel {
/**
* Constructor of the kernel
*
* @param radius the resulting diameter will be radius * 2 + 1
* @param sigma controls 'flatness'
*/
public GaussianKernel(int radius, double sigma) {
super(radius * 2 + 1, radius * 2 + 1, createKernel(radius, sigma));
}
private static float[] createKernel(int radius, double sigma) {
int diameter = radius * 2 + 1;
float[] data = new float[diameter * diameter];
double sigma22 = 2 * sigma * sigma;
double constant = Math.PI * sigma22;
for (int y = -radius; y <= radius; ++y) {
for (int x = -radius; x <= radius; ++x) {
data[(y + radius) * diameter + x + radius] = (float) (Math.exp(-(x * x + y * y) / sigma22) / constant);
}
}
return data;
}
}
// $Id$
/*
* WorldEditLibrary
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.math.convolution;
import java.awt.image.Kernel;
/**
* A Gaussian Kernel generator (2D bellcurve)
*
* @author Grum
*/
public class GaussianKernel extends Kernel {
/**
* Constructor of the kernel
*
* @param radius the resulting diameter will be radius * 2 + 1
* @param sigma controls 'flatness'
*/
public GaussianKernel(int radius, double sigma) {
super(radius * 2 + 1, radius * 2 + 1, createKernel(radius, sigma));
}
private static float[] createKernel(int radius, double sigma) {
int diameter = radius * 2 + 1;
float[] data = new float[diameter * diameter];
double sigma22 = 2 * sigma * sigma;
double constant = Math.PI * sigma22;
for (int y = -radius; y <= radius; ++y) {
for (int x = -radius; x <= radius; ++x) {
data[(y + radius) * diameter + x + radius] = (float) (Math.exp(-(x * x + y * y) / sigma22) / constant);
}
}
return data;
}
}

Datei anzeigen

@ -1,120 +1,120 @@
// $Id$
/*
* WorldEditLibrary
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.filtering;
import java.awt.image.Kernel;
/**
* Allows applications of Kernels onto the region's heightmap.
* Only used for smoothing (with a GaussianKernel).
*
* @author Grum
*/
public class HeightMapFilter {
private Kernel kernel;
/**
* Construct the HeightMapFilter object.
*
* @param kernel
*/
public HeightMapFilter(Kernel kernel) {
this.kernel = kernel;
}
/**
* Construct the HeightMapFilter object.
*
* @param kernelWidth
* @param kernelHeight
* @param kernelData
*/
public HeightMapFilter(int kernelWidth, int kernelHeight, float[] kernelData) {
this.kernel = new Kernel(kernelWidth, kernelHeight, kernelData);
}
/**
* @return the kernel
*/
public Kernel getKernel() {
return kernel;
}
/**
* Set Kernel
*
* @param kernel
*/
public void setKernel(Kernel kernel) {
this.kernel = kernel;
}
/**
* Filter with a 2D kernel
*
* @param inData
* @param width
* @param height
* @return the modified heightmap
*/
public int[] filter(int[] inData, int width, int height) {
int index = 0;
float[] matrix = kernel.getKernelData(null);
int[] outData = new int[inData.length];
int kh = kernel.getHeight();
int kw = kernel.getWidth();
int kox = kernel.getXOrigin();
int koy = kernel.getYOrigin();
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
float z = 0;
for (int ky = 0; ky < kh; ++ky) {
int offsetY = y + ky - koy;
// Clamp coordinates inside data
if (offsetY < 0 || offsetY >= height) {
offsetY = y;
}
offsetY *= width;
int matrixOffset = ky * kw;
for (int kx = 0; kx < kw; ++kx) {
float f = matrix[matrixOffset + kx];
if (f == 0) continue;
int offsetX = x + kx - kox;
// Clamp coordinates inside data
if (offsetX < 0 || offsetX >= width) {
offsetX = x;
}
z += f * inData[offsetY + offsetX];
}
}
outData[index++] = (int) (z + 0.5);
}
}
return outData;
}
}
// $Id$
/*
* WorldEditLibrary
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.math.convolution;
import java.awt.image.Kernel;
/**
* Allows applications of Kernels onto the region's heightmap.
* Only used for smoothing (with a GaussianKernel).
*
* @author Grum
*/
public class HeightMapFilter {
private Kernel kernel;
/**
* Construct the HeightMapFilter object.
*
* @param kernel
*/
public HeightMapFilter(Kernel kernel) {
this.kernel = kernel;
}
/**
* Construct the HeightMapFilter object.
*
* @param kernelWidth
* @param kernelHeight
* @param kernelData
*/
public HeightMapFilter(int kernelWidth, int kernelHeight, float[] kernelData) {
this.kernel = new Kernel(kernelWidth, kernelHeight, kernelData);
}
/**
* @return the kernel
*/
public Kernel getKernel() {
return kernel;
}
/**
* Set Kernel
*
* @param kernel
*/
public void setKernel(Kernel kernel) {
this.kernel = kernel;
}
/**
* Filter with a 2D kernel
*
* @param inData
* @param width
* @param height
* @return the modified heightmap
*/
public int[] filter(int[] inData, int width, int height) {
int index = 0;
float[] matrix = kernel.getKernelData(null);
int[] outData = new int[inData.length];
int kh = kernel.getHeight();
int kw = kernel.getWidth();
int kox = kernel.getXOrigin();
int koy = kernel.getYOrigin();
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
float z = 0;
for (int ky = 0; ky < kh; ++ky) {
int offsetY = y + ky - koy;
// Clamp coordinates inside data
if (offsetY < 0 || offsetY >= height) {
offsetY = y;
}
offsetY *= width;
int matrixOffset = ky * kw;
for (int kx = 0; kx < kw; ++kx) {
float f = matrix[matrixOffset + kx];
if (f == 0) continue;
int offsetX = x + kx - kox;
// Clamp coordinates inside data
if (offsetX < 0 || offsetX >= width) {
offsetX = x;
}
z += f * inData[offsetY + offsetX];
}
}
outData[index++] = (int) (z + 0.5);
}
}
return outData;
}
}

Datei anzeigen

@ -1,44 +1,44 @@
// $Id$
/*
* WorldEditLibrary
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.filtering;
import java.awt.image.Kernel;
/**
* A linear Kernel generator (all cells weight the same)
*
* @author Grum
*/
public class LinearKernel extends Kernel {
public LinearKernel(int radius) {
super(radius * 2 + 1, radius * 2 + 1, createKernel(radius));
}
private static float[] createKernel(int radius) {
int diameter = radius * 2 + 1;
float[] data = new float[diameter * diameter];
for (int i = 0; i < data.length; data[i++] = 1.0f / data.length) ;
return data;
}
}
// $Id$
/*
* WorldEditLibrary
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.math.convolution;
import java.awt.image.Kernel;
/**
* A linear Kernel generator (all cells weight the same)
*
* @author Grum
*/
public class LinearKernel extends Kernel {
public LinearKernel(int radius) {
super(radius * 2 + 1, radius * 2 + 1, createKernel(radius));
}
private static float[] createKernel(int radius) {
int diameter = radius * 2 + 1;
float[] data = new float[diameter * diameter];
for (int i = 0; i < data.length; data[i++] = 1.0f / data.length) ;
return data;
}
}

Datei anzeigen

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.interpolation;
package com.sk89q.worldedit.math.interpolation;
import java.util.List;

Datei anzeigen

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.interpolation;
package com.sk89q.worldedit.math.interpolation;
import java.util.Collections;
import java.util.List;

Datei anzeigen

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.interpolation;
package com.sk89q.worldedit.math.interpolation;
import java.util.List;

Datei anzeigen

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.interpolation;
package com.sk89q.worldedit.math.interpolation;
import com.sk89q.worldedit.Vector;

Datei anzeigen

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.interpolation;
package com.sk89q.worldedit.math.interpolation;
import java.util.List;
import java.util.Map.Entry;

Datei anzeigen

@ -24,8 +24,8 @@ import com.sk89q.worldedit.HeightMap;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.filtering.GaussianKernel;
import com.sk89q.worldedit.filtering.HeightMapFilter;
import com.sk89q.worldedit.math.convolution.GaussianKernel;
import com.sk89q.worldedit.math.convolution.HeightMapFilter;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;