Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.6.3
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AdjacencyList.hpp
1#pragma once
2
3#include <Core/Containers/AlignedStdVector.hpp>
4#include <Core/Containers/VectorArray.hpp>
5#include <Core/RaCore.hpp>
6#include <Eigen/Core>
7#include <iostream>
8#include <memory>
9#include <vector>
10
11namespace Ra {
12namespace Core {
13
14using ParentList = AlignedStdVector<int>;
15using LevelList = AlignedStdVector<uint8_t>;
16using ChildrenList = AlignedStdVector<uint8_t>;
17using Adjacency = AlignedStdVector<ChildrenList>;
18
23class RA_CORE_API AdjacencyList
24{
25 public:
26 enum class ConsistencyStatus {
27 Valid,
28 IncompatibleChildrenAndParentList,
29 WrongParentOrdering,
30 WrongParentIndex,
31 InconsistentParentIndex,
32 NonLeafNodeWithoutChild
33 };
34
36 // CONSTRUCTOR
39 explicit AdjacencyList( const uint n );
40 AdjacencyList( const AdjacencyList& adj );
41 AdjacencyList& operator=( const AdjacencyList& ) = default;
42
44 // DESTRUCTOR
47
49 // NODE
52 uint addRoot();
54 uint addNode( const uint parent );
56 void pruneLeaves( std::vector<uint>& pruned, std::vector<bool>& delete_flag );
58 void pruneLeaves();
67 VectorArray<Eigen::Matrix<uint, 2, 1>> extractEdgeList( bool include_leaf = false ) const;
68
70 // SIZE
73 inline uint size() const;
75 inline void clear();
76
78 // QUERY
81 ConsistencyStatus computeConsistencyStatus() const;
83 inline bool isEmpty() const { return ( size() == 0 ); }
85 inline bool isRoot( const uint i ) const;
87 inline bool isLeaf( const uint i ) const;
89 inline bool isBranch( const uint i ) const;
91 inline bool isJoint( const uint i ) const;
93 inline bool isEdge( const uint i, const uint j ) const;
94
95 inline const Adjacency& children() const { return m_child; }
96
97 inline const ParentList& parents() const { return m_parent; }
98
100 // VARIABLE
102 private:
104 Adjacency m_child;
106 ParentList m_parent;
107 LevelList m_level;
108};
109
110RA_CORE_API std::ofstream& operator<<( std::ofstream& ofs, const AdjacencyList& p );
111
112inline uint AdjacencyList::size() const {
113 CORE_ASSERT( m_parent.size() == m_child.size(), "List size inconsistency" );
114 return m_parent.size();
115}
116
117inline void AdjacencyList::clear() {
118 m_child.clear();
119 m_parent.clear();
120}
121
122inline bool AdjacencyList::isRoot( const uint i ) const {
123 CORE_ASSERT( i < size(), " Index i out of bounds " );
124 return ( m_parent[i] == -1 );
125}
126
127inline bool AdjacencyList::isLeaf( const uint i ) const {
128 CORE_ASSERT( i < size(), " Index i out of bounds " );
129 return ( m_child[i].size() == 0 );
130}
131
132inline bool AdjacencyList::isBranch( const uint i ) const {
133 CORE_ASSERT( i < size(), " Index i out of bounds " );
134 return ( m_child[i].size() > 1 );
135}
136
137inline bool AdjacencyList::isJoint( const uint i ) const {
138 CORE_ASSERT( i < size(), " Index i out of bounds " );
139 return ( m_child[i].size() == 1 );
140}
141
142inline bool AdjacencyList::isEdge( const uint i, const uint j ) const {
143 CORE_ASSERT( i < size(), " Index i out of bounds " );
144 CORE_ASSERT( j < size(), " Index j out of bounds " );
145 for ( const auto& item : m_child[i] ) {
146 if ( item == j ) return true;
147 }
148 return false;
149}
150} // namespace Core
151} // namespace Ra
void clear()
Clear the vectors.
uint size() const
Return the number of nodes in the graph.
bool isJoint(const uint i) const
Return true if the node is a joint node. ( |child| == 1 )
bool isLeaf(const uint i) const
Return true if the node is a leaf node.
bool isBranch(const uint i) const
Return true if the node is a branch node. ( |child| > 1 )
bool isRoot(const uint i) const
Return true if a node is a root node.
bool isEmpty() const
Return true if the graph is empty.
bool isEdge(const uint i, const uint j) const
Return true if the edge { i, j } exists.
This class implements ContainerIntrospectionInterface for AlignedStdVector.
T clear(T... args)
std::vector< T, Eigen::aligned_allocator< T > > AlignedStdVector
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4
T size(T... args)