DHART
Loading...
Searching...
No Matches
node.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#ifndef HF_NODE
11#define HF_NODE
12
13#include <array>
14#include <ostream>
15
16namespace HF
17{
18 namespace SpatialStructures {
19
29 enum NODE_TYPE {
30 GRAPH = 0,
31 POI = 1,
32 OTHER = 2
33 };
34
38 struct Node {
39 public:
40 float x, y, z;
41 short type = GRAPH;
42 int id;
43
47
54 Node();
55
63
71 Node(float x, float y, float z, int ID = -1);
72
77
85 Node(const std::array<float, 3>& position);
86
99 Node(const std::array<float, 3>& position, NODE_TYPE t, int id);
100
106
116 float distanceTo(const Node& n2) const;
117
123
129 float angleTo(const Node& n2) const;
130
136
147 std::array<float, 3> directionTo(const Node& n2) const;
148
153
171 std::array<float, 3> getArray() const;
172
173 // Operators
174
180
194 float& operator[](int i);
195
201
218 float operator[](int i) const;
219
226
244 bool operator==(const Node& n2) const;
245
252
272 bool operator!=(const Node& n2) const;
273
279
294 Node operator-(const Node& n2) const;
295
301
315 Node operator+(const Node& n2) const;
316
322
336 Node operator*(const Node& n2) const;
337
343
354 bool operator<(const Node& n2) const;
355
362
386 bool operator<(const Node& n2);
387
393
405 bool operator>(const Node& n2) const;
406 };
407 };
408}
409
411namespace std {
413 template <typename SizeT>
414 inline void hash_combine_impl(SizeT& seed, SizeT value) noexcept
415 {
416 seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2);
417 }
418
420 template <>
421 struct hash<HF::SpatialStructures::Node>
422 {
423 inline std::size_t operator()(const HF::SpatialStructures::Node& k) const noexcept
424 {
425 size_t seed = std::hash<float>()(k.x);
426 hash_combine_impl(seed, std::hash<float>()(k.y));
427 hash_combine_impl(seed, std::hash<float>()(k.z));
428 return seed;
429 }
430 };
431
433 inline ostream& operator<<(ostream& os, const HF::SpatialStructures::Node n) {
434 os << "(" << n.x << ", " << n.y << ", " << n.z << ")";
435 return os;
436 }
437
439 inline ostream& operator<<(ostream& os, const std::array<float, 3> n) {
440 os << "(" << n[0] << "," << n[1] << "," << n[2] << ")";
441 return os;
442 }
443}
444
445#endif
STL namespace.
void hash_combine_impl(SizeT &seed, SizeT value) noexcept
combine value into the hash value of seed
Definition: node.h:414
ostream & operator<<(ostream &os, const HF::SpatialStructures::Node n)
Create a string containing the x,y,z position of this node.
Definition: node.h:433
Perform human scale analysis on 3D environments.
NODE_TYPE
The type of node this is.
Definition: node.h:29
@ POI
POI is 'point of interest'.
Definition: node.h:31
@ GRAPH
This node is a graph node.
Definition: node.h:30
@ OTHER
This node doesn't belong in any other category.
Definition: node.h:32
A point in space with an ID.
Definition: node.h:38
Node operator+(const Node &n2) const
Creates a new node from the vector addition of this node and n2.
Definition: node.cpp:104
Node operator*(const Node &n2) const
Creates a new node from the dot product of this node and n2.
Definition: node.cpp:114
bool operator<(const Node &n2) const
Determines if this node's id (an integer) is less than n2's id.
Definition: node.cpp:118
float angleTo(const Node &n2) const
Calculate the angle between node 1 and n2
short type
Unused.
Definition: node.h:41
Node()
Default constructor. Every element contained is defaulted to NAN.
Definition: node.cpp:15
float z
Cartesian coordinates x, y, z.
Definition: node.h:40
std::array< float, 3 > getArray() const
Returns the x,y,z of this node as an array of 3 floats.
Definition: node.cpp:141
float & operator[](int i)
Directly access a nodes's position as if it were an array of 3 floats,
Definition: node.cpp:51
bool operator!=(const Node &n2) const
See operator==, checks if this node does NOT occupy the same space as n2.
Definition: node.cpp:96
int id
Node identifier.
Definition: node.h:42
bool operator>(const Node &n2) const
Determines if this node's id (an integer) is greater than n2's id
Definition: node.cpp:120
float distanceTo(const Node &n2) const
Calculate the distance between this node and n2.
Definition: node.cpp:40
std::array< float, 3 > directionTo(const Node &n2) const
Get the direction between this node and another node
Definition: node.cpp:131
Node operator-(const Node &n2) const
Creates a node from the vector subtraction of this node and n2's position.
Definition: node.cpp:100
bool operator==(const Node &n2) const
Check if this node occupies the same space as n2.
Definition: node.cpp:83
std::size_t operator()(const HF::SpatialStructures::Node &k) const noexcept
Definition: node.h:423