SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CUFTree.hpp
Go to the documentation of this file.
1 /*
2  * Copyright(c):
3  * Signal Image and Communications (SIC) Department
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * - University of Poitiers, France http://www.univ-poitiers.fr
6  * - XLIM Institute UMR CNRS 7252 http://www.xlim.fr/
7  *
8  * and
9  *
10  * D2 Fluid, Thermic and Combustion
11  * - University of Poitiers, France http://www.univ-poitiers.fr
12  * - PPRIME Institute - UPR CNRS 3346 http://www.pprime.fr
13  * - ISAE-ENSMA http://www.ensma.fr
14  *
15  * Contributor(s):
16  * The SLIP team,
17  * Benoit Tremblais <tremblais_AT_sic.univ-poitiers.fr>,
18  * Laurent David <laurent.david_AT_lea.univ-poitiers.fr>,
19  * Ludovic Chatellier <ludovic.chatellier_AT_univ-poitiers.fr>,
20  * Lionel Thomas <lionel.thomas_AT_univ-poitiers.fr>,
21  * Denis Arrivault <arrivault_AT_sic.univ-poitiers.fr>,
22  * Julien Dombre <julien.dombre_AT_univ-poitiers.fr>.
23  *
24  * Description:
25  * The Simple Library of Image Processing (SLIP) is a new image processing
26  * library. It is written in the C++ language following as much as possible
27  * the ISO/ANSI C++ standard. It is consequently compatible with any system
28  * satisfying the ANSI C++ complience. It works on different Unix , Linux ,
29  * Mircrosoft Windows and Mac OS X plateforms. SLIP is a research library that
30  * was created by the Signal, Image and Communications (SIC) departement of
31  * the XLIM, UMR 7252 CNRS Institute in collaboration with the Fluids, Thermic
32  * and Combustion departement of the P', UPR 3346 CNRS Institute of the
33  * University of Poitiers.
34  *
35  * The SLIP Library source code has been registered to the APP (French Agency
36  * for the Protection of Programs) by the University of Poitiers and CNRS,
37  * under registration number IDDN.FR.001.300034.000.S.P.2010.000.21000.
38 
39  * http://www.sic.sp2mi.univ-poitiers.fr/slip/
40  *
41  * This software is governed by the CeCILL-C license under French law and
42  * abiding by the rules of distribution of free software. You can use,
43  * modify and/ or redistribute the software under the terms of the CeCILL-C
44  * license as circulated by CEA, CNRS and INRIA at the following URL
45  * http://www.cecill.info.
46  * As a counterpart to the access to the source code and rights to copy,
47  * modify and redistribute granted by the license, users are provided only
48  * with a limited warranty and the software's author, the holder of the
49  * economic rights, and the successive licensors have only limited
50  * liability.
51  *
52  * In this respect, the user's attention is drawn to the risks associated
53  * with loading, using, modifying and/or developing or reproducing the
54  * software by the user in light of its specific status of free software,
55  * that may mean that it is complicated to manipulate, and that also
56  * therefore means that it is reserved for developers and experienced
57  * professionals having in-depth computer knowledge. Users are therefore
58  * encouraged to load and test the software's suitability as regards their
59  * requirements in conditions enabling the security of their systems and/or
60  * data to be ensured and, more generally, to use and operate it in the
61  * same conditions as regards security.
62  *
63  * The fact that you are presently reading this means that you have had
64  * knowledge of the CeCILL-C license and that you accept its terms.
65  */
66 
67 
75 #ifndef SLIP_CUFTREE_HPP
76 #define SLIP_CUFTREE_HPP
77 
78 #include <cstdio>
79 
80 namespace slip
81 {
82  // extern long int NbOfCrossedEdges(0);
83  static long int NbOfCrossedEdges_(0);
94  template<typename T>
95  class CUFTree
96  {
97  public :
98 
99  typedef T value_type;
100  typedef CUFTree<T> self;
101  typedef self* self_pointer;
102 
103  typedef std::size_t size_type;
104 
106  typedef const value_type& const_reference;
107 
112 
116  CUFTree();
117 
122  CUFTree( self_pointer ATree );
123 
127  ~CUFTree();
128 
136  self& operator=(const self & rsh);
137 
142  void set_Element(const_reference inel);
143 
149 
154  void set_FFather(self_pointer inFFather);
155 
156 
157 
163  self_pointer find();
164 
169  void merge( self_pointer ATree );
170 
171  private:
172 
173  self_pointer FFather; // the father adress
174  size_type FHeight; // Sup value of the tree height
175  value_type Element; //label if needed
176  };
177 
178 }//slip::
179 
180 namespace slip
181 {
182  template <typename T>
183  inline
185  FFather (this),
186  FHeight(0),
187  Element()
188  {}
189 
190  template <typename T>
191  inline
192  CUFTree<T>::CUFTree(CUFTree* ATree) :
193  FFather (ATree),
194  FHeight(0),
195  Element(ATree->Element)
196  {}
197 
198  template <typename T>
199  inline
201  {}
202 
203  template<typename T>
204  inline
206  {
207  if(this != &rhs)
208  {
209  if(rhs.FFather == &rhs)
210  this->FFather = this;
211  else
212  this->FFather = rhs.FFather;
213  this->FHeight = rhs.FHeight;
214  this->Element = rhs.Element;
215  }
216  return *this;
217  }
218 
219  template <typename T>
220  inline
221  void CUFTree<T>::set_Element(const T & inel)
222  {
223  this->Element = inel;
224  }
225 
226  template <typename T>
227  inline
229  {
230  return ((this->find())->Element);
231  // return (this->Element);
232  }
233 
234  template <typename T>
235  inline
237  {
238  this->FFather = inFFather;
239  }
240 
241 
242 
243  template <typename T>
244  inline
246  {
247  CUFTree<T>* res = this->FFather;
248  while ( res->FFather!=res )
249  {
250  ++NbOfCrossedEdges_; // The number of crossed edges is increased
251  res = res->FFather;
252  }
253 
254  CUFTree<T>* actu = this;
255  CUFTree<T>* next = NULL;
256  while ( actu!=res )
257  {
258  next = actu->FFather;
259  actu->FFather = res;
260  // actu->Element = res->Element;
261  actu = next;
262  }
263  return res;
264  }
265 
266  template <typename T>
267  inline
269  {
270  this->Element = ATree->Element;
271  CUFTree<T>* tree1 = find();
272  CUFTree<T>* tree2 = ATree->find();
273 
274  if ( tree1==tree2 )
275  return; // Both trees are already merged
276 
277  // fusion.
278  if ( tree1->FHeight < tree2->FHeight )
279  {
280  tree1->FFather=tree2;
281  }
282  else
283  {
284  tree2->FFather=tree1;
285  if ( tree1->FHeight == tree2->FHeight )
286  ++tree1->FHeight; // the height is increased
287  }
288  }
289 
290 }//slip::
291 
292 #endif //CUFTREE_HPP
293 
void set_FFather(self_pointer inFFather)
mutator method on the FFather
Definition: CUFTree.hpp:236
std::size_t size_type
Definition: CUFTree.hpp:103
CUFTree()
Construct a CUFTree.
Definition: CUFTree.hpp:184
value_type get_Element()
accessor method on the element
Definition: CUFTree.hpp:228
self * self_pointer
Definition: CUFTree.hpp:101
void set_Element(const_reference inel)
mutator method on the element
Definition: CUFTree.hpp:221
~CUFTree()
Destructor of the CUFTree.
Definition: CUFTree.hpp:200
void merge(self_pointer ATree)
make the smaller tree a subtree of the root of the larger tree
Definition: CUFTree.hpp:268
self & operator=(const self &rsh)
assignement method
Definition: CUFTree.hpp:205
self_pointer find()
find the root of the tree and make all the nodes found children of the root.
Definition: CUFTree.hpp:245
Define an union find tree.
Definition: CUFTree.hpp:95
value_type & reference
Definition: CUFTree.hpp:105
const value_type & const_reference
Definition: CUFTree.hpp:106