C3D export

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Mohammadreza Rezaie
Posts: 390
Joined: Fri Nov 24, 2017 12:48 am

C3D export

Post by Mohammadreza Rezaie » Tue Feb 11, 2020 4:21 pm

Dear Experts,

I have a problem in using python for OpenSim 4.1

My Anaconda is for python 2 (anaconda2),
I created a new environment for OpenSim 4.1 with python 3.7
The 4.1\bin folder is on my system path environment.
The codes are exactly the same as "Reading C3D files through Python"
in addition to importing os, opensim and numpy

But this error appears in that code:

(opensim41) C:\Users\MohammadReza\Desktop>python opensim41.py

Traceback (most recent call last):
File "opensim41.py", line 14, in <module>
tables = C3DFileAdapter.readFile(os.path.join(test_dir, 'walking2.c3d'), 1)
NameError: name 'C3DFileAdapter' is not defined

Would you please help me with this code and error?

Your help would be greatly appreciated.

Cheers

Tags:

User avatar
Ayman Habib
Posts: 2238
Joined: Fri Apr 01, 2005 12:24 pm

Re: C3D export

Post by Ayman Habib » Tue Feb 11, 2020 10:33 pm

Hello,

The interface to C3DFileAdapter has changed, please consult the doxygen documentation here for available methods
https://simtk.org/api_docs/opensim/api_ ... apter.html

The class now uses the generic read method from its base class rather than a custom readFile method as of version 4.1

Best regards,
-Ayman

User avatar
Mohammadreza Rezaie
Posts: 390
Joined: Fri Nov 24, 2017 12:48 am

Re: C3D export

Post by Mohammadreza Rezaie » Wed Feb 12, 2020 12:58 am

Hi Aymen,

Many thanks for your reply.
Is there anything wrong with this new code?


import opensim
C3DFileAdapter c3dFileAdapter;
c3dFileAdapter.setLocationForForceExpression(opensim.C3DFileAdapter.ForceLocation_CenterOfPressure);
tables = c3dFileAdapter.read("walking5.c3d")
markers = tables['markers']
forces = tables['forces']



There is still an error:

(opensim41) C:\Users\MohammadReza\Desktop>python opensim41.py
File "opensim41.py", line 2
C3DFileAdapter c3dFileAdapter;
^
SyntaxError: invalid syntax



I execute this code in Anaconda Prompt and this is my python version:

(opensim41) C:\Users\MohammadReza\Desktop>python --version
Python 3.7.6


I'm grateful for your help
Cheers

User avatar
Thomas Uchida
Posts: 1787
Joined: Wed May 16, 2012 11:40 am

Re: C3D export

Post by Thomas Uchida » Wed Feb 12, 2020 1:05 am

It looks like your code is part C++ and part Python. For reference, there's a related test case here: https://github.com/opensim-org/opensim- ... ter.py#L33. You should have something like this:

Code: Select all

import opensim
c3dFileAdapter = opensim.C3DFileAdapter()
...

User avatar
Mohammadreza Rezaie
Posts: 390
Joined: Fri Nov 24, 2017 12:48 am

Re: C3D export

Post by Mohammadreza Rezaie » Wed Feb 12, 2020 1:17 am

tkuchida wrote:
Wed Feb 12, 2020 1:05 am
It looks like your code is part C++ and part Python.
Thanks Tom,

There is an example on doxygen for python:
1.JPG
1.JPG (19.68 KiB) Viewed 468 times
https://simtk.org/api_docs/opensim/api_ ... apter.html

But now it works well

Cheers

User avatar
Thomas Uchida
Posts: 1787
Joined: Wed May 16, 2012 11:40 am

Re: C3D export

Post by Thomas Uchida » Wed Feb 12, 2020 8:14 am

Great. Thanks for reporting- I'll submit a fix.

User avatar
Mohammadreza Rezaie
Posts: 390
Joined: Fri Nov 24, 2017 12:48 am

Re: C3D export

Post by Mohammadreza Rezaie » Wed Feb 12, 2020 1:06 pm

Hi,

It would be great if these examples become updated for 4.1 version as well.

https://simtk-confluence.stanford.edu:8 ... d%29+Files

Best Wishes

User avatar
Thomas Uchida
Posts: 1787
Joined: Wed May 16, 2012 11:40 am

Re: C3D export

Post by Thomas Uchida » Wed Feb 12, 2020 1:14 pm

Thanks for reporting. I've opened an Issue on GitHub (https://github.com/opensim-org/opensim-core/issues/2673) to investigate.

User avatar
Mohammadreza Rezaie
Posts: 390
Joined: Fri Nov 24, 2017 12:48 am

Re: C3D export

Post by Mohammadreza Rezaie » Thu Feb 13, 2020 11:24 am

Hi again,

In MATLAB, "rotateData" and "convertMillimeters2Meters" were defined
but in python, I can't find them. are there any examples of these
functions in python for "forces"?

adapter = opensim.C3DFileAdapter()
task = adapter.read(os.path.join(output_dir, 'task.c3d'))
forces = adapter.getForcesTable(task)

Your response would be greatly appreciated.

Cheers

User avatar
Thomas Uchida
Posts: 1787
Joined: Wed May 16, 2012 11:40 am

Re: C3D export

Post by Thomas Uchida » Fri Feb 14, 2020 8:58 am

rotateData() and convertMillimeters2Meters() are functions written in Matlab (https://github.com/opensim-org/opensim- ... C3D.m#L138 and https://github.com/opensim-org/opensim- ... C3D.m#L154). You can implement them in Python if you need them there.

POST REPLY