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.LayerVisitor;
import com.sk89q.worldedit.function.visitor.RecursiveVisitor; import com.sk89q.worldedit.function.visitor.RecursiveVisitor;
import com.sk89q.worldedit.function.visitor.RegionVisitor; import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.interpolation.Interpolation; import com.sk89q.worldedit.math.interpolation.Interpolation;
import com.sk89q.worldedit.interpolation.KochanekBartelsInterpolation; import com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation;
import com.sk89q.worldedit.interpolation.Node; import com.sk89q.worldedit.math.interpolation.Node;
import com.sk89q.worldedit.masks.Mask; import com.sk89q.worldedit.masks.Mask;
import com.sk89q.worldedit.math.noise.RandomNoise; import com.sk89q.worldedit.math.noise.RandomNoise;
import com.sk89q.worldedit.math.transform.AffineTransform; 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.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID; 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; 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.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.expression.ExpressionException; import com.sk89q.worldedit.expression.ExpressionException;
import com.sk89q.worldedit.filtering.GaussianKernel; import com.sk89q.worldedit.math.convolution.GaussianKernel;
import com.sk89q.worldedit.filtering.HeightMapFilter; import com.sk89q.worldedit.math.convolution.HeightMapFilter;
import com.sk89q.worldedit.function.GroundFunction; import com.sk89q.worldedit.function.GroundFunction;
import com.sk89q.worldedit.function.generator.FloraGenerator; import com.sk89q.worldedit.function.generator.FloraGenerator;
import com.sk89q.worldedit.function.generator.ForestGenerator; import com.sk89q.worldedit.function.generator.ForestGenerator;

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.List;

Datei anzeigen

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

Datei anzeigen

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.List;

Datei anzeigen

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

Datei anzeigen

@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.List;
import java.util.Map.Entry; 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.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.filtering.GaussianKernel; import com.sk89q.worldedit.math.convolution.GaussianKernel;
import com.sk89q.worldedit.filtering.HeightMapFilter; import com.sk89q.worldedit.math.convolution.HeightMapFilter;
import com.sk89q.worldedit.patterns.Pattern; import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;