DHART
Loading...
Searching...
No Matches
HF::SpatialStructures::Node Struct Reference

A point in space with an ID. More...

#include <node.h>

+ Collaboration diagram for HF::SpatialStructures::Node:

Public Member Functions

 Node ()
 Default constructor. Every element contained is defaulted to NAN. More...
 
 Node (float x, float y, float z, int ID=-1)
 Create a node without an ID. More...
 
 Node (const std::array< float, 3 > &position)
 Create a node from an array. More...
 
 Node (const std::array< float, 3 > &position, NODE_TYPE t, int id)
 Constructor to create a node with a different NODE_TYPE. More...
 
float distanceTo (const Node &n2) const
 Calculate the distance between this node and n2. More...
 
float angleTo (const Node &n2) const
 Calculate the angle between node 1 and n2 More...
 
std::array< float, 3 > directionTo (const Node &n2) const
 Get the direction between this node and another node More...
 
std::array< float, 3 > getArray () const
 Returns the x,y,z of this node as an array of 3 floats. More...
 
float & operator[] (int i)
 Directly access a nodes's position as if it were an array of 3 floats, More...
 
float operator[] (int i) const
 Access a nodes's position, by value. More...
 
bool operator== (const Node &n2) const
 Check if this node occupies the same space as n2. More...
 
bool operator!= (const Node &n2) const
 See operator==, checks if this node does NOT occupy the same space as n2.

Parameters
n2Node to compare with this node.
More...
 
Node operator- (const Node &n2) const
 Creates a node from the vector subtraction of this node and n2's position. More...
 
Node operator+ (const Node &n2) const
 Creates a new node from the vector addition of this node and n2. More...
 
Node operator* (const Node &n2) const
 Creates a new node from the dot product of this node and n2. More...
 
bool operator< (const Node &n2) const
 Determines if this node's id (an integer) is less than n2's id. More...
 
bool operator< (const Node &n2)
 Determines if this node's id (an integer) is less than n2's id. const qualification omitted for std::sort. More...
 
bool operator> (const Node &n2) const
 Determines if this node's id (an integer) is greater than n2's id More...
 

Public Attributes

float x
 
float y
 
float z
 Cartesian coordinates x, y, z. More...
 
short type = GRAPH
 Unused. More...
 
int id
 Node identifier. More...
 

Detailed Description

A point in space with an ID.

Definition at line 38 of file node.h.

Constructor & Destructor Documentation

◆ Node() [1/4]

HF::SpatialStructures::Node::Node ( )

Default constructor. Every element contained is defaulted to NAN.

// be sure to #include "node.h"
HF::SpatialStructures::Node node(); // all fields initialized to NAN
A point in space with an ID.
Definition: node.h:38

Definition at line 15 of file node.cpp.

References x, y, and z.

Referenced by operator*(), operator+(), and operator-().

+ Here is the caller graph for this function:

◆ Node() [2/4]

HF::SpatialStructures::Node::Node ( float  x,
float  y,
float  z,
int  ID = -1 
)

Create a node without an ID.

Parameters
xX coordinate.
yY coordinate.
zZ coordinate.
idID of the node
// be sure to #include "node.h"
HF::SpatialStructures::Node node_0(12.0, 23.1, 34.2); // default ID is -1

Definition at line 22 of file node.cpp.

◆ Node() [3/4]

HF::SpatialStructures::Node::Node ( const std::array< float, 3 > &  position)

Create a node from an array.

Parameters
positionAn array of 3 floats for x,y,z.
// be sure to #include "node.h"
std::array<float, 3> pos = { 12.0, 23.1, 34.2 };
HF::SpatialStructures::Node node(pos); // id == -1, type == NODE_TYPE::GRAPH

Definition at line 24 of file node.cpp.

References HF::SpatialStructures::GRAPH, type, x, y, and z.

◆ Node() [4/4]

HF::SpatialStructures::Node::Node ( const std::array< float, 3 > &  position,
NODE_TYPE  t,
int  id 
)

Constructor to create a node with a different NODE_TYPE.

See also
NODE_TYPE
// be sure to #include "node.h"
std::array<float, 3> pos = { 12.0, 23.1, 34.2 };
@ GRAPH
This node is a graph node.
Definition: node.h:30

Definition at line 32 of file node.cpp.

References type, x, y, and z.

Member Function Documentation

◆ angleTo()

float HF::SpatialStructures::Node::angleTo ( const Node n2) const

Calculate the angle between node 1 and n2

Parameters
n2Node to calculate direction to
Returns
Angle between this node and n2
TODO code sample: line 40 of node.cpp - 'This needs an actual angle formula'

◆ directionTo()

std::array< float, 3 > HF::SpatialStructures::Node::directionTo ( const Node n2) const

Get the direction between this node and another node

Parameters
n2The node to get the direction to
Returns
an array of 3 floats indicating a direction
// be sure to #include "node.h"
HF::SpatialStructures::Node node_0(12.0, 23.1, 34.2, 456);
HF::SpatialStructures::Node node_1(45.3, 56.4, 67.5, 789);
std::array<float, 3> direction_vector = node_0.directionTo(node_1);

Definition at line 131 of file node.cpp.

References HF::SpatialStructures::Normalize(), x, y, and z.

Referenced by HF::SpatialStructures::CostAlgorithms::CalculateEnergyExpenditure(), HF::SpatialStructures::CostAlgorithms::GetPerpendicularEdges(), and HF::VisibilityGraph::IsOcclusionBetween().

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

◆ distanceTo()

float HF::SpatialStructures::Node::distanceTo ( const Node n2) const

Calculate the distance between this node and n2.

Parameters
n2Note to calculate the distance to.
Returns
Distance between this node and n2.
// be sure to #include "node.h"
HF::SpatialStructures::Node node_0(12.0, 23.1, 34.2, 456);
HF::SpatialStructures::Node node_1(45.3, 56.4, 67.5, 789);
float euclidean_distance = node_0.distanceTo(node_1);

Definition at line 40 of file node.cpp.

References x, y, and z.

Referenced by HF::VisibilityGraph::AllToAll(), HF::VisibilityGraph::AllToAllUndirected(), HF::SpatialStructures::CostAlgorithms::CalculateEnergyExpenditure(), HF::VisibilityGraph::GroupToGroup(), and HF::VisibilityGraph::IsOcclusionBetween().

+ Here is the caller graph for this function:

◆ getArray()

std::array< float, 3 > HF::SpatialStructures::Node::getArray ( ) const

Returns the x,y,z of this node as an array of 3 floats.

Returns
The x,y, and z coordinates of this node as an array of floats.
// be sure to #include "node.h"
HF::SpatialStructures::Node node(12.0, 23.1, 34.2, 456);
// An array is created from within the getArray() member function
std::array<float, 3> arr = node.getArray();
// ref_arr and ref_node have the same value, but
// refer to different locations in memory --
// arr does not consist of the same memory locations as
// that of the coordinate fields within node.
float& ref_arr = arr[0];
float& ref_node = node.x;

Definition at line 141 of file node.cpp.

References x, y, and z.

◆ operator!=()

bool HF::SpatialStructures::Node::operator!= ( const Node n2) const

See operator==, checks if this node does NOT occupy the same space as n2.

Parameters
n2Node to compare with this node.

Returns
True if the distance between n1 and n2 greator greater than or equal to Rounding Precision, false otherwise.
// be sure to #include "node.h"
HF::SpatialStructures::Node node_0(12.0, 23.1, 34.2, 456);
HF::SpatialStructures::Node node_1(45.3, 56.4, 67.5, 789);
// Does the inverse of operator==.
bool different_positions = node_0 != node_1;
if (different_positions) {
std::cout << "Different positions" << std::endl;
} else {
std::cout << "Occupies the same space" << std::endl;
}
// different_positions evaluates to true

Definition at line 96 of file node.cpp.

References operator==().

+ Here is the call graph for this function:

◆ operator*()

Node HF::SpatialStructures::Node::operator* ( const Node n2) const

Creates a new node from the dot product of this node and n2.

Parameters
n2Second factor of dot product, N1 (dot) N2
Returns
A node with the values obtained from the dot product of N1 and N2
// be sure to #include "node.h"
HF::SpatialStructures::Node node_0(12.0, 23.1, 34.2, 456);
HF::SpatialStructures::Node node_1(45.3, 56.4, 67.5, 789);
HF::SpatialStructures::Node node_2 = node_1 * node_0;
// node_2 has values (x = 543.6, y = 1302.84, z = 2308.5, id = -1, type = NODE_TYPE::GRAPH)
// id and type are given default values as per Node::Node(const std::array<float, 3>& position)

Definition at line 114 of file node.cpp.

References Node(), x, y, and z.

+ Here is the call graph for this function:

◆ operator+()

Node HF::SpatialStructures::Node::operator+ ( const Node n2) const

Creates a new node from the vector addition of this node and n2.

Parameters
n2Node to add to n1
Returns
A node with the values obtained from n1 + n2
// be sure to #include "node.h"
HF::SpatialStructures::Node node_0(12.0, 23.1, 34.2, 456);
HF::SpatialStructures::Node node_1(45.3, 56.4, 67.5, 789);
HF::SpatialStructures::Node node_2 = node_1 + node_0;
// node_2 has values (x = 57.3, y = 79.5, z = 101.7, id = -1, type = NODE_TYPE::GRAPH)
// id and type are given default values as per Node::Node(const std::array<float, 3>& position)

Definition at line 104 of file node.cpp.

References Node(), x, y, and z.

+ Here is the call graph for this function:

◆ operator-()

Node HF::SpatialStructures::Node::operator- ( const Node n2) const

Creates a node from the vector subtraction of this node and n2's position.

Parameters
n2Node to subtract from this node.
Returns
A node with the values obtained from n1 - n2
// be sure to #include "node.h"
HF::SpatialStructures::Node node_0(12.0, 23.1, 34.2, 456);
HF::SpatialStructures::Node node_1(45.3, 56.4, 67.5, 789);
HF::SpatialStructures::Node node_2 = node_1 - node_0;
// node_2 has values (x = 33.3, y = 33.3, z = 33.3, id = -1, type = NODE_TYPE::GRAPH)
// id and type are given default values as per Node::Node(const std::array<float, 3>& position)

Definition at line 100 of file node.cpp.

References Node(), x, y, and z.

+ Here is the call graph for this function:

◆ operator<() [1/2]

bool HF::SpatialStructures::Node::operator< ( const Node n2)

Determines if this node's id (an integer) is less than n2's id. const qualification omitted for std::sort.

Parameters
n2Node whose id will be compared with n1
Returns
True if this node's id is less than n2's id, false otherwise
// be sure to #include "node.h", and #include <algorithm>
// For this example, we are not concerned about the node coordinates.
HF::SpatialStructures::Node node_0(0.0, 0.0, 0.0, 3);
HF::SpatialStructures::Node node_1(0.0, 0.0, 0.0, 1);
HF::SpatialStructures::Node node_2(0.0, 0.0, 0.0, 2);
HF::SpatialStructures::Node node_3(0.0, 0.0, 0.0, 0);
std::vector<HF::SpatialStructures::Node> vec{ node_0, node_1, node_2, node_3 };
// operator< sorts Node by ID, in non-decreasing order
std::sort(vec.begin(), vec.end()); // uses natural ordering through operator<, non-const
std::vector<HF::SpatialStructures::Node>::iterator it = vec.begin();
while (it != vec.end()) {
std::cout << "Node ID: " << it->id << std::endl;
\++it;
} // Node ID will print in order by ID, from smallest to largest

Definition at line 119 of file node.cpp.

References id.

◆ operator<() [2/2]

bool HF::SpatialStructures::Node::operator< ( const Node n2) const

Determines if this node's id (an integer) is less than n2's id.

Parameters
n2Node to compare against.
Returns
True if this node's id is less than n2's id, false otherwise
// be sure to #include "node.h"
HF::SpatialStructures::Node node_0(12.0, 23.1, 34.2, 456);
HF::SpatialStructures::Node node_1(45.3, 56.4, 67.5, 789);
// operator< compares ID fields of node_0 and node_1
bool compare = node_0 < node_1; // evaluates to true, since 456 < 789

Definition at line 118 of file node.cpp.

References id.

◆ operator==()

bool HF::SpatialStructures::Node::operator== ( const Node n2) const

Check if this node occupies the same space as n2.

Parameters
n2Node to compare with n1
Returns
True if the distance between n1 and n2 is less than Rounding Precision, false otherwise.
// be sure to #include "node.h"
HF::SpatialStructures::Node node_0(12.0, 23.1, 34.2, 456);
HF::SpatialStructures::Node node_1(45.3, 56.4, 67.5, 789);
bool same_position = node_0 == node_1;
if (same_position) {
std::cout << "Occupies the same space" << std::endl;
} else {
std::cout << "Different positions" << std::endl;
}
// same_position evaluates to false

Definition at line 83 of file node.cpp.

References HF::SpatialStructures::ROUNDING_PRECISION, x, y, and z.

Referenced by operator!=().

+ Here is the caller graph for this function:

◆ operator>()

bool HF::SpatialStructures::Node::operator> ( const Node n2) const

Determines if this node's id (an integer) is greater than n2's id

Parameters
n2Node whose id will be compared with n1
Returns
True if n1's id is greater than n2's id, false otherwise
// be sure to #include "node.h"
HF::SpatialStructures::Node node_0(12.0, 23.1, 34.2, 456);
HF::SpatialStructures::Node node_1(45.3, 56.4, 67.5, 789);
// operator< compares ID fields of node_0 and node_1
bool compare = node_0 > node_1; // evaluates to false, since 456 < 789

Definition at line 120 of file node.cpp.

References id.

◆ operator[]() [1/2]

float & HF::SpatialStructures::Node::operator[] ( int  i)

Directly access a nodes's position as if it were an array of 3 floats,

Parameters
iIndex. 0 = x, 1 = y, 2 = z
Returns
A reference to the member float for the requested coordinate
Exceptions
std::exceptioni was greater than 2 or less than 0.
Todo:
Exception should be std::out_of_range to match other functionality
// be sure to #include "node.h"
HF::SpatialStructures::Node node(12.0, 23.1, 34.2, 456); // (x, y, z), ID
float& position = node[1]; // access by reference
position = 93.5; // node.y is now 93.5

Definition at line 51 of file node.cpp.

References x, y, and z.

◆ operator[]() [2/2]

float HF::SpatialStructures::Node::operator[] ( int  i) const

Access a nodes's position, by value.

Parameters
iIndex. 0 = x, 1 = y, 2 = z
Returns
the value (copy) of the member float for the requested coordinate
Remarks
Unlike the non-const version of this function, this will actually allow the caller to change the value of x, y, or z. Will automatically be selected if the node isn't const.
Exceptions
std::exceptioni was greater than 2 or less than 0.
Todo:
Exception should be std::out_of_range to match other functionality
// be sure to #include "node.h"
HF::SpatialStructures::Node node(12.0, 23.1, 34.2, 456); // (x, y, z), ID
float position = node[1]; // access by reference
position = 93.5 // node.y is still 23.1

Definition at line 67 of file node.cpp.

References x, y, and z.

Member Data Documentation

◆ id

◆ type

short HF::SpatialStructures::Node::type = GRAPH

Unused.

See also
NODE_TYPE for more infomration about this.

Definition at line 41 of file node.h.

Referenced by Node().

◆ x

float HF::SpatialStructures::Node::x

◆ y

float HF::SpatialStructures::Node::y

◆ z

float HF::SpatialStructures::Node::z

The documentation for this struct was generated from the following files: