<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from . . ext . six import string_types <EOL> def _fast_cross_3d ( x , y ) : <EOL> """<STR_LIT>""" <EOL> assert x . ndim == <NUM_LIT:2> <EOL> assert y . ndim == <NUM_LIT:2> <EOL> assert x . shape [ <NUM_LIT:1> ] == <NUM_LIT:3> <EOL> assert y . shape [ <NUM_LIT:1> ] == <NUM_LIT:3> <EOL> assert ( x . shape [ <NUM_LIT:0> ] == <NUM_LIT:1> or y . shape [ <NUM_LIT:0> ] == <NUM_LIT:1> ) or x . shape [ <NUM_LIT:0> ] == y . shape [ <NUM_LIT:0> ] <EOL> if max ( [ x . shape [ <NUM_LIT:0> ] , y . shape [ <NUM_LIT:0> ] ] ) >= <NUM_LIT> : <EOL> return np . c_ [ x [ : , <NUM_LIT:1> ] * y [ : , <NUM_LIT:2> ] - x [ : , <NUM_LIT:2> ] * y [ : , <NUM_LIT:1> ] , <EOL> x [ : , <NUM_LIT:2> ] * y [ : , <NUM_LIT:0> ] - x [ : , <NUM_LIT:0> ] * y [ : , <NUM_LIT:2> ] , <EOL> x [ : , <NUM_LIT:0> ] * y [ : , <NUM_LIT:1> ] - x [ : , <NUM_LIT:1> ] * y [ : , <NUM_LIT:0> ] ] <EOL> else : <EOL> return np . cross ( x , y ) <EOL> def _calculate_normals ( rr , tris ) : <EOL> """<STR_LIT>""" <EOL> rr = rr . astype ( np . float64 ) <EOL> r1 = rr [ tris [ : , <NUM_LIT:0> ] , : ] <EOL> r2 = rr [ tris [ : , <NUM_LIT:1> ] , : ] <EOL> r3 = rr [ tris [ : , <NUM_LIT:2> ] , : ] <EOL> tri_nn = _fast_cross_3d ( ( r2 - r1 ) , ( r3 - r1 ) ) <EOL> size = np . sqrt ( np . sum ( tri_nn * tri_nn , axis = <NUM_LIT:1> ) ) <EOL> size [ size == <NUM_LIT:0> ] = <NUM_LIT:1.0> <EOL> tri_nn /= size [ : , np . newaxis ] <EOL> npts = len ( rr ) <EOL> nn = np . zeros ( ( npts , <NUM_LIT:3> ) ) <EOL> for verts in tris . T : <EOL> for idx in range ( <NUM_LIT:3> ) : <EOL> nn [ : , idx ] += np . bincount ( verts . astype ( np . int32 ) , <EOL> tri_nn [ : , idx ] , minlength = npts ) <EOL> size = np . sqrt ( np . sum ( nn * nn , axis = <NUM_LIT:1> ) ) <EOL> size [ size == <NUM_LIT:0> ] = <NUM_LIT:1.0> <EOL> nn /= size [ : , np . newaxis ] <EOL> return nn <EOL> def resize ( image , shape , kind = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> image = np . array ( image , float ) <EOL> shape = np . array ( shape , int ) <EOL> if shape . ndim != <NUM_LIT:1> or shape . size != <NUM_LIT:2> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if image . ndim < <NUM_LIT:2> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if not isinstance ( kind , string_types ) or kind not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> r = np . linspace ( <NUM_LIT:0> , image . shape [ <NUM_LIT:0> ] - <NUM_LIT:1> , shape [ <NUM_LIT:0> ] ) <EOL> c = np . linspace ( <NUM_LIT:0> , image . shape [ <NUM_LIT:1> ] - <NUM_LIT:1> , shape [ <NUM_LIT:1> ] ) <EOL> if kind == '<STR_LIT>' : <EOL> r_0 = np . floor ( r ) . astype ( int ) <EOL> c_0 = np . floor ( c ) . astype ( int ) <EOL> r_1 = r_0 + <NUM_LIT:1> <EOL> c_1 = c_0 + <NUM_LIT:1> <EOL> top = ( r_1 - r ) [ : , np . newaxis ] <EOL> bot = ( r - r_0 ) [ : , np . newaxis ] <EOL> lef = ( c - c_0 ) [ np . newaxis , : ] <EOL> rig = ( c_1 - c ) [ np . newaxis , : ] <EOL> c_1 = np . minimum ( c_1 , image . shape [ <NUM_LIT:1> ] - <NUM_LIT:1> ) <EOL> r_1 = np . minimum ( r_1 , image . shape [ <NUM_LIT:0> ] - <NUM_LIT:1> ) <EOL> for arr in ( top , bot , lef , rig ) : <EOL> arr . shape = arr . shape + ( <NUM_LIT:1> , ) * ( image . ndim - <NUM_LIT:2> ) <EOL> out = top * rig * image [ r_0 ] [ : , c_0 , ... ] <EOL> out += bot * rig * image [ r_1 ] [ : , c_0 , ... ] <EOL> out += top * lef * image [ r_0 ] [ : , c_1 , ... ] <EOL> out += bot * lef * image [ r_1 ] [ : , c_1 , ... ] <EOL> else : <EOL> r = np . round ( r ) . astype ( int ) <EOL> c = np . round ( c ) . astype ( int ) <EOL> out = image [ r ] [ : , c , ... ] <EOL> return out </s>
