Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing vertices data from c3d file #76

Open
mdkdy opened this issue Mar 6, 2017 · 5 comments
Open

Importing vertices data from c3d file #76

mdkdy opened this issue Mar 6, 2017 · 5 comments
Assignees
Milestone

Comments

@mdkdy
Copy link

mdkdy commented Mar 6, 2017

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 mdkdy changed the title Importing vertices data from file Importing vertices data from c3d file Mar 6, 2017
@Alzathar Alzathar self-assigned this Mar 8, 2017
@Alzathar Alzathar added this to the 0.1 milestone Mar 8, 2017
@Alzathar
Copy link
Member

Alzathar commented Mar 8, 2017

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.

@mdkdy
Copy link
Author

mdkdy commented Mar 8, 2017

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

@Alzathar
Copy link
Member

Alzathar commented Mar 8, 2017

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.

@mdkdy
Copy link
Author

mdkdy commented Mar 8, 2017

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.

@Alzathar Alzathar added todo and removed bug labels Mar 8, 2017
@Alzathar
Copy link
Member

Alzathar commented Mar 8, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants