Developer Documentation
SmartTaggerT_impl.hh
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openmesh.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenMesh. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  * ========================================================================= */
41 
42 #define OPENMESH_SMARTTAGGERT_C
43 
44 //== INCLUDES =================================================================
45 
46 #include "SmartTaggerT.hh"
47 
48 #include <iostream>
49 #include <limits>
50 
51 //== NAMESPACES ===============================================================
52 
53 namespace OpenMesh {
54 
55 //== IMPLEMENTATION ==========================================================
56 
57 template <class Mesh, class EHandle, class EPHandle>
59 SmartTaggerT(Mesh& _mesh, unsigned int _tag_range)
60  : mesh_(_mesh),
61  current_base_(0),
62  tag_range_(_tag_range)
63 {
64  // add new property
65  mesh_.add_property(ep_tag_);
66 
67  // reset all tags once
68  all_tags_to_zero();
69 }
70 
71 
72 //-----------------------------------------------------------------------------
73 
74 
75 template <class Mesh, class EHandle, class EPHandle>
78 {
79  mesh_.remove_property(ep_tag_);
80 }
81 
82 
83 //-----------------------------------------------------------------------------
84 
85 
86 template <class Mesh, class EHandle, class EPHandle>
87 void
90 {
91  unsigned int max_uint = std::numeric_limits<unsigned int>::max();
92 
93  if( current_base_ < max_uint - 2*tag_range_)
94  current_base_ += tag_range_;
95  else
96  {
97  //overflow -> reset all tags
98 #ifdef STV_DEBUG_CHECKS
99  std::cerr << "Tagging Overflow occured...\n";
100 #endif
101  current_base_ = 0;
102  all_tags_to_zero();
103  }
104 }
105 
106 
107 //-----------------------------------------------------------------------------
108 
109 
110 template <class Mesh, class EHandle, class EPHandle>
111 void
113 untag_all( const unsigned int _new_tag_range)
114 {
115  set_tag_range(_new_tag_range);
116 }
117 
118 
119 //-----------------------------------------------------------------------------
120 
121 template <class Mesh, class EHandle, class EPHandle>
122 void
124 set_tag ( const EHandle _eh, unsigned int _tag)
125 {
126 #ifdef STV_DEBUG_CHECKS
127  if( _tag > tag_range_)
128  std::cerr << "ERROR in set_tag tag range!!!\n";
129 #endif
130 
131  mesh_.property(ep_tag_, _eh) = current_base_ + _tag;
132 }
133 
134 
135 //-----------------------------------------------------------------------------
136 
137 
138 template <class Mesh, class EHandle, class EPHandle>
139 unsigned int
141 get_tag ( const EHandle _eh) const
142 {
143  unsigned int t = mesh_.property(ep_tag_, _eh);
144 
145 #ifdef STV_DEBUG_CHECKS
146  if( t > current_base_ + tag_range_)
147  std::cerr << "ERROR in get_tag tag range!!!\n";
148 #endif
149 
150  if( t<= current_base_) return 0;
151  else return t-current_base_;
152 }
153 
154 
155 //-----------------------------------------------------------------------------
156 
157 
158 template <class Mesh, class EHandle, class EPHandle>
159 bool
161 is_tagged( const EHandle _eh) const
162 {
163  return bool(get_tag(_eh));
164 }
165 
166 
167 //-----------------------------------------------------------------------------
168 
169 
170 template <class Mesh, class EHandle, class EPHandle>
171 void
173 set_tag_range( const unsigned int _tag_range)
174 {
175  if( _tag_range <= tag_range_)
176  {
177  untag_all();
178  tag_range_ = _tag_range;
179  }
180  else
181  {
182  tag_range_ = _tag_range;
183  untag_all();
184  }
185 }
186 
187 
188 //-----------------------------------------------------------------------------
189 
190 
191 template <class Mesh, class EHandle, class EPHandle>
192 void
195 {
196  // iterate over property vector
197  for(unsigned int i=0; i<mesh_.property(ep_tag_).n_elements(); ++i)
198  {
199  mesh_.property(ep_tag_)[i] = 0;
200  }
201 }
202 
203 //=============================================================================
204 } // namespace OpenMesh
205 //=============================================================================
SmartTaggerT(Mesh &_mesh, unsigned int _tag_range=1)
Constructor.