Commit 9cf1b5c4cce49cb82a38f86a57ce405066686edc
1 parent
a5da43e3
Exists in
master
and in
68 other branches
ENH: Removing duplicated dicom reading in preview
Showing
2 changed files
with
20 additions
and
10 deletions
Show diff stats
invesalius/gui/dicom_preview_panel.py
| ... | ... | @@ -202,9 +202,9 @@ class SingleImagePreview(wx.Panel): |
| 202 | 202 | self.text_acquisition.SetValue(value) |
| 203 | 203 | |
| 204 | 204 | # READ FILE |
| 205 | - filename = dicom.image.file | |
| 206 | - reader = vtkgdcm.vtkGDCMImageReader() | |
| 207 | - reader.SetFileName(filename) | |
| 205 | + #filename = dicom.image.file | |
| 206 | + #reader = vtkgdcm.vtkGDCMImageReader() | |
| 207 | + #reader.SetFileName(filename) | |
| 208 | 208 | |
| 209 | 209 | # ADJUST CONTRAST |
| 210 | 210 | window_level = dicom.image.level |
| ... | ... | @@ -214,7 +214,7 @@ class SingleImagePreview(wx.Panel): |
| 214 | 214 | print window_level |
| 215 | 215 | print window_width |
| 216 | 216 | colorer = vtk.vtkImageMapToWindowLevelColors() |
| 217 | - colorer.SetInput(reader.GetOutput()) | |
| 217 | + colorer.SetInput(dicom.image.imagedata) | |
| 218 | 218 | colorer.SetWindow(float(window_width)) |
| 219 | 219 | colorer.SetLevel(float(window_level)) |
| 220 | 220 | |
| ... | ... | @@ -223,6 +223,9 @@ class SingleImagePreview(wx.Panel): |
| 223 | 223 | self.renderer.ResetCamera() |
| 224 | 224 | self.interactor.Render() |
| 225 | 225 | |
| 226 | + def __del__(self): | |
| 227 | + print "---------> morri" | |
| 228 | + | |
| 226 | 229 | |
| 227 | 230 | |
| 228 | 231 | myEVT_SELECT = wx.NewEventType() |
| ... | ... | @@ -412,9 +415,11 @@ class Preview(wx.Panel): |
| 412 | 415 | |
| 413 | 416 | self.ID = image_file[5] |
| 414 | 417 | |
| 415 | - image_reader = vtkgdcm.vtkGDCMImageReader() | |
| 416 | - image_reader.SetFileName(image_file[0]) | |
| 417 | - image = image_reader.GetOutput() | |
| 418 | + #image_reader = vtkgdcm.vtkGDCMImageReader() | |
| 419 | + #image_reader.SetFileName(image_file[0]) | |
| 420 | + #image = image_reader.GetOutput() | |
| 421 | + | |
| 422 | + image = image_file[0] | |
| 418 | 423 | |
| 419 | 424 | scale = image.GetScalarRange() |
| 420 | 425 | |
| ... | ... | @@ -595,7 +600,7 @@ class DicomPreviewSeries(wx.Panel): |
| 595 | 600 | self.group_list = group_list |
| 596 | 601 | n = 0 |
| 597 | 602 | for group in group_list: |
| 598 | - info = (group.dicom.image.file, | |
| 603 | + info = (group.dicom.image.imagedata, | |
| 599 | 604 | float(group.dicom.image.window), |
| 600 | 605 | float(group.dicom.image.level), |
| 601 | 606 | group.title, |
| ... | ... | @@ -699,6 +704,7 @@ class DicomPreview(wx.Panel): |
| 699 | 704 | self.Bind(wx.EVT_SCROLL, self.OnScroll) |
| 700 | 705 | |
| 701 | 706 | def SetDicomDirectory(self, directory): |
| 707 | + print "Setting Dicom Directory", directory | |
| 702 | 708 | self.directory = directory |
| 703 | 709 | self.series = dicom_reader.GetSeries(directory)[0] |
| 704 | 710 | |
| ... | ... | @@ -715,7 +721,7 @@ class DicomPreview(wx.Panel): |
| 715 | 721 | dicom_files = group.GetHandSortedList() |
| 716 | 722 | n = 0 |
| 717 | 723 | for dicom in dicom_files: |
| 718 | - info = (dicom.image.file, | |
| 724 | + info = (dicom.image.imagedata, | |
| 719 | 725 | dicom.image.window, |
| 720 | 726 | dicom.image.level, |
| 721 | 727 | "Image %d" % (dicom.image.number), |
| ... | ... | @@ -740,7 +746,7 @@ class DicomPreview(wx.Panel): |
| 740 | 746 | dicom_files = group.GetHandSortedList() |
| 741 | 747 | n = 0 |
| 742 | 748 | for dicom in dicom_files: |
| 743 | - info = (dicom.image.file, | |
| 749 | + info = (dicom.image.imagedata, | |
| 744 | 750 | dicom.image.window, |
| 745 | 751 | dicom.image.level, |
| 746 | 752 | "Image %d" % (dicom.image.number), | ... | ... |
invesalius/reader/dicom.py
| ... | ... | @@ -207,6 +207,9 @@ class Parser(): |
| 207 | 207 | |
| 208 | 208 | return False |
| 209 | 209 | |
| 210 | + def GetImageData(self): | |
| 211 | + return self.vtkgdcm_reader.GetOutput() | |
| 212 | + | |
| 210 | 213 | def GetImageWindowLevel(self, preset=WL_PRESET, multiple=WL_MULT): |
| 211 | 214 | """ |
| 212 | 215 | Return image window center / level (related to brightness). |
| ... | ... | @@ -1820,6 +1823,7 @@ class Image(object): |
| 1820 | 1823 | self.time = parser.GetImageTime() |
| 1821 | 1824 | self.type = parser.GetImageType() |
| 1822 | 1825 | self.size = (parser.GetDimensionX(), parser.GetDimensionY()) |
| 1826 | + self.imagedata = parser.GetImageData() | |
| 1823 | 1827 | |
| 1824 | 1828 | if (parser.GetImageThickness()): |
| 1825 | 1829 | try: | ... | ... |