本文整理汇总了Java中processing.core.PVector.div方法的典型用法代码示例。如果您正苦于以下问题:Java PVector.div方法的具体用法?Java PVector.div怎么用?Java PVector.div使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类processing.core.PVector
的用法示例。
在下文中一共展示了PVector.div方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reduceResolution
import processing.core.PVector; //导入方法依赖的package包/类
/**
* Reduces the scan resolution by a given factor, smoothing the points at the same time
*
* @param reductionFactor the scale reduction factor
*/
public void reduceResolution(int reductionFactor) {
if (reductionFactor > 1) {
// Obtain the dimensions of the new reduced arrays
int widthNew = width / reductionFactor + 2;
int heightNew = height / reductionFactor + 2;
int nPointsNew = widthNew * heightNew;
PVector[] pointsNew = new PVector[nPointsNew];
int[] colorsNew = new int[nPointsNew];
boolean[] visibilityMaskNew = new boolean[nPointsNew];
// Populate the arrays
for (int row = 0; row < heightNew; row++) {
for (int col = 0; col < widthNew; col++) {
int indexNew = col + row * widthNew;
// Average between nearby pixels
PVector pointAverage = new PVector();
int redAverage = 0;
int greenAverage = 0;
int blueAverage = 0;
int counter = 0;
for (int i = -reductionFactor / 2; i <= reductionFactor / 2; i++) {
for (int j = -reductionFactor / 2; j <= reductionFactor / 2; j++) {
int rowNearby = row * reductionFactor + i;
int colNearby = col * reductionFactor + j;
if (colNearby >= 0 && colNearby < width && rowNearby >= 0 && rowNearby < height) {
int indexNearby = colNearby + rowNearby * width;
if (visibilityMask[indexNearby]) {
pointAverage.add(points[indexNearby]);
int color = colors[indexNearby];
redAverage += (color >> 16) & 0xff;
greenAverage += (color >> 8) & 0xff;
blueAverage += color & 0xff;
counter++;
}
}
}
}
if (counter > 0) {
pointsNew[indexNew] = pointAverage.div(counter);
colorsNew[indexNew] = ((redAverage / counter) << 16) | ((greenAverage / counter) << 8)
| (blueAverage / counter) | 0xff000000;
visibilityMaskNew[indexNew] = true;
} else {
pointsNew[indexNew] = pointAverage;
}
}
}
// Update the arrays to the new resolution
width = widthNew;
height = heightNew;
nPoints = nPointsNew;
points = pointsNew;
colors = colorsNew;
visibilityMask = visibilityMaskNew;
// Update the normals array
updateNormals();
// Remove the meshes
mesh = null;
pointsMesh = null;
linesMesh = null;
}
}
示例2: gaussianSmooth
import processing.core.PVector; //导入方法依赖的package包/类
/**
* Smoothes the scan points using a Gaussian kernel
*
* @param kernelSize the kernel size. Should be an odd number larger than 1
*/
public void gaussianSmooth(int kernelSize) {
if (kernelSize > 1) {
// Make sure that the kernel size is an even number
if (kernelSize % 2 == 0) {
kernelSize++;
}
// Create the Gaussian kernel
float[][] kernel = new float[kernelSize][kernelSize];
int kernelMiddlePoint = (kernelSize - 1) / 2;
float maxDistanceSq = PApplet.sq(kernelMiddlePoint);
float sigmaSq = PApplet.sq(kernelMiddlePoint / 2f);
for (int i = 0; i < kernelSize; i++) {
for (int j = 0; j < kernelSize; j++) {
float distanceSq = PApplet.sq(i - kernelMiddlePoint) + PApplet.sq(j - kernelMiddlePoint);
if (distanceSq <= maxDistanceSq) {
kernel[i][j] = PApplet.pow(2.718f, -distanceSq / (2 * sigmaSq));
}
}
}
// Calculate the smoothed points
PVector[] smoothedPoints = new PVector[nPoints];
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
int index = col + row * width;
if (visibilityMask[index]) {
PVector pointsSum = new PVector();
float kernelValueCounter = 0;
for (int i = 0; i < kernelSize; i++) {
int rowStep = row - kernelMiddlePoint + i;
for (int j = 0; j < kernelSize; j++) {
int colStep = col - kernelMiddlePoint + j;
if (colStep >= 0 && colStep < width && rowStep >= 0 && rowStep < height) {
int indexStep = colStep + rowStep * width;
if (visibilityMask[indexStep]) {
PVector pointStep = points[indexStep];
float kernelValue = kernel[i][j];
if (kernelValue != 0 && connected(points[index], pointStep)) {
pointsSum.add(kernelValue * pointStep.x, kernelValue * pointStep.y,
kernelValue * pointStep.z);
kernelValueCounter += kernelValue;
}
}
}
}
}
smoothedPoints[index] = pointsSum.div(kernelValueCounter);
} else {
smoothedPoints[index] = points[index];
}
}
}
// Update the points array
points = smoothedPoints;
// Update the normals array
updateNormals();
// Remove the meshes
mesh = null;
pointsMesh = null;
linesMesh = null;
}
}