OrbitHistory.cpp

Go to the documentation of this file.
00001 
00002 
00008 /*  
00009 */
00011 
00012 #include "OrbitHistory.h"
00013 namespace O_SESSAME {
00014 
00015 OrbitHistory::OrbitHistory()
00016 {
00017     ResetHistory();
00018     m_OrbitHistory.reserve(HISTORY_RESERVE_SIZE);
00019     m_OrbitInterpolations.reserve(HISTORY_RESERVE_SIZE);
00020 }
00021     
00022 void OrbitHistory::AppendHistory(const double &_appendTime, const OrbitState &_appendOrbitState)
00023 {
00024     AppendHistory(ssfTime(_appendTime), _appendOrbitState);
00025 }
00026 
00027 void OrbitHistory::AppendHistory(const ssfTime &_appendTime, const OrbitState &_appendOrbitState)
00028 {
00029     History::AppendHistory(_appendTime);
00030     m_OrbitHistory.push_back(_appendOrbitState);
00031     return;
00032 }
00033 
00034 void OrbitHistory::AppendHistory(const vector<ssfTime> &_appendTime, const vector<OrbitState> &_appendOrbitState)
00035 {
00036     vector<OrbitState>::const_iterator iter;
00037     // History::AppendHistory returns the distance from the end over any overlapping states.
00038     vector<ssfTime>::difference_type retDistance = History::AppendHistory(_appendTime);
00039     
00040     // If there is an overlap, delete the orbit states following the overlap point.
00041     if(retDistance != 0)
00042         m_OrbitHistory.erase(m_OrbitHistory.end()-retDistance, m_OrbitHistory.end());
00043         
00044     // Append the new states to the orbit history.
00045     for(iter = _appendOrbitState.begin(); iter != _appendOrbitState.end(); ++iter)
00046         m_OrbitHistory.push_back(*iter);
00047 
00048     return;
00049 }
00050 
00051 void OrbitHistory::ResetHistory()
00052 {
00053     vector<OrbitState> newOrbit(0);
00054     m_OrbitHistory.swap(newOrbit);
00055     History::ResetHistory();
00056     return;
00057 }
00058 
00059 
00060 Matrix OrbitHistory::GetHistory()
00061 {
00063     // initialize the output matrix based on the size of the desired output state, 
00064     // and an element for time. The number of rows is equal to the number of time elements.
00065     int OrbitVectorSize = (m_OrbitHistory.back()).GetState().getIndexBound();
00066     Matrix returnMatrix(m_TimeHistory.size(), 1 + OrbitVectorSize);
00067     
00068     for(int ii = 0; ii < m_TimeHistory.size(); ii++)
00069     {
00070         returnMatrix(MatrixIndexBase + ii, MatrixIndexBase) = m_TimeHistory[ii].GetSeconds();
00071         returnMatrix(MatrixIndexBase + ii, _(MatrixIndexBase+1,MatrixIndexBase + OrbitVectorSize)) = ~m_OrbitHistory[ii].GetState();
00072     }
00073     return returnMatrix;
00074 }
00075 OrbitState OrbitHistory::GetState(const ssfTime& _requestedTime)
00076 {
00077     OrbitState tempOrbState;
00078     GetState(_requestedTime, tempOrbState);
00079     return tempOrbState;
00080 }
00081 void OrbitHistory::GetState(const ssfTime& _requestedTime, OrbitState& _returnOrbitState)
00082 {
00083     // History::GetState returns the index of the nearest state.
00084     vector<ssfTime>::difference_type nearestTimeIndex = History::GetState(_requestedTime);
00085  
00086     int numDataPoints = 0;
00087     if(m_OriginalInterpolator)
00088         numDataPoints = m_OriginalInterpolator->GetNumberDataPoints();
00089     else 
00090         return;
00091     Vector timeVector(numDataPoints);
00092     Matrix dataMatrix(numDataPoints, NUM_POSVEL_ELEMENTS);
00093     Vector tempVector(NUM_POSVEL_ELEMENTS);
00094     
00095     // See if there is data at the requested time.
00096     if(m_TimeHistory[nearestTimeIndex] != _requestedTime)
00097     {
00098         // Determine if there is currently an interpolation through the requested point.
00099         //      if there isn't, create one, then evaluate the interpolation at the requested data point.
00100         while(m_OrbitInterpolations.capacity() < nearestTimeIndex)
00101         {
00102             m_OrbitInterpolations.reserve(m_OrbitHistory.capacity() + HISTORY_RESERVE_SIZE);
00103         }
00104         // Check to see if the data is initialized to hold an interpolation
00105         if(!m_OrbitInterpolations[nearestTimeIndex])
00106         {            
00107             // fill in the 'missing' interpolations
00108             for(int kk = m_OrbitInterpolations.size(); kk < nearestTimeIndex; ++kk)
00109                     m_OrbitInterpolations.push_back(m_OriginalInterpolator->NewPointer());
00110 
00111             m_OrbitInterpolations.push_back(m_OriginalInterpolator->NewPointer());
00112         }
00113         // Calculate the interpolation parameters if necessary
00114         if(!m_OrbitInterpolations[nearestTimeIndex]->GetValid())
00115         {
00116             for(int ii = 1; ii <= numDataPoints; ++ii) 
00117             {
00118                 timeVector(ii) = m_TimeHistory[nearestTimeIndex - (numDataPoints/2-1) + ii].GetSeconds();
00119                 dataMatrix(ii,_) = ~m_OrbitHistory[nearestTimeIndex - (numDataPoints/2-1) + ii].GetStateRepresentation()->GetPositionVelocity();
00120             }
00121 
00122             m_OrbitInterpolations[nearestTimeIndex]->Interpolate(timeVector, dataMatrix); 
00123         }
00124 
00125         tempVector = m_OrbitInterpolations[nearestTimeIndex]->Evaluate(_requestedTime.GetSeconds());
00126         _returnOrbitState.SetStateRepresentation(new PositionVelocity);
00127         _returnOrbitState.GetStateRepresentation()->SetPositionVelocity(tempVector);
00128             
00129         // Set the returned orbit frame to the same as the history's stored orbit states.
00130         _returnOrbitState.SetOrbitFrame((m_OrbitHistory.front()).GetOrbitFrame());
00131     }
00132     else
00133     { // there happens to be meshpoint data at the requested time, return it.
00134          _returnOrbitState = m_OrbitHistory[nearestTimeIndex];
00135     }
00136 
00137     return;
00138 }
00139 } // close namespace O_SESSAME
00140 
00141 // Do not change the comments below - they will be added automatically by CVS
00142 /*****************************************************************************
00143 *       $Log: OrbitHistory.cpp,v $
00144 *       Revision 1.7  2003/05/22 21:01:31  nilspace
00145 *       Updated comments and added SetOrbitRepresentation(new PositionVelocity).
00146 *       
00147 *       Revision 1.6  2003/05/20 17:50:01  nilspace
00148 *       Updated comments.
00149 *       
00150 *       Revision 1.5  2003/05/13 18:45:35  nilspace
00151 *       Added interpolation functionality.
00152 *       
00153 *       Revision 1.4  2003/05/01 18:24:36  nilspace
00154 *       Prevented overlapping Appends by removing the old states and times.
00155 *       
00156 *       Revision 1.3  2003/04/27 22:04:33  nilspace
00157 *       Created the namespace O_SESSAME.
00158 *       
00159 *       Revision 1.2  2003/04/25 17:15:00  nilspace
00160 *       Added OrbitHistory & made sure it builds.
00161 *       Moved Appending time to History.cpp.
00162 *       
00163 *       Revision 1.1  2003/04/25 13:39:08  nilspace
00164 *       Initial Submission.
00165 *       
00166 *       Revision 1.1  2003/03/27 20:29:19  nilspace
00167 *       Initial Submission.
00168 *
00169 ******************************************************************************/

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