Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SmartTaggerT.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
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 //=============================================================================
43 //
44 // CLASS SmartTaggerVT
45 //
46 //
47 // original Author: David Bommes <bommes@cs.rwth-aachen.de>
48 // $Revision: 18033 $
49 // $Author: moeller $
50 // $Date: 2014-01-16 17:17:07 +0100 (Do, 16. Jan 2014) $
51 //
52 //=============================================================================
53
54 //=============================================================================
55 //
56 // CLASS SmartTaggerT - IMPLEMENTATION
57 //
58 //=============================================================================
59
60 #define ACG_SMARTTAGGERT_C
61
62 //== INCLUDES =================================================================
63
64 #include "SmartTaggerT.hh"
65
66 #include <iostream>
67 #include <limits>
68
69 //== NAMESPACES ===============================================================
70
71 namespace ACG {
72
73 //== IMPLEMENTATION ==========================================================
74
75 template <class Mesh, class EHandle, class EPHandle>
76 SmartTaggerT<Mesh, EHandle, EPHandle>::
77 SmartTaggerT(Mesh& _mesh, unsigned int _tag_range)
78 : mesh_(_mesh),
79 current_base_(0),
80 tag_range_(_tag_range)
81 {
82 // add new property
83 mesh_.add_property(ep_tag_);
84
85 // reset all tags once
86 all_tags_to_zero();
87 }
88
89
90 //-----------------------------------------------------------------------------
91
92
93 template <class Mesh, class EHandle, class EPHandle>
94 SmartTaggerT<Mesh, EHandle, EPHandle>::
95 ~SmartTaggerT()
96 {
97 mesh_.remove_property(ep_tag_);
98 }
99
100
101 //-----------------------------------------------------------------------------
102
103
104 template <class Mesh, class EHandle, class EPHandle>
105 void
106 SmartTaggerT<Mesh, EHandle, EPHandle>::
107 untag_all()
108 {
109 unsigned int max_uint = std::numeric_limits<unsigned int>::max();
110
111 if( current_base_ < max_uint - 2*tag_range_)
112 current_base_ += tag_range_;
113 else
114 {
115 //overflow -> reset all tags
116 #ifdef STV_DEBUG_CHECKS
117 std::cerr << "Tagging Overflow occured...\n";
118 #endif
119 current_base_ = 0;
120 all_tags_to_zero();
121 }
122 }
123
124
125 //-----------------------------------------------------------------------------
126
127
128 template <class Mesh, class EHandle, class EPHandle>
129 void
130 SmartTaggerT<Mesh, EHandle, EPHandle>::
131 untag_all( const unsigned int _new_tag_range)
132 {
133 set_tag_range(_new_tag_range);
134 }
135
136
137 //-----------------------------------------------------------------------------
138
139 template <class Mesh, class EHandle, class EPHandle>
140 void
141 SmartTaggerT<Mesh, EHandle, EPHandle>::
142 set_tag ( const EHandle _eh, unsigned int _tag)
143 {
144 #ifdef STV_DEBUG_CHECKS
145 if( _tag > tag_range_)
146 std::cerr << "ERROR in set_tag tag range!!!\n";
147 #endif
148
149 mesh_.property(ep_tag_, _eh) = current_base_ + _tag;
150 }
151
152
153 //-----------------------------------------------------------------------------
154
155
156 template <class Mesh, class EHandle, class EPHandle>
157 unsigned int
158 SmartTaggerT<Mesh, EHandle, EPHandle>::
159 get_tag ( const EHandle _eh) const
160 {
161 unsigned int t = mesh_.property(ep_tag_, _eh);
162
163 #ifdef STV_DEBUG_CHECKS
164 if( t > current_base_ + tag_range_)
165 std::cerr << "ERROR in get_tag tag range!!!\n";
166 #endif
167
168 if( t<= current_base_) return 0;
169 else return t-current_base_;
170 }
171
172
173 //-----------------------------------------------------------------------------
174
175
176 template <class Mesh, class EHandle, class EPHandle>
177 bool
178 SmartTaggerT<Mesh, EHandle, EPHandle>::
179 is_tagged( const EHandle _eh) const
180 {
181 return bool(get_tag(_eh));
182 }
183
184
185 //-----------------------------------------------------------------------------
186
187
188 template <class Mesh, class EHandle, class EPHandle>
189 void
190 SmartTaggerT<Mesh, EHandle, EPHandle>::
191 set_tag_range( const unsigned int _tag_range)
192 {
193 if( _tag_range <= tag_range_)
194 {
195 untag_all();
196 tag_range_ = _tag_range;
197 }
198 else
199 {
200 tag_range_ = _tag_range;
201 untag_all();
202 }
203 }
204
205
206 //-----------------------------------------------------------------------------
207
208
209 template <class Mesh, class EHandle, class EPHandle>
210 void
211 SmartTaggerT<Mesh, EHandle, EPHandle>::
212 all_tags_to_zero()
213 {
214 // iterate over property vector
215 for(unsigned int i=0; i<mesh_.property(ep_tag_).n_elements(); ++i)
216 {
217 mesh_.property(ep_tag_)[i] = 0;
218 }
219 }
220
221 //=============================================================================
222 } // namespace ACG
223 //=============================================================================
ACG::SmartTaggerT::is_tagged
bool is_tagged(const EHandle _eh) const
overloaded member for boolean tags
Definition: SmartTaggerT.cc:179
ACG
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
ACG::SmartTaggerT::set_tag_range
void set_tag_range(const unsigned int _tag_range)
set new tag range and untag_all
Definition: SmartTaggerT.cc:191
ACG::SmartTaggerT
Smart Tagger.
Definition: SmartTaggerT.hh:113
ACG::SmartTaggerT::~SmartTaggerT
~SmartTaggerT()
Destructor.
Definition: SmartTaggerT.cc:95
OpenMesh::TriMesh_ArrayKernelT< CustomTraits >
ACG::SmartTaggerT::get_tag
unsigned int get_tag(const EHandle _eh) const
get tag value in range [0..tag_range]
Definition: SmartTaggerT.cc:159
ACG::SmartTaggerT::SmartTaggerT
SmartTaggerT(Mesh &_mesh, unsigned int _tag_range=1)
Constructor.
Definition: SmartTaggerT.cc:77
ACG::SmartTaggerT::untag_all
void untag_all()
untag all elements
Definition: SmartTaggerT.cc:107
ACG::SmartTaggerT::set_tag
void set_tag(const EHandle _eh, unsigned int _tag=1)
set tag to a value in [0..tag_range]
Definition: SmartTaggerT.cc:142