openma
openma copied to clipboard
Importing vertices data from c3d file
I managed to open a file using ma::io::File
class (isOpen
returned true
). I am trying to compehend the list of classes but I am having a hard time to actually import data from this file and store it in some data structure (I need xyz positions (as in plug-in gait) of vertices in each frame).
It seems that data
method returns char array but what's next?
As a first start you can do the following:
#include <openma/base.h>
#include <openma/io.h>
#include <iostream>
// Read your file and store in a Node* data structure
auto root = ma::io::read("your_file.c3d");
// Extract all the time sequences known as a position (a.k.a markers).
positions = root.findChildren<ma::TimeSequence*>("",{{"type",ma::TimeSequence::Position}});
// Loop over the found positions
for (auto position : positions
{
// Print the name
std::cout << position->name() << std::endl;
}
For more information on the content of a ma::TimeSequence
object, you can read its documentation page.
double& data(unsigned sample, std::initializer_list<unsigned>&& indices)
is private. But I changed it to public and it works.
You have also this method template <typename... Is> double& data(unsigned sample, Is... indices) _OPENMA_NOEXCEPT;
.
In your case, the following might be enough:
// ts is a pointer to a TimeSequence object
for (unsigned i = 0, len = ts->samples() ; i < len ; ++i)
{
// Extract each element of the first column (a.k.a X component)
double x = ts->data(i, 0);
// Extract each element of the second column (a.k.a X component)
double y = ts->data(i, 1);
// Extract each element of the third column (a.k.a X component)
double z = ts->data(i, 2);
}
However, be careful with these methods, I do not yet implement unit tests to verify the behaviour.
Depending of your need you can rely directly on the double* data()
method. For example:
// ts is a pointer to a TimeSequence object
auto data = ts->data();
for (unsigned i = 0, len = ts->samples() ; i < len ; ++i)
{
// Extract the each element of the first column (a.k.a X component)
double x = data[i];
// Extract the each element of the second column (a.k.a Y component)
double y = data[i + 1 * len];
// Extract the each element of the third column (a.k.a Z component)
double z = data[i + 2 * len];
}
The last example is faster if you want to iterate through all your data.
I see. I was calling this as pos->data(0, {2});
as I thought I should and this was private method. My first step is to visualize moving markers via OpenGL.
An improvement of the documentation is needed to explain how to retrieve data.