c3d-utils
count_invalid.cpp

A good starting point for getting acquainted with the library is the following example.

/*
A C3D file contains a number of frames (time steps) and labels.
In every frame a label can either be not present (invalid), measured
(detected by hardware) or generated (e.g., filled in by interpolation).
This program counts those three possibilities and displays the totals for
every label.
*/

#include "uuc3d.hpp"
#include <iostream>

using std::cerr;
using std::vector;
using UuIcsC3d::SpacePaddedString;
using UuIcsC3d::DataPoint3d;

void do_work(std::string filename)
{
    // Open the file and read the header information
    // Will throw OpenError if reading is not possible.
    UuIcsC3d::C3dFileInfo fi(filename);
    // Every frame contains the same number of points.
    int ppf = fi.points_per_frame(); 
    if (ppf <= 0)
        return;
    int fc = fi.frame_count();
    // Get the labels. Not every point needs to have a label name.
    // We add dummy labels if necessary to supply a name for every point.
    vector<SpacePaddedString> labels(fi.point_labels());
    for (int i=labels.size(); i<ppf; ++i) {
        labels.push_back(SpacePaddedString("<no label>"));
    }
    // Declare the vectors that maintain the count for each point (label).
    vector<int> invalid(ppf, 0), generated(ppf, 0), measured(ppf, 0);
    // Open the C3D file
    std::auto_ptr<UuIcsC3d::C3dFile> filep(fi.open());
    // Read every frame in variable frame_data and process it
    UuIcsC3d::FrameData frame_data;
    for (int i=0; i<fc; ++i) {
        filep->get_frame_data(frame_data, i);
        // For every point in the frame record its type
        for (int j=0; j<ppf; ++j) {
            DataPoint3d const &dp=frame_data.points[j];
            switch (dp.status()) {
            case DataPoint3d::Invalid:
                ++invalid[j];
                break;
            case DataPoint3d::Generated:
                ++generated[j];
                break;
            case DataPoint3d::Measured:
                ++measured[j];
                break;
            }
        }
    }
    // report the counts for every label
    for (int i=0; i<ppf; ++i) {
        std::cout <<measured[i]<<"\t"<<generated[i]<<"\t"<<invalid[i]
        <<"\t"<<labels[i].stripped()<<"\n";
    }
}

// The main function checks the number of arguments and deals with exceptions
int main(int argc, char* argv[])
{
    if (argc<2) {
        cerr<<"Expected filename as argument.\n";
        return 1;
    }
    try {
        do_work(argv[1]);
    } catch (UuIcsC3d::OpenError const &err) {
        cerr<<"An error occurred while opening file "<<err.filename();
        return 2;
    }
    return 0;
}

 All Classes Namespaces Files Functions Variables Typedefs Enumerations