IsoEx
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
Edge2VertexMapT.hh
1 /*===========================================================================*\
2  * *
3  * IsoEx *
4  * Copyright (C) 2002 by Computer Graphics Group, RWTH Aachen *
5  * www.rwth-graphics.de *
6  * *
7  *---------------------------------------------------------------------------*
8  * *
9  * License *
10  * *
11  * This library is free software; you can redistribute it and/or modify it *
12  * under the terms of the GNU Library General Public License as published *
13  * by the Free Software Foundation, version 2. *
14  * *
15  * This library is distributed in the hope that it will be useful, but *
16  * WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
18  * Library General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU Library General Public *
21  * License along with this library; if not, write to the Free Software *
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
23  * *
24 \*===========================================================================*/
25 
26 //=============================================================================
27 //
28 // CLASS Edge2VertexMapT
29 //
30 //=============================================================================
31 
32 
33 #ifndef ISOEX_EDGE2VERTEXMAPT_HH
34 #define ISOEX_EDGE2VERTEXMAPT_HH
35 
36 
37 //== INCLUDES =================================================================
38 
39 #include <map>
40 
41 //== NAMESPACES ===============================================================
42 
43 namespace IsoEx {
44 
45 //== CLASS DEFINITION =========================================================
46 
57 template <class PointIdx, class VertexHandle>
59 {
60 public:
61 
64 
65 
67  void clear() { map_.clear(); }
68 
70  void insert(PointIdx _p0, PointIdx _p1, VertexHandle _vhnd)
71  {
72  map_[EdgeKey(_p0, _p1)] = _vhnd;
73  }
74 
76  VertexHandle find(PointIdx _p0, PointIdx _p1) const
77  {
78  MyMapIterator it = map_.find(EdgeKey(_p0, _p1));
79  if (it != map_.end()) return it->second;
80  else return VertexHandle();
81  }
82 
83 
84 private:
85 
86  class EdgeKey
87  {
88  public:
89 
90  EdgeKey(PointIdx _p0, PointIdx _p1) {
91  if (_p0 < _p1) { p0_ = _p0; p1_ = _p1; }
92  else { p0_ = _p1; p1_ = _p0; }
93  }
94 
95  bool operator<(const EdgeKey& _rhs) const
96  {
97  if (p0_ != _rhs.p0_)
98  return (p0_ < _rhs.p0_);
99  else
100  return (p1_ < _rhs.p1_);
101  }
102 
103  private:
104  PointIdx p0_, p1_;
105  };
106 
107 
108  typedef std::map<EdgeKey, VertexHandle> MyMap;
109  typedef typename MyMap::const_iterator MyMapIterator;
110 
111  MyMap map_;
112 };
113 
114 
115 //=============================================================================
116 } // namespace IsoEx
117 //=============================================================================
118 #endif // ISOEX_EDGE2VERTEXMAPT_HH defined
119 //=============================================================================
120 
Edge2VertexMapT()
Constructor.
Definition: Edge2VertexMapT.hh:63
Definition: Edge2VertexMapT.hh:58
Definition: EdgeKey.hh:14
VertexHandle find(PointIdx _p0, PointIdx _p1) const
Get vertex handle from map. Returns invalid handle if not found.
Definition: Edge2VertexMapT.hh:76
void insert(PointIdx _p0, PointIdx _p1, VertexHandle _vhnd)
Store vertex in map.
Definition: Edge2VertexMapT.hh:70
void clear()
clear the map
Definition: Edge2VertexMapT.hh:67
A type for volume images, or 3D textures.