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