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
00026
00027 #include "CeylanLocatable2D.h"
00028
00029
00030 #include "CeylanHomogeneousMatrix3.h"
00031 #include "CeylanMathsBasic.h"
00032
00033 #include "CeylanLogPlug.h"
00034 #include "CeylanUtils.h"
00035 #include "CeylanOperators.h"
00036
00037
00038
00039 using std::string ;
00040
00041
00042 using namespace Ceylan ;
00043 using namespace Ceylan::Log ;
00044 using namespace Ceylan::Maths::Linear ;
00045
00046 using Ceylan::Maths::Real ;
00047
00048
00049
00050
00051
00052
00053
00054 Locatable2D::Locatable2D( Locatable2D & fatherLocatable ) :
00055 Locatable( fatherLocatable )
00056 {
00057
00058 blankLocalReferential() ;
00059
00060 }
00061
00062
00063
00064 Locatable2D::Locatable2D() :
00065 Locatable()
00066 {
00067
00068 blankLocalReferential() ;
00069
00070 }
00071
00072
00073
00074 Locatable2D::Locatable2D( Locatable2D & fatherLocatable,
00075 Matrix & localReferential ) :
00076 Locatable( fatherLocatable, localReferential )
00077 {
00078
00079 }
00080
00081
00082
00083 Locatable2D::Locatable2D( Matrix & localReferential ) :
00084 Locatable( localReferential )
00085 {
00086
00087 }
00088
00089
00090
00091 Locatable2D::~Locatable2D() throw()
00092 {
00093
00094
00095
00096 }
00097
00098
00099
00100 Matrix & Locatable2D::getLocalReferential() const
00101 {
00102
00103 if ( _localReferential == 0 )
00104 throw LocatableException( "Locatable2D::getLocalReferential(): "
00105 "no local referential available." ) ;
00106
00107
00108
00109
00110
00111
00112
00113
00114 return * _localReferential ;
00115
00116 }
00117
00118
00119
00120 void Locatable2D::blankLocalReferential()
00121 {
00122
00123
00124 if ( _localReferential == 0 )
00125 _localReferential = new HomogeneousMatrix3() ;
00126
00127 _localReferential->setToIdentity() ;
00128
00129 }
00130
00131
00132
00133 Bipoint Locatable2D::getCenter() const
00134 {
00135
00136 HomogeneousMatrix3 & localMatrix = getLocalMatrix() ;
00137
00138 Real factor = localMatrix.getElementAt( 2, 2 ) ;
00139
00140
00141 if ( Maths::IsNull( factor ) )
00142 throw LocatableException( "Locatable2D::getCenter: "
00143 "homogeneous factor is too close to zero ("
00144 + Ceylan::toString( factor ) + ")." ) ;
00145
00146 return Bipoint( localMatrix.getElementAt( 2, 0 ) / factor,
00147 localMatrix.getElementAt( 2, 1 ) / factor ) ;
00148
00149 }
00150
00151
00152
00153 void Locatable2D::setCenter( const Bipoint & newCenter )
00154 {
00155
00156 if ( _localReferential == 0 )
00157 throw LocatableException(
00158 "Locatable2D::setCenter: no local referential available." ) ;
00159
00160 HomogeneousMatrix3 & localMatrix = getLocalMatrix() ;
00161
00162 localMatrix.setElementAt( 2, 0, newCenter.getX() ) ;
00163 localMatrix.setElementAt( 2, 1, newCenter.getY() ) ;
00164
00165
00166
00167
00168
00169
00170 setUpToDateState( false ) ;
00171
00172 }
00173
00174
00175
00176 void Locatable2D::setCenter( Real newX, Real newY )
00177 {
00178
00179 if ( _localReferential == 0 )
00180 throw LocatableException(
00181 "Locatable2D::setCenter: no local referential available." ) ;
00182
00183
00184 HomogeneousMatrix3 & localMatrix = getLocalMatrix() ;
00185
00186 localMatrix.setElementAt( 2, 0, newX ) ;
00187 localMatrix.setElementAt( 2, 1, newY ) ;
00188
00189
00190
00191
00192
00193
00194 setUpToDateState( false ) ;
00195
00196 }
00197
00198
00199
00200 const string Locatable2D::toString( VerbosityLevels level ) const
00201 {
00202
00203 string res ;
00204
00205 if ( isAbsolute() )
00206 res = "Absolute" ;
00207 else
00208 res = "Relative" ;
00209
00210 return res + " Locatable2D, " + describe( level ) ;
00211
00212
00213 }
00214
00215
00216
00217 void Locatable2D::updateFromFather( const Matrix & upToDateFatherReferential )
00218 {
00219
00220 if ( _localReferential == 0 )
00221 emergencyShutdown( "Locatable2D::updateFromFather: "
00222 "no local referential available." ) ;
00223
00224 const HomogeneousMatrix3 * m =
00225 dynamic_cast<const HomogeneousMatrix3*>( & upToDateFatherReferential ) ;
00226
00227 if ( m == 0 )
00228 emergencyShutdown(
00229 "Locatable2D::updateFromFather: father matrix not a Matrix3." ) ;
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 _globalReferential = new HomogeneousMatrix3( (*m)
00240 * ( * dynamic_cast<const HomogeneousMatrix3*>(
00241 _localReferential ) ) ) ;
00242
00243 }
00244