/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef TNW_LIGHT_INTENSITY_UTILS_H_ #define TNW_LIGHT_INTENSITY_UTILS_H_ #include "OdaCommon.h" #include "NwLightIntensityUnits.h" #include #include "NwLightItem.h" /** \details Utils of light intensity conversion. */ namespace NwLightIntensityUtils { /** \details Returns the double result of converting lux light intensity into lumen. \param intensityValue [in] Double value of lux intensity to be converted. \param illuminanceAt [in] Distance from the light source to the surface. \returns Double value with the conversion result. */ constexpr double luxToLumen(double intensityValue, double illuminanceAt) { return intensityValue * illuminanceAt * illuminanceAt; } /** \details Returns the double result of converting watt light intensity into lumen. \param intensityValue [in] Double value of watt intensity to be converted. \param electricalEfficiency [in] Double value of electrical efficiency(lm/W) produced by a light source. \returns Double value with the conversion result. */ constexpr double wattToLumen(double intensityValue, double electricalEfficiency) { return intensityValue * electricalEfficiency; } /** \details Returns the double result of converting lumen light intensity into candella for isotropic distribution. \param value [in] Double value of lumen intensity to be converted. \returns Double value with the conversion result. */ constexpr double isotropicLumenToCandella(double value) { return value / (4 * OdaPI); } /** \details Returns the double result of converting lumen light intensity into candella for diffuse distribution. \param value [in] Double value of lumen intensity to be converted. \returns Double value with the conversion result. */ constexpr double diffuseLumenToCandella(double value) { return value / OdaPI; } /** \details Returns the double result of converting lumen light intensity into candella for spot distribution. \param value [in] Double value of lumen intensity to be converted. \returns Double value with the conversion result. */ constexpr double spotLumenToCandella(double value, double normalizedSpotFlux) { return value / normalizedSpotFlux; } /** \details Returns the double result of converting lumen light intensity into candella for ies distribution. \param value [in] Double value of lumen intensity to be converted. \param initialRatedLumens [in] Double value of initial rated lumens for the lamp or -1 if absolute photometry is used and the intensity values do not depend on different lamp ratings. \param maxIntensity [in] Double value of max flux intensity from .ies file. \param candellaMultiplyingFactor [in] Integer value with multiplying factor for all the candela values in the file. Normally the multiplying factor is 1. \returns Double value with the conversion result. */ constexpr double iesLumenToCandella(double value, double initialRatedLumens, double maxIntensity, OdInt32 candellaMultiplyingFactor) { return (initialRatedLumens > 0.) ? (value * maxIntensity / (candellaMultiplyingFactor * initialRatedLumens)) : value; } /** \details Converts light intensity value to candella. \param lightIntensity [in] light intensity structure value with intensity units and value to be converted. \param args [in] template parameter pack with possible additional parameters for conversion. \remarks this method change OdNwLampIntensity::m_value in inner parameter 'lightIntensity' by conversion value. */ template< typename T, T funcLumenToCandella, class ...Args> constexpr void convertIntensityToCandella(OdNwLampIntensity& lightIntensity, Args ...args) { static_assert(std::is_pointer::value, "Wrong type of function pointer to lumen-candella conversion "); static_assert(std::is_function::type>::value, "Function pointer to lumen-candella conversion is not function type"); static_assert(std::is_same::value, "Function pointer to lumen-candella conversion has wrong signature"); switch (lightIntensity.m_units) { case NwLightIntensityUnits::kCandella: break; case NwLightIntensityUnits::kLumen: lightIntensity.m_value = (*funcLumenToCandella)(lightIntensity.m_value, args...); break; case NwLightIntensityUnits::kLux: lightIntensity.m_value = (*funcLumenToCandella)(luxToLumen(lightIntensity.m_value, lightIntensity.m_illuminanceAt), args...); break; case NwLightIntensityUnits::kWatt: lightIntensity.m_value = (*funcLumenToCandella)(wattToLumen(lightIntensity.m_value, lightIntensity.m_electricalEfficiency), args...); break; default: break; } } } #endif // TNW_LIGHT_INTENSITY_UTILS_H_