C3DFileAdapter is Undefined

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
davide ferrari
Posts: 5
Joined: Fri Nov 24, 2023 8:28 am

C3DFileAdapter is Undefined

Post by davide ferrari » Thu Feb 29, 2024 8:58 am

Hi everyone,
I'm trying to use the C3DFileAdapter class in c++. However it results to be undefined. I'm trying to use the example provided by Opensim at https://simtk-confluence.stanford.edu:8 ... d%29+Files. Does anyone know if I should do something before using that class?
Thanks in advance

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

Re: C3DFileAdapter is Undefined

Post by Ayman Habib » Thu Feb 29, 2024 1:39 pm

Hi Davide,

Within C++, there're some settings and files/directories that need to be included at the top of the source file e.g. OpenSim/OpenSim.h if working with a distribution or the full path OpenSim/Common/C3DFileAdapter.h, and the paths need to be searched by your project build files etc. If you can provide the context/full file(s) and errors/warnings along with which platform/compilers that would be helpful in troubleshooting.

All the best,
-Ayman

User avatar
Nicholas Bianco
Posts: 1014
Joined: Thu Oct 04, 2012 8:09 pm

Re: C3DFileAdapter is Undefined

Post by Nicholas Bianco » Thu Feb 29, 2024 4:08 pm

Hi Davide,

You probably just need to include ezc3d during your build process, C3DFileAdapter will be disabled without it. Make sure to check the box for enabling the ezc3d superbuild in CMake when building the dependencies, and set the variable OPENSIM_C3D_PARSER to 'ezc3d' when building the main OpenSim target.

Best,
Nick

User avatar
davide ferrari
Posts: 5
Joined: Fri Nov 24, 2023 8:28 am

Re: C3DFileAdapter is Undefined

Post by davide ferrari » Tue Mar 05, 2024 7:07 am

aymanh wrote:
Thu Feb 29, 2024 1:39 pm
Hi Davide,

Within C++, there're some settings and files/directories that need to be included at the top of the source file e.g. OpenSim/OpenSim.h if working with a distribution or the full path OpenSim/Common/C3DFileAdapter.h, and the paths need to be searched by your project build files etc. If you can provide the context/full file(s) and errors/warnings along with which platform/compilers that would be helpful in troubleshooting.

All the best,
-Ayman
Thanks for the support.
This is the code:

#include <OpenSim/OpenSim.h>
#include "OpenSim/Common/STOFileAdapter.h"
#include "OpenSim/Common/C3DFileAdapter.h"
#include "OpenSim/Common/TRCFileAdapter.h"

using namespace OpenSim;
using namespace SimTK;
using namespace std;

int main()
{
string c3dFile = "walking.c3d";

C3DFileAdapter c3dFileAdapter{};
auto tables = c3dFileAdapter.read(c3dFile);
std::shared_ptr<TimeSeriesTableVec3> marker_table = c3dFileAdapter.getMarkersTable(tables);
std::shared_ptr<TimeSeriesTableVec3> force_table = c3dFileAdapter.getForcesTable(tables);
std::shared_ptr<TimeSeriesTable> analog_table = c3dFileAdapter.getAnalogDataTable(tables);
string base = "Motion";
const std::string marker_file = base + "_markers.trc";
const std::string forces_file = base + "_grfs.sto";
const std::string analogs_file = base + "_analog.sto";

TRCFileAdapter trc_adapter{};
trc_adapter.write(*marker_table, marker_file);
force_table->updTableMetaData().setValueForKey("Units", std::string{ "mm" });

STOFileAdapter sto_adapter{};
sto_adapter.write((force_table->flatten()), forces_file);
sto_adapter.write(*analog_table, analogs_file);
}





I can't build the project because "identifier "C3DFileAdapter" is undefined".
Looks like C3DFileAdapter is disabled.
Everything else works fine.
Maybe I should change something in Cmake File used to create the project in order to include ezc3d?
This is the actual CMake file:
project(OptimizationExample)

cmake_minimum_required(VERSION 3.2)

# Settings.
# ---------
set(TARGET optimizationExample CACHE TYPE STRING)

# OpenSim uses C++11 language features.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find and hook up to OpenSim.
# ----------------------------
find_package(OpenSim REQUIRED PATHS "${OPENSIM_INSTALL_DIR}")

# Configure this project.
# -----------------------
file(GLOB SOURCE_FILES *.h *.cpp)

add_executable(${TARGET} ${SOURCE_FILES})

target_link_libraries(${TARGET} ${OpenSim_LIBRARIES})

# This block copies the additional files into the running directory
# For example vtp, obj files. Add to the end for more extentions
file(GLOB DATA_FILES *.vtp *.obj *.osim)
foreach(dataFile ${DATA_FILES})
add_custom_command(
TARGET ${TARGET}
COMMAND ${CMAKE_COMMAND}
ARGS -E copy
${dataFile}
${CMAKE_BINARY_DIR})
endforeach(dataFile)


Thanks again,
Davide

User avatar
davide ferrari
Posts: 5
Joined: Fri Nov 24, 2023 8:28 am

Re: C3DFileAdapter is Undefined

Post by davide ferrari » Tue Mar 05, 2024 7:10 am

nbianco wrote:
Thu Feb 29, 2024 4:08 pm
Hi Davide,

You probably just need to include ezc3d during your build process, C3DFileAdapter will be disabled without it. Make sure to check the box for enabling the ezc3d superbuild in CMake when building the dependencies, and set the variable OPENSIM_C3D_PARSER to 'ezc3d' when building the main OpenSim target.

Best,
Nick
Thanks Nicholas,
I'm quite new to programming, so I don't really know what exactly to do in order to include ezc3d during my build process. I couldn't find any box for enabling ezc3d superbuild. Could you help me out with more accurate informations?
Thanks again,
Davide

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

Re: C3DFileAdapter is Undefined

Post by Ayman Habib » Tue Mar 05, 2024 10:16 am

Hi Davide,

I'm not sure why you're trying to build from source rather than use an existing distribution if new to programming, there could be an easier pathway to proceed but what you need to do is:
1. When building the dependencies project, enable the checkbox to SUPERBUILD_ezc3d in CMake.
2. When building opensim-core, set OPENSIM_C3D_PARSER to ezc3d in CMake as well.
I think including OpenSim,h should be enough, and you may not need the other includes.

Hope this helps,
-Ayman

User avatar
davide ferrari
Posts: 5
Joined: Fri Nov 24, 2023 8:28 am

Re: C3DFileAdapter is Undefined

Post by davide ferrari » Wed Mar 06, 2024 2:00 am

aymanh wrote:
Tue Mar 05, 2024 10:16 am
Hi Davide,

I'm not sure why you're trying to build from source rather than use an existing distribution if new to programming, there could be an easier pathway to proceed but what you need to do is:
1. When building the dependencies project, enable the checkbox to SUPERBUILD_ezc3d in CMake.
2. When building opensim-core, set OPENSIM_C3D_PARSER to ezc3d in CMake as well.
I think including OpenSim,h should be enough, and you may not need the other includes.

Hope this helps,
-Ayman
Thanks Ayman.
I'll explain better what I have done.
I've dowloaded Opensim GUI and the two folders, CODE and MODELS, that contain the examples and tutorials. I've not builded Opensim from source.
In CODE folder, there's the CPP folder with all the examples that can be generated with CMAKE. I took the OptimizationExample_Arm26, I generated the solution with CMAKE, and in the main function I removed everything and wrote my own code, that is the one shown in the previous message. I know It may not be the best way to do this stuff, but till now it worked with every OpenSim code that I wrote. However "C3DFileAdapter" results to be undefined. I saw that ezc3d.dll is present in BIN folder of Opensim 4.4. When I generate the solution with CMAKE there's no flag to enable SUPERBUILD_ezc3d.

I've tried to do the same identical stuff with Opensim 4.5. C3DFileAdapter is defined, however, building the project I get this error "Could not open the c3d file: iostream stream error". I've run the code with several c3d file, also some provided by opensim tutorials, but I get the same error.

Hope you can help me :D
Thanks again
Davide

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

Re: C3DFileAdapter is Undefined

Post by Ayman Habib » Wed Mar 06, 2024 7:20 pm

Hi Davide,

Thanks for explaining your workflow.

The header file for C3DFileAdapter is conditionally included, so you may have to define the preprocessor symbol WITH_EZC3D for the compiler.

We probably should define that in our CMakeLists.txt regardless since that's what we do during release, but let's verify first that this fixes your problem.

Best regards,
-Ayman

POST REPLY