summaryrefslogtreecommitdiff
path: root/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h
blob: 3975bb464bffb264f7738f259292cce88911b68f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * Skeleton_blocker_simple_traits.h
 *
 *  Created on: Feb 11, 2014
 *      Author: dsalinas
 */

#ifndef GUDHI_SKELETON_BLOCKERS_SIMPLE_TRAITS_H_
#define GUDHI_SKELETON_BLOCKERS_SIMPLE_TRAITS_H_

#include <string>
#include <sstream>
#include "Skeleton_blocker_simplex.h"

namespace Gudhi{

namespace skbl {

/**
 * @extends SkeletonBlockerDS
 */
struct Skeleton_blocker_simple_traits{
	/**
	 * @brief global and local handle similar to <a href="http://www.boost.org/doc/libs/1_38_0/libs/graph/doc/subgraph.html">boost subgraphs</a>.
	 * In gross, vertices are stored in a vector.
	 * For the root simplicial complex, the local and global descriptors are the same.
	 * For a subcomplex L and one of its vertices 'v', the local descriptor of 'v' is its position in
	 * the vertex vector of the subcomplex L whereas its global descriptor is the position of 'v'
	 * in the vertex vector of the root simplicial complex.
	 */
	struct Root_vertex_handle{
		typedef int boost_vertex_handle;
		explicit Root_vertex_handle(boost_vertex_handle val = -1 ):vertex(val){}
		boost_vertex_handle vertex;

		bool operator!=( const Root_vertex_handle& other) const{
			return ! (this->vertex == other.vertex);
		}

		bool operator==( const Root_vertex_handle& other) const{
			return this->vertex == other.vertex;
		}

		bool operator<( const Root_vertex_handle& other) const{
			return this->vertex < other.vertex;
		}

		friend std::ostream& operator << (std::ostream& o, const Root_vertex_handle & v)
		{
			o << v.vertex;
			return o;
		}
	};

	struct Vertex_handle{
		typedef int boost_vertex_handle;
		Vertex_handle(boost_vertex_handle val=-1):vertex(val){}

		boost_vertex_handle vertex;

		bool operator==( const Vertex_handle& other) const{
			return this->vertex == other.vertex;
		}

		bool operator!=( const Vertex_handle& other) const{
			return this->vertex != other.vertex;
		}

		bool operator<(const Vertex_handle& other) const{
			return this->vertex < other.vertex;
		}

		friend std::ostream& operator << (std::ostream& o, const Vertex_handle & v)
		{
			o << v.vertex;
			return o;
		}
	};



	class Graph_vertex {
		bool is_active_;
		Root_vertex_handle id_;
	public:
		virtual ~Graph_vertex(){}

		void activate(){is_active_=true;}
		void deactivate(){is_active_=false;}
		bool is_active() const{return is_active_;}
		void set_id(Root_vertex_handle i){id_=i;}
		Root_vertex_handle get_id() const{return id_;}

		virtual std::string to_string() const {
			std::ostringstream res;
			res<< id_;
			return res.str();
		}

		friend std::ostream& operator << (std::ostream& o, const Graph_vertex & v){
			o << v.to_string();
			return o;
		}
	};

	class Graph_edge {
		Root_vertex_handle a_;
		Root_vertex_handle b_;
		int index_;
	public:

		Graph_edge():a_(-1),b_(-1),index_(-1){}

		int& index(){return index_;}
		int index() const {return index_;}

		void setId(Root_vertex_handle a,Root_vertex_handle b){
			a_ = a;
			b_ = b;
		}

		Root_vertex_handle first() const {
			return a_;
		}

		Root_vertex_handle second() const {
			return b_;
		}

		friend std::ostream& operator << (std::ostream& o, const Graph_edge & v){
			o << "("<<v.a_<<","<<v.b_<<" - id = "<<v.index();
			return o;
		}
	};

};

}

}  // namespace GUDHI

#endif /* GUDHI_SKELETON_BLOCKERS_SIMPLE_TRAITS_H_ */