Exemplo n.º 1
0
    def __init__(self, module_manager):
        # initialise our base class
        ModuleBase.__init__(self, module_manager)
        # initialise any mixins we might have
        NoConfigModuleMixin.__init__(self)


        self._imageReslice = vtk.vtkImageReslice()
        self._imageReslice.SetInterpolationModeToCubic()

        self._matrixToHT = vtk.vtkMatrixToHomogeneousTransform()
        self._matrixToHT.Inverse()


        module_utils.setup_vtk_object_progress(self, self._imageReslice,
                                           'Resampling volume')

        self._viewFrame = self._createViewFrame(
            {'Module (self)' : self,
             'vtkImageReslice' : self._imageReslice})

        # pass the data down to the underlying logic
        self.config_to_logic()
        # and all the way up from logic -> config -> view to make sure
        self.syncViewWithLogic()     
Exemplo n.º 2
0
    def __init__(self, module_manager):
        # initialise our base class
        ModuleBase.__init__(self, module_manager)
        # initialise any mixins we might have
        NoConfigModuleMixin.__init__(self)

        self._imageReslice = vtk.vtkImageReslice()
        self._imageReslice.SetInterpolationModeToCubic()

        self._matrixToHT = vtk.vtkMatrixToHomogeneousTransform()
        self._matrixToHT.Inverse()

        module_utils.setup_vtk_object_progress(self, self._imageReslice,
                                               'Resampling volume')

        self._viewFrame = self._createViewFrame({
            'Module (self)':
            self,
            'vtkImageReslice':
            self._imageReslice
        })

        # pass the data down to the underlying logic
        self.config_to_logic()
        # and all the way up from logic -> config -> view to make sure
        self.syncViewWithLogic()
Exemplo n.º 3
0
def reslice(img, transform, data):
    reslicer=vtk.vtkImageReslice()

    reslicer.SetInputData(img)

    transform = numpy2vtkMatrix(transform)
    vtkTrans = vtk.vtkMatrixToHomogeneousTransform()
    vtkTrans.SetInput(transform)

    reslicer.SetResliceTransform(vtkTrans)
    reslicer.SetOutputOrigin(data.GetOrigin())
    reslicer.SetOutputSpacing(data.GetSpacing())
    reslicer.SetOutputExtent(data.GetExtent())
def xform_mesh(mesh, xform_4x4):
    xform_4x4_vtk = vtkMatrix4x4()
    for i in range(4):
        for j in range(4):
            xform_4x4_vtk.SetElement(i, j, xform_4x4[i, j])

    mat_to_xform = vtkMatrixToHomogeneousTransform()
    mat_to_xform.SetInput(xform_4x4_vtk)

    xform_polydata = vtkTransformPolyDataFilter()
    xform_polydata.SetInputData(mesh)
    xform_polydata.SetTransform(mat_to_xform)
    xform_polydata.Update()

    return xform_polydata.GetOutput()
Exemplo n.º 5
0
a12 = vtk.vtkActor()
a12.SetMapper(m12)
a12.GetProperty().SetColor(0.9, 0.9, 0)
a12.GetProperty().SetRepresentationToWireframe()
ren12 = vtk.vtkRenderer()
ren12.SetViewport(0.0, 0.0, 0.25, 0.5)
ren12.ResetCamera(-0.5, 0.5, -0.5, 0.5, -1, 1)
ren12.AddActor(a12)
renWin.AddRenderer(ren12)
#--------------------------
# perspective transform matrix
m2 = vtk.vtkMatrix4x4()
m2.SetElement(3, 0, -0.11)
m2.SetElement(3, 1, 0.3)
m2.SetElement(3, 2, 0.2)
t2 = vtk.vtkMatrixToHomogeneousTransform()
t2.SetInput(m2)
f21 = vtk.vtkTransformPolyDataFilter()
f21.SetInputConnection(ap.GetOutputPort())
f21.SetTransform(t2)
m21 = vtk.vtkDataSetMapper()
m21.SetInputConnection(f21.GetOutputPort())
a21 = vtk.vtkActor()
a21.SetMapper(m21)
a21.GetProperty().SetColor(1, 0, 0)
a21.GetProperty().SetRepresentationToWireframe()
ren21 = vtk.vtkRenderer()
ren21.SetViewport(0.25, 0.5, 0.50, 1.0)
ren21.ResetCamera(-0.5, 0.5, -0.5, 0.5, -1, 1)
ren21.AddActor(a21)
renWin.AddRenderer(ren21)
Exemplo n.º 6
0
a12 = vtk.vtkActor()
a12.SetMapper(m12)
a12.GetProperty().SetColor(0.9,0.9,0)
a12.GetProperty().SetRepresentationToWireframe()
ren12 = vtk.vtkRenderer()
ren12.SetViewport(0.0,0.0,0.25,0.5)
ren12.ResetCamera(-0.5,0.5,-0.5,0.5,-1,1)
ren12.AddActor(a12)
renWin.AddRenderer(ren12)
#--------------------------
# perspective transform matrix
m2 = vtk.vtkMatrix4x4()
m2.SetElement(3,0,-0.11)
m2.SetElement(3,1,0.3)
m2.SetElement(3,2,0.2)
t2 = vtk.vtkMatrixToHomogeneousTransform()
t2.SetInput(m2)
f21 = vtk.vtkTransformPolyDataFilter()
f21.SetInputConnection(ap.GetOutputPort())
f21.SetTransform(t2)
m21 = vtk.vtkDataSetMapper()
m21.SetInputConnection(f21.GetOutputPort())
a21 = vtk.vtkActor()
a21.SetMapper(m21)
a21.GetProperty().SetColor(1,0,0)
a21.GetProperty().SetRepresentationToWireframe()
ren21 = vtk.vtkRenderer()
ren21.SetViewport(0.25,0.5,0.50,1.0)
ren21.ResetCamera(-0.5,0.5,-0.5,0.5,-1,1)
ren21.AddActor(a21)
renWin.AddRenderer(ren21)
Exemplo n.º 7
0
def resliceImage(img, transform, origin2=None, dimension2=None, spacing2=None, interpolate=True):
    if isinstance(transform, (np.matrix, np.ndarray)):
        transform = numpy2vtkMatrix(transform)
        print 'bu'
    if isinstance(transform, vtk.vtkMatrix4x4):
        vtkTrans = vtk.vtkMatrixToHomogeneousTransform()
        vtkTrans.SetInput(transform)
        if spacing2 is None or origin2 is None:
            transform_i = transform.NewInstance()
            transform_i.DeepCopy(transform)
            transform_i.Invert()
            if spacing2 is None:
                org = np.array(transform_i.MultiplyDoublePoint((0,0,0,1)))
                next_pt = np.array(transform_i.MultiplyDoublePoint((1,1,1,1)))
                delta = (org[0:3]/org[3]) - (next_pt[0:3]/next_pt[3])
                spacing2 = delta
                #spacing2 = [transform_i.GetElement(0, 0), transform_i.GetElement(1, 1), transform_i.GetElement(2, 2)]
            if origin2 is None or spacing2 is None:

                if origin2 is None:
                    # TODO: Use a better strategy to find the new origin; this doesn't
                    # work with large rotations or reflections
                    x_min, x_max, y_min, y_max, z_min, z_max = img.GetBounds()
                    corners = [(x_min, y_min, z_min), (x_min, y_min, z_max), (x_min, y_max, z_min),
                               (x_min, y_max, z_max),
                               (x_max, y_min, z_min), (x_max, y_min, z_max), (x_max, y_max, z_min),
                               (x_max, y_max, z_max)]

                    corners2 = []
                    for c in corners:
                        ch = c + (1,)
                        corners2.append(transform_i.MultiplyDoublePoint(ch))
                    x2_min, y2_min, z2_min, _ = np.min(corners2, axis=0)
                    x2_max, y2_max, z2_max, _ = np.max(corners2, axis=0)
                    origin2 = [0, 0, 0]
                    origin2[0] = x2_min if spacing2[0] >= 0 else x2_max
                    origin2[1] = y2_min if spacing2[1] >= 0 else y2_max
                    origin2[2] = z2_min if spacing2[2] >= 0 else z2_max

                    if dimension2 is None:
                        dimension2 = [0, 0, 0]
                        dimension2[0] = int(np.ceil(np.abs((x2_min - x2_max) / spacing2[0])))
                        dimension2[1] = int(np.ceil(np.abs((y2_min - y2_max) / spacing2[1])))
                        dimension2[2] = int(np.ceil(np.abs((z2_min - z2_max) / spacing2[2])))


    elif isinstance(transform, vtk.vtkAbstractTransform):
        vtkTrans = transform
        if None == spacing2 or None == origin2:
            log = logging.getLogger(__name__)
            log.error(
                "spacing2 and origin2 are required when using a general transform")
            raise Exception(
                "spacing2 and origin2 are required when using a general transform")
    else:
        log = logging.getLogger(__name__)
        log.error("Method not implemented for %s transform" % type(transform))
        raise Exception(
            "Method not implemented for %s transform" % type(transform))
    if None == dimension2:
        dimension2 = img.GetDimensions()
        #=============================Finished parsing arguments===============

    reslicer = vtk.vtkImageReslice()
    reslicer.SetResliceTransform(vtkTrans)
    reslicer.SetInputData(img)
    outData = vtk.vtkImageData()
    outData.SetOrigin(origin2)
    outData.SetDimensions(dimension2)
    outData.SetSpacing(spacing2)
    reslicer.SetInformationInput(outData)
    if interpolate is False:
        reslicer.SetInterpolationModeToNearestNeighbor()
    else:
        reslicer.SetInterpolationModeToCubic()
    reslicer.Update()
    outImg = reslicer.GetOutput()
    # print dimension2
    return outImg