Esempio n. 1
0
    def __init__(self, vol, a_transversal, a_coronal, a_sagittal, a_text):

        # Create text objects
        self._labelx = vv.Label(a_text)
        self._labely = vv.Label(a_text)
        self._labelz = vv.Label(a_text)
        self._labelx.position = 10, 10
        self._labely.position = 10, 30
        self._labelz.position = 10, 50

        # Create Finish button
        self._finished = False
        self._but = vv.PushButton(a_text)
        self._but.position = 10, 80
        self._but.text = 'Finish'

        # Get short name for sampling
        if isinstance(vol, Aarray):
            self._sam = sam = vol.sampling
        else:
            self._sam = None
            sam = (1, 1, 1)

        # Calculate mips and deal with anisotropy
        mipz = np.max(vol, 0)
        mipz = Aarray(mipz, (sam[1], sam[2]))
        mipy = np.max(vol, 1)
        mipy = Aarray(mipy, (sam[0], sam[2]))
        mipx = np.max(vol, 2)
        mipx = Aarray(mipx, (sam[0], sam[1]))

        # Display the mips
        vv.imshow(mipz, axes=a_transversal)
        vv.imshow(mipy, axes=a_coronal)
        vv.imshow(mipx, axes=a_sagittal)

        # Initialize range objects
        self._range_transversal = RangeWobject2D(a_transversal, mipz)
        self._range_coronal = RangeWobject2D(a_coronal, mipy)
        self._range_sagittal = RangeWobject2D(a_sagittal, mipx)

        # Get list of all range wobjects
        self._rangeWobjects = [
            self._range_transversal, self._range_coronal, self._range_sagittal
        ]

        # Bind events
        fig = a_text.GetFigure()
        fig.eventClose.Bind(self._OnFinish)
        self._but.eventPress.Bind(self._OnFinish)
        for r in self._rangeWobjects:
            r.eventRangeUpdated.Bind(self._OnRangeUpdated)

        # Almost done
        self._SetTexts()
Esempio n. 2
0
    def __init__(self,
                 vol,
                 a_transversal,
                 a_coronal,
                 a_sagittal,
                 a_MIP,
                 a_text,
                 nr_of_stents,
                 clim=None):
        self.nr_of_stents = nr_of_stents
        self.f = vv.gcf()
        self.vol = vol

        # Create empty list of endpoints
        self.endpoints = []
        self.endpoints = ['xx,yy,zz'] * nr_of_stents * 2
        self.endpointsindex = 0

        # Create text objects
        self._labelcurrent = vv.Label(a_text)
        self._labelx = vv.Label(a_text)
        self._labelxslice = vv.Label(a_text)
        self._labely = vv.Label(a_text)
        self._labelyslice = vv.Label(a_text)
        self._labelz = vv.Label(a_text)
        self._labelzslice = vv.Label(a_text)
        self._labelcurrent.position = -250, 10
        self._labelx.position = -250, 35
        self._labelxslice.position = -200, 35
        self._labely.position = -250, 55
        self._labelyslice.position = -200, 55
        self._labelz.position = -250, 75
        self._labelzslice.position = -200, 75

        self._labelendpointstext = []
        self._labelendpointstext.append(vv.Label(a_text))
        self._labelendpointstext[0].position = 100, -5
        self._labelendpointstext.append(vv.Label(a_text))
        self._labelendpointstext[1].position = 230, -5
        for i in range(2, self.nr_of_stents + 2):
            self._labelendpointstext.append(vv.Label(a_text))
            self._labelendpointstext[i].position = 40, 15 + (20 * (i - 2))

        self._labelendpoints = []
        for i in range(0, self.nr_of_stents * 2, 2):
            self._labelendpoints.append(vv.Label(a_text))
            self._labelendpoints[i].position = 100, 15 + (20 * (i / 2)), 50, 20
            self._labelendpoints.append(vv.Label(a_text))
            self._labelendpoints[i + 1].position = 230, 15 + (20 *
                                                              (i / 2)), 50, 20

        # Create Select button
        self._select = False
        self._butselect = vv.PushButton(a_text)
        self._butselect.position = -110, 150
        self._butselect.text = 'Select'

        # Create Back button
        self._back = False
        self._butback = vv.PushButton(a_text)
        self._butback.position = 10, 150
        self._butback.text = 'Back'

        # Create Close button
        self._finished = False
        self._butclose = vv.PushButton(a_text)
        self._butclose.position = -50, 180
        self._butclose.text = 'Finish'

        # Get short name for sampling
        if isinstance(vol, Aarray):
            self._sam = sam = vol.sampling
        else:
            self._sam = None
            sam = (1, 1, 1)

        # Display the slices and 3D MIP
        self.b1 = VolViewer(vol, 0, axes=a_transversal, clim=clim)
        self.b2 = VolViewer(vol, 1, axes=a_coronal, clim=clim)
        self.b3 = VolViewer(vol, 2, axes=a_sagittal, clim=clim)

        renderstyle = 'mip'
        a_MIP.daspect = 1, 1, -1
        self.b4 = vv.volshow(vol,
                             clim=(0, 2500),
                             renderStyle=renderstyle,
                             axes=a_MIP)
        c = vv.ClimEditor(a_MIP)
        c.position = (10, 50)

        # set axis settings
        for a in [a_transversal, a_coronal, a_sagittal, a_MIP]:
            a.bgcolor = [0, 0, 0]
            a.axis.visible = False
            a.showAxis = True

        # get current slice number
        Zslice = self.b1.GetCurrentSlice()
        Yslice = self.b2.GetCurrentSlice()
        Xslice = self.b3.GetCurrentSlice()
        size = vol.shape

        # create lines for position of x,y and z slices
        origin = vol.origin
        Zrange = (origin[0], (size[0] * sam[0]) + origin[0])
        Xrange = (origin[1], (size[1] * sam[1]) + origin[1])
        Yrange = (origin[2], (size[2] * sam[2]) + origin[2])

        self.l11 = vv.Line(a_transversal, [(Yslice, Xrange[0]),
                                           (Yslice, Xrange[1])])
        self.l12 = vv.Line(a_transversal, [(Yrange[0], Xslice),
                                           (Yrange[1], Xslice)])

        self.l21 = vv.Line(a_coronal, [(Zslice, Zrange[0]),
                                       (Zslice, Zrange[1])])
        self.l22 = vv.Line(a_coronal, [(Yrange[0], Xslice),
                                       (Yrange[1], Xslice)])

        self.l31 = vv.Line(a_sagittal, [(Zslice, Zrange[0]),
                                        (Zslice, Zrange[1])])
        self.l32 = vv.Line(a_sagittal, [(Xrange[0], Yslice),
                                        (Xrange[1], Yslice)])

        # change color of the lines
        for i in [self.l11, self.l12, self.l21, self.l22, self.l31, self.l32]:
            i.lc = 'g'

        # create a point in the MIP figure for the current position
        self.mippoint = vv.Line(a_MIP, [(Zslice, Xslice, Yslice)])
        self.mippoint.ms = 'o'
        self.mippoint.mw = 5
        self.mippoint.mc = 'g'
        self.mippoint.alpha = 0.9

        # Get list of all range wobjects
        self._volviewers = [self.b1, self.b2, self.b3]

        # Bind events
        fig = a_text.GetFigure()
        fig.eventClose.Bind(self._OnFinish)
        self._butclose.eventPress.Bind(self._OnFinish)
        self._butselect.eventPress.Bind(self._OnSelect)
        self._butback.eventPress.Bind(self._OnBack)

        for r in self._volviewers:
            r.eventPositionUpdate.Bind(self._OnMouseClickAxis)
        for s in range(len(self._labelendpoints)):
            self._labelendpoints[s].eventMouseDown.Bind(
                self._OnMouseClickEndpoint)

        # Almost done
        self._SetTexts()
        self.updatePosition()
Esempio n. 3
0
    def __init__(self,
                 dirsave,
                 ptcode,
                 ctcode,
                 cropname,
                 s,
                 what='phases',
                 axes=None,
                 **kwargs):
        """ s is struct from loadvol
        """

        self.fig = vv.figure(1)
        vv.clf()
        self.fig.position = 0.00, 29.00, 1680.00, 973.00
        self.defaultzoom = 0.025  # check current zoom with foo.ax.GetView()
        self.what = what
        self.ptcode = ptcode
        self.dirsave = dirsave
        self.ctcode = ctcode
        self.cropname = cropname
        if self.what == 'phases':
            self.phase = 0
        else:
            self.phase = self.what  # avgreg
        # self.vol = s.vol0
        self.s = s  # s with vol(s)
        self.s_landmarks = vv.ssdf.new()
        self.graph = stentgraph.StentGraph()
        self.points = []  # selected points
        self.nodepoints = []
        self.pointindex = 0  # for selected points
        try:
            self.vol = s.vol0  # when phases
        except AttributeError:
            self.vol = s.vol  # when avgreg

        self.ax = vv.subplot(121)
        self.axref = vv.subplot(122)

        self.label = DrawModelAxes(self.vol,
                                   ax=self.ax)  # label of clicked point
        self.axref.bgcolor = 0, 0, 0
        self.axref.visible = False

        # create axis for buttons
        a_select = vv.Wibject(self.ax)  # on self.ax or fig?
        a_select.position = 0.55, 0.7, 0.6, 0.5  # x, y, w, h

        # Create text objects
        self._labelcurrentIndexT = vv.Label(a_select)  # for text title
        self._labelcurrentIndexT.position = 125, 180
        self._labelcurrentIndexT.text = ' Total selected ='
        self._labelcurrentIndex = vv.Label(a_select)
        self._labelcurrentIndex.position = 225, 180

        # Create Select button
        self._select = False
        self._butselect = vv.PushButton(a_select)
        self._butselect.position = 10, 150
        self._butselect.text = 'Select'

        # Create Back button
        self._back = False
        self._butback = vv.PushButton(a_select)
        self._butback.position = 125, 150
        self._butback.text = 'Undo'

        # Create Next/Save button
        self._finished = False
        self._butclose = vv.PushButton(a_select)
        self._butclose.position = 10, 230
        self._butclose.text = 'Next/Save'

        # # Create Save landmarks button
        # self._save = False
        # self._butsave = vv.PushButton(a_select)
        # self._butsave.position = 125,230
        # self._butsave.text = 'Save|Finished'

        # Create Reset-View button
        self._resetview = False
        self._butresetview = vv.PushButton(a_select)
        self._butresetview.position = 10, 180
        self._butresetview.text = 'Default Zoom'  # back to default zoom

        # bind event handlers
        self.fig.eventClose.Bind(self._onFinish)
        self._butclose.eventPress.Bind(self._onFinish)
        self._butselect.eventPress.Bind(self._onSelect)
        self._butback.eventPress.Bind(self._onBack)
        self._butresetview.eventPress.Bind(self._onView)
        # self._butsave.eventPress.Bind(self._onSave)

        self._updateTextIndex()
        self._updateTitle()
Esempio n. 4
0
# Initialize axes to put widgets and labels in
container = vv.Wibject(vv.gcf())
container.position = 0.65, 0.5, 0.3, 0.5

# Create labels to show measurements
labelpool = []
for i in range(16):
    label = vv.Label(container)
    label.fontSize = 11
    label.position = 10, 100 + 25 * i, -20, 25
    labelpool.append(label)

# Initialize sliders and buttons
slider_ref = vv.Slider(container, fullRange=(1, len(centerline) - 2), value=10)
slider_ves = vv.Slider(container, fullRange=(1, len(centerline) - 2), value=10)
button_go = vv.PushButton(container, "Take all measurements (incl. volume)")
slider_ref.position = 10, 5, -20, 25
slider_ves.position = 10, 40, -20, 25
button_go.position = 10, 70, -20, 25
button_go.bgcolor = slider_ref.bgcolor = slider_ves.bgcolor = 0.8, 0.8, 1.0

# Initialize line objects for showing the plane orthogonal to centerline
slider_ref.line_plane = vv.plot([], [], [],
                                axes=axes1,
                                ls='-',
                                lw=3,
                                lc='w',
                                alpha=0.9)
slider_ves.line_plane = vv.plot([], [], [],
                                axes=axes1,
                                ls='-',