Blender V2.61 - r43446
|
00001 00004 // Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be> 00005 00006 // Version: 1.0 00007 // Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be> 00008 // Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be> 00009 // URL: http://www.orocos.org/kdl 00010 00011 // This library is free software; you can redistribute it and/or 00012 // modify it under the terms of the GNU Lesser General Public 00013 // License as published by the Free Software Foundation; either 00014 // version 2.1 of the License, or (at your option) any later version. 00015 00016 // This library is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 // Lesser General Public License for more details. 00020 00021 // You should have received a copy of the GNU Lesser General Public 00022 // License along with this library; if not, write to the Free Software 00023 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 #include "jntarray.hpp" 00026 00027 namespace KDL 00028 { 00029 JntArray::JntArray(): 00030 size(0), 00031 data(NULL) 00032 { 00033 } 00034 00035 JntArray::JntArray(unsigned int _size): 00036 size(_size) 00037 { 00038 assert(0 < size); 00039 data = new double[size]; 00040 SetToZero(*this); 00041 } 00042 00043 00044 JntArray::JntArray(const JntArray& arg): 00045 size(arg.size) 00046 { 00047 data = ((0 < size) ? new double[size] : NULL); 00048 for(unsigned int i=0;i<size;i++) 00049 data[i]=arg.data[i]; 00050 } 00051 00052 JntArray& JntArray::operator = (const JntArray& arg) 00053 { 00054 assert(size==arg.size); 00055 for(unsigned int i=0;i<size;i++) 00056 data[i]=arg.data[i]; 00057 return *this; 00058 } 00059 00060 00061 JntArray::~JntArray() 00062 { 00063 delete [] data; 00064 } 00065 00066 void JntArray::resize(unsigned int newSize) 00067 { 00068 delete [] data; 00069 size = newSize; 00070 data = new double[size]; 00071 SetToZero(*this); 00072 } 00073 00074 double JntArray::operator()(unsigned int i,unsigned int j)const 00075 { 00076 assert(i<size&&j==0); 00077 assert(0 != size); // found JntArray containing no data 00078 return data[i]; 00079 } 00080 00081 double& JntArray::operator()(unsigned int i,unsigned int j) 00082 { 00083 assert(i<size&&j==0); 00084 assert(0 != size); // found JntArray containing no data 00085 return data[i]; 00086 } 00087 00088 unsigned int JntArray::rows()const 00089 { 00090 return size; 00091 } 00092 00093 unsigned int JntArray::columns()const 00094 { 00095 return 0; 00096 } 00097 00098 void Add(const JntArray& src1,const JntArray& src2,JntArray& dest) 00099 { 00100 assert(src1.size==src2.size&&src1.size==dest.size); 00101 for(unsigned int i=0;i<dest.size;i++) 00102 dest.data[i]=src1.data[i]+src2.data[i]; 00103 } 00104 00105 void Subtract(const JntArray& src1,const JntArray& src2,JntArray& dest) 00106 { 00107 assert(src1.size==src2.size&&src1.size==dest.size); 00108 for(unsigned int i=0;i<dest.size;i++) 00109 dest.data[i]=src1.data[i]-src2.data[i]; 00110 } 00111 00112 void Multiply(const JntArray& src,const double& factor,JntArray& dest) 00113 { 00114 assert(src.size==dest.size); 00115 for(unsigned int i=0;i<dest.size;i++) 00116 dest.data[i]=factor*src.data[i]; 00117 } 00118 00119 void Divide(const JntArray& src,const double& factor,JntArray& dest) 00120 { 00121 assert(src.rows()==dest.size); 00122 for(unsigned int i=0;i<dest.size;i++) 00123 dest.data[i]=src.data[i]/factor; 00124 } 00125 00126 void MultiplyJacobian(const Jacobian& jac, const JntArray& src, Twist& dest) 00127 { 00128 assert(jac.columns()==src.size); 00129 SetToZero(dest); 00130 for(unsigned int i=0;i<6;i++) 00131 for(unsigned int j=0;j<src.size;j++) 00132 dest(i)+=jac(i,j)*src.data[j]; 00133 } 00134 00135 void SetToZero(JntArray& array) 00136 { 00137 for(unsigned int i=0;i<array.size;i++) 00138 array.data[i]=0; 00139 } 00140 00141 bool Equal(const JntArray& src1, const JntArray& src2,double eps) 00142 { 00143 assert(src1.size==src2.size); 00144 bool ret = true; 00145 for(unsigned int i=0;i<src1.size;i++) 00146 ret = ret && Equal(src1.data[i],src2.data[i],eps); 00147 return ret; 00148 } 00149 00150 bool operator==(const JntArray& src1,const JntArray& src2){return Equal(src1,src2);}; 00151 //bool operator!=(const JntArray& src1,const JntArray& src2){return Equal(src1,src2);}; 00152 00153 } 00154 00155