AttitudeHistory.cpp

Go to the documentation of this file.
00001 
00002 
00008 /*  
00009 */
00011 
00012 #include "AttitudeHistory.h"
00013 namespace O_SESSAME {
00014 
00015 AttitudeHistory::AttitudeHistory()
00016 {
00017     ResetHistory();
00018     m_AttitudeHistory.reserve(HISTORY_RESERVE_SIZE);
00019     m_AttitudeInterpolations.reserve(HISTORY_RESERVE_SIZE);
00020 }
00021 
00022 AttitudeHistory::~AttitudeHistory()
00023 {
00024 
00025 }
00026 
00027 void AttitudeHistory::AppendHistory(const double &_appendTime, const Rotation &_appendRotation, const Vector &_appendAngVel)
00028 {
00029     AppendHistory(ssfTime(_appendTime), AttitudeState(_appendRotation, _appendAngVel));
00030 }
00031 
00032 void AttitudeHistory::AppendHistory(const ssfTime &_appendTime, const Rotation &_appendRotation, const Vector &_appendAngVel)
00033 {
00034     History::AppendHistory(_appendTime);
00035     m_AttitudeHistory.push_back(AttitudeState(_appendRotation, _appendAngVel));
00036     return;
00037 }
00038     
00039 void AttitudeHistory::AppendHistory(const double &_appendTime, const AttitudeState &_appendAttitudeState)
00040 {
00041     AppendHistory(ssfTime(_appendTime), _appendAttitudeState);
00042 }
00043 
00044 void AttitudeHistory::AppendHistory(const ssfTime &_appendTime, const AttitudeState &_appendAttitudeState)
00045 {
00046     History::AppendHistory(_appendTime);
00047     m_AttitudeHistory.push_back(_appendAttitudeState);
00048     return;
00049 }
00050 
00052 void AttitudeHistory::AppendHistory(const vector<ssfTime> &_appendTime, const vector<AttitudeState> &_appendAttitudeState)
00053 {
00054     vector<AttitudeState>::const_iterator iter = _appendAttitudeState.begin();
00055     // History::AppendHistory returns the distance from the end over any overlapping states.
00056     vector<ssfTime>::difference_type retDistance = History::AppendHistory(_appendTime);
00057     
00058     // If there is an overlap, delete the attitude states following the overlap point.
00059     if(retDistance != 0)
00060         m_AttitudeHistory.erase(m_AttitudeHistory.end()-retDistance, m_AttitudeHistory.end());
00061 
00062     for(iter = _appendAttitudeState.begin(); iter != _appendAttitudeState.end(); ++iter)
00063         m_AttitudeHistory.push_back(*iter);
00064 
00065     return;
00066 }
00067 
00069 void AttitudeHistory::AppendHistory(const vector<ssfTime> &_appendTime, const vector<Rotation> &_appendRotation, const vector<Vector> &_appendAngVel)
00070 {
00071     vector<ssfTime>::const_iterator iterTime;
00072     vector<Rotation>::const_iterator iterRot;
00073         iterRot = _appendRotation.begin();
00074     vector<Vector>::const_iterator iterVec;
00075         iterVec = _appendAngVel.begin();
00076         
00077     for(iterTime = _appendTime.begin(); iterTime != _appendTime.end(); ++iterTime)
00078     {
00079         AppendHistory(*iterTime, *iterRot, *iterVec);
00080         ++iterRot;
00081         ++iterVec;
00082     }
00083     return;
00084 }
00085 
00086 void AttitudeHistory::ResetHistory()
00087 {
00088     vector<AttitudeState> newAttitude(0);
00089     m_AttitudeHistory.swap(newAttitude);
00090     History::ResetHistory();
00091     return;
00092 }
00093 
00094 
00095 Matrix AttitudeHistory::GetHistory(const RotationType &_rotType)
00096 {
00097     // initialize the output matrix based on the size of the desired output rotation, the angular velocity 
00098     //  output, and an element for time. The number of rows is equal to the number of time elements.
00099     int RotVectorSize = (m_AttitudeHistory.back()).GetRotation().GetRotation(_rotType).getIndexBound();
00100     int AngVelVectorSize = (m_AttitudeHistory.back()).GetAngularVelocity().getIndexBound();
00101     Matrix returnMatrix(m_TimeHistory.size(), 1 + RotVectorSize + AngVelVectorSize);
00102     
00103     for(int ii = 0; ii < m_TimeHistory.size(); ii++)
00104     {
00105         returnMatrix(MatrixIndexBase + ii, MatrixIndexBase) = m_TimeHistory[ii].GetSeconds();
00106         returnMatrix(MatrixIndexBase + ii, _(MatrixIndexBase+1,MatrixIndexBase + RotVectorSize)) = ~m_AttitudeHistory[ii].GetRotation().GetRotation(_rotType);
00107         returnMatrix(MatrixIndexBase + ii, _(MatrixIndexBase + 1 + RotVectorSize, MatrixIndexBase + RotVectorSize + AngVelVectorSize)) = ~(m_AttitudeHistory[ii].GetAngularVelocity()(_));
00108     }
00109     return returnMatrix;
00110 }
00111 
00112 AttitudeState AttitudeHistory::GetState(const ssfTime& _requestedTime)
00113 {
00114     Rotation tempRot;
00115     Vector tempAngVel(3);
00116     GetState(_requestedTime, tempRot, tempAngVel);
00117     return AttitudeState(tempRot, tempAngVel);
00118 }
00119 void AttitudeHistory::GetState(const ssfTime& _requestedTime, Rotation& _returnRotation, Vector& _returnAngVelVector)
00120 {
00121     int RotVectorSize = QUATERNION_SIZE;
00122     int AngVelVectorSize = (m_AttitudeHistory.back()).GetAngularVelocity().getIndexBound();
00123  
00124     // History::GetState returns the index of the nearest state.
00125     vector<ssfTime>::difference_type nearestTimeIndex = History::GetState(_requestedTime);
00126  
00127     int numDataPoints = 0;
00128     if(m_OriginalInterpolator)
00129         numDataPoints = m_OriginalInterpolator->GetNumberDataPoints();
00130     else 
00131         return;
00132     Vector timeVector(numDataPoints);
00133     Matrix dataMatrix(numDataPoints, RotVectorSize+AngVelVectorSize);
00134     Vector tempVector(RotVectorSize+AngVelVectorSize);
00135     
00136     // See if there is data at the requested time.
00137     if(m_TimeHistory[nearestTimeIndex] != _requestedTime)
00138     {
00139         // Determine if there is currently an interpolation through the requested point.
00140         //      if there isn't, create one, then evaluate the interpolation at the requested data point.
00141         while(m_AttitudeInterpolations.capacity() < nearestTimeIndex)
00142         {
00143             m_AttitudeInterpolations.reserve(m_AttitudeHistory.capacity() + HISTORY_RESERVE_SIZE);
00144         }
00145         // Check to see if the data is initialized to hold an interpolation
00146         if(!m_AttitudeInterpolations[nearestTimeIndex])
00147         {            
00148             // fill in the 'missing' interpolations
00149             for(int kk = m_AttitudeInterpolations.size(); kk < nearestTimeIndex; ++kk)
00150                     m_AttitudeInterpolations.push_back(m_OriginalInterpolator->NewPointer());
00151 
00152             m_AttitudeInterpolations.push_back(m_OriginalInterpolator->NewPointer());
00153         }
00154         // Calculate the interpolation parameters if necessary
00155         if(!m_AttitudeInterpolations[nearestTimeIndex]->GetValid())
00156         {
00157             for(int ii = 1; ii <= numDataPoints; ++ii) 
00158             {
00159                 timeVector(ii) = m_TimeHistory[nearestTimeIndex - (numDataPoints/2-1) + ii].GetSeconds();
00160                 dataMatrix(ii,_(1,RotVectorSize)) = ~m_AttitudeHistory[nearestTimeIndex - (numDataPoints/2-1) + ii].GetRotation().GetRotation(Quaternion_Type);
00161                 dataMatrix(ii,_(RotVectorSize+1,RotVectorSize+AngVelVectorSize)) = ~m_AttitudeHistory[nearestTimeIndex - (numDataPoints/2-1) + ii].GetAngularVelocity();
00162             }
00163 
00164             m_AttitudeInterpolations[nearestTimeIndex]->Interpolate(timeVector, dataMatrix); 
00165         }
00166 
00167         tempVector = m_AttitudeInterpolations[nearestTimeIndex]->Evaluate(_requestedTime.GetSeconds());
00168         _returnRotation.Set(Quaternion(~tempVector(_(1,4))));
00169         _returnAngVelVector(_)  = tempVector(_(5,7));
00170     }
00171     else
00172     { // there happens to be meshpoint data at the requested time, return it.
00173         _returnRotation = m_AttitudeHistory[nearestTimeIndex].GetRotation();
00174         _returnAngVelVector =  m_AttitudeHistory[nearestTimeIndex].GetAngularVelocity();
00175     }
00176 
00177     return;
00178 }
00179 
00180 } // close namespace O_SESSAME
00181 
00182 // Do not change the comments below - they will be added automatically by CVS
00183 /*****************************************************************************
00184 *       $Log: AttitudeHistory.cpp,v $
00185 *       Revision 1.10  2003/05/27 17:35:52  nilspace
00186 *       Updated to prevent errors.
00187 *       
00188 *       Revision 1.9  2003/05/20 17:50:01  nilspace
00189 *       Updated comments.
00190 *       
00191 *       Revision 1.8  2003/05/13 18:45:35  nilspace
00192 *       Added interpolation functionality.
00193 *       
00194 *       Revision 1.7  2003/05/01 18:24:36  nilspace
00195 *       Prevented overlapping Appends by removing the old states and times.
00196 *       
00197 *       Revision 1.6  2003/04/29 20:57:46  nilspace
00198 *       Updated to work with Propagator.
00199 *       
00200 *       Revision 1.5  2003/04/27 22:04:33  nilspace
00201 *       Created the namespace O_SESSAME.
00202 *       
00203 *       Revision 1.4  2003/04/25 17:14:59  nilspace
00204 *       Added OrbitHistory & made sure it builds.
00205 *       Moved Appending time to History.cpp.
00206 *       
00207 *       Revision 1.3  2003/04/23 17:00:46  nilspace
00208 *       Changed to work with AttitudeState and not Rotation and AngVel seperately.
00209 *       Time is now stored as ssfTime.
00210 *       
00211 *       Revision 1.1  2003/03/27 20:29:19  nilspace
00212 *       Initial Submission.
00213 *
00214 ******************************************************************************/

Generated on Wed Aug 6 12:58:42 2003 for Open-Sessame Framework by doxygen1.3