Beispiel #1
0
 def make_actor(self):
     self.mapper = vtk.vtkOpenGLPolyDataMapper()
     # normals
     normals = vtk.vtkPolyDataNormals()
     normals.SetInputData(self.vtk_obj)
     normals.ComputePointNormalsOn()
     normals.SplittingOff()
     normals.AutoOrientNormalsOn()
     normals.ConsistencyOn()
     normals.Update()
     self.mapper.SetInputData(normals.GetOutput())
     self.actor = vtk.vtkOpenGLActor()
     self.actor.SetMapper(self.mapper)
     self.actor.GetProperty().SetColor(self.colour)
     if self.vtk_args.wireframe:
         self.actor.GetProperty().SetRepresentationToWireframe()
     if self.alpha:
         self.actor.GetProperty().SetOpacity(self.alpha)
     if self.vtk_args.view_edges:
         self.actor.GetProperty().EdgeVisibilityOn()
         self.actor.GetProperty().SetEdgeColor(*self.edge_colour)
     # lighting and shading
     # self.actor.GetProperty().SetInterpolationToPhong()
     # self.actor.GetProperty().SetDiffuse(0.7)
     # self.actor.GetProperty().SetSpecular(0.5)
     # self.actor.GetProperty().SetSpecularPower(40)
     # self.actor.GetProperty().BackfaceCullingOn()
     # self.actor.GetProperty().FrontfaceCullingOn()
     return self.actor
Beispiel #2
0
    def GridSurface(self):
        #----------------------------------------------------------------------
        # ELECTRODE CONTACT DELAUNAY TRIANGULATION ----------------------------
        deln = vtk.vtkDelaunay3D()
        deln.SetInput(self.electrodePolyData)
        deln.SetTolerance(0.01)
        tmapper = vtk.vtkTextureMapToSphere()
        tmapper.SetInputConnection(deln.GetOutputPort())
        #tmapper.PreventSeamOn()
        mapper = vtk.vtkDataSetMapper()
        mapper.SetInputConnection(tmapper.GetOutputPort())

        # TEST TEXTURE PART
        atext = vtk.vtkOpenGLTexture()

        self.contactScalarData = vtk.vtkDoubleArray()
        self.contactScalarData.SetNumberOfComponents(1)
        for tupleID in range(self.electrodePolyData.GetNumberOfPoints()):
            self.contactScalarData.InsertNextValue(random.uniform(0, 1))

        self.UpdateGridSurface()
        atext.SetInput(self.electrodePolyData)
        self.triangulation = vtk.vtkOpenGLActor()
        self.triangulation.SetMapper(mapper)
        self.triangulation.SetTexture(atext)
        self.triangulation.GetProperty().SetOpacity(1)
Beispiel #3
0
def extract(color, isovalue):
    skinExtractor = vtk.vtkDiscreteMarchingCubes()
    skinExtractor.SetInputConnection(dataImporter.GetOutputPort())
    skinExtractor.SetValue(0, isovalue)

    smooth = vtk.vtkSmoothPolyDataFilter()
    smooth.SetInputConnection(skinExtractor.GetOutputPort())
    smooth.SetNumberOfIterations(15)
    smooth.SetRelaxationFactor(0.2)
    smooth.FeatureEdgeSmoothingOff()
    smooth.BoundarySmoothingOn()
    smooth.Update()

    skinStripper = vtk.vtkStripper()
    skinStripper.SetInputConnection(smooth.GetOutputPort())

    skinMapper = vtk.vtkOpenGLPolyDataMapper()
    skinMapper.SetInputConnection(skinStripper.GetOutputPort())
    skinMapper.ScalarVisibilityOff()

    skin = vtk.vtkOpenGLActor()
    skin.SetMapper(skinMapper)
    skin.GetProperty().SetDiffuseColor(colors.GetColor3d(color))
    skin.GetProperty().SetSpecular(.3)
    skin.GetProperty().SetSpecularPower(20)
    return skin
    def GridSurface(self):
        #----------------------------------------------------------------------
        # ELECTRODE CONTACT DELAUNAY TRIANGULATION ----------------------------
        deln = vtk.vtkDelaunay3D()
        deln.SetInput(self.electrodePolyData)
        deln.SetTolerance(0.01)
        tmapper = vtk.vtkTextureMapToSphere()
        tmapper.SetInputConnection(deln.GetOutputPort())
        #tmapper.PreventSeamOn()
        mapper = vtk.vtkDataSetMapper()
        mapper.SetInputConnection(tmapper.GetOutputPort())

        # TEST TEXTURE PART
        atext = vtk.vtkOpenGLTexture()

        self.contactScalarData = vtk.vtkDoubleArray()
        self.contactScalarData.SetNumberOfComponents(1)
        for tupleID in range(self.electrodePolyData.GetNumberOfPoints()):
            self.contactScalarData.InsertNextValue(random.uniform(0, 1))

        self.UpdateGridSurface()
        atext.SetInput(self.electrodePolyData)
        self.triangulation = vtk.vtkOpenGLActor()
        self.triangulation.SetMapper(mapper)
        self.triangulation.SetTexture(atext)
        self.triangulation.GetProperty().SetOpacity(1)
Beispiel #5
0
 def render(self, renderer):
     assert isinstance(renderer, vtk.vtkRenderer)
     if any([
             self._vtk_args.all_contours, self._vtk_args.x_contours,
             self._vtk_args.y_contours, self._vtk_args.z_contours
     ]):
         _d = list()
         if self._vtk_args.all_contours:
             _d = ['x', 'y', 'z']
         else:
             if self._vtk_args.x_contours:
                 _d += ['x']
             if self._vtk_args.y_contours:
                 _d += ['y']
             if self._vtk_args.z_contours:
                 _d += ['z']
     for d in _d:
         self.mapper = vtk.vtkOpenGLPolyDataMapper()
         self.mapper.SetInputData(getattr(self, '{}_vtkcontours'.format(d)))
         self.actor = vtk.vtkOpenGLActor()
         self.actor.SetMapper(self.mapper)
         self.actor.GetProperty().SetColor(1, 1, 0)
         self.actor.GetProperty().SetOpacity(1)
         renderer.AddActor(self.actor)
     return renderer
Beispiel #6
0
def MakeActor(polydata):
    mapper = vtk.vtkOpenGLPolyDataMapper()
    mapper.SetInputData(polydata)

    #Disable VBO shfit and scale
    mapper.SetVBOShiftScaleMethod(0)
    actor = vtk.vtkOpenGLActor()
    actor.SetMapper(mapper)

    return actor
Beispiel #7
0
def load_maps(mol,rendmod,gfx,atomcol):
	mol.reader = vtk.vtkStructuredPointsReader()
	mol.reader.SetFileName(mol.mod.dfn)
	mol.reader.Update() #by calling Update() we read the file
	mol.iso = vtk.vtkMarchingContourFilter()
	mol.iso.UseScalarTreeOn()
	mol.iso.ComputeNormalsOn()
	mol.iso.SetInputConnection(mol.reader.GetOutputPort())
	mol.iso.SetValue(0,mol.mod.isov*mol.mod.sigavg[0]+mol.mod.sigavg[1])
	clean = vtk.vtkCleanPolyData()
  	clean.SetInputConnection(mol.iso.GetOutputPort())
 	clean.ConvertStripsToPolysOn()
	smooth = vtk.vtkWindowedSincPolyDataFilter()
 	smooth.SetInputConnection(clean.GetOutputPort())
 	smooth.BoundarySmoothingOn()
 	smooth.GenerateErrorVectorsOn()
  	smooth.GenerateErrorScalarsOn()
  	smooth.NormalizeCoordinatesOn()
  	smooth.NonManifoldSmoothingOn()
  	smooth.FeatureEdgeSmoothingOn()
  	smooth.SetEdgeAngle(90)
	smooth.SetFeatureAngle(90)
	smooth.Update()
	mol.mapper = vtk.vtkOpenGLPolyDataMapper()
	mol.mapper.SetInputConnection(smooth.GetOutputPort()) ### <- connection here
	mol.mapper.ScalarVisibilityOff()
	mol.mapper.Update()
	mol.acteur= vtk.vtkOpenGLActor()
	mol.acteur.SetMapper(mol.mapper)
	mol.acteur.GetProperty().SetColor(mol.col)
	if rendmod==5:
		mol.acteur.GetProperty().SetRepresentationToSurface()
	elif rendmod==6:
		mol.acteur.GetProperty().SetRepresentationToWireframe()
	elif rendmod==7:
		mol.acteur.GetProperty().SetRepresentationToPoints()
	else :
		mol.acteur.GetProperty().SetRepresentationToSurface()
	mol.acteur.GetProperty().SetInterpolationToGouraud()
	mol.acteur.GetProperty().SetSpecular(.4)
	mol.acteur.GetProperty().SetSpecularPower(10)
	gfx.renderer.AddActor(mol.acteur)
	gfx.renwin.Render()
Beispiel #8
0
    def __init__(self, data, app=None):
        self.patient_data = data
        self.app = app
        self.centroid = None
        self.principal_dir = None
        self.vtavoxels = None
        self.polygonActor = None
        self.clabel = -1

        self.linethickness = 1.0
        self.falloff = 10.0

        self.gl_mapper = vtk.vtkOpenGLPolyDataMapper()
        self.actor = vtk.vtkOpenGLActor()
        self.polydata = vtk.vtkPolyData()

        self.findVTAVoxels()
        self.computeDataCentroid()
        self.computePrincipalDirection()
        self.generateVolumetricLine()
Beispiel #9
0
 def load_spectra(self, gfx, mod, nbstep):
     self.renderer.RemoveAllViewProps()
     gfx.itf.status.set('Loading all conformers, please wait ...')
     spectra = []
     cpt = 0
     self.nbstep = nbstep
     self.display_progression()
     for outnb in range(-nbstep, nbstep + 1):
         fn = gfx.tmpdir + '/%s/' % mod.un + 'out%s' % (outnb)
         if path.exists(fn):
             cpt += 1
             pdb = open(fn, 'r')
             nat = 0
             vx = []
             vy = []
             vz = []
             for l in pdb:
                 if l[0:4] == 'ATOM':
                     nat += 1
                     x = float(l[30:38])
                     y = float(l[38:46])
                     z = float(l[46:54])
                     vx += [x]
                     vy += [y]
                     vz += [z]
             pdb.close()
             camax = 50
             reader = vtk.vtkAppendPolyData()
             for i in range(nat - 1):
                 #if ( (vx[i]-vx[i+1])**2+(vy[i]-vy[i+1])**2+(vz[i]-vz[i+1])**2 ) < camax :#avoid long lines
                 s = vtk.vtkLineSource()
                 s.SetPoint1([vx[i], vy[i], vz[i]])
                 s.SetPoint2([vx[i + 1], vy[i + 1], vz[i + 1]])
                 reader.AddInput(s.GetOutput())
             mapper = vtk.vtkPolyDataMapper()
             mapper.SetInputConnection(reader.GetOutputPort())
             mapper.UseLookupTableScalarRangeOff()
             mapper.SetScalarVisibility(1)
             mapper.SetScalarModeToDefault()
             acteur = vtk.vtkOpenGLActor()
             acteur.SetMapper(mapper)
             acteur.GetProperty().SetColor(0, 1, 0)
             acteur.GetProperty().SetLineWidth(3)
             acteur.SetMapper(mapper)
             spectra += [acteur]
             self.renderer.AddActor(acteur)
             acteur.VisibilityOff()
             self.tm.SetInput("%3.1f" % ((100. * cpt) / (nbstep * 2. + 1)) +
                              ' %')
             self.renwin.Render()
     self.tm.SetInput("")
     self.renderer.ResetCameraClippingRange()
     self.renwin.Render()
     mod.nmcl = spectra[:]
     self.currentmod = mod
     self.currentmod.nmcl[
         self.nbstep].VisibilityOn()  #on allume la structure non déformée
     self.oldon = None
     self.renwin.Render()
     self.renderer.ResetCameraClippingRange()
     gfx.itf.confscroll.configure(from_=-self.nbstep, to=self.nbstep)
     gfx.itf.varconformer.set(0)
     gfx.itf.status.clear()
Beispiel #10
0
 def display_in_situ(self, gfx, mol, nbstep):
     gfx.itf.status.set(
         'Loading all conformers, progression : 0.0 percents ')
     spectra = []
     cpt = 0
     self.nbstep = nbstep
     for outnb in range(-nbstep, nbstep + 1):
         fn = gfx.tmpdir + '/%s/' % mol.mod.un + 'out%s' % (outnb)
         if path.exists(fn):
             cpt += 1
             pdb = open(fn, 'r')
             nat = 0
             vx = []
             vy = []
             vz = []
             for l in pdb:
                 if l[0:4] == 'ATOM':
                     nat += 1
                     x = float(l[30:38])
                     y = float(l[38:46])
                     z = float(l[46:54])
                     vx += [x]
                     vy += [y]
                     vz += [z]
             pdb.close()
             camax = 50
             reader = vtk.vtkAppendPolyData()
             for i in range(nat - 1):
                 #if ( (vx[i]-vx[i+1])**2+(vy[i]-vy[i+1])**2+(vz[i]-vz[i+1])**2 ) < camax :#avoid long lines
                 s = vtk.vtkLineSource()
                 s.SetPoint1([vx[i], vy[i], vz[i]])
                 s.SetPoint2([vx[i + 1], vy[i + 1], vz[i + 1]])
                 reader.AddInput(s.GetOutput())
             mapper = vtk.vtkPolyDataMapper()
             mapper.SetInputConnection(reader.GetOutputPort())
             mapper.UseLookupTableScalarRangeOff()
             mapper.SetScalarVisibility(1)
             mapper.SetScalarModeToDefault()
             acteur = vtk.vtkOpenGLActor()
             acteur.SetMapper(mapper)
             if mol.acteur.GetClassName() == 'vtkAssembly':
                 acteur.GetProperty().SetColor(
                     mol.acteur.GetParts().GetItemAsObject(
                         0).GetProperty().GetColor())
                 acteur.GetProperty().SetLineWidth(
                     mol.acteur.GetParts().GetItemAsObject(
                         0).GetProperty().GetLineWidth())
             else:
                 acteur.GetProperty().SetColor(
                     mol.acteur.GetProperty().GetColor())
                 acteur.GetProperty().SetLineWidth(
                     mol.acteur.GetProperty().GetLineWidth())
             assigne_rotra(mol, acteur)
             spectra += [acteur]
             gfx.renderer.AddActor(acteur)
             acteur.VisibilityOff()
             gfx.itf.status.set(
                 'Loading all conformers, progression : %3.1f percents' %
                 ((100. * cpt) / (nbstep * 2. + 1)))
             gfx.renwin.Render()
     gfx.renderer.ResetCameraClippingRange()
     gfx.renwin.Render()
     mol.nmcl = spectra[:]
     self.currentmol = mol
     self.oldon = None
     self.currentmol.nmcl[0].VisibilityOn()
     self.currentmol.acteur.VisibilityOff()
     if self.currentmol.lsm != []:
         self.currentmol.lsm[0].VisibilityOff()
     gfx.renwin.Render()
     gfx.renderer.ResetCameraClippingRange()
     self.loop = Callbackinsitu(gfx)
     self.loopobs = gfx.iren.AddObserver('TimerEvent', self.loop.loop)
     gfx.iren.CreateRepeatingTimer(100)
     gfx.iren.TimerEventResetsTimerOn()
     gfx.iren.Start()
     gfx.itf.status.clear()
Beispiel #11
0
def load_map(gfx, mapfile, root, status, scale, rendtype, isov, opct,
             cropentry, nfv, vardeci, varsmooth, color, caller):
    if caller != 'fit':
        root.configure(cursor='watch')
        status.set('Map loading ... please wait')
    if mapfile == '' or mapfile == None or mapfile == ():
        MB.showwarning('Info', 'Select map file')
        status.clear()
        root.configure(cursor='arrow')
        return
    try:
        gfx.renderer.RemoveActor(gfx.map[0].acteur)
        gfx.renderer.RemoveActor(gfx.map[0].box)
    except:
        pass
    if mapfile == 0:
        mapfile = gfx.map[0].fn
    if gfx.map == []:
        gfx.map = [Map()]
        gfx.map[0].id = 0
    if 'map' in caller:
        clean_map(gfx)  #supression des fichiers sort.s xudi et iudi
    if '.vtk' in mapfile:
        chdir(gfx.tmpdir)
        v2v_out = 'info_map'
        if caller != 'crop':
            gfx.map[0].sigma, gfx.map[0].avg = map_sigma_avg(v2v_out)
        if scale != gfx.map[0].scale:
            spc = None
            o = None
            f = open(mapfile, 'r')
            for l in f:
                if l.startswith('SPACING'):
                    spc = l.split()[1:4]
                if l.startswith('ORIGIN'):
                    o = l.split()[1:4]
                if spc != None and o != None:
                    break
            f.close()
            gfx.map[0].ratio = scale / gfx.map[0].scale
            if spc != None and o != None:
                system("sed -i -e /^SPACING/s/.*/'SPACING %f %f %f'/ %s" %
                       (float(spc[0]) * gfx.map[0].ratio,
                        float(spc[1]) * gfx.map[0].ratio,
                        float(spc[2]) * gfx.map[0].ratio, mapfile))
                system("sed -i -e /^ORIGIN/s/.*/'ORIGIN %f %f %f'/ %s" %
                       (float(o[0]) * gfx.map[0].ratio,
                        float(o[1]) * gfx.map[0].ratio,
                        float(o[2]) * gfx.map[0].ratio, mapfile))
        chdir(gfx.workdir)
    if '.ezd' in mapfile:
        chdir(gfx.tmpdir)
        mapfileout = extract_file_from_path(mapfile)[:-4] + '.vtk'
        e2v_out = 'info_map'
        system(gfx.vedabin +
               '/e2v.exe >> %s <<ENDOF\n%s  \n%f  \n%s  \nENDOF' %
               (e2v_out, mapfile, scale, mapfileout))
        mapfile = gfx.tmpdir + '/' + mapfileout
        gfx.map[0].sigma, gfx.map[0].avg = map_sigma_avg(e2v_out)
        chdir(gfx.workdir)
    gfx.map[0].fn = mapfile
    gfx.map[0].id = set_map_id(gfx)
    gfx.map[0].color = color
    gfx.map[0].oldscale = gfx.map[0].scale
    gfx.map[0].scale = scale
    if nfv != None:
        nfv.set(extract_file_from_path(gfx.map[0].fn))
    reader = vtk.vtkStructuredPointsReader()
    reader.SetFileName(mapfile)
    reader.Update()  #by calling Update() we read the file
    gfx.map[0].reader = reader
    iso = vtk.vtkMarchingContourFilter()
    iso.UseScalarTreeOn()
    iso.ComputeNormalsOn()
    iso.SetInputConnection(reader.GetOutputPort())
    iso.SetValue(0, isov * gfx.map[0].sigma + gfx.map[0].avg)
    gfx.map[0].iso = iso
    gfx.map[0].isov = isov
    if varsmooth == '1':
        #generate vectors
        clean = vtk.vtkCleanPolyData()
        clean.SetInputConnection(iso.GetOutputPort())
        clean.ConvertStripsToPolysOn()
        smooth = vtk.vtkWindowedSincPolyDataFilter()
        smooth.SetInputConnection(clean.GetOutputPort())
        smooth.BoundarySmoothingOn()
        smooth.GenerateErrorVectorsOn()
        smooth.GenerateErrorScalarsOn()
        smooth.NormalizeCoordinatesOn()
        smooth.NonManifoldSmoothingOn()
        smooth.FeatureEdgeSmoothingOn()
        smooth.SetEdgeAngle(90)
        smooth.SetFeatureAngle(90)
        smooth.Update()
    if vardeci == '1':
        deci = vtk.vtkDecimatePro()
        if varsmooth == '0':
            deci.SetInput(iso.GetOutput())
        else:
            deci.SetInput(smooth.GetOutput())
        deci.PreserveTopologyOn()
        deci.BoundaryVertexDeletionOn()
        deci.SplittingOn()
        deci.PreSplitMeshOn()
        deci.SetTargetReduction(0.97)
        gfx.map[0].isdeci = '1'
        mapper = vtk.vtkOpenGLPolyDataMapper()
        mapper.SetInputConnection(deci.GetOutputPort())
    else:
        mapper = vtk.vtkOpenGLPolyDataMapper()
        if varsmooth == '1':
            mapper.SetInputConnection(
                smooth.GetOutputPort())  ### <- connection here
        else:
            mapper.SetInputConnection(iso.GetOutputPort())
        #mapper.SetInput(newpd) ### <- newpd connect there
        gfx.map[0].isdeci = '0'
    mapper.ScalarVisibilityOff()
    mapper.Update()
    gfx.map[0].mapper = mapper
    actor = vtk.vtkOpenGLActor()
    actor.SetMapper(mapper)
    gfx.map[0].acteur = actor
    #actor.SetScale(scale,scale,scale) gerer differament
    actor.GetProperty().SetColor(gfx.map[0].color)
    actor.PickableOff()
    #definition de la box
    outline = vtk.vtkOutlineFilter()
    outline.SetInput(reader.GetOutput())
    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInput(outline.GetOutput())
    box = vtk.vtkActor()
    box.SetMapper(outlineMapper)
    box.GetProperty().SetColor((invcolor(gfx.map[0].color)))
    box.PickableOff()
    #box.SetScale(scale,scale,scale)
    gfx.map[0].box = box
    #get boxwidget bounds and set axes lenth
    (xmin, xmax, ymin, ymax, zmin, zmax) = box.GetBounds()
    x = abs(xmin - xmax) / 2.0
    y = abs(ymin - ymax) / 2.0
    z = abs(zmin - zmax) / 2.0
    gfx.axes.SetTotalLength(x, y, z)  #defini la longeurs des axe
    init_cam_slab(
        gfx, (xmin, xmax, ymin, ymax, zmin, zmax))  #defini le slab correct
    gfx.map[0].rendtype = rendtype
    if rendtype == 'Wireframe':
        actor.GetProperty().SetRepresentationToWireframe()
    elif rendtype == 'Surface':
        actor.GetProperty().SetRepresentationToSurface()
    elif rendtype == 'Points':
        actor.GetProperty().SetRepresentationToPoints()
        actor.GetProperty().SetPointSize(5)
    else:
        actor.GetProperty().SetRepresentationToWireframe()
    gfx.map[0].opct = opct
    actor.GetProperty().SetOpacity(opct)
    actor.GetProperty().SetInterpolationToGouraud()
    actor.GetProperty().SetSpecular(.4)
    actor.GetProperty().SetSpecularPower(10)
    if cropentry != None:
        if gfx.crop == None:
            gfx.crop = Crop(gfx, iso, cropentry, None)  #here entryval = None
    rendermap(gfx)
    #ajustement pour la symetry helicoidale
    if gfx.map[0].scale != gfx.map[0].oldscale:  #changement de scale
        gfx.itf.propagate_scale(gfx, scale, caller)
        if gfx.ps != None:
            if gfx.ps.solidtype == 'Helicoidal':
                gfx.ps.display_tube(gfx, caller)
            elif gfx.ps.solidtype == 'Icosahedral' or gfx.ps.solidtype == 'Octahedral' or gfx.ps.solidtype == 'Tetrahedral':
                gfx.ps.display_platonic(gfx, gfx.ps.ori)
            elif gfx.ps.solidtype == 'Cn' or gfx.ps.solidtype == 'Dn':
                gfx.ps.display_Xn(gfx)
    if caller == 'crop':  #crop uniquement helicoidal
        if gfx.ps != None:
            if gfx.ps.solidtype == 'Helicoidal':
                gfx.ps.display_tube(gfx, caller)
    if caller != 'fit':
        status.clear()
        root.configure(cursor='arrow')
Beispiel #12
0
    def __init__(self, electrode_data):
        def __pca(A):
            """
            Principal Component Analaysis
            """
            # Get Dimensions
            num_data, dim = A.shape

            # Center data
            mean_A = A.mean(axis=0)
            for i in range(num_data):
                A[i] -= mean_A

            u, s, v = np.linalg.svd(A)

            normPos = s.argmin()
            return v[:, normPos]

        """
        Setup Surface Rendering
        """

        # Apply a discrete marching cubes algorithm to extract segmented
        # surface contours with incremental values
        self.electrodeExtractor = vtk.vtkDiscreteMarchingCubes()
        self.electrodeExtractor.SetInput(electrode_data.GetOutput())
        self.electrodeExtractor.GenerateValues(1,\
                np.min(electrode_data.GetArray()),\
                np.max(electrode_data.GetArray()))

        self.electrodeMapper = vtk.vtkPolyDataMapper()
        self.electrodeMapper.SetInputConnection(\
                self.electrodeExtractor.GetOutputPort())
        self.electrodeMapper.ScalarVisibilityOff()

        self.electrodeProperty = vtk.vtkProperty()
        self.electrodeProperty.SetColor(1.0, 0.5, 0.0)

        self.SetMapper(self.electrodeMapper)
        self.SetProperty(self.electrodeProperty)
        self.electrodeExtractor.Update()

        self.grid = vtk.vtkAssembly()
        self.electrodePolyData = vtk.vtkPolyData()
        electrodePoints = vtk.vtkPoints()
        ePointMat = np.mat(np.zeros(shape=(36, 3)))
        chanIdx = 0
        for segLabel in np.unique(electrode_data.GetArray()):
            # This is hacked for MAYO34 in order to show just the 6x6 grid
            sphere = vtk.vtkSphereSource()
            sphere.SetRadius(2)

            sphereMap = vtk.vtkPolyDataMapper()
            sphereMap.SetInput(sphere.GetOutput())

            if (segLabel > 0 and segLabel < 37):
                x, y, z = np.nonzero(electrode_data.GetArray() == segLabel)
                nx = 0.9375 * np.mean(z)
                ny = 0.9375 * np.mean(y)
                nz = 1.5 * np.mean(x)

                ePointMat[chanIdx] = [nx, ny, nz]
                chanIdx = chanIdx + 1
        normalVector = __pca(ePointMat.copy())

        for chan in range(chanIdx):
            xx = ePointMat[chan, 0]
            yy = ePointMat[chan, 1]
            zz = ePointMat[chan, 2]

            sphereActor = vtk.vtkOpenGLActor()
            sphereActor.SetMapper(sphereMap)
            sphereActor.GetProperty().SetColor(1.0, 0.0, 1.0)
            sphereActor.SetPosition(xx - 0 * normalVector[0],\
                                    yy - 0 * normalVector[1],\
                                    zz - 0 * normalVector[2])

            electrodePoints.InsertNextPoint(xx - 0 * normalVector[0],\
                                            yy - 0 * normalVector[1],\
                                            zz - 0 * normalVector[2])
            self.grid.AddPart(sphereActor)

        self.electrodePolyData.SetPoints(electrodePoints)
        self.GridSurface()
Beispiel #13
0
    for min_max, color, opacity in settings:

        # contour
        data_contour = vtk.vtkMarchingCubes()
        data_contour.SetInput(data)
        data_contour.ComputeNormalsOn()
        data_contour.GenerateValues(5, min_max[0], min_max[1])
        data_contour.Update()

        # geometry
        data_geometry = vtk.vtkPolyDataMapper()
        data_geometry.SetInputConnection(data_contour.GetOutputPort())
        data_geometry.ScalarVisibilityOff()

        # actor
        data_actor = vtk.vtkOpenGLActor()
        data_actor.SetMapper(data_geometry)
        data_actor.GetProperty().SetColor(*color)
        data_actor.GetProperty().SetOpacity(opacity)

        actors.append(data_actor)

    # to plot the outline
    outline = vtk.vtkOutlineFilter()
    outline.SetInput(data)
    outline_mapper = vtk.vtkPolyDataMapper()
    outline_mapper.SetInputConnection(outline.GetOutputPort())
    outline_actor = vtk.vtkOpenGLActor()
    outline_actor.SetMapper(outline_mapper)
    outline_actor.GetProperty().SetColor(1, 1, 1)
Beispiel #14
0
# Wrap with sphere

# Delaynay
deln = vtk.vtkDelaunay3D()
deln.SetInputConnection(meshReader.GetOutputPort())
deln.SetTolerance(0.01)

tmapper = vtk.vtkTextureMapToSphere()
#tmapper.SetInputConnection(deln.GetOutputPort())
tmapper.SetInputConnection(meshReader.GetOutputPort())

#tmapper.PreventSeamOn()
mapper = vtk.vtkDataSetMapper()
mapper.SetInputConnection(tmapper.GetOutputPort())

triangulation = vtk.vtkOpenGLActor()
triangulation.SetMapper(mapper)
triangulation.SetTexture(texture)
triangulation.GetProperty().SetOpacity(1)

renderer = vtk.vtkRenderer()
renderer.AddActor(triangulation)
renderer.SetBackground(colors.GetColor3d("Black"))

renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindow.SetWindowName("TexturedSphere")

renWinInteractor = vtk.vtkRenderWindowInteractor()
renWinInteractor.SetRenderWindow(renderWindow)
Beispiel #15
0
def display(volumes, args):
    """Display the volumes provided in the iterable

    This function relies on VTK to do the visualisation.

    :param list volumes: a list of either MAP, STA or TransformedSTA object
    :param args: command-line arguments
    :type args: argparse.Namespace
    """
    # display data
    # create an actor for each datum
    actors = list()
    for volume in volumes:
        # source
        vol = vtk.vtkImageData()
        z_size, y_size, x_size = volume.data.shape
        x_origin, y_origin, z_origin = volume.origin
        # this is a weirdly complex calculation
        # suppose I have a distance of size D (distance)
        # the index of the first position is S (start)
        # the index of the last position is E (end)
        # the relationship between these three values is
        # E - S + 1 = D
        # therefore, E = D + S - 1
        vol.SetExtent(
            x_origin, x_size + x_origin - 1,
            y_origin, y_size + y_origin - 1,
            z_origin, z_size + z_origin - 1,
        )
        vol.SetOrigin(x_origin, y_origin, z_origin)
        sp_x = volume.x_voxel_size
        sp_y = volume.y_voxel_size
        sp_z = volume.z_voxel_size
        vol.SetSpacing(sp_x, sp_y, sp_z)
        vol.AllocateScalars(vtk.VTK_FLOAT, 1)
        # voxel data
        print(f"Inserting voxel data...", end="")
        # numpy to vtk; https://pyscience.wordpress.com/2014/09/06/numpy-to-vtk-converting-your-numpy-arrays-to-vtk-arrays-and-files/
        voxels = vtk.util.numpy_support.numpy_to_vtk(volume.data.ravel(), deep=1, array_type=vtk.VTK_FLOAT)
        print(f"done!")
        vol.GetPointData().SetScalars(voxels)
        # contour
        contours = vtk.vtkContourFilter()
        contours.SetInputData(vol)
        contours.SetValue(0, args.contour_level)
        contours.Update()
        contoursOutput = contours.GetOutput()
        # data
        obj = vtk.vtkPolyData()
        obj.SetPoints(contoursOutput.GetPoints())
        obj.SetPolys(contoursOutput.GetPolys())
        # mapper
        mapper = vtk.vtkOpenGLPolyDataMapper()
        mapper.SetInputData(obj)
        # actor & transform
        actor = vtk.vtkOpenGLActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetColor(volume.colour)
        actor.GetProperty().SetOpacity(volume.opacity)
        if isinstance(volume, TransformedSTA):
            transform = vtk.vtkTransform()
            matrix = vtk.vtkMatrix4x4()
            for i in range(4):
                for j in range(4):
                    matrix.SetElement(i, j, volume.transform[i, j])
            transform.SetMatrix(matrix)
            print(transform)
            actor.SetUserTransform(transform)
        actors += [actor]
    # renderer
    renderer = vtk.vtkOpenGLRenderer()
    [renderer.AddActor(actor) for actor in actors]
    # cube axes
    cubeAxesActor = vtk.vtkCubeAxesActor()
    cubeAxesActor.SetBounds(renderer.ComputeVisiblePropBounds())
    cubeAxesActor.SetCamera(renderer.GetActiveCamera())
    cubeAxesActor.SetFlyMode(4)
    cubeAxesActor.SetFlyModeToStaticEdges()  # how the cube axes will appear
    cubeAxesActor.GetTitleTextProperty(0).SetColor(1.0, 1.0, 1.0)
    cubeAxesActor.GetTitleTextProperty(1).SetColor(1.0, 1.0, 1.0)
    cubeAxesActor.GetTitleTextProperty(2).SetColor(1.0, 1.0, 1.0)
    cubeAxesActor.XAxisMinorTickVisibilityOff()
    cubeAxesActor.YAxisMinorTickVisibilityOff()
    cubeAxesActor.ZAxisMinorTickVisibilityOff()
    renderer.AddActor(cubeAxesActor)
    # rendererwindow
    render_window = vtk.vtkRenderWindow()
    render_window.AddRenderer(renderer)
    # render window interactor
    render_window_interactor = vtk.vtkRenderWindowInteractor()
    render_window_interactor.SetRenderWindow(render_window)
    render_window_interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
    axes_actor = vtk.vtkAxesActor()
    axes_widget = vtk.vtkOrientationMarkerWidget()
    axes_widget.SetOrientationMarker(axes_actor)
    axes_widget.SetViewport(0, 0, 0.2, 0.2)
    axes_widget.SetInteractor(render_window_interactor)
    axes_widget.SetEnabled(1)
    renderer.ResetCamera()
    # display
    render_window_interactor.Initialize()
    render_window_interactor.Start()
    return os.EX_OK
Beispiel #16
0
if __name__ == '__main__':
    mixer = read_data()

    mixer_contour = vtk.vtkMarchingCubes()
    mixer_contour.SetInputConnection(mixer.GetOutputPort())
    mixer_contour.ComputeNormalsOn()
    mixer_contour.SetValue(0, 1)

    stream_actors = make_stream_actors((0, 15, 30), (0, 1, 0))
    stream_actors += make_stream_actors((0, 45, 30), (0, 0, 1))

    mixer_geometry = vtk.vtkPolyDataMapper()
    mixer_geometry.SetInputConnection(mixer_contour.GetOutputPort())
    mixer_geometry.ScalarVisibilityOff()

    mixer_actor = vtk.vtkOpenGLActor()
    mixer_actor.SetMapper(mixer_geometry)
    mixer_actor.GetProperty().SetColor(.5, .5, .5)
    mixer_actor.GetProperty().SetOpacity(1.)

    # Standard vtk environment stuff
    renderer = vtk.vtkOpenGLRenderer()
    render_window = vtk.vtkRenderWindow()
    render_window.AddRenderer(renderer)
    render_interactor = vtk.vtkRenderWindowInteractor()

    renderer.AddActor(mixer_actor)
    for actor in stream_actors:
        renderer.AddActor(actor)
    renderer.SetBackground(0.1, 0.1, 0.1)
    render_window.SetSize(500, 500)
Beispiel #17
0
	def display_mod(self,mod):
		self.renderer.RemoveAllViewProps()
		if mod.type == 'mol':
			if mod.dspmodtype == 'CA':
				reader = vtk.vtkPDBReader()
				reader.SetFileName(mod.dfn)
				reader.SetHBScale(0)
				reader.SetBScale(4.0)
				mapper = vtk.vtkPolyDataMapper()
				mapper.SetInputConnection(reader.GetOutputPort())
				mapper.SetScalarModeToDefault()
				acteur = vtk.vtkActor()
				acteur.SetMapper(mapper)
			else: #all atoms or backbone case
				reader = vtk.vtkPDBReader()
				reader.SetFileName(mod.dfn)
				mapper = vtk.vtkPolyDataMapper()
				mapper.SetInputConnection(reader.GetOutputPort())
				mapper.SetScalarModeToDefault()
				acteur = vtk.vtkActor()
				acteur.SetMapper(mapper)
			self.camera.SetFocalPoint(0, 0, 0)
			self.camera.SetPosition(0, 0, 250)
		elif mod.type=='map':
			reader = vtk.vtkStructuredPointsReader()
			reader.SetFileName(mod.dfn)
			reader.Update() #by calling Update() we read the file
			iso = vtk.vtkMarchingContourFilter()
			iso.UseScalarTreeOn()
			iso.ComputeNormalsOn()
			iso.SetInputConnection(reader.GetOutputPort())
			iso.SetValue(0,mod.isov*mod.sigavg[0]+mod.sigavg[1])
			mapper = vtk.vtkOpenGLPolyDataMapper()
			mapper.SetInputConnection(iso.GetOutputPort()) ### <- connection here
			mapper.ScalarVisibilityOff()
			mapper.Update()
			acteur= vtk.vtkOpenGLActor()
			acteur.SetMapper(mapper)
			acteur.GetProperty().SetColor(0,0.35,1)
			if mod.rep=='Wireframe':
				acteur.GetProperty().SetRepresentationToWireframe()
			elif mod.rep=='Surface':
				acteur.GetProperty().SetRepresentationToSurface()
			else :
				acteur.GetProperty().SetRepresentationToWireframe()
			acteur.GetProperty().SetInterpolationToGouraud()
			acteur.GetProperty().SetSpecular(.4)
			acteur.GetProperty().SetSpecularPower(10)
			(xmin,xmax,ymin,ymax,zmin,zmax)=acteur.GetBounds()
			maxi=max(xmax-xmin,ymax-ymin,zmax-zmin)
			mini=min(xmax-xmin,ymax-ymin,zmax-zmin)
			fp=((xmax+xmin)/2.,(ymax+ymin)/2.,(zmax+zmin)/2.)
			self.camera.SetFocalPoint(fp[0],fp[1],fp[2])
			self.camera.SetPosition(fp[0],fp[1],fp[2]+(zmax-zmin)*4.)
		else :
			print 'strange Error in mod.type'
		(xl, xu, yl, yu, zl, zu)=acteur.GetBounds()
		mod.coldist = min(xu-xl,yu-yl,zu-zl)/2.
		mod.sphdist = max(xu-xl,yu-yl,zu-zl)/2.
		self.renderer.AddActor(acteur)
		self.renderer.ResetCameraClippingRange()
		self.renwin.Render()
Beispiel #18
0
def load_map(gfx,mapfile,root,status,scale,rendtype,isov,opct,cropentry,nfv,vardeci,varsmooth,color,caller):
	if caller != 'fit':
		root.configure(cursor='watch')
		status.set('Map loading ... please wait')
	if mapfile =='' or mapfile == None or mapfile ==() :
		MB.showwarning('Info','Select map file')
		status.clear()
		root.configure(cursor='arrow')
		return
	try:
		gfx.renderer.RemoveActor(gfx.map[0].acteur)
		gfx.renderer.RemoveActor(gfx.map[0].box)
	except:
		pass
	if mapfile == 0:
		mapfile = gfx.map[0].fn
	if gfx.map == []:
		gfx.map = [Map()]
		gfx.map[0].id=0
	if 'map' in caller :
		clean_map(gfx) #supression des fichiers sort.s xudi et iudi
	if '.vtk' in mapfile:
		chdir(gfx.tmpdir)
		v2v_out='info_map'
		if caller != 'crop':
			gfx.map[0].sigma,gfx.map[0].avg = map_sigma_avg(v2v_out)
		if scale != gfx.map[0].scale:
			spc = None
			o = None
			f = open(mapfile,'r')
			for l in f:
				if l.startswith('SPACING'):
					spc = l.split()[1:4]
				if l.startswith('ORIGIN'):
					o = l.split()[1:4]
				if spc != None and o != None:
					break
			f.close()
			gfx.map[0].ratio = scale/gfx.map[0].scale
			if spc != None and o != None:
				system("sed -i -e /^SPACING/s/.*/'SPACING %f %f %f'/ %s"%(float(spc[0])*gfx.map[0].ratio,float(spc[1])*gfx.map[0].ratio,float(spc[2])*gfx.map[0].ratio,mapfile))
				system("sed -i -e /^ORIGIN/s/.*/'ORIGIN %f %f %f'/ %s"%(float(o[0])*gfx.map[0].ratio,float(o[1])*gfx.map[0].ratio,float(o[2])*gfx.map[0].ratio,mapfile))
		chdir(gfx.workdir)
	if '.ezd' in mapfile:
		chdir(gfx.tmpdir)
		mapfileout = extract_file_from_path(mapfile)[:-4]+'.vtk'
		e2v_out='info_map'
		system(gfx.vedabin+'/e2v.exe >> %s <<ENDOF\n%s  \n%f  \n%s  \nENDOF'%(e2v_out,mapfile,scale,mapfileout))
		mapfile = gfx.tmpdir + '/' + mapfileout
		gfx.map[0].sigma,gfx.map[0].avg = map_sigma_avg(e2v_out)
		chdir(gfx.workdir)
	gfx.map[0].fn = mapfile
	gfx.map[0].id = set_map_id(gfx)
	gfx.map[0].color = color
	gfx.map[0].oldscale = gfx.map[0].scale
	gfx.map[0].scale = scale
	if nfv !=None:
		nfv.set(extract_file_from_path(gfx.map[0].fn))
	reader = vtk.vtkStructuredPointsReader()
	reader.SetFileName(mapfile)
	reader.Update() #by calling Update() we read the file
	gfx.map[0].reader=reader
	iso = vtk.vtkMarchingContourFilter()
	iso.UseScalarTreeOn()
	iso.ComputeNormalsOn()
	iso.SetInputConnection(reader.GetOutputPort())
	iso.SetValue(0,isov*gfx.map[0].sigma+gfx.map[0].avg)
	gfx.map[0].iso=iso
	gfx.map[0].isov=isov
	if varsmooth == '1':
		#generate vectors
		clean = vtk.vtkCleanPolyData()
	  	clean.SetInputConnection(iso.GetOutputPort())
	 	clean.ConvertStripsToPolysOn()
		smooth = vtk.vtkWindowedSincPolyDataFilter()
	 	smooth.SetInputConnection(clean.GetOutputPort())
	 	smooth.BoundarySmoothingOn()
	 	smooth.GenerateErrorVectorsOn()
	  	smooth.GenerateErrorScalarsOn()
	  	smooth.NormalizeCoordinatesOn()
	  	smooth.NonManifoldSmoothingOn()
	  	smooth.FeatureEdgeSmoothingOn()
	  	smooth.SetEdgeAngle(90)
		smooth.SetFeatureAngle(90)
		smooth.Update()
	if vardeci=='1':
		deci = vtk.vtkDecimatePro()
		if varsmooth == '0':
			deci.SetInput(iso.GetOutput())
		else :
			deci.SetInput(smooth.GetOutput())
		deci.PreserveTopologyOn()
		deci.BoundaryVertexDeletionOn()
		deci.SplittingOn()
		deci.PreSplitMeshOn()
		deci.SetTargetReduction(0.97)
		gfx.map[0].isdeci='1'
		mapper = vtk.vtkOpenGLPolyDataMapper()
		mapper.SetInputConnection(deci.GetOutputPort())
	else :
		mapper = vtk.vtkOpenGLPolyDataMapper()
		if varsmooth == '1':
			mapper.SetInputConnection(smooth.GetOutputPort()) ### <- connection here
		else :
			mapper.SetInputConnection(iso.GetOutputPort())
		#mapper.SetInput(newpd) ### <- newpd connect there
		gfx.map[0].isdeci='0'
	mapper.ScalarVisibilityOff()
	mapper.Update()
	gfx.map[0].mapper=mapper
	actor = vtk.vtkOpenGLActor()
	actor.SetMapper(mapper)
	gfx.map[0].acteur=actor
	#actor.SetScale(scale,scale,scale) gerer differament
	actor.GetProperty().SetColor(gfx.map[0].color)
	actor.PickableOff()
	#definition de la box
	outline = vtk.vtkOutlineFilter()
        outline.SetInput(reader.GetOutput())
        outlineMapper = vtk.vtkPolyDataMapper()
        outlineMapper.SetInput(outline.GetOutput())
	box=vtk.vtkActor()
        box.SetMapper( outlineMapper )
        box.GetProperty().SetColor((invcolor(gfx.map[0].color)))
        box.PickableOff()
	#box.SetScale(scale,scale,scale)
	gfx.map[0].box = box
	#get boxwidget bounds and set axes lenth
	(xmin,xmax,ymin,ymax,zmin,zmax)=box.GetBounds()
        x=abs(xmin-xmax)/2.0
	y=abs(ymin-ymax)/2.0
	z=abs(zmin-zmax)/2.0
	gfx.axes.SetTotalLength( x, y , z ) #defini la longeurs des axe
	init_cam_slab(gfx,(xmin,xmax,ymin,ymax,zmin,zmax)) #defini le slab correct
	gfx.map[0].rendtype=rendtype
	if rendtype=='Wireframe':
		actor.GetProperty().SetRepresentationToWireframe()
	elif rendtype=='Surface':
		actor.GetProperty().SetRepresentationToSurface()
	elif rendtype=='Points':
		actor.GetProperty().SetRepresentationToPoints()
		actor.GetProperty().SetPointSize(5)
	else :
		actor.GetProperty().SetRepresentationToWireframe()
	gfx.map[0].opct=opct
	actor.GetProperty().SetOpacity(opct)
	actor.GetProperty().SetInterpolationToGouraud()
	actor.GetProperty().SetSpecular(.4)
	actor.GetProperty().SetSpecularPower(10)
	if cropentry!=None:
		if gfx.crop==None:
			gfx.crop=Crop(gfx,iso,cropentry,None) #here entryval = None
	rendermap(gfx)
	#ajustement pour la symetry helicoidale
	if gfx.map[0].scale != gfx.map[0].oldscale:#changement de scale
		gfx.itf.propagate_scale(gfx,scale,caller)
		if gfx.ps != None:
			if gfx.ps.solidtype == 'Helicoidal':
				gfx.ps.display_tube(gfx,caller)
			elif gfx.ps.solidtype == 'Icosahedral' or gfx.ps.solidtype =='Octahedral' or gfx.ps.solidtype == 'Tetrahedral':
				gfx.ps.display_platonic(gfx,gfx.ps.ori)
			elif gfx.ps.solidtype =='Cn' or gfx.ps.solidtype == 'Dn':
				gfx.ps.display_Xn(gfx)
	if caller == 'crop':#crop uniquement helicoidal
		if gfx.ps != None:
			if gfx.ps.solidtype == 'Helicoidal':
				gfx.ps.display_tube(gfx,caller)
	if caller != 'fit':
		status.clear()
		root.configure(cursor='arrow')
Beispiel #19
0
if __name__ == "__main__":
    np_data = getData()
    vtk_data = numpy_to_vtk(np_data)

    contour = vtk.vtkMarchingCubes()
    contour.SetInputConnection(vtk_data.GetOutputPort())
    contour.ComputeNormalsOn()
    contour.SetValue(0, 7)

    geometry = vtk.vtkPolyDataMapper()
    geometry.SetInputConnection(contour.GetOutputPort())
    geometry.ScalarVisibilityOff()

    #actor = vtk.vtkLODActor()
    actor = vtk.vtkOpenGLActor()
    #actor.SetNumberOfCloudPoints(1000000)
    actor.SetMapper(geometry)
    actor.GetProperty().SetColor(0.333, 0.333, 0)#colors.green_to_white(0, 255))
    actor.GetProperty().SetOpacity(0.3)#colors.default_opacity(0, 255, 0.5))

    renderer = vtk.vtkOpenGLRenderer()
    render_window = vtk.vtkRenderWindow()

    renderer.AddActor(actor)
    renderer.SetBackground(0.32157, 0.34118, 0.43137)
    render_window.SetSize(500, 500)

    render_window.AddRenderer(renderer)
    render_interactor = vtk.vtkRenderWindowInteractor()
    render_interactor.SetRenderWindow(render_window)
    def __init__(self, electrode_data):

        def __pca(A):
            """
            Principal Component Analaysis
            """
            # Get Dimensions
            num_data, dim = A.shape

            # Center data
            mean_A = A.mean(axis=0)
            for i in range(num_data):
                A[i] -= mean_A

            u,s,v = np.linalg.svd(A)

            normPos = s.argmin()
            return v[:, normPos]

        """
        Setup Surface Rendering
        """

        # Apply a discrete marching cubes algorithm to extract segmented
        # surface contours with incremental values
        self.electrodeExtractor = vtk.vtkDiscreteMarchingCubes()
        self.electrodeExtractor.SetInput(electrode_data.GetOutput())
        self.electrodeExtractor.GenerateValues(1,\
                np.min(electrode_data.GetArray()),\
                np.max(electrode_data.GetArray()))

        self.electrodeMapper = vtk.vtkPolyDataMapper()
        self.electrodeMapper.SetInputConnection(\
                self.electrodeExtractor.GetOutputPort())
        self.electrodeMapper.ScalarVisibilityOff()

        self.electrodeProperty = vtk.vtkProperty()
        self.electrodeProperty.SetColor(1.0, 0.5, 0.0)

        self.SetMapper(self.electrodeMapper)
        self.SetProperty(self.electrodeProperty)
        self.electrodeExtractor.Update()

        self.grid = vtk.vtkAssembly()
        self.electrodePolyData = vtk.vtkPolyData()
        electrodePoints = vtk.vtkPoints()
        ePointMat = np.mat(np.zeros(shape = (36, 3)))
        chanIdx = 0
        for segLabel in np.unique(electrode_data.GetArray()):
            # This is hacked for MAYO34 in order to show just the 6x6 grid
            sphere = vtk.vtkSphereSource()
            sphere.SetRadius(2)

            sphereMap = vtk.vtkPolyDataMapper()
            sphereMap.SetInput(sphere.GetOutput())

            if (segLabel > 0 and segLabel < 37):
                x,y,z = np.nonzero(electrode_data.GetArray() == segLabel)
                nx = 0.9375*np.mean(z)
                ny = 0.9375*np.mean(y)
                nz = 1.5*np.mean(x)

                ePointMat[chanIdx] = [nx, ny, nz]
                chanIdx = chanIdx + 1
        normalVector = __pca(ePointMat.copy())

        for chan in range(chanIdx):
            xx = ePointMat[chan, 0]
            yy = ePointMat[chan, 1]
            zz = ePointMat[chan, 2]

            sphereActor = vtk.vtkOpenGLActor()
            sphereActor.SetMapper(sphereMap)
            sphereActor.GetProperty().SetColor(1.0, 0.0, 1.0)
            sphereActor.SetPosition(xx - 0 * normalVector[0],\
                                    yy - 0 * normalVector[1],\
                                    zz - 0 * normalVector[2])

            electrodePoints.InsertNextPoint(xx - 0 * normalVector[0],\
                                            yy - 0 * normalVector[1],\
                                            zz - 0 * normalVector[2])
            self.grid.AddPart(sphereActor)

        self.electrodePolyData.SetPoints(electrodePoints)
        self.GridSurface()