List of usage examples for org.apache.commons.lang3.mutable MutableDouble setValue
@Override public void setValue(final Number value)
From source file:bwem.util.Utils.java
/** * Returns true if the lines intersect, otherwise false. In addition, if the lines * intersect the intersection point may be stored in iX and iY. * * From http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect *//*from www. j av a 2 s. co m*/ public static boolean getLineIntersection(double p0X, double p0Y, double p1X, double p1Y, double p2X, double p2Y, double p3X, double p3Y, MutableDouble iX, MutableDouble iY) { double s1X, s1Y; double s2X, s2Y; s1X = p1X - p0X; s1Y = p1Y - p0Y; s2X = p3X - p2X; s2Y = p3Y - p2Y; double s, t; s = (-s1Y * (p0X - p2X) + s1X * (p0Y - p2Y)) / (-s2X * s1Y + s1X * s2Y); t = (s2X * (p0Y - p2Y) - s2Y * (p0X - p2X)) / (-s2X * s1Y + s1X * s2Y); if (s >= 0 && s <= 1 && t >= 0 && t <= 1) { // Collision detected if (iX != null) iX.setValue(p0X + (t * s1X)); if (iY != null) iY.setValue(p0Y + (t * s1Y)); return true; } return false; // No collision }
From source file:de.biomedical_imaging.ij.steger.Correct.java
static boolean line_corrections(double sigma, double w_est, double r_est, MutableDouble w, MutableDouble h, MutableDouble correct, MutableDouble w_strong, MutableDouble w_weak) { int i_we, i_re; boolean is_valid; double a, b;// w w w . jav a 2 s. c o m w_est = w_est / sigma; if (w_est < 2 || w_est > 6 || r_est < 0 || r_est > 1) { w.setValue(0); h.setValue(0); correct.setValue(0); w_strong.setValue(0); w_weak.setValue(0); return true; } i_we = (int) Math.floor((w_est - 2) * 10); i_re = (int) Math.floor(r_est * 20); if (i_we == 40) i_we = 39; if (i_re == 20) i_re = 19; is_valid = getCTable(i_re, i_we).is_valid && getCTable(i_re, (i_we + 1)).is_valid && getCTable((i_re + 1), i_we).is_valid && getCTable((i_re + 1), (i_we + 1)).is_valid; a = (w_est - 2) * 10 - i_we; b = r_est * 20 - i_re; w.setValue(BILINEAR(a, b, i_re, i_we, 0) * sigma); h.setValue(BILINEAR(a, b, i_re, i_we, 1)); correct.setValue(BILINEAR(a, b, i_re, i_we, 2) * sigma); w_strong.setValue(BILINEAR(a, b, i_re, i_we, 3) * sigma); w_weak.setValue(BILINEAR(a, b, i_re, i_we, 4) * sigma); return !is_valid; }
From source file:de.biomedical_imaging.ij.steger.Position.java
/** Solve the linear equation a*x+b=0 and return the result in t and the number of solutions in num. **//*from w ww. j a v a2 s. c o m*/ public void solve_linear(double a, double b, MutableDouble t, MutableInt num) { if (a == 0.0) { // num.setValue(0); return; } else { num.setValue(1); t.setValue(-b / a); return; } }
From source file:edu.byu.nlp.dataset.BasicSparseFeatureVector.java
@Override public Double getValue(final int targetIndex) { final MutableDouble retval = new MutableDouble(Double.NaN); visitSparseEntries(new EntryVisitor() { @Override/*w w w. ja v a2s .c om*/ public void visitEntry(int index, double value) { if (index == targetIndex) { retval.setValue(value); return; } } }); return (Double.isNaN(retval.getValue())) ? null : retval.getValue(); }
From source file:de.biomedical_imaging.ij.steger.Link.java
private void closest_point(double lx, double ly, double dx, double dy, double px, double py, MutableDouble cx, MutableDouble cy, MutableDouble t) { double mx, my, den, nom, tt; mx = px - lx;/*from w w w . j a va 2 s . c om*/ my = py - ly; den = dx * dx + dy * dy; nom = mx * dx + my * dy; if (den != 0) tt = nom / den; else tt = 0; cx.setValue(lx + tt * dx); cy.setValue(ly + tt * dy); t.setValue(tt); }
From source file:de.biomedical_imaging.ij.steger.Link.java
private void interpolate_gradient(float[] gradx, float[] grady, double px, double py, int width, MutableDouble gx, MutableDouble gy) { int gix, giy, gpos; double gfx, gfy, gx1, gy1, gx2, gy2, gx3, gy3, gx4, gy4; gix = (int) Math.floor(px); giy = (int) Math.floor(py); gfx = px % 1.0;/*from www.ja v a2s.com*/ ; gfy = py % 1.0; gpos = LinesUtil.LINCOOR(gix, giy, width); gx1 = gradx[gpos]; gy1 = grady[gpos]; gpos = LinesUtil.LINCOOR(gix + 1, giy, width); gx2 = gradx[gpos]; gy2 = grady[gpos]; gpos = LinesUtil.LINCOOR(gix, giy + 1, width); gx3 = gradx[gpos]; gy3 = grady[gpos]; gpos = LinesUtil.LINCOOR(gix + 1, giy + 1, width); gx4 = gradx[gpos]; gy4 = grady[gpos]; gx.setValue((1 - gfy) * ((1 - gfx) * gx1 + gfx * gx2) + gfy * ((1 - gfx) * gx3 + gfx * gx4)); gy.setValue((1 - gfy) * ((1 - gfx) * gy1 + gfx * gy2) + gfy * ((1 - gfx) * gy3 + gfx * gy4)); }
From source file:de.biomedical_imaging.ij.steger.Width.java
private void fix_locations(double[] width_l, double[] width_r, double[] grad_l, double[] grad_r, double[] pos_x, double[] pos_y, double[] correction, double[] contr, double[] asymm, double sigma, int mode, boolean correct_pos, Line cont) { int i;/* ww w . j av a 2 s .c o m*/ int num_points; double px, py; double nx, ny; double w_est, r_est; MutableDouble w_real, h_real, corr; w_real = new MutableDouble(); h_real = new MutableDouble(); corr = new MutableDouble(); MutableDouble w_strong = new MutableDouble(); MutableDouble w_weak = new MutableDouble(); double correct, asymmetry, response, width, contrast; boolean weak_is_r; boolean correct_start, correct_end; Convol convol = new Convol(); fill_gaps(width_l, grad_l, null, cont); fill_gaps(width_r, grad_r, null, cont); num_points = cont.num; /* Calculate true line width, asymmetry, and position correction. */ if (correct_pos) { /* Do not correct the position of a junction point if its width is found by interpolation, i.e., if the position could be corrected differently for each junction point, thereby destroying the junction. */ correct_start = ((cont.getContourClass() == LinesUtil.contour_class.cont_no_junc || cont.getContourClass() == LinesUtil.contour_class.cont_end_junc || cont.getContourClass() == LinesUtil.contour_class.cont_closed) && (width_r[0] > 0 && width_l[0] > 0)); correct_end = ((cont.getContourClass() == LinesUtil.contour_class.cont_no_junc || cont.getContourClass() == LinesUtil.contour_class.cont_start_junc || cont.getContourClass() == LinesUtil.contour_class.cont_closed) && (width_r[(num_points - 1)] > 0 && width_l[(num_points - 1)] > 0)); /* Calculate the true width and assymetry, and its corresponding correction for each line point. */ for (i = 0; i < num_points; i++) { if (width_r[i] > 0 && width_l[i] > 0) { w_est = (width_r[i] + width_l[i]) * LINE_WIDTH_COMPENSATION; if (grad_r[i] <= grad_l[i]) { r_est = grad_r[i] / grad_l[i]; weak_is_r = true; } else { r_est = grad_l[i] / grad_r[i]; weak_is_r = false; } Correct.line_corrections(sigma, w_est, r_est, w_real, h_real, corr, w_strong, w_weak); w_real.setValue(w_real.getValue() / LINE_WIDTH_COMPENSATION); corr.setValue(corr.getValue() / LINE_WIDTH_COMPENSATION); width_r[i] = w_real.getValue(); width_l[i] = w_real.getValue(); if (weak_is_r) { asymm[i] = h_real.getValue(); correction[i] = -corr.getValue(); } else { asymm[i] = -h_real.getValue(); correction[i] = corr.getValue(); } } } fill_gaps(width_l, correction, asymm, cont); for (i = 0; i < num_points; i++) width_r[i] = width_l[i]; /* Adapt the correction for junction points if necessary. */ if (!correct_start) correction[0] = 0; if (!correct_end) correction[(num_points - 1)] = 0; for (i = 0; i < num_points; i++) { px = pos_x[i]; py = pos_y[i]; nx = Math.cos(cont.angle[i]); ny = Math.sin(cont.angle[i]); px = px + correction[i] * nx; py = py + correction[i] * ny; pos_x[i] = px; pos_y[i] = py; } } /* Update the position of a line and add the extracted width. */ cont.width_l = new float[num_points]; cont.width_r = new float[num_points]; for (i = 0; i < num_points; i++) { cont.width_l[i] = (float) width_l[i]; cont.width_r[i] = (float) width_r[i]; cont.row[i] = (float) pos_x[i]; cont.col[i] = (float) pos_y[i]; } /* Now calculate the true contrast. */ if (correct_pos) { cont.asymmetry = new float[num_points]; cont.intensity = new float[num_points]; for (i = 0; i < num_points; i++) { response = cont.response[i]; asymmetry = Math.abs(asymm[i]); correct = Math.abs(correction[i]); width = cont.width_l[i]; if (width < MIN_LINE_WIDTH) contrast = 0; else contrast = (response / Math.abs(convol.phi2(correct + width, sigma) + (asymmetry - 1) * convol.phi2(correct - width, sigma))); if (contrast > MAX_CONTRAST) contrast = 0; contr[i] = contrast; } fill_gaps(contr, null, null, cont); for (i = 0; i < num_points; i++) { cont.asymmetry[i] = (float) asymm[i]; if (mode == LinesUtil.MODE_LIGHT) cont.intensity[i] = (float) contr[i]; else cont.intensity[i] = (float) -contr[i]; } } }
From source file:com.quinsoft.zeidon.vml.VmlOperation.java
protected int SysConvertStringToDecimal(String stringValue, MutableDouble returnDouble) { returnDouble.setValue(Double.parseDouble(stringValue)); return 0;//from w w w. j a v a 2s. c o m }
From source file:com.quinsoft.zeidon.vml.VmlOperation.java
protected int GetDecimalFromAttribute(MutableDouble returnDecimalValue, View view, String entityName, String attributeName) {//from ww w.ja va 2 s . c o m int nRC; Double d; EntityCursor cursor = view.cursor(entityName); if (cursor.isNull()) { nRC = zCALL_ERROR; d = 0.0; } else { d = cursor.getAttribute(attributeName).getDouble(); if (d == null) { nRC = -1; d = 0.0; } else { nRC = 0; } } returnDecimalValue.setValue(d); return nRC; }
From source file:com.quinsoft.swauopencuas.ZGLOBAL2_Operation.java
public int ComputeHighExamScoreACT(MutableDouble ReturnedScore, View mProspct) { zVIEW mProspct2 = new zVIEW(); //:DECIMAL dTotalComposite double dTotalComposite = 0.0; int RESULT = 0; //:// Compute the highest total score for SAT exams for any object that has the ExamHistory subobject. //:CreateViewFromView( mProspct2, mProspct ) CreateViewFromView(mProspct2, mProspct); //:dTotalComposite = 0 dTotalComposite = 0;//from w w w . j a v a2 s. c o m //:FOR EACH mProspct2.ExamHistory RESULT = SetCursorFirstEntity(mProspct2, "ExamHistory", ""); while (RESULT > zCURSOR_UNCHANGED) { //:IF mProspct2.ExamHistory.ExamType = "ACT" if (CompareAttributeToString(mProspct2, "ExamHistory", "ExamType", "ACT") == 0) { //:IF mProspct2.ExamHistory.TotalComposite > dTotalComposite if (CompareAttributeToDecimal(mProspct2, "ExamHistory", "TotalComposite", dTotalComposite) > 0) { //:dTotalComposite = mProspct2.ExamHistory.TotalComposite { MutableDouble md_dTotalComposite = new MutableDouble(dTotalComposite); GetDecimalFromAttribute(md_dTotalComposite, mProspct2, "ExamHistory", "TotalComposite"); dTotalComposite = md_dTotalComposite.doubleValue(); } } //:END } RESULT = SetCursorNextEntity(mProspct2, "ExamHistory", ""); //:END } //:END //:ReturnedScore = dTotalComposite ReturnedScore.setValue(dTotalComposite); //:DropView( mProspct2 ) DropView(mProspct2); return (0); // END }