示例#1
0
void compareMotionTables(const TimeSeriesTable& report,
                         const TimeSeriesTable& standard)
{
    ASSERT(report.getNumRows() == standard.getNumRows());
    ASSERT(report.getNumColumns() == standard.getNumColumns());

    auto reportLabels = report.getColumnLabels();
    auto stdLabels = standard.getColumnLabels();

    std::vector<int> mapStdToReport;
    // cycle through the coordinates in the model order and store the
    // corresponding column index in the table according to column name
    for (auto& label : reportLabels) {
        int index = -1;
        auto found = std::find(stdLabels.begin(), stdLabels.end(), label);
        if (found != stdLabels.end()) {
            // skip any pelvis translations
            if (found->find("pelvis_t") == std::string::npos) {
                index = (int)std::distance(stdLabels.begin(), found);
            }
        }
        mapStdToReport.push_back(index);
    }

    size_t nt = report.getNumRows();

    //For simplicity, we ignore pelvis coordinates 0-5
    for (size_t i = 0; i < mapStdToReport.size(); ++i) {
        if (mapStdToReport[i] >= 0) {
            auto repVec = report.getDependentColumnAtIndex(i);
            auto stdVec = standard.getDependentColumnAtIndex(mapStdToReport[i]);
            auto error = SimTK::Real(SimTK_RTD)*repVec - stdVec;
            cout << "Column '" << reportLabels[i] << "' has RMSE = "
                << sqrt(error.normSqr() / nt) << "degrees" << endl;
            SimTK_ASSERT1_ALWAYS((sqrt(error.normSqr() / nt) < 0.1),
                "Column '%s' FAILED to meet accuracy of 0.1 degree RMS.",
                reportLabels[i].c_str());
        }
    }
}
void tableAndTrajectoryMatch(const Model& model,
                             const TimeSeriesTable& table,
                             const StatesTrajectory& states,
                             std::vector<std::string> columns = {}) {

    const auto stateNames = model.getStateVariableNames();

    size_t numColumns{};
    if (columns.empty()) {
        numColumns = stateNames.getSize();
    } else {
        numColumns = columns.size();
    }
    SimTK_TEST(table.getNumColumns() == numColumns);
    SimTK_TEST(table.getNumRows() == states.getSize());

    const auto& colNames = table.getColumnLabels();

    // Test that the data table has exactly the same numbers.
    for (size_t itime = 0; itime < states.getSize(); ++itime) {
        // Test time.
        SimTK_TEST(table.getIndependentColumn()[itime] ==
                   states[itime].getTime());

        // Test state values.
        for (size_t icol = 0; icol < table.getNumColumns(); ++icol) {
            const auto& stateName = colNames[icol];

            const auto& valueInStates = model.getStateVariableValue(
                    states[itime], stateName);
            const auto& column = table.getDependentColumnAtIndex(icol);
            const auto& valueInTable = column[static_cast<int>(itime)];

            SimTK_TEST(valueInStates == valueInTable);
        }
    }
}