Skip to content

Commit

Permalink
- Updated standard library.
Browse files Browse the repository at this point in the history
- Standard library is now auto-loaded

- Fixed a bug in statcmp that would be triggered by very small radiuses (<= half of the pixdim).
  • Loading branch information
vincenzoml committed Oct 24, 2019
1 parent 50e6d18 commit 49b7222
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Interpreter.fs
Expand Up @@ -148,16 +148,16 @@ type Interpreter(model : IModel, checker : ModelChecker) =
else raise <| ImportNotFoundException(fname,libdir)
else raise <| ImportNotFoundException(fname,libdir)
ErrorMsg.Logger.DebugOnly <| sprintf "Import \"%s\"" fname
ErrorMsg.Logger.Debug <| sprintf "Importing file \"%s\"" path
if not (parsedImports.Contains(path)) then
ErrorMsg.Logger.Debug <| sprintf "Importing file \"%s\"" path
let parsed = parseImport path
evaluate env (parsedImports.Add path) (parsed@rest) jobs
else evaluate env parsedImports rest jobs
| [] -> List.rev jobs
job { ErrorMsg.Logger.Debug "Parsing input..."
let p = parseProgram filename s
ErrorMsg.Logger.Debug "Preparing computation..."
let jobs = evaluate (emptyEnv()) (Set.empty) p []
let jobs = evaluate (emptyEnv()) (Set.empty) (Import "stdlib.imgql"::p) []
ErrorMsg.Logger.Debug "Starting computation..."
do! checker.Check
do! Util.Concurrent.conIgnore (Array.ofList jobs)
Expand Down
8 changes: 7 additions & 1 deletion src/SITKUtil.fs
Expand Up @@ -20,6 +20,8 @@ open itk.simple
open System.IO
open System
open VoxLogicA
open VoxLogicA.ErrorMsg
open VoxLogicA.ErrorMsg

exception UnsupportedImageTypeException of s : string
with override this.Message = sprintf "Unsupported image type: %s" this.s
Expand Down Expand Up @@ -494,7 +496,11 @@ let crosscorrelation (rad : float) (a : Image) (b : Image) (fb : Image) (m1 : fl
job {
let dims = a.GetSpacing()
let ballRadius = Array.create dims.Count 0
for i = 0 to dims.Count - 1 do ballRadius.[i] <- int (round (rad / (float dims.[i]))) // Compute anisotropic voxel radiuses from real-world radius
for i = 0 to dims.Count - 1 do
ballRadius.[i] <- int (round (rad / (float dims.[i]))) // Compute anisotropic voxel radiuses from real-world radius
if ballRadius.[i] = 0 then
Logger.Debug (sprintf "Computing cross correlation with radius %A but the pixdim number %A (starting from 0) is %A; approximated to 1 voxel in this dimension" rad i dims.[i])
ballRadius.[i] <- 1
use vradius = new VectorUInt32(Array.map uint32 ballRadius)
use outerImage = SimpleITK.ConstantPad(a,vradius,vradius,infinity) // To be returned
let size = Array.ofSeq (Seq.map int (a.GetSize()))
Expand Down
2 changes: 1 addition & 1 deletion src/VERSION.txt
@@ -1 +1 @@
0.5.4
0.5.5
17 changes: 12 additions & 5 deletions src/stdlib.imgql
Expand Up @@ -33,13 +33,10 @@ let B+(a) = (near(a)) \ a
// Set theoretic subtraction
let \(a,b) = and(a,not(b))

// Distance operators
let distgeq(x,y) = x .<= dt(y)
let distleq(x,y) = x .>= dt(y)

// Reachability derived operators
let mayReach(a,b) = N((b ~> N a) | a)
let touch(a,b) = a ~> N b
let grow(a,b) = (a | touch(b,a))
let T(a,b) = touch(a,b)

let surrounded(a,b) = a \ mayReach(not(a | b),not(b))
Expand All @@ -57,7 +54,17 @@ let =. (i,n) = n .= i
let .* (a,b) = b *. a
let .+ (a,b) = b +. a


// Distance operators
let pdt(x) = mask(dt(x),dt(x) >. 0)
let distgeq(x,y) = x .<= pdt(y)
let distleq(x,y) = x .>= pdt(y)

// More advanced functions
let smoothen(a,x) = distleq(x,distgeq(x,!a))

let ~ (a,b,rad,bins) = crossCorrelation(rad,a,b,tt,min(b),max(b),bins)
let ~ (a,b,rad,bins) = crossCorrelation(rad,a,b,tt,min(b),max(b),bins)

let booleanToNumber(k,x) = mask(constant(k),x)

let norm(k,x) = (k .* x) /. max(x)

0 comments on commit 49b7222

Please sign in to comment.