1.3.49
 
Loading...
Searching...
No Matches
global.h File Reference
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <exception>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <random>
#include <set>
#include <sstream>
#include <stdexcept>
#include <thread>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include "helios_vector_types.h"
#include "pugixml.hpp"

Go to the source code of this file.

Data Structures

struct  helios::Timer
 MATLAB-style timer. Call tic() to start timer, call toc() to stop timer and print duration. More...
 
class  helios::ProgressBar
 Simple progress bar for console output. More...
 
class  helios::PixelUVKey
 Represents a unique key for a pixel using its UV coordinates. More...
 
struct  helios::PixelUVKeyHash
 A hash function object for PixelUVKey. More...
 
struct  helios::capture_cerr
 A utility struct to capture and store what is written to std::cerr. More...
 
struct  helios::capture_cout
 A utility struct to capture and store what is written to std::cout. More...
 

Macros

#define DEPRECATED_MSG(msg, func)   func
 Macro for marking functions as deprecated with optional custom message.
 
#define DEPRECATED_NOMSG(func)   func
 
#define GET_ARG_COUNT(...)   GET_ARG_COUNT_IMPL(__VA_ARGS__, 2, 1)
 
#define GET_ARG_COUNT_IMPL(_1, _2, N, ...)   N
 
#define DEPRECATED(...)   GET_DEPRECATED_MACRO(__VA_ARGS__)(__VA_ARGS__)
 
#define GET_DEPRECATED_MACRO(...)   GET_DEPRECATED_MACRO_IMPL(GET_ARG_COUNT(__VA_ARGS__))
 
#define GET_DEPRECATED_MACRO_IMPL(count)   GET_DEPRECATED_MACRO_IMPL2(count)
 
#define GET_DEPRECATED_MACRO_IMPL2(count)   DEPRECATED_##count##_ARGS
 
#define DEPRECATED_1_ARGS(func)   DEPRECATED_NOMSG(func)
 
#define DEPRECATED_2_ARGS(func, msg)   DEPRECATED_MSG(msg, func)
 
#define M_PI   3.14159265358979323846
 Pi constant.
 

Typedefs

typedef unsigned int uint
 Unsigned integer type.
 

Functions

template<typename To , typename From >
constexpr To scast (From &&v) noexcept
 Static cast for converting between types.
 
void helios::helios_runtime_error (const std::string &error_message)
 Function to throw a runtime error.
 
void helios::makeRotationMatrix (float rotation, const char *axis, float(&transform)[16])
 Construct a rotation matrix to perform rotation about the x-, y-, or z-axis.
 
void helios::makeRotationMatrix (float rotation, const helios::vec3 &axis, float(&transform)[16])
 Construct a rotation matrix to perform rotation about an arbitrary axis passing through the origin.
 
void helios::makeRotationMatrix (float rotation, const helios::vec3 &origin, const helios::vec3 &axis, float(&transform)[16])
 Construct a rotation matrix to perform rotation about an arbitrary line (not necessarily passing through the origin).
 
void helios::makeTranslationMatrix (const helios::vec3 &translation, float(&transform)[16])
 Construct translation matrix.
 
void helios::makeScaleMatrix (const helios::vec3 &scale, float(&transform)[16])
 Construct matrix to scale about the origin.
 
void helios::makeScaleMatrix (const helios::vec3 &scale, const helios::vec3 &point, float(&transform)[16])
 Construct matrix to scale about arbitrary point in space.
 
void helios::matmult (const float ML[16], const float MR[16], float(&T)[16])
 Multiply 4x4 matrices: T=ML*MR.
 
void helios::vecmult (const float M[16], const float v[3], float(&result)[3])
 Multiply 4x4 transformation matrix by 3-element vector: T=M*v.
 
void helios::vecmult (const float M[16], const helios::vec3 &v3, helios::vec3 &result)
 Multiply 4x4 transformation matrix by 3D vector: T=M*v.
 
void helios::makeIdentityMatrix (float(&T)[16])
 Construct an identity matrix.
 
float helios::deg2rad (float deg)
 Convert degrees to radians.
 
float helios::rad2deg (float rad)
 Convert radians to degrees.
 
float helios::atan2_2pi (float y, float x)
 Four quadrant arc tangent between 0 and 2*pi.
 
SphericalCoord helios::cart2sphere (const vec3 &Cartesian)
 Convert Cartesian coordinates to spherical coordinates.
 
vec3 helios::sphere2cart (const SphericalCoord &Spherical)
 Convert Spherical coordinates to Cartesian coordinates.
 
vec2 helios::string2vec2 (const char *str)
 Convert a space-delimited string into a vec2 vector.
 
vec3 helios::string2vec3 (const char *str)
 Convert a space-delimited string into a vec3 vector.
 
vec4 helios::string2vec4 (const char *str)
 Convert a space-delimited string into a vec4 vector.
 
int2 helios::string2int2 (const char *str)
 Convert a space-delimited string into an int2 vector.
 
int3 helios::string2int3 (const char *str)
 Convert a space-delimited string into an int3 vector.
 
int4 helios::string2int4 (const char *str)
 Convert a space-delimited string into an int4 vector.
 
bool helios::parse_float (const std::string &input_string, float &converted_float)
 Convert a string into a float with error checking.
 
bool helios::parse_double (const std::string &input_string, double &converted_double)
 Convert a string into a double with error checking.
 
bool helios::parse_int (const std::string &input_string, int &converted_int)
 Convert a string into an integer with error checking.
 
bool helios::parse_int2 (const std::string &input_string, int2 &converted_int2)
 Convert a string into an int2 with error checking.
 
bool helios::parse_int3 (const std::string &input_string, int3 &converted_int3)
 Convert a string into an int3 with error checking.
 
bool helios::parse_uint (const std::string &input_string, uint &converted_uint)
 Convert a string into an unsigned integer with error checking.
 
bool helios::parse_vec2 (const std::string &input_string, vec2 &converted_vec2)
 Convert a string into a vec2 with error checking.
 
bool helios::parse_vec3 (const std::string &input_string, vec3 &converted_vec3)
 Convert a string into a vec3 with error checking.
 
bool helios::parse_RGBcolor (const std::string &input_string, RGBcolor &converted_rgb)
 Convert a string into an RGBcolor with error checking.
 
bool helios::open_xml_file (const std::string &xml_file, pugi::xml_document &xmldoc, std::string &error_string)
 Opens and parses an XML file into a pugi::xml_document object.
 
int helios::parse_xml_tag_int (const pugi::xml_node &node, const std::string &tag, const std::string &calling_function)
 Parse an XML tag containing an integer value.
 
float helios::parse_xml_tag_float (const pugi::xml_node &node, const std::string &tag, const std::string &calling_function)
 Parse an XML tag containing a float value.
 
vec2 helios::parse_xml_tag_vec2 (const pugi::xml_node &node, const std::string &tag, const std::string &calling_function)
 Parse an XML tag containing a vec2 value (i.e., two space delimited floats)
 
vec3 helios::parse_xml_tag_vec3 (const pugi::xml_node &node, const std::string &tag, const std::string &calling_function)
 Parse an XML tag containing a vec3 value (i.e., three space delimited floats)
 
std::string helios::parse_xml_tag_string (const pugi::xml_node &node, const std::string &tag, const std::string &calling_function)
 Parse an XML tag containing a string.
 
RGBAcolor helios::string2RGBcolor (const char *str)
 Convert a space-delimited string into an RGBcolor vector.
 
std::string helios::deblank (const char *input)
 Remove all whitespace from character array.
 
std::string helios::deblank (const std::string &input)
 Remove all whitespace from a string.
 
std::string helios::trim_whitespace (const std::string &input)
 Remove leading and trailing whitespace from a string.
 
std::vector< std::string > helios::separate_string_by_delimiter (const std::string &inputstring, const std::string &delimiter)
 Separate string by delimiter and store into a vector.
 
template<typename anytype >
anytype helios::clamp (anytype value, anytype min, anytype max)
 Clamp value to be within some specified bounds.
 
float helios::sum (const std::vector< float > &vect)
 Sum of a vector of floats.
 
float helios::mean (const std::vector< float > &vect)
 Mean value of a vector of floats.
 
float helios::min (const std::vector< float > &vect)
 Minimum value of a vector of floats.
 
int helios::min (const std::vector< int > &vect)
 Minimum value of a vector of ints.
 
vec3 helios::min (const std::vector< vec3 > &vect)
 Minimum value of a vector of vec3's.
 
float helios::max (const std::vector< float > &vect)
 Maximum value of a vector of floats.
 
int helios::max (const std::vector< int > &vect)
 Maximum value of a vector of ints.
 
vec3 helios::max (const std::vector< vec3 > &vect)
 Maximum value of a vector of vec3's.
 
float helios::stdev (const std::vector< float > &vect)
 Standard deviation of a vector of floats.
 
float helios::median (std::vector< float > vect)
 Median of a vector of floats.
 
template<typename anytype >
std::enable_if< std::is_default_constructible< anytype >::value >::type helios::resize_vector (std::vector< std::vector< anytype > > &vec, size_t Nx, size_t Ny)
 Resize 2D C++ vector.
 
template<typename anytype >
std::enable_if< std::is_default_constructible< anytype >::value >::type helios::resize_vector (std::vector< std::vector< std::vector< anytype > > > &vec, size_t Nx, size_t Ny, size_t Nz)
 Resize 3D C++ vector.
 
template<typename anytype >
std::enable_if< std::is_default_constructible< anytype >::value >::type helios::resize_vector (std::vector< std::vector< std::vector< std::vector< anytype > > > > &vec, size_t Nx, size_t Ny, size_t Nz, size_t Nw)
 Resize 4D C++ vector.
 
RGBcolor helios::blend (const RGBcolor &color0, const RGBcolor &color1, float weight)
 Blend two RGB colors together.
 
RGBAcolor helios::blend (const RGBAcolor &color0, const RGBAcolor &color1, float weight)
 Blend two RGBA colors together.
 
vec3 helios::rotatePoint (const vec3 &position, const SphericalCoord &rotation)
 Function to rotate a 3D vector given spherical angles elevation and azimuth.
 
vec3 helios::rotatePoint (const vec3 &position, float theta, float phi)
 Function to rotate a 3D vector given spherical angles elevation and azimuth.
 
vec3 helios::rotatePointAboutLine (const vec3 &point, const vec3 &line_base, const vec3 &line_direction, float theta)
 Rotate a 3D vector about an arbitrary line.
 
float helios::calculateTriangleArea (const vec3 &v0, const vec3 &v1, const vec3 &v2)
 Calculate the area of a triangle given its three vertices.
 
Date helios::CalendarDay (int Julian_day, int year)
 Convert Julian day to calendar day (day,month,year)
 
int helios::JulianDay (int day, int month, int year)
 Convert calendar day (day,month,year) to Julian day.
 
int helios::JulianDay (const Date &date)
 Convert calendar day (day,month,year) to Julian day.
 
float helios::randu ()
 Random number from a uniform distribution between 0 and 1.
 
int helios::randu (int imin, int imax)
 Random integer from a uniform distribution between imin and imax.
 
float helios::acos_safe (float x)
 arccosine function to handle cases when round-off errors cause an argument <-1 or >1, and thus regular acos() returns NaN
 
float helios::asin_safe (float x)
 arcsine function to handle cases when round-off errors cause an argument <-1 or >1, and thus regular asin() returns NaN
 
template<typename T >
helios::powi (T base, std::size_t exp)
 Exponentiation function for integer powers.
 
bool helios::lineIntersection (const vec2 &p1, const vec2 &q1, const vec2 &p2, const vec2 &q2)
 Determine if two line segments intersect. The lines segments are defined by vertices (p1,q1) and (p2,q2)
 
bool helios::pointOnSegment (const vec2 &point, const vec2 &seg_start, const vec2 &seg_end)
 Determines if a point lies on a given segment.
 
bool helios::pointInPolygon (const vec2 &point, const std::vector< vec2 > &polygon_verts)
 Determine whether point lines within a polygon.
 
void helios::wait (float seconds)
 Wait/sleep for a specified amount of time.
 
bool helios::PNGHasAlpha (const char *filename)
 Check whether PNG image file has an alpha/transparency channel.
 
std::vector< std::vector< bool > > helios::readPNGAlpha (const std::string &filename)
 Function to read the alpha channel from a PNG image.
 
void helios::readPNG (const std::string &filename, uint &width, uint &height, std::vector< helios::RGBAcolor > &pixel_data)
 Function to read a PNG image file into pixel data array.
 
void helios::writePNG (const std::string &filename, uint width, uint height, const std::vector< helios::RGBAcolor > &pixel_data)
 Function to write a PNG image based on pixel data.
 
void helios::writePNG (const std::string &filename, uint width, uint height, const std::vector< unsigned char > &pixel_data)
 Function to write a PNG image based on pixel data.
 
void helios::readJPEG (const std::string &filename, uint &width, uint &height, std::vector< helios::RGBcolor > &pixel_data)
 Function to read a JPEG image file into pixel data array.
 
helios::int2 helios::getImageResolutionJPEG (const std::string &filename)
 Function to read a JPEG image file into pixel data array.
 
void helios::writeJPEG (const std::string &filename, uint width, uint height, const std::vector< helios::RGBcolor > &pixel_data)
 Function to write a JPEG image based on pixel data.
 
void helios::writeJPEG (const std::string &filename, uint width, uint height, const std::vector< unsigned char > &pixel_data)
 Function to write a JPEG image based on pixel data.
 
template<typename T >
std::vector< T > helios::flatten (const std::vector< std::vector< T > > &vec)
 Template function to flatten a 2D vector into a 1D vector.
 
template<typename T >
std::vector< T > helios::flatten (const std::vector< std::vector< std::vector< T > > > &vec)
 Template function to flatten a 3D vector into a 1D vector.
 
template<typename T >
std::vector< T > helios::flatten (const std::vector< std::vector< std::vector< std::vector< T > > > > &vec)
 Template function to flatten a 4D vector into a 1D vector.
 
helios::vec3 helios::spline_interp3 (float u, const vec3 &x_start, const vec3 &tan_start, const vec3 &x_end, const vec3 &tan_end)
 Function to perform cubic Hermite spline interpolation.
 
float helios::XMLloadfloat (pugi::xml_node node, const char *field)
 Function to load and convert a field in a pugi XML node into a float.
 
int helios::XMLloadint (pugi::xml_node node, const char *field)
 Function to load and convert a field in a pugi XML node into an int.
 
std::string helios::XMLloadstring (pugi::xml_node node, const char *field)
 Function to load and convert a field in a pugi XML node into a string.
 
helios::vec2 helios::XMLloadvec2 (pugi::xml_node node, const char *field)
 Function to load and convert a field in a pugi XML node into a vec2.
 
helios::vec3 helios::XMLloadvec3 (pugi::xml_node node, const char *field)
 Function to load and convert a field in a pugi XML node into a vec3.
 
helios::vec4 helios::XMLloadvec4 (pugi::xml_node node, const char *field)
 Function to load and convert a field in a pugi XML node into a vec4.
 
helios::int2 helios::XMLloadint2 (pugi::xml_node node, const char *field)
 Function to load and convert a field in a pugi XML node into a vec2.
 
helios::int3 helios::XMLloadint3 (pugi::xml_node node, const char *field)
 Function to load and convert a field in a pugi XML node into a int3.
 
helios::int4 helios::XMLloadint4 (pugi::xml_node node, const char *field)
 Function to load and convert a field in a pugi XML node into a int4.
 
helios::RGBcolor helios::XMLloadrgb (pugi::xml_node node, const char *field)
 Function to load and convert a field in a pugi XML node into an RGB color vector.
 
helios::RGBAcolor helios::XMLloadrgba (pugi::xml_node node, const char *field)
 Function to load and convert a field in a pugi XML node into an RGBA color vector.
 
float helios::fzero (float(*function)(float value, std::vector< float > &variables, const void *parameters), std::vector< float > &variables, const void *parameters, float init_guess, float err_tol=0.0001f, int max_iterations=100)
 Use Newton-Raphson method to find the zero of a function.
 
float helios::fzero (float(*function)(float value, std::vector< float > &variables, const void *parameters), std::vector< float > &variables, const void *parameters, float init_guess, bool &converged, float err_tol=0.0001f, int max_iterations=100)
 Use Newton-Raphson method to find the zero of a function with convergence status.
 
float helios::interp1 (const std::vector< helios::vec2 > &points, float x)
 Function to perform linear interpolation based on a vector of discrete (x,y) values.
 
float helios::point_distance (const helios::vec3 &p1, const helios::vec3 &p2)
 Function to calculate the distance between two points.
 
std::vector< float > helios::linspace (float start, float end, int num)
 Generate linearly spaced values between two endpoints.
 
std::vector< vec2helios::linspace (const vec2 &start, const vec2 &end, int num)
 Generate linearly spaced vec2 values between two endpoints.
 
std::vector< vec3helios::linspace (const vec3 &start, const vec3 &end, int num)
 Generate linearly spaced vec3 values between two endpoints.
 
std::vector< vec4helios::linspace (const vec4 &start, const vec4 &end, int num)
 Generate linearly spaced vec4 values between two endpoints.
 
std::string helios::getFileExtension (const std::string &filepath)
 Parse a file string to get the extension.
 
std::string helios::getFileStem (const std::string &filepath)
 Parse a file string to get the filename without extension.
 
std::string helios::getFileName (const std::string &filepath)
 Parse a file string to get the filename including extension.
 
std::string helios::getFilePath (const std::string &filepath, bool trailingslash=true)
 Parse a file string to get the path (i.e., portion of the string before the file name).
 
bool helios::validateOutputPath (std::string &output_directory, const std::vector< std::string > &allowable_file_extensions={})
 Check whether output file and/or directory is valid. Add a trailing slash if it is a directory.
 
std::filesystem::path helios::resolveAssetPath (const std::string &relativePath)
 Resolve asset file path using cpplocate, allowing executables to run from any directory.
 
std::filesystem::path helios::resolvePluginAsset (const std::string &pluginName, const std::string &assetPath)
 Resolve plugin-specific asset path.
 
std::filesystem::path helios::resolveFilePath (const std::string &filename)
 Resolve file path using standard Helios resolution hierarchy.
 
std::filesystem::path helios::resolveSpectraPath (const std::string &spectraFile)
 Resolve spectral data file path.
 
bool helios::validateAssetPath (const std::filesystem::path &assetPath)
 Validate that an asset file exists and is readable.
 
std::filesystem::path helios::findProjectRoot (const std::filesystem::path &startPath=std::filesystem::current_path())
 Find the project root directory (directory containing top-level CMakeLists.txt)
 
std::filesystem::path helios::resolveProjectFile (const std::string &relativePath)
 Resolve file path using project-based resolution strategy.
 
std::vector< float > helios::importVectorFromFile (const std::string &filepath)
 Read values contained in a text file into a one-dimensional vector of floats.
 
float helios::sample_Beta_distribution (float mu, float nu, std::minstd_rand0 *generator)
 Sample from Beta(μ,ν) distribution.
 
float helios::sample_ellipsoidal_azimuth (float e, float phi0_degrees, std::minstd_rand0 *generator)
 Samples an azimuth angle for an ellipsoidal distribution.
 
std::vector< float > & helios::operator+= (std::vector< float > &lhs, const std::vector< float > &rhs)
 
std::vector< float > helios::operator+ (const std::vector< float > &vector1, const std::vector< float > &vector2)
 

Variables

constexpr float PI_F = 3.14159265358979323846f
 Pi constant as a float.
 
SphericalCoord helios::nullrotation = make_SphericalCoord(0, 0)
 Default null SphericalCoord that applies no rotation.
 
vec3 helios::nullorigin = make_vec3(0, 0, 0)
 Default null vec3 that gives the origin (0,0,0)
 

Detailed Description

Header file for all global function/object definitions.

Copyright (C) 2016-2025 Brian Bailey

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Definition in file global.h.

Macro Definition Documentation

◆ DEPRECATED

#define DEPRECATED (   ...)    GET_DEPRECATED_MACRO(__VA_ARGS__)(__VA_ARGS__)

Definition at line 42 of file global.h.

◆ DEPRECATED_1_ARGS

#define DEPRECATED_1_ARGS (   func)    DEPRECATED_NOMSG(func)

Definition at line 47 of file global.h.

◆ DEPRECATED_2_ARGS

#define DEPRECATED_2_ARGS (   func,
  msg 
)    DEPRECATED_MSG(msg, func)

Definition at line 48 of file global.h.

◆ DEPRECATED_MSG

#define DEPRECATED_MSG (   msg,
  func 
)    func

Macro for marking functions as deprecated with optional custom message.

Definition at line 33 of file global.h.

◆ DEPRECATED_NOMSG

#define DEPRECATED_NOMSG (   func)    func

Definition at line 34 of file global.h.

◆ GET_ARG_COUNT

#define GET_ARG_COUNT (   ...)    GET_ARG_COUNT_IMPL(__VA_ARGS__, 2, 1)

Definition at line 38 of file global.h.

◆ GET_ARG_COUNT_IMPL

#define GET_ARG_COUNT_IMPL (   _1,
  _2,
  N,
  ... 
)    N

Definition at line 39 of file global.h.

◆ GET_DEPRECATED_MACRO

#define GET_DEPRECATED_MACRO (   ...)    GET_DEPRECATED_MACRO_IMPL(GET_ARG_COUNT(__VA_ARGS__))

Definition at line 43 of file global.h.

◆ GET_DEPRECATED_MACRO_IMPL

#define GET_DEPRECATED_MACRO_IMPL (   count)    GET_DEPRECATED_MACRO_IMPL2(count)

Definition at line 44 of file global.h.

◆ GET_DEPRECATED_MACRO_IMPL2

#define GET_DEPRECATED_MACRO_IMPL2 (   count)    DEPRECATED_##count##_ARGS

Definition at line 45 of file global.h.

◆ M_PI

#define M_PI   3.14159265358979323846

Pi constant.

Definition at line 52 of file global.h.

Typedef Documentation

◆ uint

typedef unsigned int uint

Unsigned integer type.

Definition at line 88 of file global.h.

Function Documentation

◆ blend() [1/2]

RGBAcolor helios::blend ( const RGBAcolor color0,
const RGBAcolor color1,
float  weight 
)

Blend two RGBA colors together.

Parameters
[in]color0First color to blend
[in]color1Second color to blend
[in]weightWeighting to apply to each color during blending. E.g., weight=0 will produce color0, weight=0.5 will be an average of color0 and color1, weight=1 will produce color1.
[in]color0First color to be blended.
[in]color1Second color to be blended.
[in]weightWeighting factor (0<weight<1). A weight of 0 returns color0, weight of 1 returns color1.

Definition at line 93 of file global.cpp.

◆ blend() [2/2]

RGBcolor helios::blend ( const RGBcolor color0,
const RGBcolor color1,
float  weight 
)

Blend two RGB colors together.

Parameters
[in]color0First color to blend
[in]color1Second color to blend
[in]weightWeighting to apply to each color during blending. E.g., weight=0 will produce color0, weight=0.5 will be an average of color0 and color1, weight=1 will produce color1.
[in]color0First color to be blended.
[in]color1Second color to be blended.
[in]weightWeighting factor (0<weight<1). A weight of 0 returns color0, weight of 1 returns color1.

Definition at line 84 of file global.cpp.

◆ CalendarDay()

Date helios::CalendarDay ( int  Julian_day,
int  year 
)

Convert Julian day to calendar day (day,month,year)

Parameters
[in]Julian_dayJulian day of year (1-366)
[in]yearYear in YYYY format
Returns
int3, with int3::x = day, int3::y = month, int3::z = year
See also
JulianDay()

Definition at line 1327 of file global.cpp.

◆ fzero() [1/2]

float helios::fzero ( float(*)(float value, std::vector< float > &variables, const void *parameters)  function,
std::vector< float > &  variables,
const void *  parameters,
float  init_guess,
bool &  converged,
float  err_tol = 0.0001f,
int  max_iterations = 100 
)

Use Newton-Raphson method to find the zero of a function with convergence status.

Parameters
[in]functionFunction to be evaluated. The function should take as its first argument the value at which the function should be evaluated, as second argument any function arguments.
[in]variablesVector of function arguments
[in]parametersPointer to any additional parameters needed by the function
[in]init_guessInitial guess for the zero of the function.
[out]convergedBoolean indicating whether the solver converged successfully.
[in]err_tol[optional] Maximum allowable relative error in solution.
[in]max_iterations[optional] Maximum number of iterations to allow before exiting solver.
Returns
Value of function zero (best estimate even if not converged).

◆ fzero() [2/2]

float helios::fzero ( float(*)(float value, std::vector< float > &variables, const void *parameters)  function,
std::vector< float > &  variables,
const void *  parameters,
float  init_guess,
float  err_tol = 0.0001f,
int  max_iterations = 100 
)

Use Newton-Raphson method to find the zero of a function.

Parameters
[in]functionFunction to be evaluated. The function should take as its first argument the value at which the function should be evaluated, as second argument any function arguments.
[in]variablesVector of function arguments
[in]parametersPointer to any additional parameters needed by the function
[in]init_guessInitial guess for the zero of the function.
[in]err_tol[optional] Maximum allowable relative error in solution.
[in]max_iterations[optional] Maximum number of iterations to allow before exiting solver.

◆ getFileExtension()

std::string helios::getFileExtension ( const std::string &  filepath)

Parse a file string to get the extension.

Example: /path/to/file/filename.ext -> extension=".ext"

Parameters
[in]filepathString containing file path and name
Returns
File extension contained in input string
Note
If the string does not contain an extension, an empty string is returned

Definition at line 2501 of file global.cpp.

◆ getFileName()

std::string helios::getFileName ( const std::string &  filepath)

Parse a file string to get the filename including extension.

Example: /path/to/file/filename.ext -> filename="filename.ext"

Parameters
[in]filepathString containing file path and name
Returns
Filename including extension contained in input string
Note
If the string does not contain a file name, an empty string is returned

Definition at line 2511 of file global.cpp.

◆ getFilePath()

std::string helios::getFilePath ( const std::string &  filepath,
bool  trailingslash = true 
)

Parse a file string to get the path (i.e., portion of the string before the file name).

Example: /path/to/file/filename.ext -> path="/path/to/file/"

Parameters
[in]filepathString containing file path and name
[in]trailingslashIf true, a trailing slash is added to the path
Returns
File path contained in input string
Note
If the string does not contain a path, an empty string is returned

Definition at line 2516 of file global.cpp.

◆ getFileStem()

std::string helios::getFileStem ( const std::string &  filepath)

Parse a file string to get the filename without extension.

Example: /path/to/file/filename.ext -> stem="filename"

Parameters
[in]filepathString containing file path and name
Returns
Filename without extension contained in input string
Note
If the string does not contain a file name, an empty string is returned

Definition at line 2506 of file global.cpp.

◆ getImageResolutionJPEG()

helios::int2 helios::getImageResolutionJPEG ( const std::string &  filename)

Function to read a JPEG image file into pixel data array.

Parameters
[in]filenameName of the JPEG image file

Definition at line 1900 of file global.cpp.

◆ helios_runtime_error()

void helios::helios_runtime_error ( const std::string &  error_message)

Function to throw a runtime error.

Parameters
[in]error_messageMessage to be issued when error is thrown.

Definition at line 32 of file global.cpp.

◆ importVectorFromFile()

std::vector< float > helios::importVectorFromFile ( const std::string &  filepath)

Read values contained in a text file into a one-dimensional vector of floats.

Parameters
[in]filepathPath to text file
Returns
One-dimensional vector of floats contained in text file

Definition at line 2712 of file global.cpp.

◆ interp1()

float helios::interp1 ( const std::vector< helios::vec2 > &  points,
float  x 
)

Function to perform linear interpolation based on a vector of discrete (x,y) values.

Parameters
[in]pointsVector of (x,y) pairs. x values must be monotonically increasing and not duplicated.
[in]xx value at which to interpolate. If x is less than the first x-value in points or greater than the last x-value in points, interp1 will respectively return the first or last y value.
Returns
Value of y interpolated at location x.

Definition at line 2399 of file global.cpp.

◆ JulianDay()

int helios::JulianDay ( int  day,
int  month,
int  year 
)

Convert calendar day (day,month,year) to Julian day.

Parameters
[in]dayDay of month (1-31)
[in]monthMonth of year (1-12)
[in]yearYear in YYYY format
Returns
Julian day of year
See also
CalendarDay()

Definition at line 1366 of file global.cpp.

◆ makeIdentityMatrix()

void helios::makeIdentityMatrix ( float(&)  T[16])

Construct an identity matrix.

Parameters
[in,out]TA reference to a 16-element array representing a flat 4x4 matrix. The array will be filled with the identity matrix values.

Definition at line 688 of file global.cpp.

◆ matmult()

void helios::matmult ( const float  ML[16],
const float  MR[16],
float(&)  T[16] 
)

Multiply 4x4 matrices: T=ML*MR.

Performs matrix multiplication between two 4x4 matrices (ML and MR) and stores the result in the output matrix T. This function implements the standard matrix multiplication algorithm where each element of the result is the dot product of the corresponding row of ML and column of MR.

Parameters
[in]MLThe left 4x4 matrix in the multiplication
[in]MRThe right 4x4 matrix in the multiplication
[out]TReference to a 4x4 matrix where the result will be stored

Definition at line 641 of file global.cpp.

◆ open_xml_file()

bool helios::open_xml_file ( const std::string &  xml_file,
pugi::xml_document &  xmldoc,
std::string &  error_string 
)

Opens and parses an XML file into a pugi::xml_document object.

Parameters
[in]xml_filePath to the XML file to be opened and parsed
[out]xmldocReference to a pugi::xml_document object that will hold the parsed XML data
[out]error_stringReference to a string that will be populated with error information if the function fails
Returns
true if the XML file was successfully opened and parsed, false otherwise (in case of failure, check error_string for details)

Definition at line 1040 of file global.cpp.

◆ operator+()

std::vector< float > helios::operator+ ( const std::vector< float > &  vector1,
const std::vector< float > &  vector2 
)
inline

Definition at line 1282 of file global.h.

◆ operator+=()

std::vector< float > & helios::operator+= ( std::vector< float > &  lhs,
const std::vector< float > &  rhs 
)
inline

Definition at line 1268 of file global.h.

◆ parse_double()

bool helios::parse_double ( const std::string &  input_string,
double &  converted_double 
)

Convert a string into a double with error checking.

Parameters
[in]input_stringString to be converted to numerical value
[out]converted_doubleOutput numerical value converted from input string
Returns
True if conversion was successful, false if unsuccessful

Definition at line 922 of file global.cpp.

◆ parse_float()

bool helios::parse_float ( const std::string &  input_string,
float &  converted_float 
)

Convert a string into a float with error checking.

Parameters
[in]input_stringString to be converted to numerical value
[out]converted_floatOutput numerical value converted from input string
Returns
True if conversion was successful, false if unsuccessful

Definition at line 908 of file global.cpp.

◆ parse_int()

bool helios::parse_int ( const std::string &  input_string,
int &  converted_int 
)

Convert a string into an integer with error checking.

Parameters
[in]input_stringString to be converted to numerical value
[out]converted_intOutput numerical value converted from input string
Returns
True if conversion was successful, false if unsuccessful

Definition at line 935 of file global.cpp.

◆ parse_int2()

bool helios::parse_int2 ( const std::string &  input_string,
int2 converted_int2 
)

Convert a string into an int2 with error checking.

Parameters
[in]input_stringString to be converted to numerical value
[out]converted_int2Output numerical value converted from input string
Returns
True if conversion was successful, false if unsuccessful

Definition at line 948 of file global.cpp.

◆ parse_int3()

bool helios::parse_int3 ( const std::string &  input_string,
int3 converted_int3 
)

Convert a string into an int3 with error checking.

Parameters
[in]input_stringString to be converted to numerical value
[out]converted_int3Output numerical value converted from input string
Returns
True if conversion was successful, false if unsuccessful

Definition at line 962 of file global.cpp.

◆ parse_RGBcolor()

bool helios::parse_RGBcolor ( const std::string &  input_string,
RGBcolor converted_rgb 
)

Convert a string into an RGBcolor with error checking.

Parameters
[in]input_stringString to be converted to numerical value
[out]converted_rgbOutput numerical value converted from input string
Returns
True if conversion was successful, false if unsuccessful

Definition at line 1022 of file global.cpp.

◆ parse_uint()

bool helios::parse_uint ( const std::string &  input_string,
uint converted_uint 
)

Convert a string into an unsigned integer with error checking.

Parameters
[in]input_stringString to be converted to numerical value
[out]converted_uintOutput numerical value converted from input string
Returns
True if conversion was successful, false if unsuccessful

Definition at line 977 of file global.cpp.

◆ parse_vec2()

bool helios::parse_vec2 ( const std::string &  input_string,
vec2 converted_vec2 
)

Convert a string into a vec2 with error checking.

Parameters
[in]input_stringString to be converted to numerical value
[out]converted_vec2Output numerical value converted from input string
Returns
True if conversion was successful, false if unsuccessful

Definition at line 993 of file global.cpp.

◆ parse_vec3()

bool helios::parse_vec3 ( const std::string &  input_string,
vec3 converted_vec3 
)

Convert a string into a vec3 with error checking.

Parameters
[in]input_stringString to be converted to numerical value
[out]converted_vec3Output numerical value converted from input string
Returns
True if conversion was successful, false if unsuccessful

Definition at line 1007 of file global.cpp.

◆ parse_xml_tag_float()

float helios::parse_xml_tag_float ( const pugi::xml_node &  node,
const std::string &  tag,
const std::string &  calling_function 
)

Parse an XML tag containing a float value.

Parameters
[in]nodeXML node containing the tag
[in]tagName of the tag to be parsed
[in]calling_functionName of the function calling this function (for error reporting). e.g., Context::loadXML
Returns
Float value of the tag

Definition at line 1088 of file global.cpp.

◆ parse_xml_tag_int()

int helios::parse_xml_tag_int ( const pugi::xml_node &  node,
const std::string &  tag,
const std::string &  calling_function 
)

Parse an XML tag containing an integer value.

Parameters
[in]nodeXML node containing the tag
[in]tagName of the tag to be parsed
[in]calling_functionName of the function calling this function (for error reporting). e.g., Context::loadXML
Returns
Integer value of the tag

Definition at line 1076 of file global.cpp.

◆ parse_xml_tag_string()

std::string helios::parse_xml_tag_string ( const pugi::xml_node &  node,
const std::string &  tag,
const std::string &  calling_function 
)

Parse an XML tag containing a string.

Parameters
[in]nodeXML node containing the tag
[in]tagName of the tag to be parsed
[in]calling_functionName of the function calling this function (for error reporting). e.g., Context::loadXML
Returns
String value of the tag

Definition at line 1124 of file global.cpp.

◆ parse_xml_tag_vec2()

vec2 helios::parse_xml_tag_vec2 ( const pugi::xml_node &  node,
const std::string &  tag,
const std::string &  calling_function 
)

Parse an XML tag containing a vec2 value (i.e., two space delimited floats)

Parameters
[in]nodeXML node containing the tag
[in]tagName of the tag to be parsed
[in]calling_functionName of the function calling this function (for error reporting). e.g., Context::loadXML
Returns
vec2 value of the tag

Definition at line 1100 of file global.cpp.

◆ parse_xml_tag_vec3()

vec3 helios::parse_xml_tag_vec3 ( const pugi::xml_node &  node,
const std::string &  tag,
const std::string &  calling_function 
)

Parse an XML tag containing a vec3 value (i.e., three space delimited floats)

Parameters
[in]nodeXML node containing the tag
[in]tagName of the tag to be parsed
[in]calling_functionName of the function calling this function (for error reporting). e.g., Context::loadXML
Returns
vec3 value of the tag

Definition at line 1112 of file global.cpp.

◆ PNGHasAlpha()

bool helios::PNGHasAlpha ( const char *  filename)

Check whether PNG image file has an alpha/transparency channel.

Parameters
[in]filenameName of the PNG image file

Definition at line 1405 of file global.cpp.

◆ point_distance()

float helios::point_distance ( const helios::vec3 p1,
const helios::vec3 p2 
)

Function to calculate the distance between two points.

Parameters
[in]p1first point (vec3)
[in]p2second point (vec3)
Returns
distance between p1 and p2 in three dimensions

◆ pointOnSegment()

bool helios::pointOnSegment ( const vec2 point,
const vec2 seg_start,
const vec2 seg_end 
)

Determines if a point lies on a given segment.

Parameters
[in]pointThe point to check.
[in]seg_startThe start point of the segment.
[in]seg_endThe end point of the segment.
Returns
True if the point lies on the segment, otherwise false.

Definition at line 339 of file global.cpp.

◆ powi()

template<typename T >
T helios::powi ( base,
std::size_t  exp 
)

Exponentiation function for integer powers.

Parameters
[in]baseBase to be raised to a power
[in]expExponent to which the base is raised (must be a non-negative integer)

Definition at line 694 of file global.h.

◆ readJPEG()

void helios::readJPEG ( const std::string &  filename,
uint width,
uint height,
std::vector< helios::RGBcolor > &  pixel_data 
)

Function to read a JPEG image file into pixel data array.

Parameters
[in]filenameName of the JPEG image file
[out]widthImage width in pixels
[out]heightImage height in pixels
[out]pixel_dataColors at each pixel (index at pixel_data[row*width+column])

Definition at line 1836 of file global.cpp.

◆ readPNG()

void helios::readPNG ( const std::string &  filename,
uint width,
uint height,
std::vector< helios::RGBAcolor > &  pixel_data 
)

Function to read a PNG image file into pixel data array.

Parameters
[in]filenameName of the PNG image file
[out]widthImage width in pixels
[out]heightImage height in pixels
[out]pixel_dataColors at each pixel (index at pixel_data[row*width+column])

Definition at line 1596 of file global.cpp.

◆ readPNGAlpha()

std::vector< std::vector< bool > > helios::readPNGAlpha ( const std::string &  filename)

Function to read the alpha channel from a PNG image.

Parameters
[in]filenameName of the PNG image file
Returns
2D mask, where false denotes no material

Definition at line 1487 of file global.cpp.

◆ rotatePointAboutLine()

vec3 helios::rotatePointAboutLine ( const vec3 point,
const vec3 line_base,
const vec3 line_direction,
float  theta 
)

Rotate a 3D vector about an arbitrary line.

Parameters
[in]point3D coordinate of point to be rotated
[in]line_basePoint through which line passes
[in]line_directionUnit vector pointing in the direction of the line
[in]thetaRotation angle in radians

Definition at line 162 of file global.cpp.

◆ sample_Beta_distribution()

float helios::sample_Beta_distribution ( float  mu,
float  nu,
std::minstd_rand0 *  generator 
)

Sample from Beta(μ,ν) distribution.

Sample θ_L ∈ [0, π/2] from beta distribution given u∼Uniform[0,1]

Parameters
[in]muFirst parameter of beta distribution
[in]nuSecond parameter of beta distribution
[in]generatorRandom number generator

Definition at line 2724 of file global.cpp.

◆ sample_ellipsoidal_azimuth()

float helios::sample_ellipsoidal_azimuth ( float  e,
float  phi0_degrees,
std::minstd_rand0 *  generator 
)

Samples an azimuth angle for an ellipsoidal distribution.

Parameters
[in]eEccentricity of the ellipsoidal distribution.
[in]phi0_degreesAzimuthal rotation of ellipse (degrees).
[in]generatorRandom number generator.
Returns
The sampled azimuth angle.

Definition at line 2763 of file global.cpp.

◆ scast()

template<typename To , typename From >
constexpr To scast ( From &&  v)
constexprnoexcept

Static cast for converting between types.

Definition at line 92 of file global.h.

◆ validateOutputPath()

bool helios::validateOutputPath ( std::string &  output_directory,
const std::vector< std::string > &  allowable_file_extensions = {} 
)

Check whether output file and/or directory is valid. Add a trailing slash if it is a directory.

Parameters
[in,out]output_directoryString containing the output directory or file name
[in]allowable_file_extensionsVector of allowable file extensions. If the output_directory is a file, it must have one of these extensions.
Returns
True if directory/file was valid, false otherwise

Definition at line 2529 of file global.cpp.

◆ vecmult() [1/2]

void helios::vecmult ( const float  M[16],
const float  v[3],
float(&)  result[3] 
)

Multiply 4x4 transformation matrix by 3-element vector: T=M*v.

Parameters
[in]MA 4x4 matrix represented as a 1D array of 16 elements in row-major order
[in]vA 3D vector represented as an array of 3 elements
[out]resultThe resulting 3D vector after matrix-vector multiplication

Definition at line 673 of file global.cpp.

◆ vecmult() [2/2]

void helios::vecmult ( const float  M[16],
const helios::vec3 v3,
helios::vec3 result 
)

Multiply 4x4 transformation matrix by 3D vector: T=M*v.

Parameters
[in]MA 4x4 matrix represented as a float array of size 16
[in]v3Input 3D vector to be multiplied with the matrix
[out]resultOutput vector containing the result of the multiplication

Definition at line 657 of file global.cpp.

◆ writeJPEG() [1/2]

void helios::writeJPEG ( const std::string &  filename,
uint  width,
uint  height,
const std::vector< helios::RGBcolor > &  pixel_data 
)

Function to write a JPEG image based on pixel data.

Parameters
[in]filenameName of the JPEG image file
[in]widthImage width in pixels
[in]heightImage height in pixels
[in]pixel_dataColors at each pixel (index at pixel_data[row*width+column])

Definition at line 1932 of file global.cpp.

◆ writeJPEG() [2/2]

void helios::writeJPEG ( const std::string &  filename,
uint  width,
uint  height,
const std::vector< unsigned char > &  pixel_data 
)

Function to write a JPEG image based on pixel data.

Parameters
[in]filenameName of the JPEG image file
[in]widthImage width in pixels
[in]heightImage height in pixels
[in]pixel_dataFlat 1D array of pixel color data (index at pixel_data[(row*width+column)*width*height+channel]).
Note
The length of pixel_data must be width*height*3 (or if it is width*height*4, the last channel is ignored).

Definition at line 2000 of file global.cpp.

◆ writePNG() [1/2]

void helios::writePNG ( const std::string &  filename,
uint  width,
uint  height,
const std::vector< helios::RGBAcolor > &  pixel_data 
)

Function to write a PNG image based on pixel data.

Parameters
[in]filenameName of the PNG image file
[in]widthImage width in pixels
[in]heightImage height in pixels
[in]pixel_dataColors at each pixel (index at pixel_data[row*width+column])

Definition at line 1746 of file global.cpp.

◆ writePNG() [2/2]

void helios::writePNG ( const std::string &  filename,
uint  width,
uint  height,
const std::vector< unsigned char > &  pixel_data 
)

Function to write a PNG image based on pixel data.

Parameters
[in]filenameName of the PNG image file
[in]widthImage width in pixels
[in]heightImage height in pixels
[in]pixel_datapixel_data Flat 1D array of pixel color data (index at pixel_data[(row*width+column)*width*height+channel]).
Note
The length of pixel_data must be width*height*4 (or if it is width*height*3, the last channel is assumed opaque).

Definition at line 1801 of file global.cpp.

◆ XMLloadfloat()

float helios::XMLloadfloat ( pugi::xml_node  node,
const char *  field 
)

Function to load and convert a field in a pugi XML node into a float.

Parameters
[in]nodePugi XML node
[in]fieldString corresponding to field value to be read

Definition at line 2064 of file global.cpp.

◆ XMLloadint()

int helios::XMLloadint ( pugi::xml_node  node,
const char *  field 
)

Function to load and convert a field in a pugi XML node into an int.

Parameters
[in]nodePugi XML node
[in]fieldString corresponding to field value to be read

Definition at line 2079 of file global.cpp.

◆ XMLloadint2()

helios::int2 helios::XMLloadint2 ( pugi::xml_node  node,
const char *  field 
)

Function to load and convert a field in a pugi XML node into a vec2.

Parameters
[in]nodePugi XML node
[in]fieldString corresponding to field value to be read

Definition at line 2146 of file global.cpp.

◆ XMLloadint3()

helios::int3 helios::XMLloadint3 ( pugi::xml_node  node,
const char *  field 
)

Function to load and convert a field in a pugi XML node into a int3.

Parameters
[in]nodePugi XML node
[in]fieldString corresponding to field value to be read

Definition at line 2159 of file global.cpp.

◆ XMLloadint4()

helios::int4 helios::XMLloadint4 ( pugi::xml_node  node,
const char *  field 
)

Function to load and convert a field in a pugi XML node into a int4.

Parameters
[in]nodePugi XML node
[in]fieldString corresponding to field value to be read

Definition at line 2172 of file global.cpp.

◆ XMLloadrgb()

helios::RGBcolor helios::XMLloadrgb ( pugi::xml_node  node,
const char *  field 
)

Function to load and convert a field in a pugi XML node into an RGB color vector.

Parameters
[in]nodePugi XML node
[in]fieldString corresponding to field value to be read

Definition at line 2185 of file global.cpp.

◆ XMLloadrgba()

helios::RGBAcolor helios::XMLloadrgba ( pugi::xml_node  node,
const char *  field 
)

Function to load and convert a field in a pugi XML node into an RGBA color vector.

Parameters
[in]nodePugi XML node
[in]fieldString corresponding to field value to be read

Definition at line 2198 of file global.cpp.

◆ XMLloadstring()

std::string helios::XMLloadstring ( pugi::xml_node  node,
const char *  field 
)

Function to load and convert a field in a pugi XML node into a string.

Parameters
[in]nodePugi XML node
[in]fieldString corresponding to field value to be read

Definition at line 2094 of file global.cpp.

◆ XMLloadvec2()

helios::vec2 helios::XMLloadvec2 ( pugi::xml_node  node,
const char *  field 
)

Function to load and convert a field in a pugi XML node into a vec2.

Parameters
[in]nodePugi XML node
[in]fieldString corresponding to field value to be read

Definition at line 2107 of file global.cpp.

◆ XMLloadvec3()

helios::vec3 helios::XMLloadvec3 ( pugi::xml_node  node,
const char *  field 
)

Function to load and convert a field in a pugi XML node into a vec3.

Parameters
[in]nodePugi XML node
[in]fieldString corresponding to field value to be read

Definition at line 2120 of file global.cpp.

◆ XMLloadvec4()

helios::vec4 helios::XMLloadvec4 ( pugi::xml_node  node,
const char *  field 
)

Function to load and convert a field in a pugi XML node into a vec4.

Parameters
[in]nodePugi XML node
[in]fieldString corresponding to field value to be read

Definition at line 2133 of file global.cpp.

Variable Documentation

◆ nullorigin

vec3 helios::nullorigin = make_vec3(0, 0, 0)
extern

Default null vec3 that gives the origin (0,0,0)

Definition at line 82 of file global.cpp.

◆ nullrotation

SphericalCoord helios::nullrotation = make_SphericalCoord(0, 0)
extern

Default null SphericalCoord that applies no rotation.

Definition at line 81 of file global.cpp.

◆ PI_F

constexpr float PI_F = 3.14159265358979323846f
constexpr

Pi constant as a float.

Definition at line 56 of file global.h.