Java Code Examples for processing.core.PApplet#constrain()
The following examples show how to use
processing.core.PApplet#constrain() .
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: PaperScreen.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
/** * Get a square of pixels centered at the coord location of radius size. * WARNING: Unsafe to use, this will be updated/moved * * @param coord * @param cameraImage * @param radius * @return */ public int[] getPixelsFrom(PVector coord, PImage cameraImage, int radius) { int[] px = new int[radius * radius]; int x = (int) coord.x; int y = (int) coord.y; int minX = PApplet.constrain(x - radius, 0, cameraTracking.width() - 1); int maxX = PApplet.constrain(x + radius, 0, cameraTracking.width() - 1); int minY = PApplet.constrain(y - radius, 0, cameraTracking.height() - 1); int maxY = PApplet.constrain(y + radius, 0, cameraTracking.height() - 1); int k = 0; for (int j = minY; j <= maxY; j++) { for (int i = minX; i <= maxX; i++) { int offset = i + j * cameraTracking.width(); px[k++] = cameraImage.pixels[offset]; } } return px; }
Example 2
Source File: ProjectiveDeviceP.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
/** * Handle distorsions * * @param pt * @return */ public PVector worldToPixelCoord(PVector pt, boolean undist) { // Reprojection float invZ = 1.0f / pt.z; int px = PApplet.constrain(PApplet.round((pt.x * invZ * fx) + cx), 0, w - 1); int py = PApplet.constrain(PApplet.round((pt.y * invZ * fy) + cy), 0, h - 1); if (this.handleDistorsion && undist) { double[] out = device.undistort(px, py); px = (int) (out[0]); py = (int) (out[1]); } return new PVector(px, py); }
Example 3
Source File: TouchDetectionDepth.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
@Deprecated protected void setPrecisionFrom(int firstPoint) { Vec3D currentPoint = depthData.depthPoints[firstPoint]; PVector coordinates = depthData.projectiveDevice.getCoordinates(firstPoint); // Find a point. int x = (int) coordinates.x; int y = (int) coordinates.y; int minX = PApplet.constrain(x - precision, 0, depthData.projectiveDevice.getWidth() - 1); int maxX = PApplet.constrain(x + precision, 0, depthData.projectiveDevice.getWidth() - 1); int minY = PApplet.constrain(y - precision, 0, depthData.projectiveDevice.getHeight() - 1); int maxY = PApplet.constrain(y + precision, 0, depthData.projectiveDevice.getHeight() - 1); for (int j = minY; j <= maxY; j += precision) { for (int i = minX; i <= maxX; i += precision) { Vec3D nearbyPoint = depthData.projectiveDevice.pixelToWorld(i, j, currentPoint.z); // Set the distance. setDistance(currentPoint.distanceTo(nearbyPoint)); return; } } // for i }
Example 4
Source File: MathUtils.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
/** * Unsafe do not use unless you are sure. */ public static int getColorOccurencesFrom(Camera camera, PVector coord, int radius, int col, int threshold, PaperTouchScreen paperTouchScreen) { int x = (int) coord.x; int y = (int) coord.y; int minX = PApplet.constrain(x - radius, 0, camera.width() - 1); int maxX = PApplet.constrain(x + radius, 0, camera.width() - 1); int minY = PApplet.constrain(y - radius, 0, camera.height() - 1); int maxY = PApplet.constrain(y + radius, 0, camera.height() - 1); ByteBuffer buff = camera.getIplImage().getByteBuffer(); int k = 0; for (int j = minY; j <= maxY; j++) { for (int i = minX; i <= maxX; i++) { int offset = i + j * camera.width(); int pxCol = getColor(buff, offset); if (MathUtils.colorDistRGB(col, pxCol, threshold)) { k++; } } } return k; }
Example 5
Source File: MathUtils.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
/** * Unsafe do not use unless you are sure. */ public int getColorOccurencesFrom(PVector coord, PImage cameraImage, int radius, int col, int threshold, PaperTouchScreen paperTouchScreen) { int x = (int) coord.x; int y = (int) coord.y; int minX = PApplet.constrain(x - radius, 0, cameraImage.width - 1); int maxX = PApplet.constrain(x + radius, 0, cameraImage.width - 1); int minY = PApplet.constrain(y - radius, 0, cameraImage.height - 1); int maxY = PApplet.constrain(y + radius, 0, cameraImage.height - 1); int k = 0; for (int j = minY; j <= maxY; j++) { for (int i = minX; i <= maxX; i++) { int offset = i + j * cameraImage.width; int pxCol = cameraImage.pixels[offset]; if (colorDistRGB(col, pxCol, threshold)) { k++; } } } return k; }
Example 6
Source File: ProjectiveDeviceP.java From PapARt with GNU Lesser General Public License v3.0 | 5 votes |
public int worldToPixel(float x, float y, float z) { // Reprojection float invZ = 1.0f / z; int px = PApplet.constrain(PApplet.round((x * invZ * fx) + cx), 0, w - 1); int py = PApplet.constrain(PApplet.round((y * invZ * fy) + cy), 0, h - 1); return (int) (py * w + px); }
Example 7
Source File: ProjectiveDeviceP.java From PapARt with GNU Lesser General Public License v3.0 | 5 votes |
public PVector worldToPixel(PVector pt, boolean undistort) { // Reprojection float invZ = 1.0f / pt.z; int px = PApplet.constrain(PApplet.round((pt.x * invZ * fx) + cx), 0, w - 1); int py = PApplet.constrain(PApplet.round((pt.y * invZ * fy) + cy), 0, h - 1); if (undistort && this.handleDistorsion) { double[] out = device.distort(px, py); return new PVector((float) out[0], (float) out[1]); } else { return new PVector(px, py); } }
Example 8
Source File: ProjectiveDeviceP.java From PapARt with GNU Lesser General Public License v3.0 | 3 votes |
public PVector worldToPixelCoord(Vec3D pt) { // Reprojection float invZ = 1.0f / pt.z(); int px = PApplet.constrain(PApplet.round((pt.x() * invZ * fx) + cx), 0, w - 1); int py = PApplet.constrain(PApplet.round((pt.y() * invZ * fy) + cy), 0, h - 1); return new PVector(px, py); }
Example 9
Source File: ProjectiveDeviceP.java From PapARt with GNU Lesser General Public License v3.0 | 3 votes |
public int worldToPixel(PVector pt) { // Reprojection float invZ = 1.0f / pt.z; int px = PApplet.constrain(PApplet.round((pt.x * invZ * fx) + cx), 0, w - 1); int py = PApplet.constrain(PApplet.round((pt.y * invZ * fy) + cy), 0, h - 1); return (int) (py * w + px); }