X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemia%2FEEOver.fs;h=2bd13b2f6faeb744e0f0d62bfb83bf985965df11;hb=81d1b86719a1ebaf649c1de4c1364603155a53e1;hp=ef21051ddbfbb5159e9d1d9c6f2af9447610a9bd;hpb=70c9b65e9034c14b5c63345cda3d5d579bbdc57c;p=master-thesis.git diff --git a/Parasitemia/Parasitemia/EEOver.fs b/Parasitemia/Parasitemia/EEOver.fs index ef21051..2bd13b2 100644 --- a/Parasitemia/Parasitemia/EEOver.fs +++ b/Parasitemia/Parasitemia/EEOver.fs @@ -69,7 +69,6 @@ let private istanpt (x: float) (y: float) (a1: float) (b1: float) (aa: float) (b then TANGENT_POINT else INTERSECTION_POINT - let private twointpts (x: float[]) (y: float[]) (a1: float) (b1: float) (phi_1: float) (a2: float) (b2: float) (h2_tr: float) (k2_tr: float) (phi_2: float) (aa: float) (bb: float) (cc: float) (dd: float) (ee: float) (ff: float) = if abs x.[0] > a1 then x.[0] <- if x.[0] < 0.0 then -a1 else a1 @@ -181,7 +180,6 @@ let private twointpts (x: float[]) (y: float[]) (a1: float) (b1: float) (phi_1: area1 + area2 - let private threeintpts (xint: float[]) (yint: float[]) (a1: float) (b1: float) (phi_1: float) (a2: float) (b2: float) (h2_tr: float) (k2_tr: float) (phi_2: float) (aa: float) (bb: float) (cc: float) (dd: float) (ee: float) (ff: float) : float = let mutable tanpts = 0 let mutable tanindex = 0 @@ -218,7 +216,7 @@ let private fourintpts (xint: float[]) (yint: float[]) (a1: float) (b1: float) ( let theta = Array.zeroCreate 4 - for i in 0..3 do + for i in 0 .. 3 do if abs xint.[i] > a1 then xint.[i] <- if xint.[i] < 0.0 then -a1 else a1 @@ -229,7 +227,7 @@ let private fourintpts (xint: float[]) (yint: float[]) (a1: float) (b1: float) ( printf "k=%d: Theta = %f, xint=%f, yint=%f\n" k theta.[k] xint.[k] yint.[k] #endif - for j in 1..3 do + for j in 1 .. 3 do let tmp0 = theta.[j] let tmp1 = xint.[j] let tmp2 = yint.[j] @@ -334,7 +332,6 @@ let private fourintpts (xint: float[]) (yint: float[]) (a1: float) (b1: float) ( area1 + area2 + area3 + area4 + area5 - let private quadroots (p: float[]) (r: float[,]) = let mutable b = -p.[1] / (2.0 * p.[0]) let c = p.[2] / p.[0] @@ -429,7 +426,6 @@ let private cubicroots (p: float[]) (r: float[,]) = for k in 1..3 do r.[2, k] <- 0.0 - let private biquadroots (p: float[]) (r: float[,]) = if p.[0] <> 1.0 then @@ -437,33 +433,33 @@ let private biquadroots (p: float[]) (r: float[,]) = p.[k] <- p.[k] / p.[0] p.[0] <- 1.0 let e = 0.25 * p.[1] - let b = ref (2.0 * e) - let c = ref (!b ** 2.0) - let mutable d = 0.75 * !c - b := p.[3] + !b *(!c - p.[2]) + let mutable b = 2.0 * e + let mutable c = b ** 2.0 + let mutable d = 0.75 * c + b <- p.[3] + b *(c - p.[2]) let mutable a = p.[2] - d - c := p.[4] + e * (e * a - p.[3]) + c <- p.[4] + e * (e * a - p.[3]) a <- a - d - let quadExecuted = ref false - let quad () = - if not !quadExecuted + let mutable quadExecuted = false + let inline quad () = + if not quadExecuted then - p.[2] <- !c / !b + p.[2] <- c / b quadroots p r for k in 1..2 do for j in 1..2 do r.[j, k+2] <- r.[j, k] p.[1] <- -p.[1] - p.[2] <- !b + p.[2] <- b quadroots p r for k in 1..4 do r.[1,k] <- r.[1,k] - e - quadExecuted := true + quadExecuted <- true p.[1] <- 0.5 * a - p.[2] <- (p.[1] * p.[1] - !c) * 0.25 - p.[3] <- !b * !b / -64.0 + p.[2] <- (p.[1] * p.[1] - c) * 0.25 + p.[3] <- b * b / -64.0 if p.[3] < 0.0 then cubicroots p r @@ -473,50 +469,50 @@ let private biquadroots (p: float[]) (r: float[,]) = then d <- r.[1, k] * 4.0 a <- a + d - if a >= 0.0 && !b >= 0.0 + if a >= 0.0 && b >= 0.0 then p.[1] <- sqrt d - elif a <= 0.0 && !b <= 0.0 + elif a <= 0.0 && b <= 0.0 then p.[1] <- sqrt d else p.[1] <- -(sqrt d) - b := 0.5 * (a + !b / p.[1]) + b <- 0.5 * (a + b / p.[1]) quad () k <- 4 k <- k + 1 - if not !quadExecuted && p.[2] < 0.0 + if not quadExecuted && p.[2] < 0.0 then - b := sqrt !c - d <- !b + !b - a + b <- sqrt c + d <- b + b - a p.[1] <- 0.0 if d > 0.0 then p.[1] <- sqrt d - elif not !quadExecuted + elif not quadExecuted then if p.[1] > 0.0 then - b := (sqrt p.[2]) * 2.0 + p.[1] + b <- (sqrt p.[2]) * 2.0 + p.[1] else - b := -(sqrt p.[2]) * 2.0 + p.[1] + b <- -(sqrt p.[2]) * 2.0 + p.[1] - if !b <> 0.0 + if b <> 0.0 then p.[1] <- 0.0 else for k in 1..4 do r.[1, k] <- -e r.[2, k] <- 0.0 - quadExecuted := true + quadExecuted <- true quad () // Return a tuple (area, x intersections, y intersections) -let EEOverlapArea (e1: Types.Ellipse) (e2: Types.Ellipse) : (float * float[] * float[]) option = - let h1, k1, a1, b1, phi_1 = e1.Cx, e1.Cy, e1.A, e1.B, e1.Alpha - let h2, k2, a2, b2, phi_2 = e2.Cx, e2.Cy, e2.A, e2.B, e2.Alpha +let EEOverlapArea (e1: Types.Ellipse) (e2: Types.Ellipse) : (float32 * float32[] * float32[]) option = + let h1, k1, a1, b1, phi_1 = float e1.Cx, float e1.Cy, float e1.A, float e1.B, float e1.Alpha + let h2, k2, a2, b2, phi_2 = float e2.Cx, float e2.Cy, float e2.A, float e2.B, float e2.Alpha if a1 <= EPS || b1 <= EPS || a2 <= EPS || b2 <= EPS then @@ -610,15 +606,16 @@ let EEOverlapArea (e1: Types.Ellipse) (e2: Types.Ellipse) : (float * float[] * f printf "nroots = %d\n" nroots #endif - let ychk = [| - for i in 1 .. nroots do - if abs r.[2, i] < EPS - then - yield r.[1, i] * b1 + let ychk = Array.init nroots (fun _ -> Double.MaxValue) + let mutable nychk = 0 + for i in 1 .. nroots do + if abs r.[2, i] < EPS + then + ychk.[nychk] <- r.[1, i] * b1 + nychk <- nychk + 1 #if DEBUG_LOG - printf "ROOT is Real, i=%d --> %f (B1=%f)\n" i r.[1, i] b1 + printf "ROOT is Real, i=%d --> %f (B1=%f)\n" i r.[1, i] b1 #endif - |] Array.sortInPlace ychk #if DEBUG_LOG @@ -627,7 +624,6 @@ let EEOverlapArea (e1: Types.Ellipse) (e2: Types.Ellipse) : (float * float[] * f printf "\t j=%d, ychk=%f\n" j ychk.[j] #endif - let nychk = Array.length ychk let mutable nintpts = 0 let xint = Array.zeroCreate 4 @@ -718,11 +714,11 @@ let EEOverlapArea (e1: Types.Ellipse) (e2: Types.Ellipse) : (float * float[] * f | 4 -> fourintpts xint yint a1 b1 phi_1 a2 b2 h2_tr k2_tr phi_2 aa bb cc dd ee ff | _ -> -1.0 if nintpts = 0 - then Some (area, [||], [||]) + then Some (float32 area, [||], [||]) else - let xTransform = Array.zeroCreate nintpts - let yTransform = Array.zeroCreate nintpts + let xTransform : float32[] = Array.zeroCreate nintpts + let yTransform : float32[] = Array.zeroCreate nintpts for i in 0 .. (nintpts - 1) do - xTransform.[i] <- cos phi_1 * xint.[i] - sin phi_1 * yint.[i] + h1 - yTransform.[i] <- sin phi_1 * xint.[i] + cos phi_1 * yint.[i] + k1 - Some (area, xTransform, yTransform) \ No newline at end of file + xTransform.[i] <- float32 <| cos phi_1 * xint.[i] - sin phi_1 * yint.[i] + h1 + yTransform.[i] <- float32 <| sin phi_1 * xint.[i] + cos phi_1 * yint.[i] + k1 + Some (float32 area, xTransform, yTransform) \ No newline at end of file