Esempio n. 1
0
 def __init__(self, dm, fig, ax, motionPlay=(10,0.5), **kwargs):
     """ dm is deformable mesh
     """
     
     self.container = vv.Wibject(ax)
     self.slider = vv.Slider(self.container, fullRange=(0,90), value=0 ) 
     # value decimals defined in vv.Slider under def _getformat(self)
     self.slider.showTicks = True
     self.slider.edgeColor = 0,0,0
     self.slider._frontColor = 0,0,1#0.5, 0.7, 0.9
     self.container.bgcolor = 1,0,0
     self.container.position = 0.35, 0.98, 500, 20 # x y w h
     self.slider.position = 0, 0, 1, 15
     self.fig = fig
     self.maxRange = self.slider.fullRange.max
     self.dm = dm
     self.motionPlay = motionPlay 
     self._finished = False
     
     # Bind
     fig.eventClose.Bind(self._OnClose)
     fig.eventKeyDown.Bind(self._OnKey)
     fig.eventPosition.Bind(self._OnPosition)
     
     self._updateSlider()
Esempio n. 2
0
def select3dpoints(vol, nr_of_stents, fig=None, clim=None):
    """ Manually select 3d points in a volume. In the given figure (or a new 
    figure if None), three axes are created that display the transversal, 
    sagittal and coronal slices of the volume. The user can then use the mouse 
    to scroll to the correct slice and select the current position as an 
    endpoint of a stent. 
    Input: Number of stents to select start- and endpoints for.
    """

    # Create figure
    if fig is None:
        fig = vv.figure()
        figCleanup = True
    else:
        fig.Clear()
        figCleanup = False

    # Create four axes and a wibject to attach text labels to
    fig.position = 0, 22, 750, 700
    fig.title = '3D Point Selector'
    a1 = vv.subplot(321)
    a2 = vv.subplot(322)
    a3 = vv.subplot(323)
    a4 = vv.subplot(324)
    a5 = vv.Wibject(fig)

    # x-richting, y-richting, x-breedte?, y-breedte?
    a5.position = 0.5, 0.7, 0.5, 0.5

    # Set settings
    for a in [a1, a2, a3, a4]:
        a.showAxis = False

    # Create PointSelect instance
    pointselect3d = PointSelect3D(vol, a1, a3, a2, a4, a5, nr_of_stents, clim)

    # Enter a mainloop
    while not pointselect3d._finished:
        pointselect3d.Run()
        time.sleep(0.01)

    # Clean up figure (close if we opened it)
    fig.Clear()
    fig.DrawNow()
    if figCleanup:
        fig.Destroy()

    # Done (return points)
    Startpoints = []
    Endpoints = []
    for i in range(nr_of_stents):
        if isinstance(pointselect3d.endpoints[i * 2], tuple):
            Startpoints.append(pointselect3d.endpoints[i * 2])
        if isinstance(pointselect3d.endpoints[(i * 2) + 1], tuple):
            Endpoints.append(pointselect3d.endpoints[(i * 2) + 1])

    return Startpoints, Endpoints
Esempio n. 3
0
def crop3d(vol, fig=None):
    """ crop3d(vol, fig=None)
    Manually crop a volume. In the given figure (or a new figure if None),
    three axes are created that display the transversal, sagittal and
    coronal MIPs (maximum intensity projection) of the volume. The user
    can then use the mouse to select a 3D range to crop the data to.
    """
    vv.use()

    # Create figure?
    if fig is None:
        fig = vv.figure()
        figCleanup = True
    else:
        fig.Clear()
        figCleanup = False

    # Create three axes and a wibject to attach text labels to
    a1 = vv.subplot(221)
    a2 = vv.subplot(222)
    a3 = vv.subplot(223)
    a4 = vv.Wibject(fig)
    a4.position = 0.5, 0.5, 0.5, 0.5

    # Set settings
    for a in [a1, a2, a3]:
        a.showAxis = False

    # Create cropper3D instance
    cropper3d = Cropper3D(vol, a1, a3, a2, a4)

    # Enter a mainloop
    while not cropper3d._finished:
        vv.processEvents()
        time.sleep(0.01)

    # Clean up figure (close if we opened it)
    fig.Clear()
    fig.DrawNow()
    if figCleanup:
        fig.Destroy()

    # Obtain ranges
    rx = cropper3d._range_transversal._rangex
    ry = cropper3d._range_transversal._rangey
    rz = cropper3d._range_coronal._rangey

    # Perform crop
    # make sure we have int not float
    rzmin, rzmax = int(rz.min), int(rz.max)
    rymin, rymax = int(ry.min), int(ry.max)
    rxmin, rxmax = int(rx.min), int(rx.max)
    vol2 = vol[rzmin:rzmax, rymin:rymax, rxmin:rxmax]
    # vol2 = vol[rz.min:rz.max, ry.min:ry.max, rx.min:rx.max]

    # Done
    return vol2
Esempio n. 4
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. 5
0
vesselVisMesh2.cullFaces = "back"
vesselVisMesh2.faceColor = "red"

# Show the centerline
vv.plot(centerline, ms='.', ls='', mw=8, mc='b', alpha=0.5)

# Initialize 2D view
axes2 = vv.Axes(vv.gcf())
axes2.position = 0.65, 0.05, 0.3, 0.4
axes2.daspectAuto = False
axes2.camera = '2d'
axes2.axis.showGrid = True
axes2.axis.axisColor = 'k'

# 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