Пример #1
0
 def __init__(self):
     HasTraits.__init__(self)
     x, y, z = ogrid[-10:10:100j, -10:10:100j, -10:10:100j]
     scalars = sin(x*y*z)/(x*y*z)
     src = ArraySource(scalar_data=scalars)
     self.scene.mayavi_scene.add_child(src)
     src.add_module(IsoSurface())
Пример #2
0
 def __init__(self):
     HasTraits.__init__(self)
     x, y, z = ogrid[-10:10:100j, -10:10:100j, -10:10:100j]
     scalars = sin(x * y * z) / (x * y * z)
     src = ArraySource(scalar_data=scalars)
     self.scene.mayavi_scene.add_child(src)
     src.add_module(IsoSurface())
Пример #3
0
 def __init__(self):
     HasTraits.__init__(self)
     # Create some data, and plot it using the embedded scene's engine
     x, y, z = ogrid[-10:10:100j, -10:10:100j, -10:10:100j]
     scalars = sin(x * y * z) / (x * y * z)
     src = ArraySource(scalar_data=scalars)
     self.scene.engine.add_source(src)
     src.add_module(IsoSurface())
Пример #4
0
 def __init__(self):
     HasTraits.__init__(self)
     # Create some data, and plot it using the embedded scene's engine
     x, y, z = ogrid[-10:10:100j, -10:10:100j, -10:10:100j]
     scalars = sin(x*y*z)/(x*y*z)
     src = ArraySource(scalar_data=scalars)
     self.scene.engine.add_source(src)
     src.add_module(IsoSurface())
Пример #5
0
def treader(fname, engine):
    from enthought.tvtk.api import tvtk
    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
    from enthought.mayavi.sources.api import ArraySource
    # Do your own reader stuff here, I'm just reading a VTK file with a
    # different extension here.
    
    src = ArraySource()
    src.scalar_name=fname
    import os.path
    src.name=os.path.split(fname)[-1]
    return src
Пример #6
0
def spe_reader(fname, engine):
    """Reader for .zzz files.
    
    Parameters:
    -----------
    fname -- Filename to be read.
    engine -- The engine the source will be associated with.
    """
    from enthought.tvtk.api import tvtk
    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
    # Do your own reader stuff here, I'm just reading a VTK file with a
    # different extension here.
    import SpeFile as spe
    r = spe.SpeFile(fname)

    from enthought.mayavi.sources.api import ArraySource
    src = ArraySource()
    src.scalar_data = r.GetNumArray()
    src.scalar_name = fname
    import os.path
    src.name = os.path.split(fname)[-1]
    return src
Пример #7
0
    def generateOutput(self, obj_points):
        from enthought.mayavi.sources.api import ArraySource
        x = min(obj_points[0]) + (max(obj_points[0]) - min(obj_points[0])) / 2
        y = min(obj_points[1]) + (max(obj_points[1]) - min(obj_points[1])) / 2
        z = min(obj_points[2]) + (max(obj_points[2]) - min(obj_points[2])) / 2

        minx = max(x - self.max_spread_x, 0)
        maxx = min(x + self.max_spread_x,
                   self.objectsInputOverlay._data.shape[1])
        miny = max(y - self.max_spread_y, 0)
        maxy = min(y + self.max_spread_y,
                   self.objectsInputOverlay._data.shape[2])
        minz = max(z - self.max_spread_z, 0)
        maxz = min(z + self.max_spread_z,
                   self.objectsInputOverlay._data.shape[3])
        image_comp = self.objectsInputOverlay._data[0, minx:maxx, miny:maxy,
                                                    minz:maxz, 0]

        value = self.objectsInputOverlay._data[0, obj_points[0][0],
                                               obj_points[1][0],
                                               obj_points[2][0], 0]
        image = numpy.where(image_comp == value, 1, 0)

        #image = self.overlay._data[0, minx:maxx, miny:maxy, minz:maxz, 0]
        src = ArraySource(scalar_data=image)
        self.engine.add_source(src)

        #axes are needed to get all the images at the same scale
        from enthought.mayavi.modules.api import Axes
        axes = Axes()
        self.engine.add_module(axes)

        from enthought.mayavi.modules.api import IsoSurface
        iso = IsoSurface()
        self.engine.add_module(iso)
        iso.contour.contours = [1, 2]
        iso.actor.mapper.scalar_visibility = False
        iso.actor.property.specular_color = (0.58, 0.58, 0.58)
        iso.actor.property.diffuse_color = (0.58, 0.58, 0.58)
        iso.actor.property.ambient_color = (0.58, 0.58, 0.58)
        iso.actor.property.color = (0.58, 0.58, 0.58)
        fname = str(self.counter) + ".png"
        fname = os.path.join(self.outputdir, fname)
        from enthought.mayavi import mlab
        azimuth, elevation, d, f = mlab.view()
        el_deg = numpy.rad2deg(elevation)
        az_deg = numpy.rad2deg(azimuth)
        mean = numpy.zeros((1, 3))
        if len(obj_points[0]) > 100:
            #TODO: This part is not really ready yet, but somehow works
            matr = numpy.array(obj_points)
            matr = matr.transpose()
            mean = numpy.mean(matr, 0)
            meanmatr = numpy.zeros(matr.shape)
            meanmatr[:, 0] = mean[0]
            meanmatr[:, 1] = mean[1]
            meanmatr[:, 2] = mean[2]

            matr = matr - meanmatr
            u, s, vh = numpy.linalg.svd(matr, full_matrices=False)

            normal_index = numpy.argmin(s)
            normal_vector = vh[normal_index, :]
            elevation = numpy.arccos(normal_vector[2])
            azimuth = numpy.arctan(normal_vector[0] / normal_vector[1])
            el_deg = numpy.rad2deg(elevation)
            az_deg = numpy.rad2deg(azimuth)
            if normal_vector[1] < 0 and normal_vector[0] < 0:
                az_deg = az_deg + 180
            elif normal_vector[1] < 0 and normal_vector[0] > 0:
                az_deg = az_deg + 360
            elif normal_vector[1] > 0 and normal_vector[0] < 0:
                az_deg = az_deg + 180

        else:
            pass

        #print fname
        #print image.shape
        #a, e, d, f = self.scene.scene.view()
        #print a, e, d, f
        #self.scene.scene.view(azimuth, elevation, d, f)

        #mlab.view(numpy.rad2deg(azimuth), numpy.rad2deg(elevation), 'auto', focalpoint=[mean[0], mean[1], mean[2]])
        mlab.view(az_deg, el_deg)
        #self.scene.scene.camera.azimuth(azimuth)
        #self.scene.scene.camera.elevation(elevation)

        self.scene.scene.save(fname)
        self.counter = self.counter + 1
        src.remove()
        strtowrite = "<img src=\"" + fname + "\"/>"
        return strtowrite
Пример #8
0
    def generateOutput(self, obj_points):
        from enthought.mayavi.sources.api import ArraySource
        x = min(obj_points[0]) + (max(obj_points[0])-min(obj_points[0]))/2
        y = min(obj_points[1]) + (max(obj_points[1])-min(obj_points[1]))/2
        z = min(obj_points[2]) + (max(obj_points[2])-min(obj_points[2]))/2
        
        minx = max(x-self.max_spread_x, 0)
        maxx = min(x+self.max_spread_x, self.objectsInputOverlay._data.shape[1])
        miny = max(y-self.max_spread_y, 0)
        maxy = min(y+self.max_spread_y, self.objectsInputOverlay._data.shape[2])
        minz = max(z-self.max_spread_z, 0)
        maxz = min(z+self.max_spread_z, self.objectsInputOverlay._data.shape[3])
        image_comp = self.objectsInputOverlay._data[0, minx:maxx, miny:maxy, minz:maxz, 0]
        
        value = self.objectsInputOverlay._data[0, obj_points[0][0], obj_points[1][0], obj_points[2][0], 0]
        image = numpy.where(image_comp==value, 1, 0)
        
        #image = self.overlay._data[0, minx:maxx, miny:maxy, minz:maxz, 0]
        src = ArraySource(scalar_data=image)
        self.engine.add_source(src)
        

        #axes are needed to get all the images at the same scale
        from enthought.mayavi.modules.api import Axes
        axes = Axes()
        self.engine.add_module(axes)
        
        from enthought.mayavi.modules.api import IsoSurface
        iso = IsoSurface()
        self.engine.add_module(iso)
        iso.contour.contours = [1, 2]
        iso.actor.mapper.scalar_visibility = False
        iso.actor.property.specular_color = (0.58, 0.58, 0.58)
        iso.actor.property.diffuse_color = (0.58, 0.58, 0.58)
        iso.actor.property.ambient_color = (0.58, 0.58, 0.58)
        iso.actor.property.color = (0.58, 0.58, 0.58)
        fname = str(self.counter)+".png"
        fname = os.path.join(self.outputdir, fname)
        from enthought.mayavi import mlab
        azimuth, elevation, d, f = mlab.view()
        el_deg = numpy.rad2deg(elevation)
        az_deg = numpy.rad2deg(azimuth)
        mean = numpy.zeros((1, 3))
        if len(obj_points[0])>100:
            #TODO: This part is not really ready yet, but somehow works
            matr = numpy.array(obj_points)
            matr = matr.transpose()
            mean = numpy.mean(matr, 0)
            meanmatr = numpy.zeros(matr.shape)
            meanmatr[:, 0]=mean[0]
            meanmatr[:, 1]=mean[1]
            meanmatr[:, 2]=mean[2]
            
            matr = matr - meanmatr
            u, s, vh = numpy.linalg.svd(matr, full_matrices=False)            
            
            
            normal_index = numpy.argmin(s)
            normal_vector = vh[normal_index, :]
            elevation = numpy.arccos(normal_vector[2])
            azimuth = numpy.arctan(normal_vector[0]/normal_vector[1])
            el_deg = numpy.rad2deg(elevation)
            az_deg = numpy.rad2deg(azimuth)
            if normal_vector[1]<0 and normal_vector[0]<0:
                az_deg = az_deg + 180
            elif normal_vector[1]<0 and normal_vector[0]>0:
                az_deg = az_deg + 360
            elif normal_vector[1]>0 and normal_vector[0]<0:
                az_deg = az_deg + 180
            
        else:
            pass
        
        #print fname
        #print image.shape
        #a, e, d, f = self.scene.scene.view()
        #print a, e, d, f
        #self.scene.scene.view(azimuth, elevation, d, f)
        
        #mlab.view(numpy.rad2deg(azimuth), numpy.rad2deg(elevation), 'auto', focalpoint=[mean[0], mean[1], mean[2]])
        mlab.view(az_deg, el_deg)
        #self.scene.scene.camera.azimuth(azimuth)
        #self.scene.scene.camera.elevation(elevation)
        
        self.scene.scene.save(fname)
        self.counter = self.counter+1
        src.remove()
        strtowrite = "<img src=\"" + fname + "\"/>"
        return strtowrite