private void loadA2D(File f) { Reader in = null; String q = "", name, value; boolean keepOn = true, hasInfo, endOfLine, isHeader; int xIndex = 0, yIndex = 0, chIndex; char c; data = new double[0][0]; try { in = new FileReader(f); while (keepOn) { chIndex = in.read(); c = (char) chIndex; hasInfo = q.length() > 0; endOfLine = (c == '\n'); isHeader = hasInfo && (q.charAt(0) == '#'); if (hasInfo && endOfLine && isHeader) { name = q.substring(q.indexOf('#') + 1, q.indexOf(':')); value = q.substring(q.indexOf(':') + 1).trim(); if (name.equals("Size")) { res = Int2.parseInfoString(value); data = new double[res.x][res.y]; } else if (name.equals("Origin")) this.origin = Pos2d.parseInfoString(value); else if (name.equals("Step")) this.step = Vec2d.parseInfoString(value); else if (name.equals("SeamlessX")) this.seamlessX = Boolean.parseBoolean(value); else if (name.equals("SeamlessY")) this.seamlessY = Boolean.parseBoolean(value); q = ""; } else if (hasInfo && (isHeader == false) && (Character.isWhitespace(c) || chIndex == -1)) { data[xIndex][yIndex++] = Double.parseDouble(q); q = ""; if (endOfLine) { xIndex++; yIndex = 0; } } else { q += c; } keepOn = (chIndex != -1); } } catch (Exception exc) { System.err.println("Fehler beim Lesen der Datei \"" + f.getPath() + "\": " + exc); } finally { try { in.close(); } catch (Exception exc) { } } }
/** * Returns a denominator for filtering the wide-field, OTF band 0 with no attenuation. * * @param wParam Wiener filter parameter */ public Vec2d.Real getWidefieldDenominator(double wParam) { Vec2d.Real ret = Vec2d.createReal(sp, 2); addWienerDenominator(ret, 0, 0, false); final int w = ret.vectorWidth(), h = ret.vectorHeight(); for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) ret.set(x, y, 1 / (ret.get(x, y) + (float) (wParam * wParam))); return ret; }
/** * Returns a copy of a per-band, per-direction Wiener denominator. This is used mostly for * filtering intermediate results. * * @param d Direction * @param b Band * @param wParam Wiener filter parameter */ public Vec2d.Real getIntermediateDenominator(int d, int b, double wParam) { // get the otf Vec2d.Real ret = Vec2d.createReal(sp, 2); addWienerDenominator(ret, d, b, sp.otf().isAttenuate()); // add the wiener parameter final int w = ret.vectorWidth(), h = ret.vectorHeight(); for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) ret.set(x, y, 1 / (ret.get(x, y) + (float) (wParam * wParam))); return ret; }
/** * Setup the Wiener filter. This (re)initiates the cached filter values. Has to be called if the * OTF or the shift parameters change. */ public void updateCache() { Tool.Timer t1 = Tool.getTimer(); final int w = sp.vectorWidth(), h = sp.vectorHeight(); t1.start(); wDenom = Vec2d.createReal(2 * w, 2 * h); boolean useAtt = sp.otf().isAttenuate(); // loop directions, bands for (int d = 0; d < sp.nrDir(); d++) { for (int b = 0; b < sp.dir(d).nrBand(); b++) { addWienerDenominator(wDenom, d, b, useAtt); } } t1.stop(); Tool.trace("Wiener filter setup complete, took " + t1); }
public static Point closestPoint(Vec2d seg_a, Vec2d seg_b, Point circleOrigin) { Vec2d seg_v = seg_b.sub(seg_a); Vec2d pt_v = new Vec2d(circleOrigin.getX(), circleOrigin.getY()).sub(seg_a); Vec2d seg_v_unit = seg_v.div(seg_v.Length()); double proj = pt_v.Dot(seg_v_unit); Point closest; if (proj <= 0) { closest = new Point(seg_a.x, seg_b.x); } else if (proj >= seg_v.Length()) { closest = new Point(seg_b.x, seg_b.x); } else { Vec2d proj_v = seg_v_unit.mul(proj); Vec2d newVec = proj_v.add(seg_a); closest = new Point(newVec.x, newVec.y); } return closest; }