Commit 5d5cd99a1c1efaf0ffb78b152f96c66ac44cfd60

Authored by Paulo Henrique Junqueira Amorim
1 parent 275f57c0

FIX: Taiwan error open DICOM (problem caracter code with vtk), temporary fix

Showing 1 changed file with 17 additions and 14 deletions   Show diff stats
invesalius/data/vtk_utils.py
@@ -22,7 +22,7 @@ import vtk @@ -22,7 +22,7 @@ import vtk
22 import wx.lib.pubsub as ps 22 import wx.lib.pubsub as ps
23 23
24 import constants as const 24 import constants as const
25 -from gui.dialogs import ProgressDialog 25 +from gui.dialogs import ProgressDialog
26 26
27 # If you are frightened by the code bellow, or think it must have been result of 27 # If you are frightened by the code bellow, or think it must have been result of
28 # an identation error, lookup at: 28 # an identation error, lookup at:
@@ -45,36 +45,36 @@ def ShowProgress(number_of_filters = 1, @@ -45,36 +45,36 @@ def ShowProgress(number_of_filters = 1,
45 last_obj_progress = [0] 45 last_obj_progress = [0]
46 if (dialog_type == "ProgressDialog"): 46 if (dialog_type == "ProgressDialog"):
47 dlg = ProgressDialog(100) 47 dlg = ProgressDialog(100)
48 - 48 +
49 49
50 # when the pipeline is larger than 1, we have to consider this object 50 # when the pipeline is larger than 1, we have to consider this object
51 # percentage 51 # percentage
52 ratio = (100.0 / number_of_filters) 52 ratio = (100.0 / number_of_filters)
53 - 53 +
54 def UpdateProgress(obj, label=""): 54 def UpdateProgress(obj, label=""):
55 """ 55 """
56 Show progress on GUI according to pipeline execution. 56 Show progress on GUI according to pipeline execution.
57 """ 57 """
58 # object progress is cummulative and is between 0.0 - 1.0 58 # object progress is cummulative and is between 0.0 - 1.0
59 - # is necessary verify in case is sending the progress 59 + # is necessary verify in case is sending the progress
60 #represented by number in case multiprocess, not vtk object 60 #represented by number in case multiprocess, not vtk object
61 if isinstance(obj, float) or isinstance(obj, int): 61 if isinstance(obj, float) or isinstance(obj, int):
62 obj_progress = obj 62 obj_progress = obj
63 else: 63 else:
64 obj_progress = obj.GetProgress() 64 obj_progress = obj.GetProgress()
65 - 65 +
66 # as it is cummulative, we need to compute the diference, to be 66 # as it is cummulative, we need to compute the diference, to be
67 # appended on the interface 67 # appended on the interface
68 if obj_progress < last_obj_progress[0]: # current obj != previous obj 68 if obj_progress < last_obj_progress[0]: # current obj != previous obj
69 difference = obj_progress # 0 69 difference = obj_progress # 0
70 else: # current obj == previous obj 70 else: # current obj == previous obj
71 difference = obj_progress - last_obj_progress[0] 71 difference = obj_progress - last_obj_progress[0]
72 - 72 +
73 last_obj_progress[0] = obj_progress 73 last_obj_progress[0] = obj_progress
74 74
75 # final progress status value 75 # final progress status value
76 progress[0] = progress[0] + ratio*difference 76 progress[0] = progress[0] + ratio*difference
77 - 77 +
78 # Tell GUI to update progress status value 78 # Tell GUI to update progress status value
79 if (dialog_type == "GaugeProgress"): 79 if (dialog_type == "GaugeProgress"):
80 ps.Publisher().sendMessage('Update status in GUI', 80 ps.Publisher().sendMessage('Update status in GUI',
@@ -82,12 +82,12 @@ def ShowProgress(number_of_filters = 1, @@ -82,12 +82,12 @@ def ShowProgress(number_of_filters = 1,
82 else: 82 else:
83 if (int(progress[0]) == 99): 83 if (int(progress[0]) == 99):
84 progress[0] = 100 84 progress[0] = 100
85 - 85 +
86 if not(dlg.Update(progress[0],label)): 86 if not(dlg.Update(progress[0],label)):
87 dlg.Close() 87 dlg.Close()
88 - 88 +
89 return progress[0] 89 return progress[0]
90 - 90 +
91 return UpdateProgress 91 return UpdateProgress
92 92
93 class Text(object): 93 class Text(object):
@@ -133,7 +133,10 @@ class Text(object): @@ -133,7 +133,10 @@ class Text(object):
133 # With some encoding in some dicom fields (like name) raises a 133 # With some encoding in some dicom fields (like name) raises a
134 # UnicodeEncodeError because they have non-ascii characters. To avoid 134 # UnicodeEncodeError because they have non-ascii characters. To avoid
135 # that we encode in utf-8. 135 # that we encode in utf-8.
136 - self.mapper.SetInput(value.encode("cp1252")) 136 + try:
  137 + self.mapper.SetInput(value.encode("latin-1"))
  138 + except(UnicodeEncodeError):
  139 + self.mapper.SetInput(value.encode("utf-8"))
137 140
138 def SetPosition(self, position): 141 def SetPosition(self, position):
139 self.actor.GetPositionCoordinate().SetValue(position[0], 142 self.actor.GetPositionCoordinate().SetValue(position[0],
@@ -178,11 +181,11 @@ class TextZero(object): @@ -178,11 +181,11 @@ class TextZero(object):
178 property.SetColor(const.TEXT_COLOUR) 181 property.SetColor(const.TEXT_COLOUR)
179 self.property = property 182 self.property = property
180 183
181 - actor = vtk.vtkTextActor() 184 + actor = vtk.vtkTextActor()
182 actor.GetTextProperty().ShallowCopy(property) 185 actor.GetTextProperty().ShallowCopy(property)
183 - actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay() 186 + actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay()
184 actor.PickableOff() 187 actor.PickableOff()
185 - self.actor = actor 188 + self.actor = actor
186 189
187 def SetColour(self, colour): 190 def SetColour(self, colour):
188 self.property.SetColor(colour) 191 self.property.SetColor(colour)