Пример #1
0
    def Update(self):
        if shared.debug: print "Loading ", self.__filename
        self.__nim=load(self.__filename)
        if shared.debug: print self.__nim
        self.__data=self.__nim.get_data().astype("f").swapaxes(0,2)
        #self.__vtkimport.SetDataExtent(0,self.__data.shape[2]-1,0,self.__data.shape[1]-1,0,self.__data.shape[0]-1)
        self.__vtkimport.SetWholeExtent(0,self.__data.shape[2]-1,0,self.__data.shape[1]-1,0,self.__data.shape[0]-1)
        self.__vtkimport.SetDataExtentToWholeExtent()
        voxdim = self.__nim.get_header()['pixdim'][:3].copy()
        #Export data as string
        self.__data_string = self.__data.tostring()
        if shared.debug: print voxdim
        self.__vtkimport.SetDataSpacing((1.,1.,1.))#to reverse: [::-1]
        self.__vtkimport.CopyImportVoidPointer(self.__data_string,len(self.__data_string))
        self.__vtkimport.UpdateWholeExtent()

        imgData1 = self.__vtkimport.GetOutput()
        imgData1.SetExtent(self.__vtkimport.GetDataExtent())
        imgData1.SetOrigin((0,0,0))
        imgData1.SetSpacing(1.,1.,1.)
        #print imgData1
        #print self._irs
        #self._irs.SetInputConnection(self.__vtkimport.GetOutputPort())
        self._irs.SetInput(imgData1)
        #print self._irs
        self._irs.SetInterpolationModeToCubic()
        #self._irs.AutoCropOutputOn()
        
        
        affine = array_to_vtkmatrix4x4(self.__nim.get_affine())
        if shared.debug: print self._irs.GetResliceAxesOrigin()
        self._irs.SetResliceAxes(affine)
        if shared.debug: print self._irs.GetResliceAxesOrigin()
        m2t = vtk.vtkMatrixToLinearTransform()
        m2t.SetInput(affine.Invert())
        self._irs.TransformInputSamplingOff()
        self._irs.SetResliceTransform(m2t.MakeTransform())
        #self._irs.SetResliceAxesOrigin((0.,0.,0.)) #self.__vtkimport.GetOutput().GetOrigin())
        #print self.__vtkimport.GetOutput().GetBounds()
        #print self._irs.GetOutput().GetBounds()

        if shared.debug: print voxdim, self._irs.GetOutputSpacing()
        self._irs.SetOutputSpacing(abs(voxdim))
        if shared.debug: print self._irs.GetOutputSpacing()
        #print self._irs.GetOutputOrigin()
        #self._irs.SetOutputOrigin((0,0,0))
        # print self._irs.GetOutputOrigin()

        #m2t_i.DeepCopy(m2t);
        #m2t_i = affine_i.Invert();
        #m2t_i.MultiplyPoint(); 
        #self._irs.SetOutputOrigin(self.__nim.get_affine()[:3,-1])
        
        #self._irs.SetOutputExtent(self.__vtkimport.GetDataExtent())
        self._irs.AutoCropOutputOn()

        self._irs.Update()
Пример #2
0
    def set_matrix(self, registration_mat):
        print "VTKSurface.set_matrix(", registration_mat, ")!!"

        #print "calling SetUserMatrix(", array_to_vtkmatrix4x4(registration_mat) , ")"
        mat = array_to_vtkmatrix4x4(registration_mat)
        mat.Modified()

        mat2xform = vtk.vtkMatrixToLinearTransform()
        mat2xform.SetInput(mat)
        
        print "calling SetUserTransform(", mat2xform, ")"
        self.SetUserTransform(mat2xform) # see vtk Prop3d docs
        self.Modified()
        # how do we like update the render tree or somethin..
        self.renderer.Render()