00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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)
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
00105 ExpressionVector p(4);
00106 for(Int i=0; i<3; i++) p[i] = v[i];
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
00118 if (flags & HasOrient) {
00119
00120 ExpressionMatrix em3(3,3);
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