Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

base/ParametricPathRep.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)2002 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: ParametricPathRep.cpp 1029 2004-02-11 20:45:54Z jungd $
00019   $Revision: 1.1 $
00020   $Date: 2004-02-11 15:45:54 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #include <base/ParametricPathRep>
00026 
00027 #include <base/Serializer>
00028 
00029 using base::ParametricPathRep;
00030 
00031 using base::Quat4;
00032 
00033 
00034 ParametricPathRep::ParametricPathRep(const ExpressionVector& p)
00035   : v(p), flags(None)
00036 { 
00037   Assert( (p.size() == 3) || (p.size() == 6) || (p.size() == 7) );
00038   if (v.size() != 3)
00039     flags = HasOrient;
00040 }
00041 
00042 
00043 
00044 base::Point3 ParametricPathRep::position(Real s) const
00045 {
00046   Vector param(1);
00047   param[0] = s;
00048   
00049   return Point3( v[0].evaluate(param), v[1].evaluate(param), v[2].evaluate(param) );
00050 }
00051 
00052 
00053 base::Orient ParametricPathRep::orientation(Real s) const
00054 {
00055   if (!(flags & HasOrient))
00056     return Orient();
00057 
00058   Vector param(1);
00059   param[0] = s;
00060 
00061   if (v.size() == 6) // RPY
00062     return Orient( v[3].evaluate(param), v[4].evaluate(param), v[5].evaluate(param) );
00063   else
00064     return Orient( Quat4(v[3].evaluate(param), v[4].evaluate(param), v[5].evaluate(param), v[6].evaluate(param)) );
00065 }
00066 
00067 
00068 Real ParametricPathRep::distinguishedValue(Int i) const
00069 {
00070   Math::bound<Int>(i,0,1); 
00071   return (i==0)?0.0:1.0;
00072 }
00073 
00074 
00075 Int ParametricPathRep::numDistinguishedValues() const
00076 {
00077   return 2;
00078 }
00079 
00080 
00081 
00082 
00083 
00084 
00085 void ParametricPathRep::translate(const Vector3& t)
00086 {
00087   v[0] = v[0] + Expression(t.x); v[0].simplify();
00088   v[1] = v[1] + Expression(t.y); v[1].simplify();
00089   v[2] = v[2] + Expression(t.z); v[2].simplify();
00090 }
00091 
00092 
00093 void ParametricPathRep::rotate(const Quat4& r)
00094 {
00095   if (!(flags & HasOrient)) return;
00096   Unimplemented;
00097 }
00098 
00099 
00100 void ParametricPathRep::transform(const Matrix4& m)
00101 {
00102   ExpressionMatrix em4 = base::toExpressionMatrix(base::fromMatrix4(m));
00103   
00104   // first transform position components
00105   ExpressionVector p(4);
00106   for(Int i=0; i<3; i++) p[i] = v[i]; // get position components
00107   p[3] = Expression(1);
00108 
00109   ExpressionVector tp = em4*p;
00110   
00111   for(Int i=0; i<3; i++) {
00112     tp[i].simplify();
00113     v[i] = tp[i];
00114   }
00115   
00116   
00117   // now transform orientations (if any)
00118   if (flags & HasOrient) {
00119   
00120     ExpressionMatrix em3(3,3); // extract rotation only component
00121     for(Int r=0; r<3; r++)
00122       for(Int c=0; c<3; c++)
00123         em3(r,c) = em4(r,c);
00124   
00125     Assertm(false,"transformations on the orientation components of a parametric path aren't implemented yet.");
00126   
00127   }
00128   
00129 }
00130 
00131 
00132 void ParametricPathRep::scalePosition(Real s)
00133 {
00134   v[0] = v[0] * Expression(s); v[0].simplify();
00135   v[1] = v[1] * Expression(s); v[1].simplify();
00136   v[2] = v[2] * Expression(s); v[2].simplify();
00137 }
00138 
00139 
00140 void ParametricPathRep::serialize(Serializer& s)
00141 {
00142   s(flags,"flags");
00143   Int dim = v.size();
00144   s(dim,"dim");
00145   if (v.size() != dim) v.resize(dim);
00146   for(Int i=0; i<dim; i++)
00147     s(v[i],String("v")+base::intToString(i));
00148 }
00149 

Generated on Thu Jul 29 15:56:08 2004 for OpenSim by doxygen 1.3.6