Skip to content

Instantly share code, notes, and snippets.

@mattebb
Created January 4, 2013 07:17
Show Gist options
  • Save mattebb/4450615 to your computer and use it in GitHub Desktop.
Save mattebb/4450615 to your computer and use it in GitHub Desktop.
swig code to get partio attribute data as a tuple
%feature("autodoc");
%feature("docstring","Gets a single flattened tuple, containing attribute data for all particles");
PyObject* getTuple(const ParticleAttribute& attr)
{
unsigned int numparticles = $self->numParticles();
PyObject* tuple=PyTuple_New(numparticles * attr.count);
if(attr.type==Partio::INT){
for(unsigned int i=0;i<numparticles;i++) {
const int* p=$self->data<int>(attr,i);
for(int k=0;k<attr.count;k++) PyTuple_SetItem(tuple, i*attr.count+k, PyInt_FromLong(p[k]));
}
}else{
for(unsigned int i=0;i<numparticles;i++) {
const float* p=$self->data<float>(attr,i);
for(int k=0;k<attr.count;k++) PyTuple_SetItem(tuple, i*attr.count+k, PyFloat_FromDouble(p[k]));
}
}
return tuple;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment