All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends

taylor_matrix.cpp

00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 
00037 #include "fcl/ccd/taylor_matrix.h"
00038 
00039 namespace fcl
00040 {
00041 
00042 TMatrix3::TMatrix3()
00043 {
00044 }
00045 
00046 TMatrix3::TMatrix3(const boost::shared_ptr<TimeInterval>& time_interval)
00047 {
00048   setTimeInterval(time_interval);
00049 }
00050 
00051 TMatrix3::TMatrix3(TaylorModel m[3][3])
00052 {
00053   v_[0] = TVector3(m[0]);
00054   v_[1] = TVector3(m[1]);
00055   v_[2] = TVector3(m[2]);
00056 }
00057 
00058 TMatrix3::TMatrix3(const TVector3& v1, const TVector3& v2, const TVector3& v3)
00059 {
00060   v_[0] = v1;
00061   v_[1] = v2;
00062   v_[2] = v3;
00063 }
00064 
00065 
00066 TMatrix3::TMatrix3(const Matrix3f& m, const boost::shared_ptr<TimeInterval>& time_interval)
00067 {
00068   v_[0] = TVector3(m.getRow(0), time_interval);
00069   v_[1] = TVector3(m.getRow(1), time_interval);
00070   v_[2] = TVector3(m.getRow(2), time_interval);
00071 }
00072 
00073 void TMatrix3::setIdentity()
00074 {
00075   setZero();
00076   v_[0][0].coeffs_[0] = 1;
00077   v_[1][1].coeffs_[0] = 1;
00078   v_[2][2].coeffs_[0] = 1;
00079 
00080 }
00081 
00082 void TMatrix3::setZero()
00083 {
00084   v_[0].setZero();
00085   v_[1].setZero();
00086   v_[2].setZero();
00087 }
00088 
00089 TVector3 TMatrix3::getColumn(size_t i) const
00090 {
00091   return TVector3(v_[0][i], v_[1][i], v_[2][i]);
00092 }
00093 
00094 const TVector3& TMatrix3::getRow(size_t i) const
00095 {
00096   return v_[i];
00097 }
00098 
00099 const TaylorModel& TMatrix3::operator () (size_t i, size_t j) const
00100 {
00101   return v_[i][j];
00102 }
00103 
00104 TaylorModel& TMatrix3::operator () (size_t i, size_t j)
00105 {
00106   return v_[i][j];
00107 }
00108 
00109 TMatrix3 TMatrix3::operator * (const Matrix3f& m) const
00110 {
00111   const Vec3f& mc0 = m.getColumn(0);
00112   const Vec3f& mc1 = m.getColumn(1);
00113   const Vec3f& mc2 = m.getColumn(2);
00114 
00115   return TMatrix3(TVector3(v_[0].dot(mc0), v_[0].dot(mc1), v_[0].dot(mc2)),
00116                   TVector3(v_[1].dot(mc0), v_[1].dot(mc1), v_[1].dot(mc2)),
00117                   TVector3(v_[2].dot(mc0), v_[2].dot(mc1), v_[2].dot(mc2)));
00118 }
00119 
00120 
00121 TVector3 TMatrix3::operator * (const Vec3f& v) const
00122 {
00123   return TVector3(v_[0].dot(v), v_[1].dot(v), v_[2].dot(v));
00124 }
00125 
00126 TVector3 TMatrix3::operator * (const TVector3& v) const
00127 {
00128   return TVector3(v_[0].dot(v), v_[1].dot(v), v_[2].dot(v));
00129 }
00130 
00131 TMatrix3 TMatrix3::operator * (const TMatrix3& m) const
00132 {
00133   const TVector3& mc0 = m.getColumn(0);
00134   const TVector3& mc1 = m.getColumn(1);
00135   const TVector3& mc2 = m.getColumn(2);
00136 
00137   return TMatrix3(TVector3(v_[0].dot(mc0), v_[0].dot(mc1), v_[0].dot(mc2)),
00138                   TVector3(v_[1].dot(mc0), v_[1].dot(mc1), v_[1].dot(mc2)),
00139                   TVector3(v_[2].dot(mc0), v_[2].dot(mc1), v_[2].dot(mc2)));
00140 }
00141 
00142 TMatrix3 TMatrix3::operator * (const TaylorModel& d) const
00143 {
00144   return TMatrix3(v_[0] * d, v_[1] * d, v_[2] * d);
00145 }
00146 
00147 TMatrix3 TMatrix3::operator * (FCL_REAL d) const
00148 {
00149   return TMatrix3(v_[0] * d, v_[1] * d, v_[2] * d);
00150 }
00151 
00152 
00153 TMatrix3& TMatrix3::operator *= (const Matrix3f& m)
00154 {
00155   const Vec3f& mc0 = m.getColumn(0);
00156   const Vec3f& mc1 = m.getColumn(1);
00157   const Vec3f& mc2 = m.getColumn(2);
00158   
00159   v_[0] = TVector3(v_[0].dot(mc0), v_[0].dot(mc1), v_[0].dot(mc2));
00160   v_[1] = TVector3(v_[1].dot(mc0), v_[1].dot(mc1), v_[1].dot(mc2));
00161   v_[2] = TVector3(v_[2].dot(mc0), v_[2].dot(mc1), v_[2].dot(mc2));
00162   return *this;
00163 }
00164 
00165 TMatrix3& TMatrix3::operator *= (const TMatrix3& m)
00166 {
00167   const TVector3& mc0 = m.getColumn(0);
00168   const TVector3& mc1 = m.getColumn(1);
00169   const TVector3& mc2 = m.getColumn(2);
00170   
00171   v_[0] = TVector3(v_[0].dot(mc0), v_[0].dot(mc1), v_[0].dot(mc2));
00172   v_[1] = TVector3(v_[1].dot(mc0), v_[1].dot(mc1), v_[1].dot(mc2));
00173   v_[2] = TVector3(v_[2].dot(mc0), v_[2].dot(mc1), v_[2].dot(mc2));
00174   return *this;
00175 }
00176 
00177 TMatrix3& TMatrix3::operator *= (const TaylorModel& d)
00178 {
00179   v_[0] *= d;
00180   v_[1] *= d;
00181   v_[2] *= d;
00182   return *this;
00183 }
00184 
00185 TMatrix3& TMatrix3::operator *= (FCL_REAL d)
00186 {
00187   v_[0] *= d;
00188   v_[1] *= d;
00189   v_[2] *= d;
00190   return *this;
00191 }
00192 
00193 TMatrix3 TMatrix3::operator + (const TMatrix3& m) const
00194 {
00195   return TMatrix3(v_[0] + m.v_[0], v_[1] + m.v_[1], v_[2] + m.v_[2]);
00196 }
00197 
00198 TMatrix3& TMatrix3::operator += (const TMatrix3& m)
00199 {
00200   v_[0] += m.v_[0];
00201   v_[1] += m.v_[1];
00202   v_[2] += m.v_[2];
00203   return *this;
00204 }
00205 
00206 TMatrix3 TMatrix3::operator - (const TMatrix3& m) const
00207 {
00208   return TMatrix3(v_[0] - m.v_[0], v_[1] - m.v_[1], v_[2] - m.v_[2]);
00209 }
00210 
00211 TMatrix3& TMatrix3::operator -= (const TMatrix3& m)
00212 {
00213   v_[0] -= m.v_[0];
00214   v_[1] -= m.v_[1];
00215   v_[2] -= m.v_[2];
00216   return *this;
00217 }
00218 
00219 void TMatrix3::print() const
00220 {
00221   getColumn(0).print();
00222   getColumn(1).print();
00223   getColumn(2).print();
00224 }
00225 
00226 IMatrix3 TMatrix3::getBound() const
00227 {
00228   return IMatrix3(v_[0].getBound(), v_[1].getBound(), v_[2].getBound());
00229 }
00230 
00231 FCL_REAL TMatrix3::diameter() const
00232 {
00233   FCL_REAL d = 0;
00234 
00235   FCL_REAL tmp = v_[0][0].r_.diameter();
00236   if(tmp > d) d = tmp;
00237   tmp = v_[0][1].r_.diameter();
00238   if(tmp > d) d = tmp;
00239   tmp = v_[0][2].r_.diameter();
00240   if(tmp > d) d = tmp;
00241 
00242   tmp = v_[1][0].r_.diameter();
00243   if(tmp > d) d = tmp;
00244   tmp = v_[1][1].r_.diameter();
00245   if(tmp > d) d = tmp;
00246   tmp = v_[1][2].r_.diameter();
00247   if(tmp > d) d = tmp;
00248 
00249   tmp = v_[2][0].r_.diameter();
00250   if(tmp > d) d = tmp;
00251   tmp = v_[2][1].r_.diameter();
00252   if(tmp > d) d = tmp;
00253   tmp = v_[2][2].r_.diameter();
00254   if(tmp > d) d = tmp;
00255 
00256   return d;
00257 }
00258 
00259 void TMatrix3::setTimeInterval(const boost::shared_ptr<TimeInterval>& time_interval)
00260 {
00261   v_[0].setTimeInterval(time_interval);
00262   v_[1].setTimeInterval(time_interval);
00263   v_[2].setTimeInterval(time_interval);
00264 }
00265 
00266 
00267 }