SampleData.h 2.56 KB
Newer Older
1 2 3 4
#ifndef _RDL_BENCHMARK_SAMPLE_DATA_H__
#define _RDL_BENCHMARK_SAMPLE_DATA_H__

#include "rdl_dynamics/rdl_eigenmath.h"
5

6 7 8 9
struct SampleData
{
    SampleData() : count(0), q(NULL), qdot(NULL), qddot(NULL), tau(NULL)
    {
10
    }
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

    ~SampleData()
    {
        deleteData();
    }

    SampleData(const SampleData &data)
    {
        count = data.count;

        q = new RobotDynamics::Math::VectorNd[count];
        qdot = new RobotDynamics::Math::VectorNd[count];
        qddot = new RobotDynamics::Math::VectorNd[count];
        tau = new RobotDynamics::Math::VectorNd[count];

        for(int si = 0; si < count; si++)
        {
            q[si] = data.q[si];
            qdot[si] = data.qdot[si];
            qddot[si] = data.qddot[si];
            tau[si] = data.tau[si];
        }
    }

    SampleData &operator=(const SampleData &data)
    {
        if(this != &data)
        {
            deleteData();
            *this = SampleData(data);
        }
        return *this;
    }

    unsigned int count;
    RobotDynamics::Math::VectorNd *q;
    RobotDynamics::Math::VectorNd *qdot;
    RobotDynamics::Math::VectorNd *qddot;
    RobotDynamics::Math::VectorNd *tau;

    void deleteData()
    {
        count = 0;

        if(q)
        {
            delete[] q;
        }
        q = NULL;

        if(qdot)
        {
            delete[] qdot;
        }
        qdot = NULL;

        if(qddot)
        {
            delete[] qddot;
        }
        qddot = NULL;

        if(tau)
        {
            delete[] tau;
        }
        tau = NULL;
78
    }
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

    void fillRandom(int dof_count, int sample_count)
    {
        deleteData();
        count = sample_count;

        q = new RobotDynamics::Math::VectorNd[count];
        qdot = new RobotDynamics::Math::VectorNd[count];
        qddot = new RobotDynamics::Math::VectorNd[count];
        tau = new RobotDynamics::Math::VectorNd[count];

        for(int si = 0; si < count; si++)
        {
            q[si].resize(dof_count);
            qdot[si].resize(dof_count);
            qddot[si].resize(dof_count);
            tau[si].resize(dof_count);

            for(int i = 0; i < dof_count; i++)
            {
                q[si][i] = (static_cast<double>(rand()) / static_cast<double>(RAND_MAX)) * 2. - 1.;
                qdot[si][i] = (static_cast<double>(rand()) / static_cast<double>(RAND_MAX)) * 2. - 1.;
                qddot[si][i] = (static_cast<double>(rand()) / static_cast<double>(RAND_MAX)) * 2. - 1.;
                tau[si][i] = (static_cast<double>(rand()) / static_cast<double>(RAND_MAX)) * 2. - 1.;
            }
        }
105 106 107 108
    }
};

#endif