;i{W6ddlZddlmZGddeZdS)N)QtGuiceZdZdZd dZdZdZdZd!dZd"d Z d Z d Z d Z d Z dZd!dZd!dZd!dZd!dZd!dZd!dZdZdZdZdZdZdZdZed#dZeddgddfdZdS)$MeshDataa Class for storing and operating on 3D mesh data. May contain: - list of vertex locations - list of edges - list of triangles - colors per vertex, edge, or tri - normals per vertex or tri This class handles conversion between the standard [list of vertexes, list of faces] format (suitable for use with glDrawElements) and 'indexed' [list of vertexes] format (suitable for use with glDrawArrays). It will automatically compute face normal vectors as well as averaged vertex normal vectors. The class attempts to be as efficient as possible in caching conversion results and avoiding unnecessary conversions. Ncjd|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_||M||d|||d|||ddSdS||||||||||dSdSdS)a- ============== ===================================================== **Arguments:** vertexes (Nv, 3) array of vertex coordinates. If faces is not specified, then this will instead be interpreted as (Nf, 3, 3) array of coordinates. faces (Nf, 3) array of indexes into the vertex array. edges [not available yet] vertexColors (Nv, 4) array of vertex colors. If faces is not specified, then this will instead be interpreted as (Nf, 3, 4) array of colors. faceColors (Nf, 4) array of face colors. ============== ===================================================== All arguments are optional. Nfacesindexed) _vertexes_vertexesIndexedByFaces_vertexesIndexedByEdges_faces_edges _vertexFaces _vertexEdges_vertexNormals_vertexNormalsIndexedByFaces _vertexColors_vertexColorsIndexedByFaces_vertexColorsIndexedByEdges _faceNormals_faceNormalsIndexedByFaces _faceColors_faceColorsIndexedByFaces_faceColorsIndexedByEdges _edgeColors_edgeColorsIndexedByEdges setVertexessetVertexColors setFaceColorssetFaces)selfvertexesredges vertexColors faceColorss MC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\pyqtgraph/opengl/MeshData.py__init__zMeshData.__init__s"'+$'+$    #,0)!+/(+/(!*.')-&)-& )-&  }  7 ;;;+((w(GGG)&&z7&CCCCC*)  *** e$$$+((666)&&z22222 *)c|jS)zReturn an array (Nf, 3) of vertex indexes, three per triangular face in the mesh. If faces have not been computed for this mesh, the function returns None. )rr"s r'rzMeshData.facesXs {r)cF|j||jS)zDReturn an array (Nf, 3) of vertex indexes, two per edge in the mesh.)r _computeEdgesr+s r'r$zMeshData.edges_s$ ;     {r)c||_d|_d|_d|_|d|_d|_dS)zSet the (Nf, 3) array of faces. Each rown in the array contains three indexes into the vertex array, specifying the three corners of a triangular face.N)rrrr resetNormalsrr)r"rs r'r!zMeshData.setFacesesJ   '+$ +/()-&&&r)c|)|j|j||jS|dkr9|j+|j$|j||_|jSt d)a4Return an array (N,3) of the positions of vertexes in the mesh. By default, each unique vertex appears only once in the array. If indexed is 'faces', then the array will instead contain three vertexes per face in the mesh (and a single vertex may appear more than once in the array).Nr-Invalid indexing mode. Accepts: None, 'faces')r r _computeUnindexedVertexesr Exceptionr"r s r'r#zMeshData.vertexesqs} ?~%$*F*R..000> !   +38R/3~djjll/K,/ /KLL Lr)Tc |/|%tj|tj|_d|_nD|dkr/d|_|%tj|tj|_nt d|r|dSdS)a. Set the array (Nv, 3) of vertex coordinates. If indexed=='faces', then the data must have shape (Nf, 3, 3) and is assumed to be already indexed as a list of faces. This will cause any pre-existing normal vectors to be cleared unless resetNormals=False. Ndtyperr1)npascontiguousarrayfloat32r r r3r/)r"vertsr r/s r'rzMeshData.setVertexess ? !#!5e2:!N!N!N+/D ( ( g  !DN /1/CEQSQ[/\/\/\,KLL L           r)c>d|_d|_d|_d|_dSN)rrrrr+s r'r/zMeshData.resetNormalss(",0) *.'''r)c|jduS)zGReturn True if this object already has vertex positions indexed by faceN)r r+s r'hasFaceIndexedDatazMeshData.hasFaceIndexedDatas+477r)c|jduSr=)r r+s r'hasEdgeIndexedDatazMeshData.hasEdgeIndexedDatas+477r)c>|j|j|jfD]}|dSdS)z9Return True if this data set has vertex color informationNTF)rrrr"vs r'hasVertexColorzMeshData.hasVertexColors7$d&FHhi  A}ttur)c>|j|j|jfD]}|dSdS)z7Return True if this data set has face color informationNTF)rrrrCs r' hasFaceColorzMeshData.hasFaceColors7"D$BDDbc  A}ttur)c|j^|d}tj|dddf|dddfz |dddf|dddfz |_||jS|dkrk|j]tj|jjdddftj}|jddtjddf|dd<||_|jStd ) z Return an array (Nf, 3) of normal vectors for each face. If indexed='faces', then instead return an indexed array (Nf, 3, 3) (this is just the same array with each vector copied three times). Nrr rrr6r1) rr#r8crossremptyshaper:newaxisr3)r"r rDnormss r' faceNormalszMeshData.faceNormalss   $ g ..A "111Q3!!!A#!!!A#q1v F FD  ?$ $   .6$"3"9!"+?rz"R"R"RD  4Q 788 3 3!&)u::??29D'/!%(yyay((q ,,.2#F++ ?& &   &tzz||4 4KLL Lr)c||jS|dkr2|j$|j||_|jStd)z Return an array (Nv, 4) of vertex colors. If indexed=='faces', then instead return an indexed array (Nf, 3, 4). Nrr1)rrrr3r4s r'r%zMeshData.vertexColorssV ?% %   /7373Edjjll3S03 3KLL Lr)c|.tj|tj|_d|_dS|dkr.d|_tj|tj|_dSt d)z Set the vertex color array (Nv, 4). If indexed=='faces', then the array will be interpreted as indexed and should have shape (Nf, 3, 4) Nr6rr1)r8r9r:rrr3r"colorsr s r'rzMeshData.setVertexColorssu ?!#!5fBJ!O!O!OD /3D , , ,   !%D /1/CFRTR\/]/]/]D , , ,KLL Lr)c(||jS|dkru|jg|j`|jjd}tj|ddf|jj|_|j|dd|jdd<|jStd) z Return an array (Nf, 4) of face colors. If indexed=='faces', then instead return an indexed array (Nf, 3, 4) (note this is just the same array with each color repeated three times). NrrrJr6rIr1)rrrMr8rLr7reshaper3)r"r Nfs r'r&zMeshData.faceColorss ?# #   -5$:J:V%+A.132q!*DL\Lb1c1c1c.484D4L4LRQRTU4V4V.qqq11 1KLL Lr)c|.tj|tj|_d|_dS|dkr.d|_tj|tj|_dSt d)z Set the face color array (Nf, 4). If indexed=='faces', then the array will be interpreted as indexed and should have shape (Nf, 3, 4) Nr6rr1)r8r9r:rrr3r^s r'r zMeshData.setFaceColorssu ?!3F"*MMMD -1D * * *   #D -/-A&PRPZ-[-[-[D * * *KLL Lr)cj|j|jjdS|j|jjdSdS)z9 Return the number of faces in the mesh. Nr)rrMr r+s r' faceCountzMeshData.faceCount#s> ; ";$Q' '  ) 5/5a8 86 5r)c|jSr=)rr+s r' edgeColorszMeshData.edgeColors,s r)c|j}i}tj|jddtj|_g|_g|_d|_d|_ t|jdD]}||}t|jdD]}||}td|D}| |d}|P|j ||j gt|jdz }|||<|j| |||j||f<tj|jtj|_dS)Nrr6rc2g|]}t|dzS)gļB)round).0xs r' z6MeshData._computeUnindexedVertexes..Ds"777qU1T6]]777r)rI)r r8rLrMuintrr rrrrTtuplegetappendrUarrayr:) r"rr;ifacejptpt2indexs r'r2z"MeshData._computeUnindexedVertexes4sp ,hu{2A2bg>>>  "u{1~&& ) )A8D4:a=)) ) )!W77B77788 #t,,=N))"---%,,R000//1E!&E#J!%(//222#( AaC   )$. CCCr)c@|jdtt|D|_t|jjdD]4}|j|}|D]"}|j||#5|jS)zf Return list mapping each vertex index to a list of face indexes that use the vertex. Ncg|]}gSr|)rlrts r'rnz(MeshData.vertexFaces.._s I I I I I Ir)r)rrTrUr#rrMrr)r"rtruinds r'rSzMeshData.vertexFacesZs   $ I IU3t}}3G3G-H-H I I ID 4;,Q/00 5 5{1~55C%c*11!44445  r)cP|s#t|j}tj|dzdtjdfg}|jddddf|dd|<|jddddf|d|d|z<|jdddf|d| ddf<|jdddf|d| ddf<|ddddf|ddddfk}|d|dddddf|d|<tj|d|_dS|j|j}tj|j dddftj}|j d}tj |dz|ddddf<|ddddfdz|ddddf<|ddddf|ddddf<|ddddfdz|ddddf<|ddddf|ddddf<|ddddf|ddddf<||_dStd) NrJrtrr6rrIz6MeshData cannot generate edges--no faces in this data.) r?rUrr8rLrouniquerr rMaranger3)r"nfr$maskr;s r'r-zMeshData._computeEdgesss&&(( VT[!!BHRT3*;)<===E#{111RaR40E#Jqt "&+aaa!e"4E#Jr!B$w !%QQQqS!1E#JsttAv !%QQQqS!1E#JsttAv :aaac?U3Z!_4D$Sz$/$$B$7E#Jt )E**3/DKKK  ) 50EHek!na327CCCEQB9R==1,E!!!Aa%L 1Q.s(:::qqq))*:::r)) picklerrrrrrrdictdumps)r"rnamesstates` r'savez MeshData.saves ; " (+EE./E   ) LL ) ) ) )  - 9 LL6 7 7 7   ' LL ' ' ' '  + 7 LL4 5 5 5::::E:::;;||E"""r)cVddl}||}|D]}t||trXt||dtjrd||D||<t j||||<t||||dS)z9Restore the state of a mesh previously saved using save()rNcg|]=}|||g>Sr|)rmyz)rlrDs r'rnz$MeshData.restore..s7HHH!qssuu 5HHHr)) rloads isinstancelistr QVector3Dr8rssetattr)r"rrks r'restorezMeshData.restores  U## ' 'A%(D)) .eAhqk5?;;IHHuQxHHHE!H8E!H--a D!U1X & & & &  ' 'r)?ctj|dz|dft}tj|dztjz|z |dzd}|tj|z}|tj|z|d<tj|dztjz|z d|}|rA|tj|z tj|dz|dzdzz}|tj|z|d<|tj|z|d<||dz|zd|dz |dz }tj||zdzdftj}tj||dtj gdgz|ztj d d |ggz} tj||dtj gd gz|ztj |d |ggz} t|D]0} | |zdz} | | |zz|| | |z<| | |zz|| |z| |dzz<1||| }|dz } | ||| k<|| z}|j d dz }||||k<t|| S) zn Return a MeshData instance with vertexes and faces computed for a spherical surface. rIrJr6.rr.r.rIrrIrrrrIrIr#r) r8rLfloatrpirbsincosrorsrTrMr)rowscolsradiusoffsetr;phisthr rowtemplate1 rowtemplate2rowstartvminvmaxs r'spherezMeshData.spheres $q&$*%888ya  25(4/88aCC RVC[[ s +e y"RU*T1::1dCC  M  $q&(9(9(A(A$q&(K(KKLB26"::~e 26"::~e  tAvtmQ//Qay0@A$t)A+q)999400q99BHiii[rsaq5q5q5q5q5vq5q5q5q5q5r)