projects/biogears/src/engine/Systems/Nervous.cpp
void Nervous::SetPupilEffects()
{
  // Get modifiers from Drugs
  double leftPupilSizeResponseLevel = m_data.GetDrugs().GetPupillaryResponse().GetSizeModifier().GetValue();
  double leftPupilReactivityResponseLevel = m_data.GetDrugs().GetPupillaryResponse().GetReactivityModifier().GetValue();
  double rightPupilSizeResponseLevel = leftPupilSizeResponseLevel;
  double rightPupilReactivityResponseLevel = leftPupilReactivityResponseLevel;

  // Calculate the TBI response
  if (m_data.GetActions().GetPatientActions().HasBrainInjury()) {
    SEBrainInjury* b = m_data.GetActions().GetPatientActions().GetBrainInjury();

    if (b->GetSeverity().GetValue() > 0) {
      double icp_mmHg = m_data.GetCardiovascular().GetIntracranialPressure().GetValue(PressureUnit::mmHg);

      if (b->GetType() == CDM::enumBrainInjuryType::Diffuse) {
        //https://www.wolframalpha.com/input/?i=y%3D(1+%2F+(1+%2B+exp(-2.0*(x+-+24))))+from+18%3Cx%3C28
        leftPupilSizeResponseLevel += (1 / (1 + exp(-2.0 * (icp_mmHg - 24))));
        //https://www.wolframalpha.com/input/?i=y%3D-.001*pow(10,+.27*(x+-+15))+from+18%3Cx%3C28+and+-1%3Cy%3C0
        leftPupilReactivityResponseLevel += -.001 * pow(10, .27 * (icp_mmHg - 15));
        rightPupilSizeResponseLevel = leftPupilSizeResponseLevel;
        rightPupilReactivityResponseLevel = leftPupilReactivityResponseLevel;
      } else if (b->GetType() == CDM::enumBrainInjuryType::LeftFocal) {
        leftPupilSizeResponseLevel += (1 / (1 + exp(-2.0 * (icp_mmHg - 24))));
        leftPupilReactivityResponseLevel += -.001 * pow(10, .27 * (icp_mmHg - 15));
      } else if (b->GetType() == CDM::enumBrainInjuryType::RightFocal) {
        rightPupilSizeResponseLevel += (1 / (1 + exp(-2.0 * (icp_mmHg - 24))));
        rightPupilReactivityResponseLevel += -.001 * pow(10, .27 * (icp_mmHg - 15));
      }
    }
  }

  BLIM(leftPupilSizeResponseLevel, -1, 1);
  BLIM(leftPupilReactivityResponseLevel, -1, 1);
  BLIM(rightPupilSizeResponseLevel, -1, 1);
  BLIM(rightPupilReactivityResponseLevel, -1, 1);
  GetLeftEyePupillaryResponse().GetSizeModifier().SetValue(leftPupilSizeResponseLevel);
  GetLeftEyePupillaryResponse().GetReactivityModifier().SetValue(leftPupilReactivityResponseLevel);
  GetRightEyePupillaryResponse().GetSizeModifier().SetValue(rightPupilSizeResponseLevel);
  GetRightEyePupillaryResponse().GetReactivityModifier().SetValue(rightPupilReactivityResponseLevel);
}
//--------------------------------------------------------------------------------------------------
/// \brief
/// Sets pupil size and reactivity modifiers based on drug and TBI effects
///
/// \details
/// Modifiers are on a scale between -1 (for reduction in size/reactivity) and 1 (for increase)
/// TBI effects are applied to the eye on the same side of the injury if localized or both if diffuse
/// Drug and TBI pupil effects are simply summed together
//--------------------------------------------------------------------------------------------------
\brief
Sets pupil size and reactivity modifiers based on drug and TBI effects

\details
Modifiers are on a scale between -1 (for reduction in size/reactivity) and 1 (for increase)
TBI effects are applied to the eye on the same side of the injury if localized or both if diffuse
Drug and TBI pupil effects are simply summed together
\ brief Sets pupil size and reactivity modifiers based on drug and TBI effects \ details Modifiers are on a scale between - 1 ( for reduction in size / reactivity ) and 1 ( for increase ) TBI effects are applied to the eye on the same side of the injury if localized or both if diffuse Drug and TBI pupil effects are simply summed together
void Nervous::SetPupilEffects()
{
  double leftPupilSizeResponseLevel = m_data.GetDrugs().GetPupillaryResponse().GetSizeModifier().GetValue();
  double leftPupilReactivityResponseLevel = m_data.GetDrugs().GetPupillaryResponse().GetReactivityModifier().GetValue();
  double rightPupilSizeResponseLevel = leftPupilSizeResponseLevel;
  double rightPupilReactivityResponseLevel = leftPupilReactivityResponseLevel;
  if (m_data.GetActions().GetPatientActions().HasBrainInjury()) {
    SEBrainInjury* b = m_data.GetActions().GetPatientActions().GetBrainInjury();
    if (b->GetSeverity().GetValue() > 0) {
      double icp_mmHg = m_data.GetCardiovascular().GetIntracranialPressure().GetValue(PressureUnit::mmHg);
      if (b->GetType() == CDM::enumBrainInjuryType::Diffuse) {
        leftPupilSizeResponseLevel += (1 / (1 + exp(-2.0 * (icp_mmHg - 24))));
        leftPupilReactivityResponseLevel += -.001 * pow(10, .27 * (icp_mmHg - 15));
        rightPupilSizeResponseLevel = leftPupilSizeResponseLevel;
        rightPupilReactivityResponseLevel = leftPupilReactivityResponseLevel;
      } else if (b->GetType() == CDM::enumBrainInjuryType::LeftFocal) {
        leftPupilSizeResponseLevel += (1 / (1 + exp(-2.0 * (icp_mmHg - 24))));
        leftPupilReactivityResponseLevel += -.001 * pow(10, .27 * (icp_mmHg - 15));
      } else if (b->GetType() == CDM::enumBrainInjuryType::RightFocal) {
        rightPupilSizeResponseLevel += (1 / (1 + exp(-2.0 * (icp_mmHg - 24))));
        rightPupilReactivityResponseLevel += -.001 * pow(10, .27 * (icp_mmHg - 15));
      }
    }
  }
  BLIM(leftPupilSizeResponseLevel, -1, 1);
  BLIM(leftPupilReactivityResponseLevel, -1, 1);
  BLIM(rightPupilSizeResponseLevel, -1, 1);
  BLIM(rightPupilReactivityResponseLevel, -1, 1);
  GetLeftEyePupillaryResponse().GetSizeModifier().SetValue(leftPupilSizeResponseLevel);
  GetLeftEyePupillaryResponse().GetReactivityModifier().SetValue(leftPupilReactivityResponseLevel);
  GetRightEyePupillaryResponse().GetSizeModifier().SetValue(rightPupilSizeResponseLevel);
  GetRightEyePupillaryResponse().GetReactivityModifier().SetValue(rightPupilReactivityResponseLevel);
}
void Nervous :: SetPupilEffects ( ) { double leftPupilSizeResponseLevel = m_data . GetDrugs ( ) . GetPupillaryResponse ( ) . GetSizeModifier ( ) . GetValue ( ) ; double leftPupilReactivityResponseLevel = m_data . GetDrugs ( ) . GetPupillaryResponse ( ) . GetReactivityModifier ( ) . GetValue ( ) ; double rightPupilSizeResponseLevel = leftPupilSizeResponseLevel ; double rightPupilReactivityResponseLevel = leftPupilReactivityResponseLevel ; if ( m_data . GetActions ( ) . GetPatientActions ( ) . HasBrainInjury ( ) ) { SEBrainInjury * b = m_data . GetActions ( ) . GetPatientActions ( ) . GetBrainInjury ( ) ; if ( b -> GetSeverity ( ) . GetValue ( ) > 0 ) { double icp_mmHg = m_data . GetCardiovascular ( ) . GetIntracranialPressure ( ) . GetValue ( PressureUnit :: mmHg ) ; if ( b -> GetType ( ) == CDM :: enumBrainInjuryType :: Diffuse ) { leftPupilSizeResponseLevel += ( 1 / ( 1 + exp ( -2.0 * ( icp_mmHg - 24 ) ) ) ) ; leftPupilReactivityResponseLevel += -.001 * pow ( 10 , .27 * ( icp_mmHg - 15 ) ) ; rightPupilSizeResponseLevel = leftPupilSizeResponseLevel ; rightPupilReactivityResponseLevel = leftPupilReactivityResponseLevel ; } else if ( b -> GetType ( ) == CDM :: enumBrainInjuryType :: LeftFocal ) { leftPupilSizeResponseLevel += ( 1 / ( 1 + exp ( -2.0 * ( icp_mmHg - 24 ) ) ) ) ; leftPupilReactivityResponseLevel += -.001 * pow ( 10 , .27 * ( icp_mmHg - 15 ) ) ; } else if ( b -> GetType ( ) == CDM :: enumBrainInjuryType :: RightFocal ) { rightPupilSizeResponseLevel += ( 1 / ( 1 + exp ( -2.0 * ( icp_mmHg - 24 ) ) ) ) ; rightPupilReactivityResponseLevel += -.001 * pow ( 10 , .27 * ( icp_mmHg - 15 ) ) ; } } } BLIM ( leftPupilSizeResponseLevel , -1 , 1 ) ; BLIM ( leftPupilReactivityResponseLevel , -1 , 1 ) ; BLIM ( rightPupilSizeResponseLevel , -1 , 1 ) ; BLIM ( rightPupilReactivityResponseLevel , -1 , 1 ) ; GetLeftEyePupillaryResponse ( ) . GetSizeModifier ( ) . SetValue ( leftPupilSizeResponseLevel ) ; GetLeftEyePupillaryResponse ( ) . GetReactivityModifier ( ) . SetValue ( leftPupilReactivityResponseLevel ) ; GetRightEyePupillaryResponse ( ) . GetSizeModifier ( ) . SetValue ( rightPupilSizeResponseLevel ) ; GetRightEyePupillaryResponse ( ) . GetReactivityModifier ( ) . SetValue ( rightPupilReactivityResponseLevel ) ; }
\brief
Sets pupil size and reactivity modifiers based on drug and TBI effects
\ brief Sets pupil size and reactivity modifiers based on drug and TBI effects
// Get modifiers from Drugs // Calculate the TBI response //https://www.wolframalpha.com/input/?i=y%3D(1+%2F+(1+%2B+exp(-2.0*(x+-+24))))+from+18%3Cx%3C28 //https://www.wolframalpha.com/input/?i=y%3D-.001*pow(10,+.27*(x+-+15))+from+18%3Cx%3C28+and+-1%3Cy%3C0