saelly Posted April 6, 2014 Share Posted April 6, 2014 (edited) node = hou.pwd() geo = hou.pwd().geometry() for p in geo.points(): npole = hou.Vector3(node.parmTuple('north_pole').eval()) pos = hou.Vector3(p.position()) print pos - npole ============================================================ "pos - npole" (vector subtraction) To replace this code with a "numpy", what should I do? (no for loop) help me plz.. Edited April 6, 2014 by saelly Quote Link to comment Share on other sites More sharing options...
ali Posted April 6, 2014 Share Posted April 6, 2014 (edited) import numpy node = hou.pwd() geo = node.geometry() # Add code to modify contents of geo. # Use drop down menu to select examples. #get array of all points attr "P" as string buffer... string_buffer = geo.pointFloatAttribValuesAsString("P", float_type=hou.numericData.Float32) #create numpy array from our string buffer... array_of_pos = numpy.fromstring(string_buffer, dtype='float32' ).reshape(-1, 3) # and reshape to make it 2dimentional (array of vectors) # doing something with your array... (google the numpy broadcast rules) array_of_pos -= (20, 4, 2) #per-element operation #and then you need to copy your numpy array back to points attr "P" geo.setPointFloatAttribValuesFromString("P", numpy.getbuffer(array_of_pos), float_type=hou.numericData.Float32) # WORKED (h13)! Edited April 6, 2014 by ali Quote Link to comment Share on other sites More sharing options...
saelly Posted April 7, 2014 Author Share Posted April 7, 2014 import numpy node = hou.pwd() geo = node.geometry() # Add code to modify contents of geo. # Use drop down menu to select examples. #get array of all points attr "P" as string buffer... string_buffer = geo.pointFloatAttribValuesAsString("P", float_type=hou.numericData.Float32) #create numpy array from our string buffer... array_of_pos = numpy.fromstring(string_buffer, dtype='float32' ).reshape(-1, 3) # and reshape to make it 2dimentional (array of vectors) # doing something with your array... (google the numpy broadcast rules) array_of_pos -= (20, 4, 2) #per-element operation #and then you need to copy your numpy array back to points attr "P" geo.setPointFloatAttribValuesFromString("P", numpy.getbuffer(array_of_pos), float_type=hou.numericData.Float32) # WORKED (h13)! Thank you peon!!! thanks a lot~^^ Have a nice day~!!! Quote Link to comment Share on other sites More sharing options...
freaq Posted April 9, 2014 Share Posted April 9, 2014 what is your reason of moving to numpy btw? does it deliver better performance? or operations not available in Houdini? Quote Link to comment Share on other sites More sharing options...
saelly Posted April 16, 2014 Author Share Posted April 16, 2014 what is your reason of moving to numpy btw? does it deliver better performance? or operations not available in Houdini? numpy module is high performance Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.