コード例 #1
0
ファイル: test1.py プロジェクト: sulei1324/CODES-IN-LAB
    def initImages(self):
        global show_height, show_width, show_thickness
        if self.slice_assembly:
            collectioniteractor1 = vtk.vtkCollectionIterator()
            collectioniteractor1.SetCollection(self.slice_assembly)
            collectioniteractor1.InitTraversal()
            for i in xrange(self.slice_assembly.GetNumberOfItems()):
                collectioniteractor1.GetCurrentObject().GetViewProp(
                ).SetVisibility(False)
                collectioniteractor1.GoToNextItem()
        if self.ren1AssemblyList[self.line_index]:
            self.line_assembly_list = self.ren1AssemblyList[self.line_index]
        else:
            self.line_assembly_list = [None] * len(self.lines[self.line_index])
            self.ren1AssemblyList[self.line_index] = self.line_assembly_list
        t0 = time.clock()
        self.images = [None] * len(self.lines[self.line_index])
        self.roi_list = []
        self.image_slice = 0
        self.countRoiInLine()
        if self.line_assembly_list[self.image_slice]:
            self.slice_assembly = self.line_assembly_list[self.image_slice]
            collectioniteractor1 = vtk.vtkCollectionIterator()
            collectioniteractor1.SetCollection(self.slice_assembly)
            collectioniteractor1.InitTraversal()
            for i in xrange(self.slice_assembly.GetNumberOfItems()):
                collectioniteractor1.GetCurrentObject().GetViewProp(
                ).SetVisibility(True)
                collectioniteractor1.GoToNextItem()
        else:
            self.slice_assembly = vtk.vtkAssemblyPath()
            self.line_assembly_list[self.image_slice] = self.slice_assembly
        self.load_mx_num = 100
        if self.load_mx_num > len(self.lines[self.line_index]):
            real_load_num = len(self.lines[self.line_index])
        else:
            real_load_num = self.load_mx_num


#         print real_load_num, len(self.lines[self.line_index])
        for i in xrange(real_load_num):
            x0, y0, z0 = self.lines[self.line_index][i][2:5]
            x_s = int((x0 * 10 / 3 - show_width / 2))
            y_s = int((y0 * 10 / 3 - show_height / 2))
            z_s = int(z0)
            tmp_image = np.zeros((show_height, show_width), dtype=np.uint16)
            for j in xrange((-show_thickness), show_thickness + 1):
                z_i = z_s + j
                if z_i < 0:
                    z_i = 0
                image_roi = (x_s, y_s, z_i, show_width, show_height, 1)
                image_j = self.loadImageFromMostd(image_roi)
                tmp_image = np.maximum(tmp_image, image_j)
            self.images[i] = tmp_image
        print time.clock() - t0
コード例 #2
0
ファイル: test1.py プロジェクト: sulei1324/CODES-IN-LAB
 def sliceForward(self, obj, e):
     global swc, main_win, mostd_src, show_width, show_height
     cur_line_index = main_win.line_index
     cur_line = main_win.lines[cur_line_index]
     cur_line_length = len(cur_line)
     cur_slice = main_win.image_slice
     if cur_slice + 1 < cur_line_length:
         next_slice = cur_slice + 1
         main_win.show_image = main_win.getImageFromLoaded(next_slice)
         main_win.image_str = main_win.show_image.tostring()
         main_win.im_importer.CopyImportVoidPointer(main_win.image_str,
                                                    len(main_win.image_str))
         main_win.im_importer.Modified()
         main_win.im_importer.Update()
         main_win.imageLevelFilter.SetInputConnection(
             main_win.im_importer.GetOutputPort())
         main_win.imageLevelFilter.Modified()
         main_win.imageLevelFilter.Update()
         main_win.image_actor.SetInput(
             main_win.imageLevelFilter.GetOutput())
         main_win.image_actor.Modified()
         main_win.image_slice = next_slice
         if (main_win.image_slice < 5) or (main_win.image_slice > len(
                 main_win.lines[main_win.line_index]) - 5):
             main_win.sphere_actor_ren2.SetVisibility(False)
         else:
             main_win.sphere_actor_ren2.SetVisibility(True)
         if main_win.slice_assembly:
             collectionInteractor1 = vtk.vtkCollectionIterator()
             collectionInteractor1.SetCollection(main_win.slice_assembly)
             collectionInteractor1.InitTraversal()
             for i in xrange(main_win.slice_assembly.GetNumberOfItems()):
                 collectionInteractor1.GetCurrentObject().GetViewProp(
                 ).SetVisibility(False)
                 collectionInteractor1.GoToNextItem()
         main_win.slice_assembly = main_win.line_assembly_list[
             main_win.image_slice]
         if main_win.slice_assembly:
             collectionInteractor1 = vtk.vtkCollectionIterator()
             collectionInteractor1.SetCollection(main_win.slice_assembly)
             collectionInteractor1.InitTraversal()
             for i in xrange(main_win.slice_assembly.GetNumberOfItems()):
                 collectionInteractor1.GetCurrentObject().GetViewProp(
                 ).SetVisibility(True)
                 collectionInteractor1.GoToNextItem()
         else:
             main_win.slice_assembly = vtk.vtkAssemblyPath()
             main_win.line_assembly_list[
                 main_win.image_slice] = main_win.slice_assembly
         main_win.vtk_widget.Render()
         main_win.renderActorsInSlice()
     else:
         next_slice = cur_slice
コード例 #3
0
ファイル: test1.py プロジェクト: sulei1324/lab_codes
    def initImages(self):
        global show_height, show_width, show_thickness
        if self.slice_assembly:
            collectioniteractor1 = vtk.vtkCollectionIterator()
            collectioniteractor1.SetCollection(self.slice_assembly)
            collectioniteractor1.InitTraversal()
            for i in xrange(self.slice_assembly.GetNumberOfItems()):
                collectioniteractor1.GetCurrentObject().GetViewProp().SetVisibility(False)
                collectioniteractor1.GoToNextItem()
        if self.ren1AssemblyList[self.line_index]:
            self.line_assembly_list = self.ren1AssemblyList[self.line_index]
        else:
            self.line_assembly_list = [None] * len(self.lines[self.line_index])
            self.ren1AssemblyList[self.line_index] = self.line_assembly_list
        t0 = time.clock()
        self.images = [None] * len(self.lines[self.line_index])
        self.roi_list = []
        self.image_slice = 0
        self.countRoiInLine()
        if self.line_assembly_list[self.image_slice]:
            self.slice_assembly = self.line_assembly_list[self.image_slice]
            collectioniteractor1 = vtk.vtkCollectionIterator()
            collectioniteractor1.SetCollection(self.slice_assembly)
            collectioniteractor1.InitTraversal()
            for i in xrange(self.slice_assembly.GetNumberOfItems()):
                collectioniteractor1.GetCurrentObject().GetViewProp().SetVisibility(True)
                collectioniteractor1.GoToNextItem()
        else:
            self.slice_assembly = vtk.vtkAssemblyPath()
            self.line_assembly_list[self.image_slice] = self.slice_assembly
        self.load_mx_num = 100
        if self.load_mx_num > len(self.lines[self.line_index]):
            real_load_num = len(self.lines[self.line_index])
        else:
            real_load_num = self.load_mx_num
#         print real_load_num, len(self.lines[self.line_index])
        for i in xrange(real_load_num):
            x0, y0, z0 = self.lines[self.line_index][i][2 : 5]
            x_s = int((x0 * 10 / 3 - show_width / 2))
            y_s = int((y0 * 10 / 3 - show_height / 2))
            z_s = int(z0)
            tmp_image = np.zeros((show_height, show_width), dtype=np.uint16)
            for j in xrange((- show_thickness), show_thickness + 1):
                z_i = z_s + j
                if z_i < 0:
                    z_i = 0
                image_roi = (x_s, y_s, z_i, show_width, show_height, 1)            
                image_j = self.loadImageFromMostd(image_roi)
                tmp_image = np.maximum(tmp_image, image_j);
            self.images[i] = tmp_image
        print time.clock() - t0
コード例 #4
0
ファイル: test1.py プロジェクト: sulei1324/lab_codes
 def sliceForward(self, obj, e):
     global swc, main_win, mostd_src, show_width, show_height
     cur_line_index = main_win.line_index
     cur_line =  main_win.lines[cur_line_index]
     cur_line_length = len(cur_line)
     cur_slice = main_win.image_slice
     if cur_slice + 1 < cur_line_length:
         next_slice = cur_slice + 1
         main_win.show_image = main_win.getImageFromLoaded(next_slice)
         main_win.image_str = main_win.show_image.tostring()
         main_win.im_importer.CopyImportVoidPointer(main_win.image_str, len(main_win.image_str))
         main_win.im_importer.Modified()
         main_win.im_importer.Update()
         main_win.imageLevelFilter.SetInputConnection(main_win.im_importer.GetOutputPort())
         main_win.imageLevelFilter.Modified()
         main_win.imageLevelFilter.Update()
         main_win.image_actor.SetInput(main_win.imageLevelFilter.GetOutput())
         main_win.image_actor.Modified()
         main_win.image_slice = next_slice
         if (main_win.image_slice < 5) or (main_win.image_slice > len(main_win.lines[main_win.line_index]) - 5):
             main_win.sphere_actor_ren2.SetVisibility(False)
         else:
             main_win.sphere_actor_ren2.SetVisibility(True)            
         if main_win.slice_assembly:
             collectionInteractor1 = vtk.vtkCollectionIterator()
             collectionInteractor1.SetCollection(main_win.slice_assembly)
             collectionInteractor1.InitTraversal()              
             for i in xrange(main_win.slice_assembly.GetNumberOfItems()):
                 collectionInteractor1.GetCurrentObject().GetViewProp().SetVisibility(False)
                 collectionInteractor1.GoToNextItem()
         main_win.slice_assembly = main_win.line_assembly_list[main_win.image_slice]
         if main_win.slice_assembly:
             collectionInteractor1 = vtk.vtkCollectionIterator()
             collectionInteractor1.SetCollection(main_win.slice_assembly)
             collectionInteractor1.InitTraversal()              
             for i in xrange(main_win.slice_assembly.GetNumberOfItems()):
                 collectionInteractor1.GetCurrentObject().GetViewProp().SetVisibility(True)
                 collectionInteractor1.GoToNextItem()
         else:
             main_win.slice_assembly = vtk.vtkAssemblyPath()
             main_win.line_assembly_list[main_win.image_slice]  = main_win.slice_assembly
         main_win.vtk_widget.Render()            
         main_win.renderActorsInSlice()
     else:
         next_slice = cur_slice
コード例 #5
0
ファイル: test14.py プロジェクト: sulei1324/lab_codes
def pickActor(obj, e):
    global iren, ren, aspath
    picker1 = vtk.vtkPropPicker()
    x, y = iren.GetEventPosition()
    picker1.Pick(x, y, 0, ren)
    print picker1.GetActor()
    i1 = vtk.vtkCollectionIterator()
    aspath.InitTraversal(i1)
    for i in xrange(aspath.GetNumberOfItems()):
        actor_i = aspath.GetNextItemAsObject()
        print id(actor_i)
    print '____________________________'
    aspath.InitTraversal()
    for i in xrange(aspath.GetNumberOfItems()):
        actor_i = aspath.GetNextItemAsObject()
        print id(actor_i)
コード例 #6
0
ファイル: test14.py プロジェクト: sulei1324/CODES-IN-LAB
def pickActor(obj, e):
    global iren, ren, aspath
    picker1 = vtk.vtkPropPicker()
    x, y = iren.GetEventPosition()
    picker1.Pick(x, y, 0, ren)
    print picker1.GetActor()
    i1 = vtk.vtkCollectionIterator()
    aspath.InitTraversal(i1)
    for i in xrange(aspath.GetNumberOfItems()):
        actor_i = aspath.GetNextItemAsObject()
        print id(actor_i)
    print '____________________________'
    aspath.InitTraversal()
    for i in xrange(aspath.GetNumberOfItems()):
        actor_i = aspath.GetNextItemAsObject()
        print id(actor_i)
コード例 #7
0
ファイル: test5.py プロジェクト: sulei1324/lab_codes
import vtk

c = vtk.vtkCollection()
i = vtk.vtkCollectionIterator()
a1 = vtk.vtkActor()
a2 = vtk.vtkActor()
c.AddItem(a1)
c.AddItem(a2)
c.InitTraversal()
ai = c.GetNextItemAsObject()



matrix1 = vtk.vtkMatrix4x4()
print matrix1

s = vtk.vtkAssemblyPath()
s.AddNode(a1, matrix1)
s.AddNode(a2, matrix1)
s.InitTraversal()
ai = s.GetNextNode()
while ai:
    ai = s.GetNextNode()
    
コード例 #8
0
import vtk

c = vtk.vtkCollection()
i = vtk.vtkCollectionIterator()
a1 = vtk.vtkActor()
a2 = vtk.vtkActor()
c.AddItem(a1)
c.AddItem(a2)
c.InitTraversal()
ai = c.GetNextItemAsObject()

matrix1 = vtk.vtkMatrix4x4()
print matrix1

s = vtk.vtkAssemblyPath()
s.AddNode(a1, matrix1)
s.AddNode(a2, matrix1)
s.InitTraversal()
ai = s.GetNextNode()
while ai:
    ai = s.GetNextNode()