§
    ÊXáj™  ã                   óÂ   — d Z ddlZddlZddlmZ ej                             dd¦  «         ddlZddl	m
Z
 ddlmZ d\  ZZZZZdZd	Zd
ZdZd\  ZZZdZi Zi Zd„ Zdd„ZdS )a›  Prototype (bench only, the package is untouched): thin walls as sheets in the surf slicer's field.

Diagnosis (field_view.py, loaf pan and GSO bowl at 10k): a wall thinner than about a spacing is oriented as one sheet, both
faces with the outer face's normal, so the inner face declares the cavity side of itself inside: the field's inside band
sits beside the wall, not in it, and its zero line wanders and breaks (fragments, C-rings).

Fix: a point is on a thin wall when at least NEED points with a parallel normal (|cos| >= PAR) lie between LO and HI
spacings along its normal and within LAT spacings of its normal line (the wall's other face); the flag then spreads to
points with SPREAD of their SPREAD_K neighbours flagged (SPREAD_ROUNDS times), and groups of fewer than MIN_GROUP connected thin points are dropped. In every layer, within
REACH spacings of the thin points in the slab (|dz| <= SLAB spacings), the field becomes min(field, d - R spacings), d the
distance to those points: the wall's band (R spacings either side of its points) is added to the inside, whatever the
orientation. Replacing the field there instead (MODE "replace") was tried first: the jump at the edge of the replaced
region draws spurious rings (parts doubled even where 0.3 % of the points were flagged).
Elsewhere the field is the package's. The kernels are untouched: the backend's field() is wrapped.

    from thinwall import encode_thinwall
é    N)ÚcKDTreez/home/joao/code/fcp_devel/api)Úhost)ÚPointSlicer)gš™™™™™Ù?ç      ø?g      è?gš™™™™™é?é   gÍÌÌÌÌÌì?r   g      ð?é   )g333333Ó?é   r   Úunionc           	      ó  — t          | ¦  «        }t          j        t          | ¦  «        t          ¦  «        }t          |                     | t          j        t          t          ¦  «        |z  ¦  «        ¦  «        D �]\  }}t          j
        |¦  «        }| |         | |         z
  }|||         z  }t          j                             ||d d …d f         ||         z  z
  d¬¦  «        }	t          j        t          j        |¦  «        t          |z  k    t          j        |¦  «        t          |z  k    z  |	t          |z  k    z  t          j        ||         ||         z  ¦  «        t           k    z  ¦  «        t"          k    ||<   �Œ
|S )Né   )Úaxis)r   ÚnpÚzerosÚlenÚboolÚ	enumerateÚquery_ball_pointÚhypotÚHIÚLATÚasarrayÚlinalgÚnormÚsumÚabsÚLOÚPARÚNEED)
ÚXÚNÚsÚTÚoutÚiÚjsÚDÚoffÚlats
             ú>/home/joao/code/data/meshes/fcp_2710_tests/scripts/thinwall.pyÚ
thin_flagsr*   '   s?  € Ý�‰
Œ
€AÝ
Œ(•3�q‘6”6�4Ñ
 Ô
 €CÝ˜1×-Ò-¨aµ´½"½cÑ1BÔ1BÀQÑ1FÑGÔGÑHÔHð Añ A‰ˆˆ2ÝŒZ˜‰^Œ^ˆØˆbŒE�A�a”D‰LˆØ�!�A”$‰hˆÝŒi�nŠn˜Q  Q Q Q¨ W¤°°!´Ñ!4Ñ4¸1ˆnÑ=Ô=ˆÝ”�œ ™œ­¨Q©Ò.µ2´6¸#±;´;Å"ÀqÁ&Ò3HÑIÈSÕTWÐZ[ÑT[Ê^Ñ\Ýœ6 ! B¤%¨!¨A¬$¡,Ñ/Ô/µ3Ò6ñ8ñ 9ô 9Ý<@òAˆˆA‰‰à€Jó    é€   Úcudac                 ó2  ‡ ‡— t          j        ‰ t          ¦  «        Š t          j        Š|fˆ ˆfd„	}|t          _        	 |dk    r"ddl} |j        ‰ f|||dœ|¤Ž‰t          _        S t          j        ‰ f|||dœ|¤Ž‰t          _        S # ‰t          _        w xY w)zefcp.encode with thin walls as bands in the slicer's field (cuts="pointtest": pointfit.py's cut rule).c                 ó
  •‡‡‡‡— t          | j        ¦  «        Š‰| j        j        z
  | j        j        z  }|                      ¦   «         | j        j        z  }|t          j        t          j         	                    |dd¬¦  «        d¦  «        z  }t          ||‰¦  «        }t          |¦  «                             |t          dz   ¦  «        d         d d …dd …f         }t          t          ¦  «        D ])}|||                              d¦  «        t"          k    z  }Œ*|                     ¦   «         �r"ddlm} ddlm} t          j        |¦  «        d         }	t          ||	         ¦  «                             t2          ‰z  d¬	¦  «        }
t5          |
¦  «        rU |t          j        t5          |
¦  «        ¦  «        |
d d …df         |
d d …df         fft5          |	¦  «        fd
z  ¬¦  «        n& |t5          |	¦  «        t5          |	¦  «        f¦  «        } ||d¬¦  «        \  }}t          j        |¦  «        |         t:          k    }d||	|          <   ||         Št<                               ||                      ¦   «         ¬¦  «         tB                               t          |                     ¦   «         ¦  «        d¬¦  «         | j"        j#        Š‰j$        Šˆˆˆˆfd„}|‰_$        	  ‰| |¦  «        ‰‰_$        S # ‰‰_$        w xY w)Nr   T)r   Úkeepdimsgê-�™—q=r   )Ú
coo_matrix)Úconnected_componentsÚndarray)Úoutput_typer   )ÚshapeF)Údirected)r   Úthin)r7   Úlayersc                 ód  •—  ‰| |||||g|¢R Ž }t          ‰¦  «        s|S t          |¦  «                             t          j        ¦  «        }t          |¦  «        t          |¦  «        t          |¦  «        t          |¦  «        f\  }	}
}}t          |¦  «        D �]Ö}|	|         |	|dz            }}||k    rŒ‰t          j        ‰d d …df         ||df         z
  ¦  «        t          ‰z  k    d d…f         }t          |¦  «        sŒl|
|         \  }}t          j	        t          j
        |¦  «        t          j
        |¦  «        d¬¦  «        \  }}t          j        ||df         |                     ¦   «         |z  z   ||df         |                     ¦   «         |z  z   f         }t          |¦  «                             |t          ‰z  ¬¦  «        d         }t          j        |¦  «        }|                     ¦   «         rs|||…         }t$          dk    r,t          j        ||         ||         t(          ‰z  z
  ¦  «        n||         t(          ‰z  z
  ||<   ||||…<   t*          dxx         dz  cc<   �ŒØ‰j                             |                     t          |¦  «        j        ¦  «        ¦  «        S )	Nr   r   Úij)Úindexingr   )Údistance_upper_boundr
   r8   )r   r   Úastyper   Úfloat64ÚfloatÚranger   ÚSLABÚmeshgridÚarangeÚc_Úravelr   ÚqueryÚREACHÚisfiniteÚanyÚMODEÚminimumÚRÚSTATSÚxpr   Údtype)ÚtotalÚnLÚoff_dÚHW_dÚgeoÚpixÚrestÚfÚfhr'   ÚHWÚgÚpxÚkÚaÚbÚTkÚHÚWÚiiÚjjÚCÚdÚnearÚsegÚBr"   Ú
orig_fieldr!   s                            €€€€r)   Úfieldz.encode_thinwall.<locals>.slices.<locals>.fieldS   sa  ø€ Ø�
˜5 " e¨T°3¸ÐC¸dÐCÐCÐCˆAÝ�q‘6”6ð Ø�Ý�a‘”—’¥¤
Ñ+Ô+ˆBÝ! %™[œ[­$¨t©*¬*µd¸3±i´iÅÀsÁÄÐK‰NˆC��Q˜Ý˜2‘Y”Yð )ñ )�Ø˜1”v˜s 1 q¡5œz�1�Ø˜’6�6ØØ•r”v˜a    1 œg¨¨!¨Q¨$¬Ñ/Ñ0Ô0µD¸1±HÒ<¸b¸q¸bÐ@ÔA�Ý˜2‘w”wð ØØ˜!”u‘��1Ýœ¥R¤Y¨q¡\¤\µ2´9¸Q±<´<È$ÐOÑOÔO‘��BÝ”E˜!˜A˜q˜Dœ' B§H¢H¡J¤J°¡OÑ3°Q°q¸!°t´W¸r¿xºx¹z¼zÈB¹Ñ5NÐNÔO�Ý˜B‘K”K×%Ò% a½eÀa¹iÐ%ÑHÔHÈÔK�Ý”{ 1‘~”~�Ø—8’8‘:”:ð )Ø˜Q˜q˜Sœ'�CÝJNÐRYÊ/È/¥¤
¨3¨t¬9°a¸´gÅÀAÁ±oÑ FÔ FÐ FÐ_`ÐaeÔ_fÕijÐmnÑinÑ_n�C˜‘IØ!�B�q˜�s‘GÝ˜(�O�O”O qÑ(�O�O‘OùØ”4—<’< §	¢	­$¨q©'¬'¬-Ñ 8Ô 8Ñ9Ô9Ð9r+   )%r?   ÚspacingÚposeÚcenterÚrotationÚworld_normalsr   Úmaximumr   r   r*   r   rF   ÚSPREAD_Kr@   ÚSPREAD_ROUNDSÚmeanÚSPREADrI   Úscipy.sparser1   Úscipy.sparse.csgraphr2   ÚnonzeroÚquery_pairsr   r   ÚonesÚbincountÚ	MIN_GROUPÚLASTÚupdateÚcopyrM   Ú_surfrh   rj   )Úselfr8   ÚXmr    r7   ÚnbÚ_r1   r2   ÚtiÚprÚGÚlabÚbigrj   rh   r"   ri   r!   ÚPÚorig_slicess                  @@@@€€r)   Úsliceszencode_thinwall.<locals>.slices9   sç  øøøøø€ Ý�$”,ÑÔˆØ�$”)Ô"Ñ" d¤iÔ&8Ñ8ˆØ×ÒÑ Ô  4¤9Ô#5Ñ5ˆØ	�RŒZ�œ	Ÿš q¨q¸4˜Ñ@Ô@À%ÑHÔHÑHˆÝ˜"˜a Ñ#Ô#ˆÝ�R‰[Œ[×Ò˜r¥8¨a¡<Ñ0Ô0°Ô3°A°A°A°q°r°r°EÔ:ˆÝ•}Ñ%Ô%ð 	7ð 	7ˆAØ˜4 œ8Ÿ=š=¨Ñ+Ô+­vÒ5Ñ6ˆDˆDØ�8Š8‰:Œ:ñ 
	#Ø/Ð/Ð/Ð/Ð/Ð/ØAÐAÐAÐAÐAÐAå”˜DÑ!Ô! !Ô$ˆBÝ˜˜Bœ‘”×,Ò,­R°!©VÀÐ,ÑKÔKˆBÝ^aÐbdÑ^eÔ^eð /�
�
�BœG¥C¨¡G¤GÑ,Ô,¨r°!°!°!°Q°$¬x¸¸A¸A¸A¸q¸D¼Ð.BÐCÍCÐPRÉGÌGÈ:ÐXYÉ>ÐZÑZÔZÐZØ�
�C ™GœG¥S¨¡W¤WÐ-Ñ.Ô.ð à)Ð)¨!°eÐ<Ñ<Ô<‰FˆAˆsÝ”+˜cÑ"Ô" 3Ô'­9Ò4ˆCØ"ˆD��S�D”‰NØˆtŒHˆÝ�Š�b˜tŸyšy™{œ{ˆÑ+Ô+Ð+Ý�Š�% §	¢	¡¤Ñ,Ô,°QˆÑ7Ô7Ð7ØŒJŒLˆØ”Wˆ
ð	:ð 	:ð 	:ð 	:ð 	:ð 	:ð 	:ð 	:ð2 ˆŒð	!Ø�;˜t VÑ,Ô,à ˆAŒGˆGø�jˆAŒGÐ Ð Ð Ð s   Ë&K9 Ë9	LÚ	pointtestr   N)Úupr8   Údevice)	r   r   r?   r   r‹   ÚpointfitÚencode_pointtestÚfcpÚencode)	r‰   r�   r8   rŽ   ÚcutsÚkwr‹   r�   rŠ   s	   `       @r)   Úencode_thinwallr•   4   sÕ   øø€ å
Œ
�1•eÑÔ€AÝÔ$€Kà"ð 7!ð 7!ð 7!ð 7!ð 7!ð 7!ð 7!ðr  …KÔð)Ø�;ÒÐØˆOˆOˆOà,�8Ô,¨QÐZ°2¸fÈVÐZÐZÐWYÐZÐZð )�ÔÐõ Œz˜!ÐG ¨6¸&ÐGÐGÀBÐGÐGà(�ÔÐø˜[�ÔÐ(Ð(Ð(Ð(s   ¾B Á&B ÂB)Nr,   r-   N)Ú__doc__ÚsysÚnumpyr   Úscipy.spatialr   ÚpathÚinsertr‘   Ú
fcp._ringsr   Ú
fcp._slicer   r   r   r   r   r   rL   rG   rA   r{   rt   rq   rr   rJ   rM   r|   r*   r•   © r+   r)   ú<module>rŸ      sî   ððð ð" €
€
€
à Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !à „‡‚�Ð2Ñ 3Ô 3Ð 3Ø 
€
€
€
Ø Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "à/Ñ €€BˆˆS�$Ø€Ø€Ø
€Ø€	Ø",Ñ €ˆ�-Ø€Ø
€Ø	€ð
ð 
ð 
ðF)ð F)ð F)ð F)ð F)ð F)r+   