Skip to content

Commit

Permalink
fiber tracto tools update
Browse files Browse the repository at this point in the history
  • Loading branch information
mfroeling committed Nov 14, 2024
1 parent 8687d30 commit 3e030af
Show file tree
Hide file tree
Showing 9 changed files with 4,141 additions and 1,216 deletions.
2 changes: 1 addition & 1 deletion QMRITools/Kernel/CardiacTools.wl
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,7 @@ MakeECVBloodMask[pre_, post_, OptionsPattern[]] := Block[{
(*MakeECVBloodMask*)


ECVCalc[mappre_, mappost_, hema_?RealQ] := Block[{z, x, y, mask},
ECVCalc[mappre_, mappost_, hema_?NumberQ] := Block[{z, x, y, mask},
mask = MakeECVBloodMask[mappre, mappost, OutputCheckImage -> False];
ECVCalc[mappre, mappost, mask, hema]
]
Expand Down
2 changes: 1 addition & 1 deletion QMRITools/Kernel/ElastixTools.wl
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ SplitRegInput[input_] := Which[
(*RegisterData*)


Options[RegisterData]={
Options[RegisterData] = {
Iterations->250,
Resolutions->1,
HistogramBins->32,
Expand Down
15 changes: 8 additions & 7 deletions QMRITools/Kernel/GeneralTools.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1136,9 +1136,7 @@ MakeIntFunction[dat_, int_?IntegerQ, opts:OptionsPattern[]] := MakeIntFunction[d

MakeIntFunction[dat_, vox_, int_?IntegerQ, opts:OptionsPattern[]] := Block[{dim, def, range},
dim = Dimensions[dat][[;;3]];

range = Thread[{vox, vox dim}] - If[OptionValue[CenterVoxel], 0.5, 0] vox - If[OptionValue[CenterRange], 0.5, 0] dim;

def = 0. dat[[1,1,1]];
def =If[ListQ[def], Flatten@def, def];

Expand All @@ -1149,13 +1147,13 @@ MakeIntFunction[dat_, vox_, int_?IntegerQ, opts:OptionsPattern[]] := Block[{dim,
InterpolatingFunction[
range,
{5,If[ArrayDepth[dat]===3, 6, 2],0, dim,
{int,int,int}+1,0,0,0,0,ex&,{},{},False},
Range[range[[#,1]],range[[#,2]],vox[[#]]]&/@{1,2,3},
{int, int, int} + 1, 0, 0, 0, 0, ex&, {}, {}, False},
Range[range[[#, 1]], range[[#, 2]], vox[[#]]]& /@ {1, 2, 3},
If[ArrayDepth[dat] === 3 && $VersionNumber >= 13.3,
{PackedArrayForm, Range[0,Length[fdat]], fdat},
ToPackedArray@N@dat
],
{Automatic,Automatic,Automatic}]
{Automatic, Automatic, Automatic}]
]
]

Expand Down Expand Up @@ -1936,15 +1934,18 @@ MakeFunctionGraph[func_, opts:OptionsPattern[]] := Block[{
Graph[edges,
VertexLabels -> vertLab, VertexShapeFunction -> vertFunc, VertexStyle -> vertCol,
VertexLabelStyle -> Directive[Black, Bold, Automatic], EdgeStyle -> Directive[Black, Thick],
VertexSize -> Automatic]
VertexSize -> Automatic, ImageSize -> {Automatic, 600}]
]


(* ::Subsubsection::Closed:: *)
(*GetDependencies*)


GetDependencies[sym_String] := If[SymbolQ[ToExpression[sym]], SelectFunctions[(Union@Level[(Hold @@ DownValues[sym])[[All, 2]], {-1}, Hold, Heads -> True])], Nothing]
GetDependencies[sym_String] := If[
Head[ToExpression[sym]] === Symbol,
(*SymbolQ[ToExpression[sym]],*)
SelectFunctions[(Union@Level[(Hold @@ DownValues[sym])[[All, 2]], {-1}, Hold, Heads -> True])], Nothing]


SelectFunctions[func_] := Select[StringSplit[ToString /@ Pick[List @@ Defer /@ func, List@ReleaseHold[FunctionQC /@ func], 1],"[" | "]"][[All, 2]], Context[#] =!= "System`" &]
Expand Down
7 changes: 4 additions & 3 deletions QMRITools/Kernel/MuscleBidsTools.wl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ VersionCheck::usage =
(* ::Subsection::Closed:: *)
(*Error Messages*)


CheckDataDiscription::key = "Datasets have duplicate names which is not allowed.";

CheckDataDiscription::type = "Unknown Muscle-BIDS type: `1`, using folder \"miss\".";
Expand Down Expand Up @@ -2011,15 +2012,15 @@ MuscleBidsTractographyI[foli_, folo_, datType_, allType_, verCheck_, met_]:=Bloc
tracto, tractType, tractSeg, tractStopLab, tractStopVal, tractStopLabNam, trkFile,
tractTypeLab, fol, parts, checkFile, outfile, seed, lenS, segBone, tractSegLab,
datfile, stopfile, tens, vox, dim, stop, ang, step, tracts, seeds, len, seg,
segfile, muscles, mlabs, mus, bones, con, leng, dens, flip, per
segfile, muscles, mlabs, mus, bones, con, leng, dens, flip, per, duplicate, key
},

debugBids["Starting MuscleBidsTractographyI"];
debugBids[foli, folo];
debugBids[datType];

(*!!options!!*)
{len, ang, step, seed} = {{15, 500}, 25, 1.5, Scaled[.35]};
{len, ang, step, seed} = {{15, 500}, 25, 1.5, Scaled[.30]};
{lenS, segBone} = {{15, 500}, 100};

(*figure out if duplicate handeling is needed.*)
Expand Down Expand Up @@ -2111,7 +2112,7 @@ MuscleBidsTractographyI[foli_, folo_, datType_, allType_, verCheck_, met_]:=Bloc
{tracts, seeds} = FiberTractography[tens, vox, stop,
InterpolationOrder -> 0, StepSize -> step, Method -> "Euler", MaxSeedPoints -> seed,
FiberLengthRange -> len, FiberAngle -> ang, TracMonitor -> False,
TensorFilps -> flip, TensorPermutations -> per
TensorFilps -> flip, TensorPermutations -> per, Parallelization -> True
];

(* Export the tractography results *)
Expand Down
33 changes: 27 additions & 6 deletions QMRITools/Kernel/PlottingTools.wl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ PlotSegmentations[seg, bone, vox] same but also generates an extra contour with
Link3DGraphic::usage =
"Link3DGraphic[3Dgraphics] creates a 3D graphic with a linked view options between all 3D graphics that have been linked."

ShowLink::usage =
"ShowLink[] shows the linked view options between all 3D graphics that have been linked."

GenerateRotationFrames::usage =
"GenerateRotationFrames[3Dgraphics, nFrames] generates nFrames of the 3D graphics rotating around the z-axis."

Expand Down Expand Up @@ -104,6 +107,9 @@ ContourColor::usage =
ContourOpacity::usage =
"ContourOpacity is an option for PlotContour and PlotSegmentations. It specifies the opacity of the contour."

ContourSpecularity::usage =
"ContourSpecularity is an option for PlotContour. It specifies the specularity of the contour."

ContourColorRange::usage =
"ContourColorRange is an option for PlotContour. If the ContourColor is an array this values gives the plot range."

Expand Down Expand Up @@ -1813,6 +1819,7 @@ GetSlicePositions[data_,vox_,OptionsPattern[]]:=Block[{
Options[PlotContour] = {
ContourColor -> Gray,
ContourOpacity -> 0.5,
ContourSpecularity -> 50,
ContourColorRange -> Automatic,
ColorFunction -> "SunsetColors",
ContourSmoothRadius -> None,
Expand All @@ -1839,6 +1846,7 @@ PlotContour[dati_, vox_, opts:OptionsPattern[]] := Block[{
scale = OptionValue[ContourScaling];
color = OptionValue[ContourColor];
opac = OptionValue[ContourOpacity];
spec = OptionValue[ContourSpecularity];

If[N[Max[dati]] === 0.,
Graphics3D[],
Expand All @@ -1853,7 +1861,7 @@ PlotContour[dati_, vox_, opts:OptionsPattern[]] := Block[{
data = SparseArray[data];

col = If[ColorQ[color], color, If[color==="Random", RandomColor[], GrayLevel[1.]]];
style = Directive[{Opacity[opac], col, Specularity[Lighter@Lighter@col, 5]}];
style = Directive[{Opacity[opac], col, Specularity[Lighter@col, spec]}];

colfunc = If[!ArrayQ[color],
Automatic,
Expand All @@ -1864,7 +1872,7 @@ PlotContour[dati_, vox_, opts:OptionsPattern[]] := Block[{
ran];
coldat = Clip[Rescale[color, ran], {0, 1}];
cdim = Dimensions[coldat];
style = Directive[{Opacity[opac],Specularity[Red,0]}];
style = Directive[{Opacity[opac], Specularity[Red, 0]}];
Function[{z, y, x},
ColorData[cfunc][coldat[[
Clip[Round[x/vox[[1]] + 0.5], {1, cdim[[1]]}],
Expand Down Expand Up @@ -1904,7 +1912,7 @@ PlotContour[dati_, vox_, opts:OptionsPattern[]] := Block[{

viewPoint = {1.3, -2.4, 2.0};
viewVertical = {0., 0., 1.};
viewAngle = 35. Degree;
viewAngle = 20. Degree;
viewCenter = {0.5, 0.5, 0.5};

Link3DGraphic[graphics_]:=Show[graphics, SphericalRegion -> True,
Expand All @@ -1915,6 +1923,16 @@ Link3DGraphic[graphics_]:=Show[graphics, SphericalRegion -> True,
]


ShowLink[]:=Dynamic[Grid[{
{"ViewPoint: ", Round[viewPoint,.01]},
{"ViewVertical: ", Round[viewVertical,.01]},
{"ViewAngle: ", Round[viewAngle/Degree,.01]},
{"ViewCenter: ", Round[viewCenter,.01]}}, Alignment -> Left]]

(* ::Subsection::Closed:: *)
(*GenerateRotationFrames*)


Options[GenerateRotationFrames] = {
ImageSize -> 500
};
Expand Down Expand Up @@ -1944,6 +1962,7 @@ Table[Rasterize[Show[gr,(*Graphics3D[InfiniteLine[{0,0,0}, {0,0,1}]]*) ViewPoint
Options[PlotSegmentations] = {
ImageSize -> 400,
ContourOpacity->0.6,
ContourSpecularity -> 5,
ColorFunction -> "DarkRainbow",
ContourSmoothRadius -> 2,
RandomizeColor->True,
Expand All @@ -1955,9 +1974,10 @@ SyntaxInformation[PlotSegmentations] = {"ArgumentsPattern" -> {_, _, _., Options
PlotSegmentations[seg_, vox_, opts : OptionsPattern[]] := PlotSegmentations[seg, None, vox, opts]

PlotSegmentations[seg_, bone_, vox_, opts : OptionsPattern[]] := Block[{
smooth, size, plotb, segM, nSeg, rSeg, cols, plotm, ranCol, op, res
smooth, size, plotb, segM, nSeg, rSeg, cols, plotm, ranCol, op, res, spec
},
{smooth, cols, size, ranCol, op, res} = OptionValue[{ContourSmoothRadius, ColorFunction, ImageSize, RandomizeColor, ContourOpacity, ContourResolution}];
{smooth, cols, size, ranCol, op, res, spec} = OptionValue[{ContourSmoothRadius, ColorFunction, ImageSize,
RandomizeColor, ContourOpacity, ContourResolution, ContourSpecularity}];

plotb = If[bone === None, Graphics3D[],
PlotContour[If[ArrayDepth[bone]===3, Unitize@bone, Unitize@Total@Transpose@bone], vox,
Expand All @@ -1976,7 +1996,8 @@ PlotSegmentations[seg_, bone_, vox_, opts : OptionsPattern[]] := Block[{
cols = Reverse[ColorData[OptionValue[ColorFunction]] /@ Rescale[rSeg]];
If[ranCol, SeedRandom[1234]; cols = cols[[RandomSample[rSeg]]]];
];
Show[Table[PlotContour[segM[[All, i]], vox, ContourColor -> cols[[i]], ContourOpacity -> op, ContourSmoothRadius -> smooth, ContourResolution->res], {i, 1, nSeg}]]
Show[Table[PlotContour[segM[[All, i]], vox, ContourColor -> cols[[i]], ContourOpacity -> op,
ContourSpecularity -> spec, ContourSmoothRadius -> smooth, ContourResolution->res], {i, 1, nSeg}]]
];

Show[plotm, plotb, ViewPoint -> Front, ImageSize -> size, Boxed -> False, Axes -> False, SphericalRegion -> False]
Expand Down
4 changes: 3 additions & 1 deletion QMRITools/Kernel/SegmentationTools.wl
Original file line number Diff line number Diff line change
Expand Up @@ -2328,7 +2328,9 @@ MakeChannelImage[data_, vox_]:=Block[{dat, imdat, rat},
(*ImportITKLabels*)


SyntaxInformation[ImportITKLabels] = {"ArgumentsPattern"->{_}};
SyntaxInformation[ImportITKLabels] = {"ArgumentsPattern"->{_.}};

ImportITKLabels[] := ImportITKLabels[GetAssetLocation["MusclesLegLabels"]];

ImportITKLabels[file_] := Block[{lines, muscleNames, muscleLabels},
(*import*)
Expand Down
Loading

0 comments on commit 3e030af

Please sign in to comment.