Jump to content

Pyton Optimization


kni8_2k

Recommended Posts

Hi All,

I was just writing a bit of python code that goes through an object and creates a dictionary of attributes and vertex indices.

It works fine for small meshes(under 100k Points, but as you get bigger it inevitably gets slower. I've tracked the majority of the slowness to a couple of lines that is run many times (per vertex)

attribStack[name].append(v.point().attribValue(attr))

indexStack[name].append(v.point().number())

I think this is because of how HOM is accessing the info (or better, how I am accessing the info through HOM)

here is the code block :


attribStack = {}
indexStack = {}


for attr in myGeo.pointAttribs():
if attr is not None:
name = attr.name()
attribStack[name] = []
indexStack[name] = []
attribStack[name].append(str(attr.dataType())+str(attr.size()))
indexStack[name].append(str(attr.dataType())+str(attr.size()))
for prim in myGeo.iterPrims():
for vid in xrange(prim.numVertices()):
# get vertex
v = prim.vertex(vid)
attribStack[name].append(v.point().attribValue(attr))
indexStack[name].append(v.point().number())[/CODE]

The basic things that I need to happen are :

Create a list of values for each attrib

Create a point index on the vertices (for shared data)

Any thoughts on other ways to optimize this bit of code. perhaps I'm missing the obvious answer.

Edited by kni8_2k
Link to comment
Share on other sites

I was recomended to use pointFloatAttribValues by sYmek on the sidefx forum.

Here is a quick implementation.

But I still have the same problem when I am going through vert attributes. (like UVs)




[code]

attribStack = {}
indexStack = {}
vList= []
startb = time.clock()
for attr in myGeo.pointAttribs():
name = attr.name()
attribStack[name] = []
indexStack[name] = []
if str(attr.dataType()) == "attribData.Float":
listPAttrib = myGeo.pointFloatAttribValues(attr.name())
pAttribSize = attr.size()
vindx = 0
for v in vertIndex:
for indx in range(pAttribSize):
attribStack[attr.name()].append(listPAttrib[(v*pAttribSize)+indx])
indexStack[attr.name()].append(vertIndex)
print (time.clock()-startb)
[/CODE]

Edited by kni8_2k
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...