Skip to content

Commit

Permalink
Update and fix some bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Brojan committed May 18, 2022
1 parent 2bee3f9 commit 86a8880
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ packages/*
primer/*
#Files to ignore
*.pdb
*.p7s
*.p7s
*.xcf
21 changes: 21 additions & 0 deletions DoseGradient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="LICENSE">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down Expand Up @@ -224,5 +227,23 @@
<ItemGroup>
<Resource Include="icon.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="images\2grad.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="images\2grad2.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="images\0grad.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="images\1grad1.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="images\2grad3.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="images\1grad2.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
14 changes: 1 addition & 13 deletions HelpWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,7 @@
<LineBreak/>
Save the new dose matrix. Import the original data with the new dose file into the TPS. On some systems you have to delete the original plan
before you can import the data back. The program changes the SOPInstanceUID of the dose file, but other files are left untouched.<LineBreak/><LineBreak/>
<Bold>LICENSE</Bold>
<LineBreak/>
The DoseGradient program is published under the MIT license. The Microsoft NuGet libraries are published under the Appache 2.0 license.<LineBreak/>
<LineBreak/>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<LineBreak/> <LineBreak/>
Denis Brojan

</TextBlock>
</Grid>
</ScrollViewer>
Expand Down
27 changes: 22 additions & 5 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@
<StackPanel Grid.Column="0" Orientation="Horizontal" Height="Auto" VerticalAlignment="Center">
<Button Grid.Column="0" Content="Open..." Width="100" Height="30" Click="Button_Click" VerticalAlignment="Center"></Button>
<Button Content="Save..." Width="100" Height="30" Margin="10,0,0,0" VerticalAlignment="Center" Click="Button_Click_5"></Button>
<CheckBox x:Name="CheckBoxOverwriteZeroVoxels" Height="30" VerticalContentAlignment="Center" VerticalAlignment="Center" Margin="15,0,0,0" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked">
<CheckBox x:Name="CheckBoxOverwriteZeroVoxels" Height="30" VerticalContentAlignment="Center" VerticalAlignment="Center" Margin="15,0,0,0">
<Label Content="Overwrite all voxels" VerticalAlignment="Top" ToolTip="Using this option will overwrite all elements of the dose matrix (in each z-slice), regardless of their value."></Label>
</CheckBox>
<CheckBox x:Name="CheckBoxChangeUID" Height="30" VerticalContentAlignment="Center" VerticalAlignment="Center" Margin="15,0,0,0" IsChecked="True">
<Label Content="Change UID" VerticalAlignment="Top" ToolTip="Using this option will change SOPInstanceUID of the RT dose file."></Label>
</CheckBox>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" Height="Auto" VerticalAlignment="Center">
<Label Content="Select plot type:" Height="30" VerticalAlignment="Center"></Label>
Expand All @@ -66,10 +69,24 @@
<GroupBox.Header>
<DockPanel HorizontalAlignment="Stretch">
<Label Content="Gradient regions" HorizontalAlignment="Left"></Label>
<Button Content="0 gradients" HorizontalAlignment="Right" Height="20" Width="80" Margin="5,0,0,0" Click="Button_Click_2"/>
<Button Content="1 gradient" HorizontalAlignment="Right" Height="20" Width="80" Margin="5,0,0,0" Click="Button_Click_3"/>
<Button Content="2 gradients" HorizontalAlignment="Right" Height="20" Width="80" Margin="5,0,0,0" Click="Button_Click_4"/>
<Button Content="Default" HorizontalAlignment="Right" Height="20" Width="60" Margin="5,0,0,0" Click="Button_Click_1"/>
<Button HorizontalAlignment="Right" Height="20" Width="25" Margin="5,0,0,0" Click="Button_Click_2">
<Image Source="/images/0grad.png"></Image>
</Button>
<Button HorizontalAlignment="Right" Height="20" Width="25" Margin="5,0,0,0" Click="Button_Click_3">
<Image Source="/images/1grad1.png"></Image>
</Button>
<Button HorizontalAlignment="Right" Height="20" Width="25" Margin="5,0,0,0" Click="Button_Click_8">
<Image Source="/images/1grad2.png"></Image>
</Button>
<Button HorizontalAlignment="Right" Height="20" Width="25" Margin="5,0,0,0" Click="Button_Click_4">
<Image Source="/images/2grad.png"></Image>
</Button>
<Button HorizontalAlignment="Right" Height="20" Width="25" Margin="5,0,0,0" Click="Button_Click_7">
<Image Source="/images/2grad2.png"></Image>
</Button>
<Button HorizontalAlignment="Right" Height="20" Width="25" Margin="5,0,0,0" Click="Button_Click_1">
<Image Source="/images/2grad3.png"></Image>
</Button>
</DockPanel>
</GroupBox.Header>
<Grid HorizontalAlignment="Stretch">
Expand Down
87 changes: 76 additions & 11 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ private void SetGradientStartingValues()

for (int i = 0; i < this.gradientXPositions.Count; i++)
{
this.gradientXPositions[i] = x0 + i * dx;
this.gradientXPositions[i] = Math.Round(x0 + i * dx, 2);
}
}

Expand Down Expand Up @@ -563,12 +563,69 @@ private void Button_Click_4(object sender, RoutedEventArgs e)
SetTextBoxes();
}


private void Button_Click_7(object sender, RoutedEventArgs e)
{
// 2 gradients upside down
if (this.DoseMatrix == null)
{
return;
}
double xmin = this.DoseImageHeatMapSeries.X0;
double xmax = this.DoseImageHeatMapSeries.X1;
SetGradientStartingValues();
this.gradientXPositions[0] = xmin;
this.gradientXPositions[1] = xmin;
this.gradientXPositions[2] = xmin;
this.gradientXPositions[3] = xmin + (xmax - xmin) / 3.0 - 0.5;
this.gradientXPositions[4] = xmin + (xmax - xmin) / 3.0 + 0.5;
this.gradientXPositions[5] = xmin + 2 * (xmax - xmin) / 3.0 - 0.5;
this.gradientXPositions[6] = xmin + 2 * (xmax - xmin) / 3.0 + 0.5;
this.gradientXPositions[7] = xmax;
this.gradientXPositions[8] = xmax;
this.gradientXPositions[9] = xmax;

this.gradientDoses = new List<double>() { 30.6, 30.6, 30.6, 30.6, 0, 0, 30.6, 30.6, 30.6, 30.6 };

CreateLineSeriesProfilePlot();
SetTextBoxes();
}


private void Button_Click_8(object sender, RoutedEventArgs e)
{
// 1 gradient left to right
if (this.DoseMatrix == null)
{
return;
}
double xmin = this.DoseImageHeatMapSeries.X0;
double xmax = this.DoseImageHeatMapSeries.X1;
SetGradientStartingValues();

this.gradientXPositions[0] = xmin;
this.gradientXPositions[1] = xmin;
this.gradientXPositions[2] = xmin;
this.gradientXPositions[3] = (xmin + xmax) / 2.0 - 0.5;
this.gradientXPositions[4] = (xmin + xmax) / 2.0 + 0.5;
this.gradientXPositions[5] = xmax;
this.gradientXPositions[6] = xmax;
this.gradientXPositions[7] = xmax;
this.gradientXPositions[8] = xmax;
this.gradientXPositions[9] = xmax;

this.gradientDoses = new List<double>() { 30.6, 30.6, 30.6, 30.6, 0, 0, 0, 0, 0, 0 };

CreateLineSeriesProfilePlot();
SetTextBoxes();
}

private bool CheckProfileValidity()
{
// All X must be increasing. Dose must be non-negative.
for (int i = 1; i < this.gradientXPositions.Count; i++)
{
if (this.gradientXPositions[i - 1] > this.gradientXPositions[i])
if (Math.Round(this.gradientXPositions[i - 1], 2) > Math.Round(this.gradientXPositions[i], 2))
{
return false;
}
Expand Down Expand Up @@ -772,34 +829,38 @@ private double GetDoseFromProfileAtPosition(double t)
{
List<double> x = this.gradientXPositions;
List<double> y = this.gradientDoses;
double dose;

if (t <= x.First())
{
return y.First();
dose = y.First();
}
else if (t >= y.Last())
else if (t >= x.Last())
{
return y.Last();
dose = y.Last();
}
else
{
int i;
for (i = 0; i < x.Count - 2; i++)
for (i = 0; i < x.Count - 1; i++)
{
if (x[i] <= t && t < x[i + 1])
if (t >= x[i] && t < x[i + 1])
{
break;
}
}
if (Math.Abs(x[i + 1] - x[i]) < 1e-8)
{
return (y[i] + y[i + 1]) / 2.0;
dose = (y[i] + y[i + 1]) / 2.0;
}
else
{
return y[i] + ((y[i + 1] - y[i]) / (x[i + 1] - x[i])) * (t - x[i]);
dose = y[i] + ((y[i + 1] - y[i]) / (x[i + 1] - x[i])) * (t - x[i]);
}

}
return dose;

}


Expand Down Expand Up @@ -1327,7 +1388,7 @@ private void SaveToDicom(string oldfilePath, string filePath, Tuple<uint[,,], ui

dcm.FindFirst(TagHelper.PixelData).DData_ = byteArray;

dcm.FindFirst(TagHelper.DoseGridScaling).DData = Double.Parse(newData.Item4.ToString("E6"));
dcm.FindFirst(TagHelper.DoseGridScaling).DData = newData.Item4;

var _smallestImagePixelValue = dcm.FindFirst(TagHelper.SmallestImagePixelValue) as AbstractElement<ushort>;
if (_smallestImagePixelValue != null)
Expand All @@ -1341,7 +1402,10 @@ private void SaveToDicom(string oldfilePath, string filePath, Tuple<uint[,,], ui
}
// Since Eclipse is using 32 bit voxels, setting the true largest pixel value would not work because only unsigned short is allowed.
// However, Eclipse is not writing this tag to dicom. Ha ha ...
dcm.FindFirst(TagHelper.SOPInstanceUID).DData = UIDHelper.GenerateUID();
if ((bool)this.CheckBoxChangeUID.IsChecked == true)
{
dcm.FindFirst(TagHelper.SOPInstanceUID).DData = UIDHelper.GenerateUID();
}
dcm.WriteAddMeta(filePath);
// using dcm.Write() doesn't work with Monaco, it works only with Eclipse
}
Expand All @@ -1357,5 +1421,6 @@ private void Button_Click_6(object sender, RoutedEventArgs e)
HelpWindow helpwindow = new HelpWindow();
helpwindow.Show();
}

}
}
Binary file added images/0grad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1grad1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1grad2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/2grad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/2grad2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/2grad3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 86a8880

Please sign in to comment.