Created
January 4, 2013 07:17
-
-
Save mattebb/4450615 to your computer and use it in GitHub Desktop.
swig code to get partio attribute data as a tuple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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