openma icon indicating copy to clipboard operation
openma copied to clipboard

Importing vertices data from c3d file

Open mdkdy opened this issue 7 years ago • 5 comments

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?

mdkdy avatar Mar 06 '17 19:03 mdkdy

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.

Alzathar avatar Mar 08 '17 11:03 Alzathar

double& data(unsigned sample, std::initializer_list<unsigned>&& indices) is private. But I changed it to public and it works.

mdkdy avatar Mar 08 '17 16:03 mdkdy

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.

Alzathar avatar Mar 08 '17 16:03 Alzathar

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.

mdkdy avatar Mar 08 '17 16:03 mdkdy

An improvement of the documentation is needed to explain how to retrieve data.

Alzathar avatar Mar 08 '17 16:03 Alzathar