#include <OMKTransform.h>
Collaboration diagram for OMK::Type::Transform:
Public Member Functions | |
void | resetToIdentity () |
Sets the transformation to the identity. | |
void | resetUnitScale () |
Sets the scales to 1 in each direction. | |
bool | getOrientation (float &head, float &pitch, float &roll) const |
Get the object orientation using Euler angles. | |
void | setOrientation (float head, float pitch, float roll) |
Set the object orientation using Euler angles. | |
float | getNorm () const |
Gets the norm of the transformation. | |
Wm4::Vector3f | applyForward (const Wm4::Vector3f &input) const |
Applies the transformation to the input vector. | |
std::vector< Wm4::Vector3f > | applyForward (const std::vector< Wm4::Vector3f > &input) const |
Applies the transformation to the input vector. | |
Wm4::Vector3f | applyInverse (const Wm4::Vector3f &input) const |
Applies the inverse transformation to the input vector. | |
std::vector< Wm4::Vector3f > | applyInverse (const std::vector< Wm4::Vector3f > &input) const |
Applies the inverse transformation to the input vector. | |
Wm4::Vector3f | invertVector (const Wm4::Vector3f &input) const |
Inverse-transforms the input vector. | |
Wm4::Plane3f | applyForward (const Wm4::Plane3f &input) const |
Transforms the plane. | |
Transform | inverse () const |
Compute the inverse transformation. | |
Wm4::Matrix4f | getHomogeneous () const |
To get the 4x4 matrix. | |
State of the transformation. | |
The following informations are implications.
So if they return false, it does not mean that the transformation is not an identity, a rotate and scale transformation or without a uniform scale, it means that this information is unknown | |
bool | isIdentity () const |
Is the tranformation an identity ? | |
bool | isUniformScale () const |
Does the transformation have a uniform scale? | |
Member access. | |
void | updateFlags () |
Update the flags to optimize computation. | |
void | setTranslate (const Wm4::Vector3f &translate) |
Set the translate vector. | |
void | setRotate (const Wm4::Matrix3f &rotate) |
Set the rotate matrix. | |
void | setRotate (const Wm4::Quaternionf &rotate) |
Set the rotate matrix. | |
void | setScale (const Wm4::Vector3f &scale) |
Set the translate vector. | |
void | setUniformScale (float scale) |
Set the translate vector. | |
const Wm4::Matrix3f & | getRotate () const |
Returns the rotate. | |
Wm4::Quaternionf | getQuaternionRotate () const |
Returns the rotate. | |
const Wm4::Vector3f & | getTranslate () const |
Returns the translate vector. | |
const Wm4::Vector3f & | getScale () const |
Returns the scale. | |
float | getUniformScale () const |
Returns the uniform scale. | |
Wm4::Vector3f | getRight () const |
Get accessor to the right vector. | |
Wm4::Vector3f | getUp () const |
Get accessor to the up vector. | |
Wm4::Vector3f | getDirection () const |
Get accessor to the direction vector. | |
Static Public Attributes | |
static const Transform | sk_identity |
The identity transformation. | |
Private Attributes | |
Wm4::Matrix3f | _matrix |
The matrix. | |
Wm4::Vector3f | _translate |
The translate vector. | |
Wm4::Vector3f | _scale |
The scale vector. | |
bool | _identity |
This flag is set if the transformation is an identity. | |
bool | _uniformScale |
This flag is set if the transformation has an uniform scale. | |
Friends | |
Transform OMK_API | product (const Transform &A, const Transform &B) |
Computes the product of the two transformations. | |
OMK_API bool | operator== (const Transform &t0, const Transform &t1) |
equality operator | |
OMK_API bool | operator!= (const Transform &t0, const Transform &t1) |
inequality operator | |
Friend stream operators. | |
std::ostream & | operator<< (std::ostream &out, const Transform &q) |
stream operator for ostream. | |
std::istream & | operator>> (std::istream &in, Transform &q) |
stream operator for istream. | |
OMK::OutgoingSynchronisationMessage & | operator<< (OMK::OutgoingSynchronisationMessage &out, const Transform &q) |
stream operator for OutgoingSynchronisationMessage. | |
OMK::IncomingSynchronisationMessage & | operator>> (OMK::IncomingSynchronisationMessage &in, Transform &q) |
stream operator for IncomingSynchronisationMessage. |
This Transform doesn't support modeling packages that allow reflections and nonuniform scales.
The vector is transformed in the forward direction to . The inverse direction transforms to , namely in the general case. In the our case of , the inverse direction is .
Definition at line 87 of file OMKTransform.h.
Transform::Transform | ( | ) |
Default constructor of Transform.
This constructor produces the identity transformation.
Definition at line 33 of file OMKTransform.cpp.
00034 : _matrix ( 1.0f, 0.0f, 0.0f, 00035 0.0f, 1.0f, 0.0f, 00036 0.0f, 0.0f, 1.0f ), 00037 _translate( 0.0f, 0.0f, 0.0f ), 00038 _scale ( 1.0f, 1.0f, 1.0f ), 00039 _identity ( true ), 00040 _uniformScale( true ) 00041 { 00042 }
Transform::Transform | ( | const Wm4::Vector3f & | translate, | |
const Wm4::Matrix3f & | rotate = Wm4::Matrix3f(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f) , |
|||
float | scale = 1.0f | |||
) |
Constructor for a translate, rotate and uniform scale transformation.
Definition at line 47 of file OMKTransform.cpp.
References OMASSERTM, and updateFlags().
00050 : _matrix ( rotate ), 00051 _translate( translate ), 00052 _scale ( scale, scale, scale ), 00053 _identity ( false ), 00054 _uniformScale( true ) 00055 { 00056 OMASSERTM( scale != 0.0f, "scale cannot be null" ) ; 00057 updateFlags() ; 00058 }
Transform::Transform | ( | const Wm4::Vector3f & | translate, | |
const Wm4::Quaternionf & | rotate, | |||
float | scale = 1.0f | |||
) |
Constructor for a translate, rotate and uniform scale transformation.
Definition at line 63 of file OMKTransform.cpp.
References _matrix, OMASSERTM, and updateFlags().
00066 : _matrix (), 00067 _translate( translate ), 00068 _scale ( scale, scale, scale ), 00069 _identity ( false ), 00070 _uniformScale( true ) 00071 { 00072 rotate.ToRotationMatrix( _matrix ) ; 00073 OMASSERTM( scale != 0.0f, "scale cannot be null" ) ; 00074 updateFlags() ; 00075 }
Transform::Transform | ( | const Wm4::Vector3f & | translate, | |
const Wm4::Matrix3f & | rotate, | |||
const Wm4::Vector3f & | scale | |||
) |
Constructor for a translate, rotate and scale transformation.
Definition at line 80 of file OMKTransform.cpp.
References OMASSERTM, and updateFlags().
00083 : _matrix ( rotate ), 00084 _translate( translate ), 00085 _scale ( scale ), 00086 _identity ( false ), 00087 _uniformScale( false ) 00088 { 00089 OMASSERTM( ( scale.X() != 0.0f 00090 && scale.Y() != 0.0f 00091 && scale.Z() != 0.0f ), "scale cannot be a null vector" ) ; 00092 updateFlags() ; 00093 }
Transform::Transform | ( | const Wm4::Vector3f & | translate, | |
const Wm4::Quaternionf & | rotate, | |||
const Wm4::Vector3f & | scale | |||
) |
Constructor for a translate, rotate and scale transformation.
Definition at line 98 of file OMKTransform.cpp.
References _matrix, OMASSERTM, and updateFlags().
00101 : _matrix (), 00102 _translate( translate ), 00103 _scale ( scale ), 00104 _identity ( false ), 00105 _uniformScale( false ) 00106 { 00107 rotate.ToRotationMatrix( _matrix ) ; 00108 OMASSERTM( ( scale.X() != 0.0f 00109 && scale.Y() != 0.0f 00110 && scale.Z() != 0.0f ), "scale cannot be a null vector" ) ; 00111 updateFlags() ; 00112 }
Transform::~Transform | ( | ) | [virtual] |
Transform::Transform | ( | ) |
Default constructor of Transform.
This constructor produces the identity transformation.
Definition at line 33 of file OMKTransform.cpp.
00034 : _matrix ( 1.0f, 0.0f, 0.0f, 00035 0.0f, 1.0f, 0.0f, 00036 0.0f, 0.0f, 1.0f ), 00037 _translate( 0.0f, 0.0f, 0.0f ), 00038 _scale ( 1.0f, 1.0f, 1.0f ), 00039 _identity ( true ), 00040 _uniformScale( true ) 00041 { 00042 }
Transform::Transform | ( | const Wm4::Vector3f & | translate, | |
const Wm4::Matrix3f & | rotate = Wm4::Matrix3f(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f) , |
|||
float | scale = 1.0f | |||
) |
Constructor for a translate, rotate and uniform scale transformation.
Definition at line 47 of file OMKTransform.cpp.
References OMASSERTM, and updateFlags().
00050 : _matrix ( rotate ), 00051 _translate( translate ), 00052 _scale ( scale, scale, scale ), 00053 _identity ( false ), 00054 _uniformScale( true ) 00055 { 00056 OMASSERTM( scale != 0.0f, "scale cannot be null" ) ; 00057 updateFlags() ; 00058 }
Transform::Transform | ( | const Wm4::Vector3f & | translate, | |
const Wm4::Quaternionf & | rotate, | |||
float | scale = 1.0f | |||
) |
Constructor for a translate, rotate and uniform scale transformation.
Definition at line 63 of file OMKTransform.cpp.
References _matrix, OMASSERTM, and updateFlags().
00066 : _matrix (), 00067 _translate( translate ), 00068 _scale ( scale, scale, scale ), 00069 _identity ( false ), 00070 _uniformScale( true ) 00071 { 00072 rotate.ToRotationMatrix( _matrix ) ; 00073 OMASSERTM( scale != 0.0f, "scale cannot be null" ) ; 00074 updateFlags() ; 00075 }
Transform::Transform | ( | const Wm4::Vector3f & | translate, | |
const Wm4::Matrix3f & | rotate, | |||
const Wm4::Vector3f & | scale | |||
) |
Constructor for a translate, rotate and scale transformation.
Definition at line 80 of file OMKTransform.cpp.
References OMASSERTM, and updateFlags().
00083 : _matrix ( rotate ), 00084 _translate( translate ), 00085 _scale ( scale ), 00086 _identity ( false ), 00087 _uniformScale( false ) 00088 { 00089 OMASSERTM( ( scale.X() != 0.0f 00090 && scale.Y() != 0.0f 00091 && scale.Z() != 0.0f ), "scale cannot be a null vector" ) ; 00092 updateFlags() ; 00093 }
Transform::Transform | ( | const Wm4::Vector3f & | translate, | |
const Wm4::Quaternionf & | rotate, | |||
const Wm4::Vector3f & | scale | |||
) |
Constructor for a translate, rotate and scale transformation.
Definition at line 98 of file OMKTransform.cpp.
References _matrix, OMASSERTM, and updateFlags().
00101 : _matrix (), 00102 _translate( translate ), 00103 _scale ( scale ), 00104 _identity ( false ), 00105 _uniformScale( false ) 00106 { 00107 rotate.ToRotationMatrix( _matrix ) ; 00108 OMASSERTM( ( scale.X() != 0.0f 00109 && scale.Y() != 0.0f 00110 && scale.Z() != 0.0f ), "scale cannot be a null vector" ) ; 00111 updateFlags() ; 00112 }
Transform::~Transform | ( | ) | [virtual] |
void OMK::Type::Transform::resetToIdentity | ( | ) | [inline] |
Sets the transformation to the identity.
Definition at line 122 of file OMKTransform.h.
Referenced by operator>>().
00122 { *this = sk_identity ; }
void Transform::resetUnitScale | ( | ) |
Sets the scales to 1 in each direction.
Definition at line 125 of file OMKTransform.cpp.
References _scale, and _uniformScale.
00126 { 00127 _scale = Wm4::Vector3f( 1.0f, 1.0f, 1.0f ); 00128 _uniformScale = true; 00129 }
bool OMK::Type::Transform::isIdentity | ( | ) | const [inline] |
Is the tranformation an identity ?
Definition at line 364 of file OMKTransform.h.
References _identity.
Referenced by applyForward(), invertVector(), operator<<(), and OMK::Type::product().
00365 { 00366 return _identity ; 00367 }
bool OMK::Type::Transform::isUniformScale | ( | ) | const [inline] |
Does the transformation have a uniform scale?
Definition at line 373 of file OMKTransform.h.
References _uniformScale.
Referenced by applyForward(), applyInverse(), getUniformScale(), invertVector(), operator<<(), OMK::Type::product(), and OMK::ParametersAccessor::setValue().
00374 { 00375 return _uniformScale ; 00376 }
void Transform::updateFlags | ( | ) |
Update the flags to optimize computation.
Sets the three flags _identity, _RSMatrix and _uniformScale according to the real value of the transform.
defined NDEBUG
Definition at line 532 of file OMKTransform.cpp.
References _identity, _matrix, _scale, _translate, _uniformScale, OMK_DEBUG_OMK_TYPE, and OMTRACEID.
Referenced by OMK::Iii::Joint::establishLink(), OMK::ParametersAccessor::getValue(), OMK::Iii::HingeSlideJoint::retroPropagation(), OMK::Iii::BallJoint::retroPropagation(), and Transform().
00533 { 00534 if( !_identity ) 00535 { // Not declared identity 00536 if( ( _matrix == Wm4::Matrix3f::IDENTITY ) 00537 && ( _translate == Wm4::Vector3f::ZERO ) 00538 && ( _scale == Wm4::Vector3f::ONE ) ) 00539 { // Test identity 00540 _identity = true ; 00541 _uniformScale = true ; 00542 } 00543 else 00544 { 00545 #if !defined NDEBUG 00546 // is it a pure rotation 00547 if( ( ( _matrix != Wm4::Matrix3f::IDENTITY ) 00548 && ( ( _matrix * _matrix.Transpose() != Wm4::Matrix3f::IDENTITY ) 00549 || ( _matrix.Determinant() != 1.0f ) ) ) ) 00550 { 00551 Wm4::Matrix3f m( _matrix * _matrix.Transpose() ) ; 00552 OMTRACEID( OMK_DEBUG_OMK_TYPE, 00553 "This transform is not a pure RS one, may be you will encounter some problem with it" << std::endl << *this ) ; 00554 } 00555 #endif 00556 // is it a uniform scale 00557 _uniformScale = ( _scale[0] == _scale[1] && _scale[1] == _scale[2] ) ; 00558 } 00559 } 00560 }
void Transform::setTranslate | ( | const Wm4::Vector3f & | translate | ) |
Set the translate vector.
[in] | translate | The translate vector |
Definition at line 147 of file OMKTransform.cpp.
References _identity, and _translate.
Referenced by OMK::Trajectory::computeParameters(), OMK::Orbit::computeParameters(), OMK::Vis::convert(), OMK::ParametersAccessor::getValue(), OMK::Inp::DistributedCameraOgreListener::keyPressed(), OMK::Trajectory::loadParameters(), OMK::Inp::DistributedCameraOgreListener::mouseMoved(), operator>>(), OMK::Type::product(), OMK::Vis::VisualObject::readConfigurationParameters(), OMK::Iii::HingeSlideJoint::retroPropagation(), and OMK::Iii::BallJoint::retroPropagation().
00148 { 00149 _translate = translate ; 00150 _identity = false ; 00151 }
void Transform::setRotate | ( | const Wm4::Matrix3f & | rotate | ) |
Set the rotate matrix.
[in] | rotate | The rotate matrix |
Definition at line 157 of file OMKTransform.cpp.
References _identity, and _matrix.
Referenced by OMK::Trajectory::computeParameters(), OMK::Orbit::computeParameters(), OMK::Vis::convert(), OMK::ParametersAccessor::getValue(), OMK::Inp::DistributedCameraOgreListener::mouseMoved(), operator>>(), OMK::Type::product(), OMK::Vis::VisualObject::readConfigurationParameters(), OMK::Iii::HingeSlideJoint::retroPropagation(), and OMK::Iii::BallJoint::retroPropagation().
void Transform::setRotate | ( | const Wm4::Quaternionf & | rotate | ) |
Set the rotate matrix.
[in] | rotate | The rotate quaternion |
Definition at line 167 of file OMKTransform.cpp.
References _identity, and _matrix.
void Transform::setScale | ( | const Wm4::Vector3f & | scale | ) |
Set the translate vector.
[in] | translate | The translate vector |
Definition at line 177 of file OMKTransform.cpp.
References _identity, _scale, _uniformScale, and OMASSERTM.
Referenced by OMK::Vis::convert(), OMK::ParametersAccessor::getValue(), operator>>(), OMK::Type::product(), and OMK::Vis::VisualObject::readConfigurationParameters().
00178 { 00179 OMASSERTM( ( scale.X() != 0.0f 00180 && scale.Y() != 0.0f 00181 && scale.Z() != 0.0f ), "The scale vector cannot be null" ) ; 00182 _scale = scale ; 00183 _identity = false ; 00184 _uniformScale = false ; 00185 }
void Transform::setUniformScale | ( | float | scale | ) |
Set the translate vector.
[in] | translate | The translate vector |
Definition at line 191 of file OMKTransform.cpp.
References _identity, _scale, _uniformScale, and OMASSERTM.
Referenced by OMK::ParametersAccessor::getValue(), operator>>(), OMK::Type::product(), and OMK::Vis::VisualObject::readConfigurationParameters().
00192 { 00193 OMASSERTM( scale != 0.0f, "The scale cannot be null" ); 00194 _scale = Wm4::Vector3f( scale, scale, scale ) ; 00195 _identity = false ; 00196 _uniformScale = true ; 00197 }
const Wm4::Matrix3f & OMK::Type::Transform::getRotate | ( | ) | const [inline] |
Returns the rotate.
Definition at line 382 of file OMKTransform.h.
References _matrix.
Referenced by OMK::Trajectory::computeParameters(), OMK::Orbit::computeParameters(), inverse(), OMK::Inp::DistributedCameraOgreListener::mouseMoved(), operator<<(), OMK::Iii::HingeSlideJoint::retroPropagation(), OMK::Iii::BallJoint::retroPropagation(), and OMK::ParametersAccessor::setValue().
00383 { 00384 return _matrix ; 00385 }
Wm4::Quaternionf OMK::Type::Transform::getQuaternionRotate | ( | ) | const [inline] |
Returns the rotate.
Definition at line 391 of file OMKTransform.h.
References _matrix.
Referenced by OMK::Vis::convert().
00392 { 00393 return Wm4::Quaternionf().FromRotationMatrix( _matrix ) ; 00394 }
const Wm4::Vector3f & OMK::Type::Transform::getTranslate | ( | ) | const [inline] |
Returns the translate vector.
Definition at line 400 of file OMKTransform.h.
References _translate.
Referenced by OMK::Vis::convert(), OMK::Iii::HingeSlideJoint::establishLink(), OMK::Iii::BallJoint::establishLink(), OMK::Inp::DistributedCameraOgreListener::keyPressed(), OMK::Tracker::loadParameters(), OMK::Inp::DistributedCameraOgreListener::mouseMoved(), operator<<(), OMK::DistanceToExtension::preComputeParameters(), OMK::Iii::HingeSlideJoint::retroPropagation(), OMK::Iii::BallJoint::retroPropagation(), and OMK::ParametersAccessor::setValue().
00401 { 00402 return _translate; 00403 }
const Wm4::Vector3f & OMK::Type::Transform::getScale | ( | ) | const [inline] |
Returns the scale.
Definition at line 409 of file OMKTransform.h.
References _scale.
Referenced by OMK::Vis::convert(), operator<<(), OMK::Type::product(), and OMK::ParametersAccessor::setValue().
00410 { 00411 return _scale ; 00412 }
float OMK::Type::Transform::getUniformScale | ( | ) | const [inline] |
Returns the uniform scale.
Definition at line 418 of file OMKTransform.h.
References _scale, isUniformScale(), and OMASSERTM.
Referenced by applyForward(), applyInverse(), invertVector(), OMK::Type::product(), and OMK::ParametersAccessor::setValue().
00419 { 00420 OMASSERTM( isUniformScale(), "Must be a Rotate and Scale tranformation with uniform scale to return the scale value, you should use isUniformScale() before calling it" ) ; 00421 return _scale.X() ; // same as Y and Z 00422 }
Wm4::Vector3f OMK::Type::Transform::getRight | ( | ) | const [inline] |
Get accessor to the right vector.
Definition at line 427 of file OMKTransform.h.
References _matrix.
Referenced by OMK::Iii::ScrewJoint::establishLink(), OMK::Inp::DistributedCameraOgreListener::keyPressed(), and OMK::Iii::HingeSlideJoint::retroPropagation().
00428 { 00429 return _matrix.GetColumn( 0 ) ; 00430 }
Wm4::Vector3f OMK::Type::Transform::getUp | ( | ) | const [inline] |
Get accessor to the up vector.
Definition at line 436 of file OMKTransform.h.
References _matrix.
Referenced by OMK::Iii::HingeSlideJoint::establishLink(), OMK::Inp::DistributedCameraOgreListener::keyPressed(), and OMK::Iii::HingeSlideJoint::retroPropagation().
00437 { 00438 return _matrix.GetColumn( 1 ) ; 00439 }
Wm4::Vector3f OMK::Type::Transform::getDirection | ( | ) | const [inline] |
Get accessor to the direction vector.
Definition at line 445 of file OMKTransform.h.
References _matrix.
Referenced by OMK::Inp::DistributedCameraOgreListener::keyPressed(), and OMK::Inp::DistributedCameraOgreListener::mouseMoved().
00446 { 00447 return _matrix.GetColumn( 2 ) ; 00448 }
bool OMK::Type::Transform::getOrientation | ( | float & | head, | |
float & | pitch, | |||
float & | roll | |||
) | const [inline] |
Get the object orientation using Euler angles.
head | rotation angle about the Up/Y vector (in radians). | |
pitch | rotation angle about the Right/X vector (in radians). | |
roll | rotation angle about the Direction/Z vector (in radians). |
Definition at line 454 of file OMKTransform.h.
References _matrix.
00455 { 00456 return _matrix.ToEulerAnglesYXZ( head, pitch, roll ) ; 00457 }
void OMK::Type::Transform::setOrientation | ( | float | head, | |
float | pitch, | |||
float | roll | |||
) | [inline] |
Set the object orientation using Euler angles.
head | rotation angle about the Up/Y vector (in radians). | |
pitch | rotation angle about the Right/X vector (in radians). | |
roll | rotation angle about the Direction/Z vector (in radians). |
Definition at line 463 of file OMKTransform.h.
References _identity, and _matrix.
00464 { 00465 // build the rotation matrix from the head, pitch and roll angles 00466 _matrix.FromEulerAnglesYXZ( head, pitch, roll ) ; 00467 _identity = false ; 00468 }
float Transform::getNorm | ( | ) | const |
Gets the norm of the transformation.
Definition at line 135 of file OMKTransform.cpp.
References _scale.
00136 { 00137 float sX = (float)::fabs( _scale.X() ) ; 00138 float sY = (float)::fabs( _scale.Y() ) ; 00139 float sZ = (float)::fabs( _scale.Z() ) ; 00140 return sX < sY ? ( sY < sZ ? sZ : sY ) : ( sX < sZ ? sZ : sX ) ; 00141 }
Wm4::Vector3f Transform::applyForward | ( | const Wm4::Vector3f & | input | ) | const |
Applies the transformation to the input vector.
[in] | input | The input vector |
Definition at line 203 of file OMKTransform.cpp.
References _matrix, _scale, _translate, and isIdentity().
00204 { 00205 Wm4::Vector3f output ; 00206 if( isIdentity() ) 00207 { // Y = X 00208 output = input; 00209 } 00210 else 00211 { 00212 // Y = R*S*X + T 00213 output = Wm4::Vector3f( _scale.X() * input.X(), 00214 _scale.Y() * input.Y(), 00215 _scale.Z() * input.Z() ); 00216 output = _matrix * output + _translate; 00217 } 00218 return output; 00219 }
std::vector< Wm4::Vector3f > Transform::applyForward | ( | const std::vector< Wm4::Vector3f > & | input | ) | const |
Applies the transformation to the input vector.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Version for a set of vectors.
Definition at line 225 of file OMKTransform.cpp.
References _matrix, _scale, _translate, and isIdentity().
00226 { 00227 std::vector<Wm4::Vector3f> output ; 00228 if ( isIdentity() ) 00229 { 00230 // Y = X 00231 output = input ; 00232 } 00233 else 00234 { 00235 // Y = R*S*X + T 00236 output.resize( input.size() ) ; 00237 for( unsigned int i( 0 ) ; i < input.size() ; ++i ) 00238 { 00239 output[i].X() = _scale.X() * input[i].X() ; 00240 output[i].Y() = _scale.Y() * input[i].Y() ; 00241 output[i].Z() = _scale.Z() * input[i].Z() ; 00242 output[i] = _matrix * output[i] + _translate; 00243 } 00244 } 00245 return output ; 00246 }
Wm4::Vector3f Transform::applyInverse | ( | const Wm4::Vector3f & | input | ) | const |
Applies the inverse transformation to the input vector.
[in] | input | The input vector |
Definition at line 252 of file OMKTransform.cpp.
References _identity, _matrix, _scale, _translate, getUniformScale(), and isUniformScale().
00253 { 00254 Wm4::Vector3f output ; 00255 if (_identity) 00256 { 00257 // X = Y 00258 output = input; 00259 } 00260 else 00261 { 00262 output = input - _translate ; 00263 // X = S^{-1}*R^t*(Y - T) 00264 output = output * _matrix; 00265 if( isUniformScale() ) 00266 { 00267 output /= getUniformScale(); 00268 } 00269 else 00270 { 00271 // The direct inverse scaling is 00272 // output.X() /= _scale.X(); 00273 // output.Y() /= _scale.Y(); 00274 // output.Z() /= _scale.Z(); 00275 // When division is much more expensive than multiplication, 00276 // three divisions are replaced by one division and ten 00277 // multiplications. 00278 float SXY = _scale.X() * _scale.Y() ; 00279 float SXZ = _scale.X() * _scale.Z() ; 00280 float SYZ = _scale.Y() * _scale.Z() ; 00281 float invDet = 1.0f / ( SXY * _scale.Z() ) ; 00282 output.X() *= invDet * SYZ ; 00283 output.Y() *= invDet * SXZ ; 00284 output.Z() *= invDet * SXY ; 00285 } 00286 } 00287 return output; 00288 }
std::vector< Wm4::Vector3f > Transform::applyInverse | ( | const std::vector< Wm4::Vector3f > & | input | ) | const |
Applies the inverse transformation to the input vector.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Version for a set of vectors.
Definition at line 294 of file OMKTransform.cpp.
References _identity, _matrix, _scale, _translate, getUniformScale(), and isUniformScale().
00295 { 00296 std::vector<Wm4::Vector3f> output ; 00297 if (_identity) 00298 { 00299 output = input ; 00300 } 00301 else 00302 { 00303 Wm4::Vector3f diff; 00304 // X = S^{-1}*R^t*(Y - T) 00305 if ( isUniformScale() ) 00306 { 00307 float invScale = 1.0f / getUniformScale() ; 00308 for( unsigned int i( 0 ) ; i < input.size() ; ++i ) 00309 { 00310 output.push_back( invScale * ( ( input[i] - _translate ) * _matrix ) ); 00311 } 00312 } 00313 else 00314 { 00315 // The direct inverse scaling is 00316 // invXScale = 1.0f/_scale.X(); 00317 // invYScale = 1.0f/_scale.Y(); 00318 // invZScale = 1.0f/_scale.Z(); 00319 // When division is much more expensive than multiplication, three 00320 // divisions are replaced by one division and ten multiplications. 00321 float SXY = _scale.X() * _scale.Y() ; 00322 float SXZ = _scale.X() * _scale.Z() ; 00323 float SYZ = _scale.Y() * _scale.Z() ; 00324 float invDet = 1.0f / ( SXY * _scale.Z() ) ; 00325 float invXScale = invDet * SYZ ; 00326 float invYScale = invDet * SXZ ; 00327 float invZScale = invDet * SXY ; 00328 for( unsigned int i( 0 ) ; i < input.size() ; ++i ) 00329 { 00330 output.push_back( ( input[i] - _translate ) * _matrix ); 00331 output[i].X() *= invXScale; 00332 output[i].Y() *= invYScale; 00333 output[i].Z() *= invZScale; 00334 } 00335 } 00336 } 00337 return output ; 00338 }
Wm4::Vector3f Transform::invertVector | ( | const Wm4::Vector3f & | input | ) | const |
Inverse-transforms the input vector.
[in] | input | The input vector. |
Definition at line 344 of file OMKTransform.cpp.
References _matrix, _scale, getUniformScale(), isIdentity(), and isUniformScale().
00345 { 00346 Wm4::Vector3f output; 00347 if( isIdentity() ) 00348 { 00349 // X = Y 00350 output = input ; 00351 } 00352 else 00353 { 00354 // X = S^{-1}*R^t*Y 00355 output = input * _matrix ; 00356 if ( isUniformScale() ) 00357 { 00358 output /= getUniformScale() ; 00359 } 00360 else 00361 { 00362 // The direct inverse scaling is 00363 // output.X() /= _scale.X(); 00364 // output.Y() /= _scale.Y(); 00365 // output.Z() /= _scale.Z(); 00366 // When division is much more expensive than multiplication, 00367 // three divisions are replaced by one division and ten 00368 // multiplications. 00369 float SXY = _scale.X() * _scale.Y() ; 00370 float SXZ = _scale.X() * _scale.Z() ; 00371 float SYZ = _scale.Y() * _scale.Z() ; 00372 float invDet = 1.0f/( SXY * _scale.Z() ) ; 00373 output.X() *= invDet * SYZ ; 00374 output.Y() *= invDet * SXZ ; 00375 output.Z() *= invDet * SXY ; 00376 } 00377 } 00378 return output; 00379 }
Wm4::Plane3f Transform::applyForward | ( | const Wm4::Plane3f & | input | ) | const |
Transforms the plane.
Transforms the plane to where both and must be unit-length normals.
Definition at line 385 of file OMKTransform.cpp.
References _matrix, _scale, _translate, getUniformScale(), isIdentity(), and isUniformScale().
00386 { 00387 Wm4::Plane3f output ; 00388 if( isIdentity() ) 00389 { 00390 output = input; 00391 } 00392 // Let X represent points in model space and Y = R*S*X+T represent 00393 // points in world space where S are the world scales, R is the world 00394 // rotation, and T is the world translation. The inverse transform is 00395 // X = S^{-1}*R^t*(Y-T). The model plane is Dot(N0,X) = C0. 00396 // Replacing the formula for X in it and applying some algebra leads 00397 // to the world plane Dot(N1,Y) = C1 where N1 = R*S^{-1}*N0 and 00398 // C1 = C0+Dot(N1,T). If S is not the identity, then N1 is not unit 00399 // length. We need to normalize N1 and adjust C1: N1' = N1/|N1| and 00400 // C1' = C1/|N1|. 00401 else if ( isUniformScale() ) 00402 { 00403 output.Normal = _matrix * input.Normal ; 00404 output.Constant = getUniformScale() * input.Constant + 00405 output.Normal.Dot( _translate ); 00406 } 00407 else 00408 { 00409 output.Normal = input.Normal ; 00410 00411 // The direct inverse scaling is 00412 // output.X() /= _scale.X(); 00413 // output.Y() /= _scale.Y(); 00414 // output.Z() /= _scale.Z(); 00415 // When division is much more expensive than multiplication, 00416 // three divisions are replaced by one division and ten 00417 // multiplications. 00418 float SXY = _scale.X() * _scale.Y() ; 00419 float SXZ = _scale.X() * _scale.Z() ; 00420 float SYZ = _scale.Y() * _scale.Z() ; 00421 float invDet = 1.0f / ( SXY * _scale.Z() ) ; 00422 output.Normal.X() *= invDet * SYZ; 00423 output.Normal.Y() *= invDet * SXZ; 00424 output.Normal.Z() *= invDet * SXY; 00425 output.Normal = _matrix * output.Normal; 00426 00427 float fInvLength = 1.0f / output.Normal.Length() ; 00428 output.Normal *= fInvLength ; 00429 output.Constant = fInvLength * input.Constant + 00430 output.Normal.Dot( _translate ); 00431 } 00432 return output; 00433 }
Transform Transform::inverse | ( | ) | const |
Compute the inverse transformation.
You should use updateFlags to update the flags according to the current values.
Definition at line 502 of file OMKTransform.cpp.
References _identity, _matrix, _scale, _translate, _uniformScale, and getRotate().
Referenced by OMK::Iii::Joint::establishLink(), OMK::Iii::HingeSlideJoint::retroPropagation(), and OMK::Iii::BallJoint::retroPropagation().
00503 { 00504 Transform inverse ; 00505 if( _identity ) 00506 { 00507 inverse = *this; 00508 } 00509 else 00510 { 00511 if( _uniformScale ) 00512 { 00513 inverse._matrix = getRotate().Transpose() / _scale[0]; 00514 inverse._uniformScale = _scale[0] != 1.0 ; 00515 } 00516 else 00517 { 00518 Wm4::Matrix3f RS = _matrix.TimesDiagonal( _scale ) ; 00519 inverse._matrix = RS.Inverse() ; 00520 inverse._uniformScale = false; 00521 } 00522 00523 inverse._translate = -( inverse._matrix * _translate ); 00524 inverse._identity = false; 00525 } 00526 return inverse ; 00527 }
Wm4::Matrix4f Transform::getHomogeneous | ( | ) | const |
To get the 4x4 matrix.
Changes the transformation into a 4 x 4 matrix.
Definition at line 566 of file OMKTransform.cpp.
References _matrix, _scale, and _translate.
00567 { 00568 Wm4::Matrix4f hMatrix ; 00569 hMatrix[0][0] = _scale[0] * _matrix[0][0] ; 00570 hMatrix[0][1] = _scale[0] * _matrix[1][0] ; 00571 hMatrix[0][2] = _scale[0] * _matrix[2][0] ; 00572 hMatrix[0][3] = 0.0f ; 00573 hMatrix[1][0] = _scale[1] * _matrix[0][1] ; 00574 hMatrix[1][1] = _scale[1] * _matrix[1][1] ; 00575 hMatrix[1][2] = _scale[1] * _matrix[2][1] ; 00576 hMatrix[1][3] = 0.0f ; 00577 hMatrix[2][0] = _scale[2] * _matrix[0][2] ; 00578 hMatrix[2][1] = _scale[2] * _matrix[1][2] ; 00579 hMatrix[2][2] = _scale[2] * _matrix[2][2] ; 00580 hMatrix[2][3] = 0.0f ; 00581 hMatrix[3][0] = _translate[0] ; 00582 hMatrix[3][1] = _translate[1] ; 00583 hMatrix[3][2] = _translate[2] ; 00584 hMatrix[3][3] = 1.0f ; 00585 00586 return hMatrix ; 00587 }
Computes the product of the two transformations.
[in] | A | The first tranformation |
[in] | B | The second tranformation |
Definition at line 439 of file OMKTransform.cpp.
00440 { 00441 Transform output ; 00442 if( A.isIdentity() ) 00443 { 00444 output = B ; 00445 } 00446 else if( B.isIdentity() ) 00447 { 00448 output = A ; 00449 } 00450 else 00451 { 00452 if( !A.isUniformScale() ) 00453 { 00454 // set correctly "_uniformScale" boolean in A if needed 00455 const_cast< Transform& >( A )._uniformScale = ( A._scale[0] == A._scale[1] && A._scale[1] == A._scale[2] ) ; 00456 } 00457 00458 output.setRotate( A._matrix * B._matrix ) ; 00459 00460 if( A.isUniformScale() ) 00461 { 00462 output.setTranslate( A.getUniformScale() * ( A._matrix * B._translate ) + A._translate ) ; 00463 00464 if ( B.isUniformScale() ) 00465 { 00466 output.setUniformScale( A.getUniformScale() * B.getUniformScale() ) ; 00467 } 00468 else 00469 { 00470 output.setScale( A.getUniformScale() * B.getScale() ) ; 00471 } 00472 } 00473 else 00474 { 00475 Wm4::Vector3f v0_translate( A._matrix * B._translate ) ; 00476 Wm4::Vector3f v1_translate( A.getScale()[0] * v0_translate[0], 00477 A.getScale()[1] * v0_translate[1], 00478 A.getScale()[2] * v0_translate[2] ) ; 00479 output.setTranslate( v1_translate + A._translate ) ; 00480 00481 if ( B.isUniformScale() ) 00482 { 00483 output.setScale( A.getScale() * B.getUniformScale() ) ; 00484 } 00485 else 00486 { 00487 Wm4::Vector3f v0_scale( A._matrix * B._scale ) ; 00488 Wm4::Vector3f v1_scale( A.getScale()[0] * v0_scale[0], 00489 A.getScale()[1] * v0_scale[1], 00490 A.getScale()[2] * v0_scale[2] ) ; 00491 output.setScale( v1_scale ) ; 00492 } 00493 } 00494 } 00495 return output ; 00496 }
equality operator
Definition at line 593 of file OMKTransform.cpp.
00594 { 00595 return ( t0._identity == t1._identity && 00596 t0._uniformScale == t1._uniformScale && 00597 t0._translate == t1._translate && 00598 t0._scale == t1._scale && 00599 t0._matrix == t1._matrix ) ; 00600 }
std::ostream& operator<< | ( | std::ostream & | out, | |
const Transform & | q | |||
) | [friend] |
stream operator for ostream.
Use by SimpleTypeT::insertInStream.
Definition at line 613 of file OMKTransform.cpp.
00614 { 00615 out << q.isIdentity() << " " ; 00616 if( !q.isIdentity() ) 00617 { 00618 out << q.isUniformScale() << " " 00619 << q.getTranslate().X() << " " 00620 << q.getTranslate().Y() << " " 00621 << q.getTranslate().Z() << " " 00622 << q.getRotate()( 0, 0 ) << " " 00623 << q.getRotate()( 0, 1 ) << " " 00624 << q.getRotate()( 0, 2 ) << " " 00625 << q.getRotate()( 1, 0 ) << " " 00626 << q.getRotate()( 1, 1 ) << " " 00627 << q.getRotate()( 1, 2 ) << " " 00628 << q.getRotate()( 2, 0 ) << " " 00629 << q.getRotate()( 2, 1 ) << " " 00630 << q.getRotate()( 2, 2 ) << " " 00631 << q.getScale().X() << " " 00632 << q.getScale().Y() << " " 00633 << q.getScale().Z() << " " ; 00634 } 00635 out << " " ; 00636 return out; 00637 }
std::istream& operator>> | ( | std::istream & | in, | |
Transform & | q | |||
) | [friend] |
stream operator for istream.
Use by SimpleTypeT::extract.
Definition at line 642 of file OMKTransform.cpp.
00643 { 00644 bool isIdentity = false ; 00645 in >> isIdentity ; 00646 if( isIdentity ) 00647 { 00648 q.resetToIdentity() ; 00649 } 00650 else 00651 { 00652 bool isUniformScale ; 00653 Wm4::Vector3f translate ; 00654 Wm4::Matrix3f matrix ; 00655 Wm4::Vector3f scale ; 00656 in >> isUniformScale 00657 >> translate.X() 00658 >> translate.Y() 00659 >> translate.Z() 00660 >> matrix( 0, 0 ) 00661 >> matrix( 0, 1 ) 00662 >> matrix( 0, 2 ) 00663 >> matrix( 1, 0 ) 00664 >> matrix( 1, 1 ) 00665 >> matrix( 1, 2 ) 00666 >> matrix( 2, 0 ) 00667 >> matrix( 2, 1 ) 00668 >> matrix( 2, 2 ) 00669 >> scale.X() 00670 >> scale.Y() 00671 >> scale.Z() ; 00672 q.setTranslate( translate ) ; 00673 q.setRotate( matrix ) ; 00674 if( isUniformScale ) q.setUniformScale( scale.X() ) ; else q.setScale( scale ) ; 00675 } 00676 return in; 00677 }
OMK::OutgoingSynchronisationMessage& operator<< | ( | OMK::OutgoingSynchronisationMessage & | out, | |
const Transform & | q | |||
) | [friend] |
stream operator for OutgoingSynchronisationMessage.
Use by SimpleTypeT::pack.
Definition at line 682 of file OMKTransform.cpp.
00683 { 00684 out << q.isIdentity() ; 00685 if( !q.isIdentity() ) 00686 { 00687 out << q.isUniformScale() 00688 << q.getTranslate().X() 00689 << q.getTranslate().Y() 00690 << q.getTranslate().Z() 00691 << q.getRotate()( 0, 0 ) 00692 << q.getRotate()( 0, 1 ) 00693 << q.getRotate()( 0, 2 ) 00694 << q.getRotate()( 1, 0 ) 00695 << q.getRotate()( 1, 1 ) 00696 << q.getRotate()( 1, 2 ) 00697 << q.getRotate()( 2, 0 ) 00698 << q.getRotate()( 2, 1 ) 00699 << q.getRotate()( 2, 2 ) 00700 << q.getScale().X() 00701 << q.getScale().Y() 00702 << q.getScale().Z() ; 00703 } 00704 return out; 00705 }
OMK::IncomingSynchronisationMessage& operator>> | ( | OMK::IncomingSynchronisationMessage & | in, | |
Transform & | q | |||
) | [friend] |
stream operator for IncomingSynchronisationMessage.
Use by SimpleTypeT::unpack.
Definition at line 710 of file OMKTransform.cpp.
00711 { 00712 bool isIdentity = false ; 00713 in >> isIdentity ; 00714 if( isIdentity ) 00715 { 00716 q.resetToIdentity() ; 00717 } 00718 else 00719 { 00720 bool isUniformScale ; 00721 Wm4::Vector3f translate ; 00722 Wm4::Matrix3f matrix ; 00723 Wm4::Vector3f scale ; 00724 in >> isUniformScale 00725 >> translate.X() 00726 >> translate.Y() 00727 >> translate.Z() 00728 >> matrix( 0, 0 ) 00729 >> matrix( 0, 1 ) 00730 >> matrix( 0, 2 ) 00731 >> matrix( 1, 0 ) 00732 >> matrix( 1, 1 ) 00733 >> matrix( 1, 2 ) 00734 >> matrix( 2, 0 ) 00735 >> matrix( 2, 1 ) 00736 >> matrix( 2, 2 ) 00737 >> scale.X() 00738 >> scale.Y() 00739 >> scale.Z() ; 00740 q.setTranslate( translate ) ; 00741 q.setRotate( matrix ) ; 00742 if( isUniformScale ) q.setUniformScale( scale.X() ) ; else q.setScale( scale ) ; 00743 } 00744 return in; 00745 }
const Transform Transform::sk_identity [static] |
The identity transformation.
Definition at line 308 of file OMKTransform.h.
Referenced by OMK::ParametersAccessor::getValue().
Wm4::Matrix3f OMK::Type::Transform::_matrix [private] |
The matrix.
This one is a rotate if _RSMatrix is set.
Definition at line 341 of file OMKTransform.h.
Referenced by applyForward(), applyInverse(), getDirection(), getHomogeneous(), getOrientation(), getQuaternionRotate(), getRight(), getRotate(), getUp(), inverse(), invertVector(), OMK::Type::operator==(), OMK::Type::product(), setOrientation(), setRotate(), Transform(), and updateFlags().
Wm4::Vector3f OMK::Type::Transform::_translate [private] |
The translate vector.
Definition at line 344 of file OMKTransform.h.
Referenced by applyForward(), applyInverse(), getHomogeneous(), getTranslate(), inverse(), OMK::Type::operator==(), OMK::Type::product(), setTranslate(), and updateFlags().
Wm4::Vector3f OMK::Type::Transform::_scale [private] |
The scale vector.
This one is valid only if _RSMatrix is set.
Definition at line 348 of file OMKTransform.h.
Referenced by applyForward(), applyInverse(), getHomogeneous(), getNorm(), getScale(), getUniformScale(), inverse(), invertVector(), OMK::Type::operator==(), OMK::Type::product(), resetUnitScale(), setScale(), setUniformScale(), and updateFlags().
bool OMK::Type::Transform::_identity [private] |
This flag is set if the transformation is an identity.
The computations will be optimized in that case.
Definition at line 352 of file OMKTransform.h.
Referenced by applyInverse(), inverse(), isIdentity(), OMK::Type::operator==(), setOrientation(), setRotate(), setScale(), setTranslate(), setUniformScale(), and updateFlags().
bool OMK::Type::Transform::_uniformScale [private] |
This flag is set if the transformation has an uniform scale.
The computations will be optimized in that case.
An uniform scale is a _scale with the same three values.
Definition at line 357 of file OMKTransform.h.
Referenced by inverse(), isUniformScale(), OMK::Type::operator==(), OMK::Type::product(), resetUnitScale(), setScale(), setUniformScale(), and updateFlags().
Documentation generated on Mon Jun 9 11:46:05 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |