DHART
Loading...
Searching...
No Matches
HF::ViewAnalysis Namespace Reference

Analyze space from the perspective of observers within a 3D environment. More...

Enumerations

enum class  AGGREGATE_TYPE {
  COUNT = 0 , SUM = 1 , AVERAGE = 2 , MAX = 3 ,
  MIN = 4
}
 The type of aggregation to use for ViewAnalysisAggregate More...
 

Functions

constexpr float ConvertToRadians (float num_in_degrees)
 Convert a number from degrees to radians. More...
 
void Normalize (std::array< float, 3 > &vec)
 Normalize a vector. More...
 
bool AltitudeWithinRange (const std::array< float, 3 > &vec, float max_angle, float min_angle)
 
vector< std::array< float, 3 > > FibbonacciDist (int num_points, float upwards_fov, float downward_fov)
 
vector< std::array< float, 3 > > FibbonacciDistributePoints (int num_points, float upwards_fov=50.0f, float downward_fov=70.0f)
 Evenly distribute a set of points around a sphere centered at the origin. More...
 
void Aggregate (float &out_total, float new_value, const AGGREGATE_TYPE agg_type, int count=0)
 
template<typename RES , typename RT , typename N >
std::vector< RES > SphericalViewAnalysis (RT &ray_tracer, const std::vector< N > &Nodes, int num_rays, float upward_limit=50.0f, float downward_limit=70.0f, float height=1.7f)
 Conduct view analysis with any Raytracer in parallel. More...
 
template<typename RT , typename N >
std::vector< float > SphericalRayshootWithAnyRTForDistance (RT &ray_tracer, const std::vector< N > &Nodes, int num_rays, float upward_limit=50.0f, float downward_limit=70.0f, float height=1.7f, const AGGREGATE_TYPE aggregation=AGGREGATE_TYPE::SUM)
 Conduct view analysis and recieve a summarized set of results for each node. More...
 

Detailed Description

Analyze space from the perspective of observers within a 3D environment.

View Analysis contains a set of algorithms dedicated to evaluating the view of an observer from specific points in a model. Generally this consists of equally distributing a series of rays in a sphere around the observer, then casting the rays and calculating a result or returning the raw results of each intersection.

See also
FibbonacciDistributePoints for the algorithm used to equally distribute rays.
SphericalViewAnalysis for a view analysis algorithm that returns the ID and distance to intersection point of every ray casted.
SphericalRayshootWithAnyRTForDistance for an algorithm that aggregates the results of view analysis into a score for each of the input observer points.

Enumeration Type Documentation

◆ AGGREGATE_TYPE

The type of aggregation to use for ViewAnalysisAggregate

Enumerator
COUNT 

Total number of intersections.

SUM 

Sum of the distance from the origin to all intersections.

AVERAGE 

Average distance from the origin to every intersection.

MAX 

Maximum distance from the origin to any intersection.

MIN 

Minimum distance from the origin to any intersection.

Definition at line 49 of file view_analysis.h.

Function Documentation

◆ Aggregate()

void HF::ViewAnalysis::Aggregate ( float &  out_total,
float  new_value,
const AGGREGATE_TYPE  agg_type,
int  count = 0 
)
inline

Apply an aggregation to the given value.

Parameters
out_totalThe total of the current aggregation. This will be modified depending on agg_type.
new_valueNew value to aggregate into out_total.
agg_typeThe type of aggregation to use.
countNumber of elements encountered so far. Used for Count/Average.
Exceptions
std::out_of_rangeagg_type didn't match any valid AGGREGATE_TYPE.

This can be called in a loop to summarize the results of some calculation as new values become available. This avoids having to allocate entire arrays of values then calculating the result at the end.

See also
AGGREGATE_TYPE for a list of supported aggregation types.
Note
This function will likely not be very useful elsewhere since most of its functionality can be replaced by single function calls like std::min(a, b) or std::max(a,b). This was made a standalone function mostly to seperate calculating the result value from the implementation of the View Analysis itself.
Example
// Requires #include "view_analysis.h", #include <numeric>
// Use this to save some space.
// Undef these since they will prevent us from calling numericlimits
#undef min
#undef max
// Define values
std::vector<int> values = { 1, 2, 3, 4, 5 };
// Calculate Average
float total = 0.0f; int count = 0;
for (int val : values) {
count += 1;
Aggregate(total, val, AGGREGATE_TYPE::AVERAGE, count);
}
std::cerr << "Average: " << total << std::endl;
// Calculate Sum
total = 0.0f;
for (int val : values) Aggregate(total, val, AGGREGATE_TYPE::SUM);
std::cerr << "Sum: " << total << std::endl;
// Calculate Max. Start total at lowest possible float value to ensure
// it overwritten by the first element.
total = std::numeric_limits<float>::min();
for (int val : values) Aggregate(total, val, AGGREGATE_TYPE::MAX);
std::cerr << "Max: " << total << std::endl;
// Calculate Min. Start total at highest possible float value to ensure
// it overwritten by the first element.
total = (std::numeric_limits<float>::max());
for (int val : values) Aggregate(total, val, AGGREGATE_TYPE::MIN);
std::cerr << "Min: " << total << std::endl;
// Calculate Count
total = 0.0f;
for (int val : values) Aggregate(total, val, AGGREGATE_TYPE::COUNT);
std::cerr << "Count: " << total << std::endl;
AGGREGATE_TYPE
The type of aggregation to use for ViewAnalysisAggregate
Definition: view_analysis.h:49
@ AVERAGE
Average distance from the origin to every intersection.
@ MAX
Maximum distance from the origin to any intersection.
@ COUNT
Total number of intersections.
@ SUM
Sum of the distance from the origin to all intersections.
@ MIN
Minimum distance from the origin to any intersection.
void Aggregate(float &out_total, float new_value, const AGGREGATE_TYPE agg_type, int count=0)

>>> Average: 3
>>> Sum: 15
>>> Max: 5
>>> Min: 1
>>> Count: 5

Todo:
Min/Max and maybe the other functions should handle NaNs for min/max to signal that no value already exists. The user can use the min and max numeric limits or zero for defaults like in the example, but it would be great to be able to use one value that would be reliably handled as default input for every case.

Definition at line 194 of file view_analysis.h.

References AVERAGE, COUNT, MAX, MIN, and SUM.

Referenced by SphericalRayshootWithAnyRTForDistance().

+ Here is the caller graph for this function:

◆ AltitudeWithinRange()

bool HF::ViewAnalysis::AltitudeWithinRange ( const std::array< float, 3 > &  vec,
float  max_angle,
float  min_angle 
)
inline

Check if a vector's altitude is between max and min angle.

Parameters
vecVector to check the altitude of
max_angleMaximum allowed angle in radians
min_angleMinimum allowed angle in radians
Returns
True if vec's altitude is between min and max angle, false if it isn't.

vec is converted to spherical coordinates to determine phi, which is then compared to max and min angle to calculate the result.

Definition at line 62 of file view_analysis.cpp.

Referenced by FibbonacciDist().

+ Here is the caller graph for this function:

◆ ConvertToRadians()

constexpr float HF::ViewAnalysis::ConvertToRadians ( float  num_in_degrees)
constexpr

Convert a number from degrees to radians.

Definition at line 27 of file view_analysis.cpp.

Referenced by FibbonacciDist().

+ Here is the caller graph for this function:

◆ FibbonacciDist()

vector< std::array< float, 3 > > HF::ViewAnalysis::FibbonacciDist ( int  num_points,
float  upwards_fov,
float  downward_fov 
)

Equally distribute points on a sphere using Fibbonacci

Parameters
num_pointsNumber of points to generate. The actual number of points generated will be lower based given field of view limits.
upwards_fovMaximum altitude of generated points in degrees.
downward_fovMinimum altitude of points in degrees.

Implementation is based on https://stackoverflow.com/questions/9600801/evenly-distributing-n-points-on-a-sphere.

See also
AltitudeWithinRange to see how altitude is limited based on upward/downward fov.

Definition at line 84 of file view_analysis.cpp.

References AltitudeWithinRange(), ConvertToRadians(), and Normalize().

Referenced by FibbonacciDistributePoints().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Normalize()

void HF::ViewAnalysis::Normalize ( std::array< float, 3 > &  vec)
inline

Normalize a vector.

Parameters
vecVector to normalize. Will be updated with the normalized value.

Definition at line 33 of file view_analysis.cpp.

Referenced by FibbonacciDist().

+ Here is the caller graph for this function: