Skip to content

Commit

Permalink
Added Facade extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
rexcardan committed Oct 31, 2018
1 parent 554fcdb commit 78f063e
Show file tree
Hide file tree
Showing 12 changed files with 851 additions and 4 deletions.
45 changes: 44 additions & 1 deletion ESAPIX.Bootstrapper/ESAPIX.Bootstrapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\ConsoleTests\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down Expand Up @@ -280,4 +280,47 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
if $(ConfigurationName) == 11.0-RELEASE goto :rel110
if $(ConfigurationName) == 13.6-RELEASE goto :rel136
if $(ConfigurationName) == 13.7-RELEASE goto :rel137
if $(ConfigurationName) == 15.0-RELEASE goto :rel150
if $(ConfigurationName) == 15.1-RELEASE goto :rel151
if $(ConfigurationName) == 15.5-RELEASE goto :rel155

goto :exit

:rel110
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)ESAPIX.Nuget\$(ProjectName)\11.0\lib\net45\$(ProjectName).dll"
goto :exit
:rel136
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)ESAPIX.Nuget\$(ProjectName)\13.6\lib\net45\$(ProjectName).dll"
goto :exit

:rel137
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)ESAPIX.Nuget\$(ProjectName)\13.7\lib\net45\$(ProjectName).dll"
goto :exit

:rel150
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)ESAPIX.Nuget\$(ProjectName)\15.0\lib\net45\$(ProjectName).dll"
goto :exit

:rel151
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)ESAPIX.Nuget\$(ProjectName)\15.1\lib\net45\$(ProjectName).dll"
goto :exit

:rel155
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)ESAPIX.Nuget\$(ProjectName)\15.5\lib\net45\$(ProjectName).dll"
goto :exit

:exit</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
35 changes: 35 additions & 0 deletions ESAPIX/Constraints/TargetStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ public static double GetCI_RTOG(Structure s, PlanningItem pi, DoseValue referenc
return prescription_volIsodose / target_vol;
}

/// Calculates the RTOG conformity index as isodose volume irradiated at reference dose (Body contour volume irradiated)
/// divided by the target volume. Does not necessarily mean the volumes are coincident!
/// </summary>
/// <param name="s">the target structure</param>
/// <param name="pi">the planning item containing the dose</param>
/// <param name="referenceDose">the reference isodose (eg. prescription dose)</param>
/// <returns>RTOG conformity index</returns>
public static double GetCI_RTOG(ESAPIX.Facade.API.Structure s, ESAPIX.Facade.API.PlanningItem pi, DoseValue referenceDose)
{
var external = pi.GetStructureSet()?.Structures.FirstOrDefault(st => st.DicomType == DICOMType.EXTERNAL);
if (external == null) { return double.NaN; }
var prescription_volIsodose = pi.GetVolumeAtDose(external, referenceDose, VolumePresentation.AbsoluteCm3);
var target_vol = s.Volume;
return prescription_volIsodose / target_vol;
}


/// <summary>
/// Calculates the Paddick conformity index (PMID 11143252) as Paddick CI = (TVPIV)2 / (TV x PIV).
Expand All @@ -48,5 +64,24 @@ public static double GetCI_Paddick(Structure s, PlanningItem pi, DoseValue refer
var target_vol = s.Volume;
return (target_volIsodose * target_volIsodose) / (target_vol * prescription_volIsodose);
}

/// Calculates the Paddick conformity index (PMID 11143252) as Paddick CI = (TVPIV)2 / (TV x PIV).
/// TVPIV = Target Volume covered by Prescription Isodose Volume
///TV = Target Volume
///PIV = Prescription Isodose Volume
/// </summary>
/// <param name="s">the target structure</param>
/// <param name="pi">the planning item containing the dose</param>
/// <param name="referenceDose">the reference isodose (eg. prescription dose)</param>
/// <returns>RTOG conformity index</returns>
public static double GetCI_Paddick(ESAPIX.Facade.API.Structure s, ESAPIX.Facade.API.PlanningItem pi, DoseValue referenceDose)
{
var external = pi.GetStructureSet()?.Structures.FirstOrDefault(st => st.DicomType == DICOMType.EXTERNAL);
if (external == null) { return double.NaN; }
var prescription_volIsodose = pi.GetVolumeAtDose(external, referenceDose, VolumePresentation.AbsoluteCm3);
var target_volIsodose = pi.GetVolumeAtDose(s, referenceDose, VolumePresentation.AbsoluteCm3);
var target_vol = s.Volume;
return (target_volIsodose * target_volIsodose) / (target_vol * prescription_volIsodose);
}
}
}
49 changes: 49 additions & 0 deletions ESAPIX/ESAPIX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,12 @@
<Compile Include="Extensions\ApiDataObjectExtensions.cs" />
<Compile Include="Extensions\ExceptionExtensions.cs" />
<Compile Include="Extensions\ExpandoExtensions.cs" />
<Compile Include="Extensions\FImageExtensions.cs" />
<Compile Include="Extensions\MayoConstraintExtensions.cs" />
<Compile Include="Extensions\F.PlanningItemExtensions.cs" />
<Compile Include="Extensions\FQueryExtensions.cs" />
<Compile Include="Extensions\F.PlanSumExtensions.cs" />
<Compile Include="Extensions\FPlanSetupExtensions.cs" />
<Compile Include="Extensions\QueryExtensions.cs" />
<Compile Include="Constraints\DVH\Query\Discriminator.cs" />
<Compile Include="Constraints\DVH\Query\MayoConstraint.cs" />
Expand All @@ -230,6 +235,7 @@
<Compile Include="Extensions\PlanSumExtensions.cs" />
<Compile Include="Extensions\SerializationExtensions.cs" />
<Compile Include="Extensions\StringExtensions.cs" />
<Compile Include="Extensions\FStructureExtensions.cs" />
<Compile Include="Extensions\StructureExtensions.cs" />
<Compile Include="Extensions\VVectorExtensions.cs" />
<Compile Include="Facade\DefaultHelper.cs" />
Expand Down Expand Up @@ -851,4 +857,47 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
if $(ConfigurationName) == 11.0-RELEASE goto :rel110
if $(ConfigurationName) == 13.6-RELEASE goto :rel136
if $(ConfigurationName) == 13.7-RELEASE goto :rel137
if $(ConfigurationName) == 15.0-RELEASE goto :rel150
if $(ConfigurationName) == 15.1-RELEASE goto :rel151
if $(ConfigurationName) == 15.5-RELEASE goto :rel155

goto :exit

:rel110
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)ESAPIX.Nuget\ESAPIX\11.0\lib\net45\$(ProjectName).dll"
goto :exit
:rel136
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)ESAPIX.Nuget\ESAPIX\13.6\lib\net45\$(ProjectName).dll"
goto :exit

:rel137
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)ESAPIX.Nuget\ESAPIX\13.7\lib\net45\$(ProjectName).dll"
goto :exit

:rel150
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)ESAPIX.Nuget\ESAPIX\15.0\lib\net45\$(ProjectName).dll"
goto :exit

:rel151
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)ESAPIX.Nuget\ESAPIX\15.1\lib\net45\$(ProjectName).dll"
goto :exit

:rel155
copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)ESAPIX.Nuget\ESAPIX\15.5\lib\net45\$(ProjectName).dll"
goto :exit

:exit</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
29 changes: 29 additions & 0 deletions ESAPIX/Extensions/DoseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,35 @@ public static DoseValue ConvertToSystemUnits(this DoseValue dv, PlanningItem pi)
return newDv;
}

/// <summary>
/// Converts the dose to the system units. It cannot convert from % to abs dose. Will return NaN if asked
/// </summary>
/// <param name="dv">the dose value to be converted</param>
/// <param name="unit">the unit desired for the returned dose</param>
/// <returns>the dose in the desired units</returns>
public static DoseValue ConvertToSystemUnits(this DoseValue dv, ESAPIX.Facade.API.PlanningItem pi)
{
var newDv = new DoseValue(dv.Dose, dv.Unit);
if (dv.GetPresentation() != DoseValuePresentation.Relative)
{
// Need to convert to system units first (ugh!)
var oldPresentation = pi.DoseValuePresentation;
pi.DoseValuePresentation = DoseValuePresentation.Absolute;
if (pi?.Dose != null)
{
var systemUnits = pi.Dose.DoseMax3D.Unit;
pi.DoseValuePresentation = oldPresentation;
//Thanks ESAPIX!
newDv = dv.ConvertUnits(systemUnits);
}
else
{
throw new Exception("Cannot determine system units for dose. Plan dose is null");
}
}
return newDv;
}

#region COMPARISONS

/// <summary>
Expand Down
42 changes: 42 additions & 0 deletions ESAPIX/Extensions/F.PlanSumExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#region

using ESAPIX.Facade.API;
using System.Linq;
using VMS.TPS.Common.Model.Types;

#endregion

namespace ESAPIX.Extensions
{
public static class FPlanSumExtensions
{
/// <summary>
/// This method exists to guess the prescription of a plan sum by summing all plan setup prescribed doses and
/// generating a
/// relative dvh curve. Can't technically do relative dose with plan sum...but let's try to do it anyway
/// </summary>
/// <param name="ps">the plan sum where relative dose dvh curve is desired</param>
/// <param name="s">the structure to sample</param>
/// <param name="vPres">the volume presentation to create the curve</param>
/// <param name="binWidth">the bin width to create the curve</param>
/// <returns></returns>
public static DVHPoint[] GetRelativeDVHCumulativeData(this PlanSum ps, Structure s, VolumePresentation vPres,
double binWidth)
{
var guessedRxGy = ps.TotalPrescribedDoseGy();
var psDVH = ps.GetDVHCumulativeData(s, DoseValuePresentation.Absolute, vPres, binWidth);
var scalingPoint = new DoseValue(guessedRxGy, DoseValue.DoseUnit.Gy);
var dvhCurve = psDVH.CurveData.ConvertToRelativeDose(scalingPoint);
return dvhCurve;
}

public static Course Course(this PlanSum ps)
{
#if VMS110
return ps.PlanSetups.FirstOrDefault()?.Course;
#else
return ps.Course;
#endif
}
}
}
Loading

0 comments on commit 78f063e

Please sign in to comment.