IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
DicomDisplay.cs
1 using UnityEngine;
2 using UnityEngine.Events;
3 using UnityEngine.UI;
4 using System.Collections;
5 using System.Collections.Generic;
6 
7 public class DicomDisplay : MonoBehaviour {
8 
9  public GameObject ListScreen;
10  public GameObject ImageScreen;
11  public GameObject ListEntry;
12  //public Image HistogramImage;
13 
14  public DicomDisplayImage DicomImage;
15  //private Dropdown mDicomList;
16 
17  public Text StatusText;
18 
19  //bool UserIsLookingAtMe = false;
20 
21  void Awake()
22  {
23  //mDicomList = transform.Find ("Canvas/DicomList").GetComponent<Dropdown>();
24  //DicomImage = transform.Find ("Canvas/DicomImage").gameObject.GetComponent<DicomDisplayImage>();
25 
26  StatusText.text = "Searching for DICOMs ...";
27  eventClear ();
28  DicomImage.widget = GetComponent<UI.Widget> ();
29  }
30 
31  void OnEnable()
32  {
33  // Register event callbacks for all DICOM events:
34  PatientEventSystem.startListening( PatientEventSystem.Event.DICOM_NewList, eventNewDicomList );
35  PatientEventSystem.startListening( PatientEventSystem.Event.DICOM_NewLoadedSlice, eventDisplayCurrentDicom );
36  PatientEventSystem.startListening( PatientEventSystem.Event.DICOM_AllCleared, eventClear );
37  PatientEventSystem.startListening( PatientEventSystem.Event.PATIENT_Closed, eventClear );
38  //PatientEventSystem.startListening( PatientEventSystem.Event.DICOM_NewLoadedVolume, eventDisplayHistogram );
39  eventClear ();
40  eventNewDicomList ();
41  //eventDisplayCurrentDicom ();
42  }
43 
44  void OnDisable()
45  {
46  // Unregister myself - no longer receive events (until the next OnEnable() call):
47  PatientEventSystem.stopListening( PatientEventSystem.Event.DICOM_NewList, eventNewDicomList );
48  PatientEventSystem.stopListening( PatientEventSystem.Event.DICOM_NewLoadedSlice, eventDisplayCurrentDicom );
49  PatientEventSystem.stopListening( PatientEventSystem.Event.DICOM_AllCleared, eventClear );
50  PatientEventSystem.stopListening( PatientEventSystem.Event.PATIENT_Closed, eventClear );
51  //PatientEventSystem.stopListening( PatientEventSystem.Event.DICOM_NewLoadedVolume, eventDisplayHistogram );
52  }
53 
55  void eventDisplayCurrentDicom( object obj = null )
56  {
57  DICOM dicom = DICOMLoader.instance.currentDICOM;
58  if( dicom != null && dicom is DICOM2D )
59  {
60  DicomImage.SetDicom (dicom as DICOM2D);
61  DicomImage.gameObject.SetActive (true);
62  StatusText.gameObject.SetActive (false);
63  ImageScreen.SetActive (true);
64  ListScreen.SetActive (false);
65  }
66  }
67 
68  void eventNewDicomList( object obj = null )
69  {
70  eventClear (); // Clear the list
71 
72  // Make sure a patient is loaded:
73  Patient p = Patient.getLoadedPatient ();
74  if (p == null) {
75  Text newEntryText = ListEntry.transform.GetComponentInChildren<Text> ();
76  newEntryText.text = "No patient loaded.";
77  ListEntry.SetActive (true);
78  return;
79  }
80  // Make sure at least one series was found:
81  List<DICOMSeries> series = DICOMLoader.instance.availableSeries;
82  if (series.Count <= 0) {
83  Text newEntryText = ListEntry.transform.GetComponentInChildren<Text> ();
84  newEntryText.text = "No series found.";
85  ListEntry.SetActive (true);
86  return;
87  }
88 
89  // Deactivate default button:
90  ListEntry.SetActive (false);
91 
92  foreach (DICOMSeries s in series) {
93  //customNames.Add (p.getDICOMNameForSeriesUID (uid));
94  GameObject newEntry = Instantiate (ListEntry) as GameObject;
95  newEntry.SetActive (true);
96 
97  Text newEntryText = newEntry.transform.GetComponentInChildren<Text> ();
98  newEntryText.text = s.getDescription ();
99  newEntry.transform.SetParent (ListEntry.transform.parent, false);
100 
101  // Keep a reference to this series:
102  DICOMSeries captured = s;
103 
104  // Make the button load the DICOM:
105  GameObject newButton = newEntry.transform.Find("EntryButton").gameObject;
106  newButton.GetComponent<Button> ().onClick.AddListener(() => selectedNewDicom( captured ));
107 
108  // Make the volume button display the DICOM as volume:
109  GameObject volumetricButton = newEntry.transform.Find ("VolumetricButton").gameObject;
110  // For now, only allow Transverse volumes:
111  if (captured.sliceOrientation == SliceOrientation.Transverse && captured.isConsecutiveVolume) {
112  volumetricButton.GetComponent<Button> ().onClick.AddListener (() => selectedNewVolumetric (captured));
113  volumetricButton.SetActive (true);
114  } else {
115  volumetricButton.SetActive (false);
116  }
117  }
118 
119  DicomImage.gameObject.SetActive (false);
120  }
121 
122  void eventClear( object obj = null )
123  {
124  foreach (Transform tf in ListEntry.transform.parent) {
125  if (tf != ListEntry.transform) {
126  Destroy (tf.gameObject);
127  }
128  }
129  Text newEntryText = ListEntry.transform.GetComponentInChildren<Text> ();
130  newEntryText.text = "No series loaded.";
131  ListEntry.SetActive (true);
132  backToList ();
133  }
134  public void selectedNewDicom( DICOMSeries series )
135  {
136  // Check if we previously loaded an image from this series. If so, figure out what
137  // the last shown layer was:
138  int previousLayer = DicomImage.GetComponent<DicomDisplayImage> ().savedLayerForSeriesUID (series.seriesUID);
139  // Load this layer:
140  DICOMLoader.instance.startLoading (series, previousLayer);
141 
142  StatusText.gameObject.SetActive (true);
143  StatusText.text = "Loading DICOM ...";
144  ImageScreen.SetActive (true);
145  ListScreen.SetActive (false);
146  //DicomImage.gameObject.SetActive (false);
147  }
148  public void selectedNewVolumetric( DICOMSeries series )
149  {
152  DICOMLoader.instance.unloadVolume ();
153  } else {
154  DICOMLoader.instance.startLoadingVolume (series);
155  }
156  }
157 
158  public void backToList()
159  {
160  ImageScreen.SetActive (false);
161  DicomImage.gameObject.SetActive (false);
162  ListScreen.SetActive (true);
163  }
164 
165 
166  /*public void Update()
167  {
168  UI.Screen myScreen = GetComponent<UI.Widget> ().layoutPosition.screen;
169  UI.Screen activeScreen = UI.Core.instance.layoutSystem.activeScreen;
170  if (myScreen == activeScreen) {
171  if (!UserIsLookingAtMe) {
172  UserIsLookingAtMe = true;
173  ToolControl.instance.overrideTool ("DICOM");
174  }
175  } else {
176  if (UserIsLookingAtMe) {
177  UserIsLookingAtMe = false;
178  ToolControl.instance.unoverrideTool ("DICOM");
179  }
180  }
181  }*/
182 
183  /*public void eventDisplayHistogram( object obj = null )
184  {
185  Histogram hist = DICOMLoader.instance.currentDICOMSeries.histogram;
186  Texture2D tex = hist.asTexture ();
187  Sprite sprite = Sprite.Create(tex, new Rect(0,0,tex.width, tex.height), new Vector2(0.5f,0.5f));
188  HistogramImage.sprite = sprite;
189  }*/
190 }
static DICOMLoader instance
Definition: DICOMLoader.cs:18
string seriesUID
Definition: DICOMSeries.cs:27
Definition: DICOM.cs:8
DICOM3D currentDICOMVolume
Definition: DICOMLoader.cs:23
DICOMSeries seriesInfo
Definition: DICOM.cs:13