-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathremoveEmptyStructure.cs
More file actions
77 lines (68 loc) · 2.79 KB
/
Copy pathremoveEmptyStructure.cs
File metadata and controls
77 lines (68 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Linq;
using System.Text;
using System.Windows;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using VMS.TPS.Common.Model.API;
using VMS.TPS.Common.Model.Types;
// TODO: Replace the following version attributes by creating AssemblyInfo.cs. You can do this in the properties of the Visual Studio project.
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
[assembly: AssemblyInformationalVersion("1.0")]
// TODO: Uncomment the following line if the script requires write access.
[assembly: ESAPIScript(IsWriteable = true)]
namespace VMS.TPS
{
public class Script
{
const string SCRIPT_NAME = "removeEmptyStructure";
public Script()
{
}
//[MethodImpl(MethodImplOptions.NoInlining)]
public void Execute(ScriptContext context /*, System.Windows.Window window, ScriptEnvironment environment*/)
{
// TODO : Add here the code that is called when the script is launched from Eclipse.
if (context.Patient == null || context.StructureSet == null)
{
MessageBox.Show("Please load a patient, 3D image, and structure set before running this script.", SCRIPT_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
context.Patient.BeginModifications(); // enable writing with this script.
StructureSet structureSet = context.StructureSet;
string log = "";
var removedStructureIds = new List<string> { };
var unremovedStructureIds = new List<string> { };
//search empty structure.
foreach (var structure in structureSet.Structures)
{
if (structure.IsEmpty == true)
{
if (structureSet.CanRemoveStructure(structure) == true)
{
removedStructureIds.Add(structure.Id);
log += structure.Id + " : removed" + "\n";
}
else
{
unremovedStructureIds.Add(structure.Id);
log += structure.Id + " : Not removed(change approval status!)" + "\n";
}
}
}
//remove empty structure.
foreach (var id in removedStructureIds)
{
if (structureSet.Structures.Any(st => st.Id == id))
{
var removedStructure = structureSet.Structures.Single(st => st.Id == id);
structureSet.RemoveStructure(removedStructure);
}
}
//show complete message.
MessageBox.Show(log+"\nDone." ,SCRIPT_NAME);
}
}
}