pyomeca / ezc3d

Easy to use C3D reader/writer for C++, Python and Matlab
https://pyomeca.github.io/Documentation/ezc3d/index.html
MIT License
145 stars 46 forks source link

Opening c3d from filestream instead of filepath #347

Open TrevorAshby opened 1 week ago

TrevorAshby commented 1 week ago

@pariterre Thanks for the great resource that ezc3d is! It's been a huge help in our work. However, we've run into an issue where we are required to load a c3d file from memory that has already been read, meaning that the 2 constructors that exist for the c3d object are insufficient.

Is this feature planned to be added? If we were to go about adding this ourselves, i've identified the following files will need modified:

What other files would I need to modify to include an additional constructor function overload? Thanks again!

pariterre commented 1 week ago

Hi there! I am not sure that I understand what you try to achieve. Do you mean that you have the equivalent of the ezc3d in the memory and you want to effectively copy it? Or, you mean that you have the actual binary loaded in memory and you want to load it into ezc3d?

If it is the former, I think a simple copy of the ezc3d structure would suffice. For the latter, you would need to add a constructor for the full reading path (including header, parameters and data). This should not be hard at all though as a FILE and a memory access are pretty much the same

TrevorAshby commented 1 week ago

Thanks for the quick comment! It is the latter! I have the c3d file loaded as binary in memory, and need to load that into the ezc3d c3d object. I'm fairly new to c3d, and it's been ages since I have done c++, but I think i've gotten close.

Essentially what I will need to do is add a constructor that takes in an fstream and is used in place of the line?

// ezc3d.cpp line 57
std::fstream stream(_filePath, std::ios::in | std::ios::binary);

I should note as well that we are using the python compiled version. My intended use would load the c3d file as a io.Bytes/BufferedReader/Bytes object which will be read into the c3d object.