MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / readFrame

Function readFrame

Tools/MeshSkinning/main.cpp:570–637  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

568}
569
570bool readFrame(std::vector<Vector3r>& x, const unsigned int frame)
571{
572 std::string fileName = convertFileName(input, frame);
573
574 x.clear();
575 id.clear();
576
577 // check if file exists
578 if (!FileSystem::fileExists(fileName))
579 return false;
580
581 // read partio file
582 Partio::ParticlesDataMutable* data = Partio::read(fileName.c_str());
583 if (!data)
584 return false;
585
586 // find position and id attribute
587 unsigned int posIndex = 0xffffffff;
588 unsigned int idIndex = 0xffffffff;
589 for (int i = 0; i < data->numAttributes(); i++)
590 {
591 Partio::ParticleAttribute attr;
592 data->attributeInfo(i, attr);
593 if (attr.name == "position")
594 posIndex = i;
595 if (attr.name == "id")
596 idIndex = i;
597 }
598
599 // read IDs
600 Partio::ParticleAttribute attr;
601 if (idIndex != 0xffffffff)
602 {
603 id.resize(data->numParticles());
604 data->attributeInfo(idIndex, attr);
605 for (int i = 0; i < data->numParticles(); i++)
606 {
607 const int* id_ = data->data<int>(attr, i);
608 id[i] = id_[0];
609 }
610 }
611
612 // compute the first id since for multiple objects, the ids might not start at 0
613 int firstId = INT_MAX;
614 for (int i = 0; i < id.size(); i++)
615 firstId = std::min(id[i], firstId);
616
617
618 // read positions
619 if (posIndex != 0xffffffff)
620 {
621 x.resize(data->numParticles());
622 data->attributeInfo(posIndex, attr);
623 for (int i = 0; i < data->numParticles(); i++)
624 {
625 const float* pos = data->data<float>(attr, i);
626
627 // use id as index if possible to consider z-sorting in the particle data

Callers 2

performMeshSkinningFunction · 0.85
meshSkinningFunction · 0.85

Calls 9

minFunction · 0.85
numParticlesMethod · 0.80
convertFileNameFunction · 0.70
readFunction · 0.50
clearMethod · 0.45
c_strMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected