aimsalgo  5.0.5
Neuroimaging image processing
stlsort.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef AIMS_DISTANCEMAP_STLSORT_H
36 #define AIMS_DISTANCEMAP_STLSORT_H
37 
38 #include <aims/mesh/texture.h>
39 #include <aims/mesh/surface.h>
40 #include <aims/data/data.h>
42 #include <set>
43 #include <map>
44 
45 namespace aims
46 {
47 
48 
49 
50  //Def of the operator < for the Point3df (required by the map and the set)
52  : public std::binary_function<Point3df,Point3df, bool>
53  {
54  bool operator () ( const Point3df & p1, const Point3df & p2 ) const
55  {
56  return p1[2] < p2[2] ||
57  ( p1[2] == p2[2] &&
58  ( p1[1] < p2[1] ||
59  ( p1[1] == p2[1] &&
60  ( p1[0] < p2[0] ) ) ) );
61  }
62  };
63 
64  //Def of the operator < for the Point3df (required by the map and the set)
65  struct Point3dCompare : public std::binary_function<Point3d,Point3d, bool>
66  {
67  bool operator () ( const Point3d & p1, const Point3d & p2 ) const
68  {
69  return p1[2] < p2[2] ||
70  ( p1[2] == p2[2] &&
71  ( p1[1] < p2[1] ||
72  ( p1[1] == p2[1] &&
73  ( p1[0] < p2[0] ) ) ) );
74  }
75  };
76 
77  template <class T>
78 struct PairCompare
79 : public std::binary_function<std::pair<T,T>, std::pair<T,T>, bool>
80 {
81  bool operator () ( const std::pair<T,T> & p,
82  const std::pair<T,T> & r ) const
83  {
84  return p.first < r.first
85  || (p.first == r.first && p.second < r.second) ;
86 
87  }
88  };
89 
90 // Def of the operator "<" for the set<T> (required by the map)
91 template <class T>
92 struct SetCompare
93  : public std::binary_function<std::set<T>,std::set<T>, bool>
94 {
95  bool operator () ( const std::set<T> & s1, const std::set<T> & s2 ) const
96  {
97  typename std::set<T>::iterator
98  is1=s1.begin(),es1=s1.end(),is2=s2.begin();
99  unsigned n1 = s1.size(), n2 = s2.size();
100  if (n1 != n2)
101  return (n1 < n2);
102  else
103  {
104  while ( ( is1 != es1) && ( (*is1) == (*is2) ) )
105  {
106  ++is1;
107  ++is2;
108  }
109  if (is1 != es1)
110  return( (*is1) < (*is2) );
111  else
112  return false;
113  }
114  }
115 };
116 
117 
118 //typedefs
119 typedef std::set<Point3df,Point3dfCompare> Point3dfSet;
120 typedef std::map<Point3df,Point3dfSet,Point3dfCompare> Point3dfNeigh;
121 }
122 
123 #endif
bool operator()(const Point3df &p1, const Point3df &p2) const
Definition: stlsort.h:54
std::set< Point3df, Point3dfCompare > Point3dfSet
Definition: stlsort.h:119
std::map< Point3df, Point3dfSet, Point3dfCompare > Point3dfNeigh
Definition: stlsort.h:120