#NEWLINE# def __init__( self , stl_file ) : #NEWLINE# #INDENT# 'given an stl file object, imports points and reshapes array to an\n        array of n_facetsx3 points.' #NEWLINE# if ( not hasattr ( stl_file , 'readline' ) ) : #NEWLINE# #INDENT# stl_file_name = stl_file #NEWLINE# stl_file = open ( stl_file , 'rb' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# stl_file_name = stl_file . name #NEWLINE# #UNINDENT# last_edited = time . ctime ( os . path . getmtime ( stl_file_name ) ) #NEWLINE# h1 = str ( hash ( last_edited ) ) . replace ( '-' , 'n' ) #NEWLINE# h2 = str ( hash ( stl_file_name ) ) . replace ( '-' , 'n' ) #NEWLINE# pkl_file_name = ( '%s_%s.stl_pkl' % ( h1 , h2 ) ) #NEWLINE# pkl_folder = 'pyBspline_pkl' #NEWLINE# pkl_file_name = os . path . join ( pkl_folder , pkl_file_name ) #NEWLINE# if ( not os . path . exists ( pkl_folder ) ) : #NEWLINE# #INDENT# os . mkdir ( pkl_folder ) #NEWLINE# #UNINDENT# if os . path . exists ( pkl_file_name ) : #NEWLINE# #INDENT# ( self . facets , self . stl_i0 , self . stl_i1 , self . p_count , self . stl_indecies , self . stl_i0 , self . points , self . point_indecies , self . triangles ) = cPickle . load ( open ( pkl_file_name ) ) #NEWLINE# return #NEWLINE# #UNINDENT# ascii = ( stl_file . readline ( ) . strip ( ) . split ( ) [ 0 ] == 'solid' ) #NEWLINE# stl_file . seek ( 0 ) #NEWLINE# if ascii : #NEWLINE# #INDENT# self . facets = parse_ascii_stl ( stl_file ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . facets = parse_binary_stl ( stl_file ) #NEWLINE# #UNINDENT# points = [ ] #NEWLINE# stl_indecies = [ ] #NEWLINE# point_indecies = [ ] #NEWLINE# point_locations = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# triangles = [ ] #NEWLINE# column = np . arange ( 3 , 12 , dtype = np . int ) #NEWLINE# row_base = np . ones ( 9 , dtype = np . int ) #NEWLINE# p_count = 0 #NEWLINE# for ( i , facet ) in enumerate ( self . facets ) : #NEWLINE# #INDENT# row = ( row_base * i ) #NEWLINE# ps = facet [ 3 : ] . reshape ( ( 3 , 3 ) ) #NEWLINE# triangle = [ ] #NEWLINE# for p in ps : #NEWLINE# #INDENT# t_p = tuple ( p ) #NEWLINE# try : #NEWLINE# #INDENT# p_index = point_locations [ t_p ] #NEWLINE# point_indecies . append ( p_index ) #NEWLINE# triangle . append ( p_index ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# points . append ( p ) #NEWLINE# point_locations [ t_p ] = p_count #NEWLINE# point_indecies . append ( p_count ) #NEWLINE# triangle . append ( p_count ) #NEWLINE# p_count += 1 #NEWLINE# #UNINDENT# #UNINDENT# triangles . append ( tuple ( triangle ) ) #NEWLINE# index = np . vstack ( ( ( row_base * i ) , column ) ) . T . reshape ( ( 3 , 3 , 2 ) ) #NEWLINE# stl_indecies . extend ( index ) #NEWLINE# #UNINDENT# self . p_count = p_count #NEWLINE# self . stl_indecies = np . array ( stl_indecies ) #NEWLINE# self . stl_i0 = self . stl_indecies [ : , : , 0 ] #NEWLINE# self . stl_i1 = self . stl_indecies [ : , : , 1 ] #NEWLINE# self . points = np . array ( points ) #NEWLINE# self . point_indecies = point_indecies #NEWLINE# self . triangles = np . array ( triangles ) #NEWLINE# pkl_data = ( self . facets , self . stl_i0 , self . stl_i1 , self . p_count , self . stl_indecies , self . stl_i0 , self . points , self . point_indecies , self . triangles ) #NEWLINE# cPickle . dump ( index , open ( pkl_file_name , 'w' ) )