Reading GeomParam attributes from particles archive

32 views
Skip to first unread message

Obeida

unread,
May 31, 2021, 5:06:20 AMMay 31
to alembic-discussion
Hello there,

I wrote some functions allowing to read samples from an alembic particles archive (IPoints) exported from Houdini. When I reach Alembic::AbcGeom::IPoints level and get a sample, I can read particles positions and velocities using getPositions() and getVelocities(). For the attributes, I use getArbGeomParams() and iterate over their properties to read the stored attributes with the particles. These attributes can have different types (float, int, V3f, C3f) and to read them I had to write a block of code per attribute type because of the difference between GeomParam types and ArraySamplePtr types, but these blocks of code are so much similar and I was wondering if there is any way to get these attributes with a single generic code. Is there any way to read attributes without having to know their PlainOldDataType ? The issue is that ther's no generic GeomParam or ArraySamplePtr type to get info from the sample.

 For instance, to read the color attribute I used attribute's name :

// color attrib
if (attribName.compare("Cd") == 0)
{
// attrib data from current sample
Alembic::AbcGeom::IC3fGeomParam clr_prop(arb_params, "Cd");
Alembic::AbcGeom::C3fArraySamplePtr clr_sample;
clr_prop.getValueProperty().get(clr_sample, iss);
sample_t<Alembic::Abc::V3f> clrSampleVec;

// iterate over points and get/push_back info
for (size_t ptnum = 0; ptnum < numPoints; ++ptnum)
{
Alembic::Abc::V3f clr_abc = clr_sample.get()->get()[ptnum];
clrSampleVec.data.push_back(clr_abc);
}
pointsColor.data.push_back(clrSampleVec);
}


And for float attributes, I used it's PlainOldDataType :

if (data_type.getPod() == Alembic::AbcGeom::kFloat32POD)
{
// attrib data from current sample
Alembic::AbcGeom::IFloatGeomParam attrib_prop(arb_params, attribName);
Alembic::AbcGeom::FloatArraySamplePtr attribSample;
attrib_prop.getValueProperty().get(attribSample, iss);

for (size_t ptnum = 0; ptnum < numPoints; ++ptnum)
{
auto attrib_abc = attribSample.get()->get()[ptnum];
attribSampleVec.data.push_back(attrib_abc);
}
}


Cheers,
Obeida

Lucas Miller

unread,
Jun 1, 2021, 11:59:56 AMJun 1
to alembic-d...@googlegroups.com
> Is there any way to read attributes without having to know their PlainOldDataType ?

Yeah, you will have to allocate the buffer yourself, but you can use getAs:

https://github.com/alembic/alembic/blob/master/lib/Alembic/Abc/IArrayProperty.h#L137

> The issue is that ther's no generic GeomParam or ArraySamplePtr type to get info from the sample.

GeomParams are either an IArrayProperty, or if indexed an
ICompoundProperty that contains 2 IArrayProperty, one for the data,
and one for the indices.

You can get a lot of info about the property via it's PropertyHeader,
and there are convenience functions that will let you know if it
matches a more complex type like a C3f, i.e.
Alembic::AbcGeom::IC3fGeomParam::matches(childHeader)

Lucas

Obeida

unread,
Jun 2, 2021, 5:23:36 AMJun 2
to alembic-discussion
Great ! This helps a lot.

Thanks
Reply all
Reply to author
Forward
0 new messages