Changeset 2848 for trunk/GSASIIplot.py


Ignore:
Timestamp:
May 31, 2017 2:48:06 PM (6 years ago)
Author:
vondreele
Message:

add polyhedron drawing for stacking layers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r2835 r2848  
    68626862    '''
    68636863
    6864     global AtNames,AtTypes,XYZ,Bonds
     6864    global AtNames,AtTypes,XYZ,Bonds,Faces
     6865
    68656866    def FindBonds(atTypes,XYZ):
    68666867        Radii = []
     
    68806881                Bonds[j].append(-Dx[j]*Radii[j]/sumR[j])
    68816882        return Bonds
     6883
     6884    def FindFaces(Bonds):
     6885        Faces = []
     6886        for bonds in Bonds:
     6887            faces = []
     6888            if len(bonds) > 2:
     6889                FaceGen = G2lat.uniqueCombinations(bonds,3)     #N.B. this is a generator
     6890                for face in FaceGen:
     6891                    vol = nl.det(face)
     6892                    if abs(vol) > .5 or len(bonds) == 3:
     6893                        if vol < 0.:
     6894                            face = [face[0],face[2],face[1]]
     6895                        face = 1.8*np.array(face)
     6896                        if not np.array([np.array(nl.det(face-bond))+0.0001 < 0 for bond in bonds]).any():
     6897                            norm = np.cross(face[1]-face[0],face[2]-face[0])
     6898                            norm /= np.sqrt(np.sum(norm**2))
     6899                            faces.append([face,norm])
     6900            Faces.append(faces)
     6901        return Faces   
    68826902       
    68836903    def getAtoms():
    6884         global AtNames,AtTypes,XYZ,Bonds
     6904        global AtNames,AtTypes,XYZ,Bonds,Faces
    68856905        AtNames = []
    68866906        AtTypes = []
     
    69226942       
    69236943        Bonds = FindBonds(AtTypes,XYZ)
     6944        Faces = FindFaces(Bonds)
    69246945                       
    69256946    def OnKeyBox(event):
     
    69516972            im.save(Fname,mode)
    69526973            print ' Drawing saved to: '+Fname
    6953         elif mode[0] in ['L','F']:
     6974        elif mode[0] in ['L','F','P']:
    69546975            event.key = cb.GetValue()[0]
    69556976            wx.CallAfter(OnPlotKeyPress,event)
     
    69746995        elif keyCode =='F' and len(laySeq) == 2:
    69756996            Page.fade = not Page.fade
     6997        elif keyCode == 'P':
     6998            Page.poly = not Page.poly
    69766999        if len(laySeq) != 2:
    69777000            return
     
    71457168        GL.glPopMatrix()
    71467169               
     7170    def RenderPolyhedra(x,y,z,Faces,color):
     7171        GL.glShadeModel(GL.GL_FLAT)
     7172        GL.glPushMatrix()
     7173        GL.glTranslate(x,y,z)
     7174        GL.glMaterialfv(GL.GL_FRONT_AND_BACK,GL.GL_DIFFUSE,color)
     7175        GL.glShadeModel(GL.GL_SMOOTH)
     7176        GL.glMultMatrixf(B4mat.T)
     7177        for face,norm in Faces:
     7178            GL.glPolygonMode(GL.GL_FRONT_AND_BACK,GL.GL_FILL)
     7179            GL.glFrontFace(GL.GL_CW)
     7180            GL.glNormal3fv(norm)
     7181            GL.glBegin(GL.GL_TRIANGLES)
     7182            for vert in face:
     7183                GL.glVertex3fv(vert)
     7184            GL.glEnd()
     7185        GL.glPopMatrix()
     7186        GL.glShadeModel(GL.GL_SMOOTH)
     7187
    71477188    def RenderLabel(x,y,z,label,matRot):       
    71487189        GL.glPushMatrix()
     
    71637204#            print caller
    71647205# end of useful debug
    7165         global AtNames,AtTypes,XYZ,Bonds
     7206        global AtNames,AtTypes,XYZ,Bonds,Faces
    71667207        cPos = defaults['cameraPos']
    71677208        VS = np.array(Page.canvas.GetSize())
     
    72007241            if len(laySeq) == 2 and AtTypes[iat][1] and Page.fade:
    72017242                color *= .5
    7202             RenderSphere(x,y,z,atomRad,color)
    7203             RenderBonds(x,y,z,Bonds[iat],bondRad,color)
     7243            if Page.poly:
     7244                if len(Faces[iat])>16:
     7245                    RenderPolyhedra(x,y,z,Faces[iat],color)
     7246            else:
     7247                RenderSphere(x,y,z,atomRad,color)
     7248                RenderBonds(x,y,z,Bonds[iat],bondRad,color)
    72047249            if Page.labels:
    72057250                RenderLabel(x,y,z,'  '+AtNames[iat],matRot)
     
    72407285        Page.labels = False
    72417286        Page.fade = False
    7242     choice = [' save as:','jpeg','tiff','bmp','use keys for:','L - toggle labels']
     7287        Page.poly = False
     7288    choice = [' save as:','jpeg','tiff','bmp','use keys for:','L - toggle labels',
     7289              'F - fade 2nd layer','P - polyhedra']
    72437290    if len(laySeq) == 2:
    72447291        choice += ['F - toggle fade','X/shift-X move Dx','Y/shift-Y move Dy','Z/shift-Z move Dz']
Note: See TracChangeset for help on using the changeset viewer.