#NEWLINE# def get_roi( self , roiname ) : #NEWLINE# #INDENT# vts = ( self . tcoords * self . svgshape ) #NEWLINE# all_splines = self . get_splines ( roiname ) #NEWLINE# vts_inside_region = np . zeros ( vts . shape [ 0 ] , dtype = bool ) #NEWLINE# for splines in all_splines : #NEWLINE# #INDENT# x0s = ( ( np . min ( vts [ : , 0 ] ) * 0.98 ) * np . ones ( x0s . shape [ 0 ] ) ) #NEWLINE# beforeSplineRegionX = ( vts [ : , 0 ] < np . min ( [ float ( sp_i . smallestX ( ) ) for sp_i in splines ] ) ) #NEWLINE# beforeSplineRegionY = ( vts [ : , 1 ] < np . min ( [ float ( sp_i . smallestY ( ) ) for sp_i in splines ] ) ) #NEWLINE# afterSplineRegionX = ( vts [ : , 0 ] > np . max ( [ float ( sp_i . biggestX ( ) ) for sp_i in splines ] ) ) #NEWLINE# afterSplineRegionY = ( vts [ : , 1 ] > np . max ( [ float ( sp_i . biggestY ( ) ) for sp_i in splines ] ) ) #NEWLINE# found_vtxs = np . zeros ( vts . shape [ 0 ] , dtype = bool ) #NEWLINE# found_vtxs [ beforeSplineRegionX ] = True #NEWLINE# found_vtxs [ beforeSplineRegionY ] = True #NEWLINE# found_vtxs [ afterSplineRegionX ] = True #NEWLINE# found_vtxs [ afterSplineRegionY ] = True #NEWLINE# vt_isx = np . vstack ( [ x0s , vts [ : , 1 ] ] ) . T #NEWLINE# vtx_is = vt_isx [ ( ~ found_vtxs ) ] #NEWLINE# splines_xs = [ ] #NEWLINE# for i in range ( len ( splines ) ) : #NEWLINE# #INDENT# splines_xs . append ( splines [ i ] . allSplineXGivenY ( vtx_is ) ) #NEWLINE# #UNINDENT# small_vts = vts [ ( ~ found_vtxs ) , : ] #NEWLINE# small_vts_inside_region = vts_inside_region [ ( ~ found_vtxs ) ] #NEWLINE# small_found_vtxs = found_vtxs [ ( ~ found_vtxs ) ] #NEWLINE# while ( sum ( small_found_vtxs ) != len ( small_found_vtxs ) ) : #NEWLINE# #INDENT# closest_xs = ( np . Inf * np . ones ( vtx_is . shape [ 0 ] ) ) #NEWLINE# for i in range ( len ( splines_xs ) ) : #NEWLINE# #INDENT# spline_i_xs = splines_xs [ i ] #NEWLINE# if ( len ( spline_i_xs . shape ) == 1 ) : #NEWLINE# #INDENT# isGreaterThanVtx = ( spline_i_xs > vtx_is [ : , 0 ] ) #NEWLINE# isLessThanClosestX = ( spline_i_xs < closest_xs ) #NEWLINE# closest_xs [ ( isGreaterThanVtx * isLessThanClosestX ) ] = spline_i_xs [ ( isGreaterThanVtx * isLessThanClosestX ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for j in range ( spline_i_xs . shape [ 1 ] ) : #NEWLINE# #INDENT# isGreaterThanVtx = ( spline_i_xs [ : , j ] > vtx_is [ : , 0 ] ) #NEWLINE# isLessThanClosestX = ( spline_i_xs [ : , j ] < closest_xs ) #NEWLINE# closest_xs [ ( isGreaterThanVtx * isLessThanClosestX ) ] = spline_i_xs [ ( ( isGreaterThanVtx * isLessThanClosestX ) , j ) ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# small_found_vtxsx = ( small_vts [ ( ( ~ small_found_vtxs ) , 0 ) ] < closest_xs ) #NEWLINE# small_found_vtxs [ ( ~ small_found_vtxs ) ] = small_found_vtxsx #NEWLINE# small_vts_inside_region [ ( ~ small_found_vtxs ) ] = ( True - small_vts_inside_region [ ( ~ small_found_vtxs ) ] ) #NEWLINE# vtx_is [ ( ( ~ small_found_vtxsx ) , 0 ) ] = closest_xs [ ( ~ small_found_vtxsx ) ] #NEWLINE# vtx_is = vtx_is [ ( ~ small_found_vtxsx ) , : ] #NEWLINE# for i in range ( len ( splines_xs ) ) : #NEWLINE# #INDENT# if ( len ( splines_xs [ i ] . shape ) == 1 ) : #NEWLINE# #INDENT# splines_xs [ i ] = splines_xs [ i ] [ ( ~ small_found_vtxsx ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# splines_xs [ i ] = splines_xs [ i ] [ ( ~ small_found_vtxsx ) , : ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# vts_inside_region [ ( ~ found_vtxs ) ] = small_vts_inside_region #NEWLINE# if ( sum ( vts_inside_region ) == len ( vts_inside_region ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# return np . nonzero ( vts_inside_region ) [ 0 ]