Welcome to mirror list, hosted at ThFree Co, Russian Federation.

jntarray.cpp « kdl « itasc « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e427239e69a042edbd55829a01006278c9971c59 (plain)
1
2
3
4
5
6
7
8
9
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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/** \file itasc/kdl/jntarray.cpp
 * \ingroup itasc
 */
// Copyright  (C)  2007  Ruben Smits <ruben dot smits at mech dot kuleuven dot be>

// Version: 1.0
// Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
// Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
// URL: http://www.orocos.org/kdl

// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

#include "jntarray.hpp"

namespace KDL
{
    JntArray::JntArray():
            size(0),
            data(NULL)
    {
    }

    JntArray::JntArray(unsigned int _size):
        size(_size)
    {
        assert(0 < size);
        data = new double[size];
        SetToZero(*this);
    }


    JntArray::JntArray(const JntArray& arg):
        size(arg.size)
    {
        data = ((0 < size) ? new double[size] : NULL);
        for(unsigned int i=0;i<size;i++)
            data[i]=arg.data[i];
    }

    JntArray& JntArray::operator = (const JntArray& arg)
    {
        assert(size==arg.size);
        for(unsigned int i=0;i<size;i++)
            data[i]=arg.data[i];
        return *this;
    }


    JntArray::~JntArray()
    {
        delete [] data;
    }

    void JntArray::resize(unsigned int newSize)
    {
        delete [] data;
        size = newSize;
        data = new double[size];
        SetToZero(*this);
    }

    double JntArray::operator[](unsigned int i)const
    {
        assert(i<size);
        return data[i];
    }

    double& JntArray::operator[](unsigned int i)
    {
        assert(i<size);
        return data[i];
    }

    double* JntArray::operator()(unsigned int i)
    {
        if (i>=size)
			return NULL;
        return &data[i];
    }

    unsigned int JntArray::rows()const
    {
        return size;
    }

    unsigned int JntArray::columns()const
    {
        return 0;
    }

    void Add(const JntArray& src1,const JntArray& src2,JntArray& dest)
    {
        assert(src1.size==src2.size&&src1.size==dest.size);
        for(unsigned int i=0;i<dest.size;i++)
            dest.data[i]=src1.data[i]+src2.data[i];
    }

    void Subtract(const JntArray& src1,const JntArray& src2,JntArray& dest)
    {
        assert(src1.size==src2.size&&src1.size==dest.size);
        for(unsigned int i=0;i<dest.size;i++)
            dest.data[i]=src1.data[i]-src2.data[i];
    }

    void Multiply(const JntArray& src,const double& factor,JntArray& dest)
    {
        assert(src.size==dest.size);
        for(unsigned int i=0;i<dest.size;i++)
            dest.data[i]=factor*src.data[i];
    }

    void Divide(const JntArray& src,const double& factor,JntArray& dest)
    {
        assert(src.rows()==dest.size);
        for(unsigned int i=0;i<dest.size;i++)
            dest.data[i]=src.data[i]/factor;
    }

    void MultiplyJacobian(const Jacobian& jac, const JntArray& src, Twist& dest)
    {
        assert(jac.columns()==src.size);
        SetToZero(dest);
        for(unsigned int i=0;i<6;i++)
            for(unsigned int j=0;j<src.size;j++)
                dest(i)+=jac(i,j)*src.data[j];
    }

    void SetToZero(JntArray& array)
    {
        for(unsigned int i=0;i<array.size;i++)
            array.data[i]=0;
    }

    bool Equal(const JntArray& src1, const JntArray& src2,double eps)
    {
        assert(src1.size==src2.size);
        bool ret = true;
        for(unsigned int i=0;i<src1.size;i++)
            ret = ret && Equal(src1.data[i],src2.data[i],eps);
        return ret;
    }

    bool operator==(const JntArray& src1,const JntArray& src2){return Equal(src1,src2);};
    //bool operator!=(const JntArray& src1,const JntArray& src2){return Equal(src1,src2);};

}