Exemplo n.º 1
0
 def __init__(self, name, x, y, z, radius, color, colorname,  method, coords, indextracks, affine, vol_shape):
     """
     """
     Actor.__init__(self, name) 
     self.coordinates = [x, y, z]
     self.radius = radius
     self.color=color
     self.colorname =colorname
     self.dims = vol_shape
     
     self.methods = {0 : self.trackvis,
        1 : self.tractome_inside,
        2 : self.tractome_intersect,
     }
     self.activemethod = self.methods[method]
     self.coords = coords
     self. indextracks  = indextracks
     # Generating index
     if affine is None: self.affine = np.eye(4, dtype = np.float32)
     else: self.affine = affine
     if method ==0:
         self.affine[1, 1] = self.affine[1, 1]*(-1)
     if vol_shape is not None:
         I, J, K = vol_shape
         centershift = img_to_ras_coords(np.array([[I/2., J/2., K/2.]]), affine)
         centeraffine = from_matvec(np.eye(3), centershift.squeeze())
         affine[:3,3] = affine[:3, 3] - centeraffine[:3, 3]
     self.glaffine = (GLfloat * 16)(*tuple(self.affine.T.ravel()))
     
     self.activemethod() 
    # vertices are still needed for something
     self.vertices = np.array([self.coordinates])
Exemplo n.º 2
0
    def __init__(self, name, color, colorname, coords, mask_coords, indextracks, affine, vol_shape):
        """
        """
        Actor.__init__(self, name) 
        self.color=color
        self.colorname =colorname

        # color_array = np.array(self.color*len(mask_coords[0]), dtype='f4')

        self.coords = coords
        self. indextracks  = indextracks
        self.mask_coords = mask_coords
        colors = [color,]*len(self.mask_coords[0])
        self.color_points = np.array(colors, dtype=np.float32)
        self.streamlines_mask()
        # Generating index
        
        if affine is None: self.affine = np.eye(4, dtype = np.float32)
        else: self.affine = affine
        if vol_shape is not None:
            I, J, K = vol_shape
            centershift = img_to_ras_coords(np.array([[I/2., J/2., K/2.]]), affine)
            centeraffine = from_matvec(np.eye(3), centershift.squeeze())
            affine[:3,3] = affine[:3, 3] - centeraffine[:3, 3]
        self.glaffine = (GLfloat * 16)(*tuple(self.affine.T.ravel()))
        
        # vertices are still needed for something
        self.vertices = np.array([self.voxels])
Exemplo n.º 3
0
    def __init__(self, name, buffers, clusters, representative_buffers=None, colors=None, vol_shape=None, representatives_line_width=5.0, streamlines_line_width=2.0, representatives_alpha=1.0, streamlines_alpha=1.0, affine=None, verbose=False, clustering_parameter=None, clustering_parameter_max=None, full_dissimilarity_matrix=None):
        """StreamlineLabeler is meant to explore and select subsets of
        the streamlines. The exploration occurs through clustering in
        order to simplify the scene.
        """
        # super(StreamlineLabeler, self).__init__(name)
        Actor.__init__(self, name) # direct call of the __init__ seems better in case of multiple inheritance

        if affine is None: self.affine = np.eye(4, dtype = np.float32)
        else: self.affine = affine
        if vol_shape is not None:
            I, J, K = vol_shape
            centershift = img_to_ras_coords(np.array([[I/2., J/2., K/2.]]), affine)
            centeraffine = from_matvec(np.eye(3), centershift.squeeze())
            affine[:3,3] = affine[:3, 3] - centeraffine[:3, 3]
        self.glaffine = (GLfloat * 16)(*tuple(affine.T.ravel()))
        self.glaff = affine
         
        self.mouse_x=None
        self.mouse_y=None

        self.buffers = buffers
        

        self.clusters = clusters
        self.save_init_set = True
         
        # MBKM:
        Manipulator.__init__(self, initial_clusters=clusters, clustering_function=mbkm_wrapper)

        # We keep the representative_ids as list to preserve order,
        # which is necessary for presentation purposes:
        self.representative_ids_ordered = sorted(self.clusters.keys())

        self.representatives_alpha = representatives_alpha

        # representative buffers:
        if representative_buffers is None:
            representative_buffers = compute_buffers_representatives(buffers, self.representative_ids_ordered)

        self.representatives_buffer = representative_buffers['buffer']
        self.representatives_colors = representative_buffers['colors']
        self.representatives_first = representative_buffers['first']
        self.representatives_count = representative_buffers['count']

        self.representatives = buffer2coordinates(self.representatives_buffer,
                                                  self.representatives_first,
                                                  self.representatives_count)

        # full tractography buffers:
        self.streamlines_buffer = buffers['buffer']
        self.streamlines_colors = buffers['colors']
        self.streamlines_first = buffers['first']
        self.streamlines_count = buffers['count']
        
        print('MBytes %f' % (self.streamlines_buffer.nbytes/2.**20,))

        self.hide_representatives = False
        self.expand = False
        self.knnreset = False
        self.representatives_line_width = representatives_line_width
        self.streamlines_line_width = streamlines_line_width
        self.vertices = self.streamlines_buffer # this is apparently requested by Actor
        
        self.color_storage = {}
        # This is the color of a selected representative.
        self.color_selected = np.array([1.0, 1.0, 1.0, 1.0], dtype='f4')

        # This are the visualized streamlines.
        # (Note: maybe a copy is not strictly necessary here)
        self.streamlines_visualized_first = self.streamlines_first.copy()
        self.streamlines_visualized_count = self.streamlines_count.copy()
        
        # Clustering:
        self.clustering_parameter = clustering_parameter
        self.clustering_parameter_max = clustering_parameter_max
        self.full_dissimilarity_matrix = full_dissimilarity_matrix
        self.cantroi = 0