Changeset 1582
- Timestamp:
- 06/03/07 13:29:14 (18 months ago)
- Location:
- trunk/components/rendering
- Files:
-
- 2 removed
- 5 modified
-
src/ome/util/math/Approximation.java (deleted)
-
src/ome/util/math/geom2D/PlanePoint.java (modified) (2 diffs)
-
src/ome/util/math/geom2D/Segment.java (modified) (6 diffs)
-
src/ome/util/math/package.html (deleted)
-
src/omeis/providers/re/metadata/StatsFactory.java (modified) (1 diff)
-
src/omeis/providers/re/quantum/Quantization_8_16_bit.java (modified) (2 diffs)
-
test/ome/util/math/geom2D/TestSegment.java (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/components/rendering/src/ome/util/math/geom2D/PlanePoint.java
r1167 r1582 141 141 return new PlanePoint(p.x1 - x1, p.x2 - x2); 142 142 } 143 144 /** 145 * Calculates the vector associated to this point and the specified 146 * argument. This is the map that makes the set A = <b>R</b><sup>2</sup> 147 * an affine space over the vector space V = <b>R</b><sup>2</sup> and is 148 * defined by: 149 * <p> 150 * <nobr><i> f: AxA ---> V <br> 151 * f(a, b) = b - a = (b<sub>1</sub> - a<sub>1</sub>, b<sub>2</sub> - a<sub>2</sub>) 152 * </i></nobr> 153 * </p> 154 * This method returns <nobr><i>f(t, p)</i></nobr>, where <i>t</i> is 155 * this point and <i>p</i> is the specified argument. 156 * 157 * @param p 158 * The other point. Mustn't be a <code>null</code> reference. 159 * @return The vector associated to this point and <i>p</i>. 160 */ 161 public PlanePoint vec(double x1, double x2) { 162 return new PlanePoint(x1 - this.x1, x2 - this.x2); 163 } 143 164 144 165 /** … … 234 255 return isEqual; 235 256 } 257 258 /** 259 * Check to see if the point values are equal. 260 * 261 * @param x1 The comparison point's first element. 262 * @param x2 The comparison point's second element. 263 * @return <code>true</code> if the points are equal, <code>false</code> 264 * otherwise. 265 */ 266 public boolean equals(double x1, double x2) { 267 return this.x1 == x1 && this.x2 == x2; 268 } 236 269 237 270 /** -
trunk/components/rendering/src/ome/util/math/geom2D/Segment.java
r1167 r1582 28 28 public class Segment { 29 29 30 /** The origin point of the segment. */ 31 public final PlanePoint origin; 30 /** The origin of the segment's first element. */ 31 public final double originX1; 32 33 /** The origin of the segment's first element. */ 34 public final double originX2; 32 35 33 /** The end point of the segment. */ 34 public final PlanePoint direction; 36 /** The end point of the segment's first element. */ 37 public final double directionX1; 38 39 /** The end point of the segment's second element. */ 40 public final double directionX2; 35 41 36 42 /** 37 43 * Creates a new instance. 38 44 * 39 * @param o 40 * The origin point of the segment. 41 * @param e 42 * The end point of the segment. 45 * @param originX1 The origin of the segment's first element. 46 * @param originX2 The origin of the segment's first element. 47 * @param o The origin point of the segment. 48 * @param endX1 The end point's first element. 49 * @param endX2 The end point's second element. 43 50 */ 44 public Segment(PlanePoint o, PlanePoint e) { 45 if (o == null) { 46 throw new NullPointerException("No origin."); 47 } 48 if (e == null) { 49 throw new NullPointerException("No end p."); 50 } 51 if (o.equals(e)) { 51 public Segment(double originX1, double originX2, double endX1, double endX2) 52 { 53 if (originX1 == endX1 && originX2 == endX2) 54 { 52 55 throw new IllegalArgumentException("Need two different points."); 53 56 } 54 origin = o; 55 direction = origin.vec(e); 57 this.originX1 = originX1; 58 this.originX2 = originX2; 59 60 /* 61 * Calculate the vector associated to the origin and the destination end 62 * point of this segment. This is the map that makes the set 63 * A = <b>R</b><sup>2</sup> an affine space over the vector space 64 * V = <b>R</b><sup>2</sup> and is defined by: 65 * <p> 66 * <nobr><i> f: AxA ---> V <br> 67 * f(a, b) = b - a = (b<sub>1</sub> - a<sub>1</sub>, b<sub>2</sub> - a<sub>2</sub>) 68 * </i></nobr> 69 * </p> 70 */ 71 directionX1 = endX1 - originX1; 72 directionX2 = endX2 - originX2; 56 73 } 57 74 58 75 /** 59 76 * Returns the point of this line defined by <code>k</code>. More … … 71 88 + "range [0, 1]."); 72 89 } 73 return new PlanePoint(origin .x1 + k * direction.x1, origin.x2 + k74 * direction .x2);90 return new PlanePoint(originX1 + k * directionX1, originX2 + k 91 * directionX2); 75 92 } 76 93 77 94 /** 78 * Tells whether thespecified point lies on this line.95 * Tells whether a specified point lies on this line. 79 96 * 80 97 * @param p … … 83 100 * <code>false</code> otherwise. 84 101 */ 85 public boolean lies(PlanePoint p) { 86 if (p == null) { 87 throw new NullPointerException("No point."); 88 } 102 public boolean lies(double x1, double x2) { 89 103 boolean result = false; 90 104 double k1, k2; 91 if (direction .x1 == 0 && direction.x2 != 0) {92 k2 = ( p.x2 - origin.x2) / direction.x2;105 if (directionX1 == 0 && directionX2 != 0) { 106 k2 = (x2 - originX2) / directionX2; 93 107 if (k2 < 0 || k2 > 1) { 94 108 result = false; 95 109 } else { 96 result = p.x1 == origin.x1;110 result = x1 == originX1; 97 111 } 98 } else if (direction .x1 != 0 && direction.x2 == 0) {99 k1 = ( p.x1 - origin.x1) / direction.x1;112 } else if (directionX1 != 0 && directionX2 == 0) { 113 k1 = (x1 - originX1) / directionX1; 100 114 if (k1 < 0 || k1 > 1) { 101 115 result = false; 102 116 } else { 103 result = p.x2 == origin.x2;117 result = x2 == originX2; 104 118 } 105 } else if (direction .x1 != 0 && direction.x2 != 0) {106 k1 = ( p.x1 - origin.x1) / direction.x1;107 k2 = ( p.x2 - origin.x2) / direction.x2;119 } else if (directionX1 != 0 && directionX2 != 0) { 120 k1 = (x1 - originX1) / directionX1; 121 k2 = (x2 - originX2) / directionX2; 108 122 if (k1 == k2) { 109 123 if (k1 < 0 || k1 > 1) { … … 115 129 } 116 130 return result; 131 } 132 133 /** 134 * Performs an equality test based on a point on this line defined 135 * by <code>k</code> as in {@link getPoint()} and another given point. 136 * @param k The coefficient to select the point. Must be in the range 137 * <code>[0, 1]</code>. 138 * @param x1 The point to test's first element. 139 * @param x2 The point to test's second element. 140 * @return <code>true</code> if the points are geometrically equal, 141 * <code>false</code> otherwise. 142 */ 143 public boolean equals(double k, double x1, double x2) 144 { 145 if (k < 0 || k > 1) { 146 throw new IllegalArgumentException("Coefficient must be in the " 147 + "range [0, 1]."); 148 } 149 double kPointX1 = originX1 + k * directionX1; 150 double kPointX2 = originX2 + k * directionX2; 151 return kPointX1 == x1 && kPointX2 == x2; 152 117 153 } 118 154 … … 128 164 if (o != null && o instanceof Line) { 129 165 Line other = (Line) o; 130 isEqual = origin == other.origin && direction == other.direction; 166 isEqual = 167 other.origin.x1 == originX1 168 && other.origin.x2 == originX2 169 && other.direction.x1 == directionX1 170 && other.direction.x2 == directionX2; 131 171 } 132 172 return isEqual; … … 141 181 @Override 142 182 public int hashCode() { 143 return origin.hashCode(); 183 long bits = Double.doubleToLongBits(originX1); 184 bits ^= Double.doubleToLongBits(originX2) * 31; 185 return (int) bits ^ (int) (bits >> 32); 144 186 } 145 187 -
trunk/components/rendering/src/omeis/providers/re/metadata/StatsFactory.java
r1167 r1582 82 82 int[] totals = new int[NB_BIN]; 83 83 locationStats = new double[NB_BIN]; 84 PlanePoint o, e;85 84 Segment[] segments = new Segment[NB_BIN]; 86 85 for (int i = 0; i < NB_BIN; i++) { 87 o = new PlanePoint(gMin + i * sizeBin, 0); 88 e = new PlanePoint(gMin + (i + 1) * sizeBin, 0); 89 segments[i] = new Segment(o, e); 90 } 91 PlanePoint point; 92 // check segment [o,e[ 86 segments[i] = new Segment( 87 gMin + i * sizeBin, 0, 88 gMin + (i + 1) * sizeBin, 0); 89 } 90 91 // check segment [o,e] 92 double pointX1; 93 double pointX2 = 0; 93 94 for (int x2 = 0; x2 < sizeX2; ++x2) { 94 95 for (int x1 = 0; x1 < sizeX1; ++x1) { 95 point = new PlanePoint(p2D.getPixelValue(x1, x2), 0);96 96 for (int i = 0; i < segments.length; i++) { 97 if (segments[i].lies(point) 98 && !segments[i].getPoint(1).equals(point)) { 97 pointX1 = p2D.getPixelValue(x1, x2); 98 if (!segments[i].equals(1, pointX1, pointX2) 99 && segments[i].lies(pointX1, pointX2)) 100 { 99 101 totals[i]++; 100 102 break; -
trunk/components/rendering/src/omeis/providers/re/quantum/Quantization_8_16_bit.java
r1574 r1582 15 15 16 16 // Application-internal dependencies 17 import ome.api.IPixels;18 17 import ome.model.display.QuantumDef; 19 18 import ome.model.enums.PixelsType; 20 import ome.util.math.Approximation;21 import omeis.providers.re.Renderer;22 19 23 20 /** … … 197 194 } 198 195 v = aNormalized * (valueMapper.transform(v, k) - ysNormalized); 199 v = Approximation.nearestInteger(v);200 v = Approximation.nearestInteger(a1 * v + cdStart);196 v = Math.round(v); 197 v = Math.round(a1 * v + cdStart); 201 198 LUT[x - min] = (byte) v; 202 199 } -
trunk/components/rendering/test/ome/util/math/geom2D/TestSegment.java
r1167 r1582 37 37 public void testSegmentBadArgs() { 38 38 try { 39 new Segment(null, null); 40 fail("Shouldn't allow nulls."); 41 } catch (NullPointerException npe) { 42 // Ok, expected. 43 } 44 try { 45 new Segment(null, new PlanePoint(0, 0)); 46 fail("Shouldn't allow null origin."); 47 } catch (NullPointerException npe) { 48 // Ok, expected. 49 } 50 try { 51 new Segment(new PlanePoint(0, 0), null); 52 fail("Shouldn't allow null head."); 53 } catch (NullPointerException npe) { 54 // Ok, expected. 55 } 56 try { 57 new Segment(new PlanePoint(1, 1), new PlanePoint(1, 1)); 39 new Segment(1, 1, 1, 1); 58 40 fail("Shouldn't allow same points."); 59 41 } catch (IllegalArgumentException iae) { … … 64 46 @Test 65 47 public void testSegment() { 66 PlanePoint o = new PlanePoint(0, 0), p = new PlanePoint(1, 1);67 Segment r = new Segment(o, p);68 assertEquals("Shouldn't change the origin .", o, r.origin);48 Segment r = new Segment(0, 0, 1, 1); 49 assertEquals("Shouldn't change the originX1.", 0.0, r.originX1); 50 assertEquals("Shouldn't change the originX2.", 0.0, r.originX2); 69 51 } 70 52 71 53 @Test 72 54 public void testGetPointXAxis() { 73 PlanePoint o = new PlanePoint(0, 0), p = new PlanePoint(1, 0);74 Segment r = new Segment( o, p);55 PlanePoint p; 56 Segment r = new Segment(0, 0, 1, 0); 75 57 double d; 76 58 for (int i = 0; i < INTERVAL; ++i) { … … 83 65 @Test 84 66 public void testGetPointYAxis() { 85 PlanePoint o = new PlanePoint(0, 0), p = new PlanePoint(0, 1);86 Segment r = new Segment( o, p);67 PlanePoint p; 68 Segment r = new Segment(0, 0, 0, 1); 87 69 double d; 88 70 for (int i = 0; i < INTERVAL; ++i) { … … 95 77 @Test 96 78 public void testGetPointParallelXAxis() { 97 PlanePoint o = new PlanePoint(0, 1), p = new PlanePoint(1, 1);98 Segment r = new Segment( o, p);79 PlanePoint p; 80 Segment r = new Segment(0, 1, 1, 1); 99 81 double d; 100 82 for (int i = 0; i < INTERVAL; ++i) { … … 107 89 @Test 108 90 public void testGetPointParallelYAxis() { 109 PlanePoint o = new PlanePoint(1, 0), p = new PlanePoint(1, 1);110 Segment r = new Segment( o, p);91 PlanePoint p; 92 Segment r = new Segment(1, 0, 1, 1); 111 93 double d; 112 94 for (int i = 0; i < INTERVAL; ++i) { … … 118 100 119 101 @Test 120 public void testLiesNull() {121 PlanePoint o = new PlanePoint(0, 1), p = new PlanePoint(1, 1);122 Segment r = new Segment(o, p);123 try {124 r.lies(null);125 fail("Souldn't accept null.");126 } catch (NullPointerException npe) {127 // Ok, expected.128 }129 }130 131 @Test132 102 public void testLies1() { 133 PlanePoint o = new PlanePoint(0, 1), p = new PlanePoint(1, 1); 134 Segment r = new Segment(o, p); 103 Segment r = new Segment(0, 1, 1, 1); 135 104 double d; 136 105 for (int i = 0; i < INTERVAL; ++i) { 137 106 d = (double) i / INTERVAL; 138 p = new PlanePoint(d, 1); 139 assertTrue("Actually lies on r [i = " + i + "].", r.lies(p)); 140 p = new PlanePoint(d, 0); 141 assertFalse("Doesn't lie on r [i = " + i + "].", r.lies(p)); 107 assertTrue("Actually lies on r [i = " + i + "].", r.lies(d, 1)); 108 assertFalse("Doesn't lie on r [i = " + i + "].", r.lies(d, 0)); 142 109 } 143 110 } … … 145 112 @Test 146 113 public void testLies2() { 147 PlanePoint o = new PlanePoint(1, 0), p = new PlanePoint(1, 1); 148 Segment r = new Segment(o, p); 114 Segment r = new Segment(1, 0, 1, 1); 149 115 double d; 150 116 for (int i = 0; i < INTERVAL; ++i) { 151 117 d = (double) i / INTERVAL; 152 p = new PlanePoint(1, d); 153 assertTrue("Actually lies on r [i = " + i + "].", r.lies(p)); 154 p = new PlanePoint(d, 0); 155 assertFalse("Doesn't lie on r [i = " + i + "].", r.lies(p)); 118 assertTrue("Actually lies on r [i = " + i + "].", r.lies(1, d)); 119 assertFalse("Doesn't lie on r [i = " + i + "].", r.lies(d, 0)); 156 120 } 157 121 } … … 159 123 @Test 160 124 public void testLies3() { 161 PlanePoint o = new PlanePoint(0, 0), p = new PlanePoint(1, 1); 162 Segment r = new Segment(o, p); 125 Segment r = new Segment(0, 0, 1, 1); 163 126 double d; 164 127 for (int i = 1; i < INTERVAL; ++i) { 165 128 d = (double) i / INTERVAL; 166 p = new PlanePoint(d, d); 167 assertTrue("Actually lies on r [i = " + i + "].", r.lies(p)); 168 p = new PlanePoint(d, 0); 169 assertFalse("Doesn't lie on r [i = " + i + "].", r.lies(p)); 129 assertTrue("Actually lies on r [i = " + i + "].", r.lies(d, d)); 130 assertFalse("Doesn't lie on r [i = " + i + "].", r.lies(d, 0)); 170 131 } 171 132 } … … 174 135 public void testEquals() { 175 136 PlanePoint o = new PlanePoint(0, 0), p = new PlanePoint(1, 1); 176 Segment r = new Segment( o, p);137 Segment r = new Segment(0, 0, 1, 1); 177 138 assertFalse("Should never be equal to null.", r.equals(null)); 178 139 assertFalse("Should never be equal to a different type.", r … … 186 147 @Test 187 148 public void testHashCodeDiffCalls() { 188 PlanePoint p = new PlanePoint(500, -30000), q = new PlanePoint(0, 0); 189 Segment r = new Segment(p, q); 149 Segment r = new Segment(500, -30000, 0, 0); 190 150 int h = r.hashCode(); 191 151 for (int i = 0; i < MAX_ITER; ++i) { … … 197 157 @Test 198 158 public void testHashCodeObjectEquality() { 199 PlanePoint p, q;200 159 Segment r, s; 201 160 for (int i = -MAX_ITER / 2; i < MAX_ITER / 2; ++i) { 202 p = new PlanePoint(i, -i); 203 q = new PlanePoint(i + 1, -i + 1); 204 r = new Segment(p, q); 205 s = new Segment(p, q); 161 r = new Segment(i, -i, i + 1, -i + 1); 162 s = new Segment(i, -i, i + 1, -i + 1); 206 163 assertEquals("Should return same value for equal objects [i = " + i 207 164 + "].", r.hashCode(), s.hashCode());
