Environment.cpp

Go to the documentation of this file.
00001 
00002 
00008 /* 
00009 *
00010 */
00012 
00013 #include "Environment.h"
00014 #include "CentralBody/CentralBody.h"
00015 namespace O_SESSAME {
00016     
00018 Environment::Environment() : m_CalculatedForces(3), 
00019                              m_CalculatedTorques(3), 
00020                              m_ForcesFunctor(const_cast<Environment*>(this), &Environment::GetForces),
00021                              m_TorquesFunctor(const_cast<Environment*>(this), &Environment::GetTorques)
00022 {
00023     m_pCB = NULL;
00024 }
00025     
00027 Environment::~Environment()
00028 {
00029     if(m_pCB)
00030         m_pCB->ReleaseReference();
00031 }
00032 
00039 Vector Environment::GetTorques(const ssfTime& _currentTime, const OrbitState& _currentOrbitState, const AttitudeState& _currentAttitudeState)
00040 {
00041     m_CalculatedTorques.setToValue(0);
00042     m_funcIterator = m_TorqueFunctions.begin();
00043     while (m_funcIterator != m_TorqueFunctions.end())
00044     {
00045         m_CalculatedTorques += (*m_funcIterator).Evaluate(_currentTime, _currentOrbitState, _currentAttitudeState);
00046         ++m_funcIterator;
00047     }
00048     return m_CalculatedTorques;
00049 }
00050 
00057 Vector Environment::GetForces(const ssfTime& _currentTime, const OrbitState& _currentOrbitState, const AttitudeState& _currentAttitudeState)
00058 {
00059     m_CalculatedForces.setToValue(0);
00060     m_funcIterator = m_ForceFunctions.begin();
00061     while (m_funcIterator != m_ForceFunctions.end())
00062     {
00063         m_CalculatedForces += (*m_funcIterator).Evaluate(_currentTime, _currentOrbitState, _currentAttitudeState);
00064         ++m_funcIterator;
00065     }
00066     return m_CalculatedForces;
00067 }
00068     
00072 void Environment::SetCentralBody(CentralBody *_pCB)
00073 {
00074     m_pCB = _pCB;
00075     return;
00076 }
00077 
00081 const CentralBody* Environment::GetCentralBody() const
00082 {
00083     return m_pCB;
00084 }
00085     
00089 void Environment::AddForceFunction(const EnvFunction &_forceFunc)
00090 {
00091     // iterate through the set of Force Functions to prevent duplication./*
00093     m_funcIterator = m_ForceFunctions.begin();
00094     while (m_funcIterator != m_ForceFunctions.end())
00095     {
00096         if(*m_funcIterator == _forceFunc)
00097             return;
00098     }*/
00099     m_ForceFunctions.push_back(_forceFunc);
00100     return;
00101 }
00105 void Environment::AddTorqueFunction(const EnvFunction &_torqueFunc)
00106 {
00107     // iterate through the set of Torque Functions to prevent duplication./*
00109     m_funcIterator = m_TorqueFunctions.begin();
00110     while (m_funcIterator != m_TorqueFunctions.end())
00111     {
00112         if(*m_funcIterator == _torqueFunc)
00113             return;
00114     }*/
00115     m_TorqueFunctions.push_back(_torqueFunc);
00116     return;
00117 }
00118     
00122 const Functor& Environment::GetForceFunction() const
00123 {
00124     return m_ForcesFunctor;
00125 }
00126 
00130 const Functor& Environment::GetTorqueFunction() const
00131 {
00132     return m_TorquesFunctor;
00133 }
00135 // EnvFunction Member Functions
00137 
00142 EnvFunction::EnvFunction(pt2EnvFunc _EnvFuncPtr) : m_NumParameters(0) , m_EnvFuncParameters(m_NumParameters)
00143 {
00144     m_EnvFuncPtr = _EnvFuncPtr;
00145 }
00152 EnvFunction::EnvFunction(pt2EnvFunc _EnvFuncPtr, const int &_numParameters) : m_NumParameters(_numParameters) , m_EnvFuncParameters(m_NumParameters)
00153 {
00154     m_EnvFuncPtr = _EnvFuncPtr;
00155 }
00163 Vector EnvFunction::Evaluate(const ssfTime& _currentTime, const OrbitState& _currentOrbitState, const AttitudeState& _currentAttitudeState)
00164 {
00165     return m_EnvFuncPtr(_currentTime, _currentOrbitState, _currentAttitudeState, m_EnvFuncParameters);
00166 }
00167 
00177 void EnvFunction::AddParameter(void* _parameter, int _paramNumber)
00178 {
00179     if (_paramNumber > m_NumParameters)
00180     {    
00181         // Calculate the number of parameters "missing" to be temporarily filled
00182         int delta = _paramNumber - m_NumParameters;
00183         if(delta > 1)
00184         {
00185             for(int ii = 1; ii < delta; ++ii)
00186             {
00187                 m_EnvFuncParameters.push_back(0);
00188             }
00189         }
00190         m_EnvFuncParameters.push_back(_parameter);
00191     }
00192     else
00193         m_EnvFuncParameters.insert(m_EnvFuncParameters.begin() + _paramNumber - 1, _parameter);
00194     
00195     m_NumParameters = _paramNumber;
00196 
00197 }
00198     
00204 void EnvFunction::ChangeParameter(void* _parameter, int _paramNumber)
00205 {
00206     RemoveParameter(_paramNumber);
00207     AddParameter(_parameter, _paramNumber);
00208 }
00209 
00218 void EnvFunction::RemoveParameter(int _paramNumber)
00219 {
00220     if(_paramNumber <= m_NumParameters)
00221         m_EnvFuncParameters.erase(m_EnvFuncParameters.begin()+_paramNumber);
00222     else if(_paramNumber == -1)
00223         m_EnvFuncParameters.pop_back();
00224     else
00225         return;
00226     
00227     --m_NumParameters;
00228 }
00229 } // close namespace O_SESSAME
00230 
00231 // Do not change the comments below - they will be added automatically by CVS
00232 /*****************************************************************************
00233 *       $Log: Environment.cpp,v $
00234 *       Revision 1.8  2003/06/12 18:06:35  nilspace
00235 *       .
00236 *       
00237 *       Revision 1.7  2003/06/10 15:58:52  nilspace
00238 *       GetTorques now incrementes the function iterator.
00239 *       
00240 *       Revision 1.6  2003/05/22 03:42:32  nilspace
00241 *       Moved documentation to the implementation file.
00242 *       
00243 *       Revision 1.5  2003/05/13 18:59:16  nilspace
00244 *       Fixed some comments.
00245 *       
00246 *       Revision 1.4  2003/05/05 20:45:46  nilspace
00247 *       Changed the pass-by-address parameters to pass-by-reference.
00248 *       
00249 *       Revision 1.3  2003/05/02 02:16:29  nilspace
00250 *       Documented the API.
00251 *       Added a GetTorquesFunction().
00252 *       
00253 *       Revision 1.2  2003/04/27 22:04:33  nilspace
00254 *       Created the namespace O_SESSAME.
00255 *       
00256 *       Revision 1.1  2003/04/08 22:37:22  nilspace
00257 *       Initial Submission.
00258 *       
00259 *
00260 ******************************************************************************/

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