]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <!-- Copyright 2008 Lubomir Bourdev and Hailin Jin |
2 | ||
3 | Distributed under the Boost Software License, Version 1.0. | |
4 | (See accompanying file LICENSE_1_0.txt or copy at | |
5 | http://www.boost.org/LICENSE_1_0.txt) | |
6 | --> | |
7 | ||
8 | <!-- | |
9 | Copyright 2005-2007 Adobe Systems Incorporated | |
10 | Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt | |
11 | or a copy at http://stlab.adobe.com/licenses.html) | |
12 | ||
13 | Some files are held under additional license. | |
14 | Please see "http://stlab.adobe.com/licenses.html" for more information. | |
15 | --> | |
16 | ||
17 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
18 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
19 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> | |
20 | ||
21 | <head> | |
22 | <TITLE>Generic Image Library: iterator_from_2d.hpp Source File</TITLE> | |
23 | <META HTTP-EQUIV="content-type" CONTENT="text/html;charset=ISO-8859-1"/> | |
24 | <LINK TYPE="text/css" REL="stylesheet" HREF="adobe_source.css"/> | |
25 | </head> | |
26 | <body> | |
27 | <table border="0" cellspacing="0" cellpadding="0" style='width: 100%; margin: 0; padding: 0'><tr> | |
28 | <td width="100%" valign="top" style='padding-left: 10px; padding-right: 10px; padding-bottom: 10px'> | |
29 | <div class="qindex"><a class="qindex" href="index.html">Modules</a> | |
30 | | <a class="qindex" href="classes.html">Alphabetical List</a> | |
31 | | <a class="qindex" href="annotated.html">Class List</a> | |
32 | | <a class="qindex" href="dirs.html">Directories</a> | |
33 | | <a class="qindex" href="files.html">File List</a> | |
34 | | <a class="qindex" href="../index.html">GIL Home Page</a> | |
35 | </div> | |
36 | <!-- End Header --> | |
37 | <!-- Generated by Doxygen 1.5.6 --> | |
38 | <div class="navpath"><a class="el" href="g_i_l_0076.html">boost</a> » <a class="el" href="g_i_l_0079.html">gil</a> | |
39 | </div> | |
40 | <div class="contents"> | |
41 | <h1>iterator_from_2d.hpp</h1><a href="g_i_l_0230.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> | |
42 | <a name="l00002"></a>00002 <span class="comment"> Copyright 2005-2007 Adobe Systems Incorporated</span> | |
43 | <a name="l00003"></a>00003 <span class="comment"> </span> | |
44 | <a name="l00004"></a>00004 <span class="comment"> Use, modification and distribution are subject to the Boost Software License,</span> | |
45 | <a name="l00005"></a>00005 <span class="comment"> Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span> | |
46 | <a name="l00006"></a>00006 <span class="comment"> http://www.boost.org/LICENSE_1_0.txt).</span> | |
47 | <a name="l00007"></a>00007 <span class="comment"></span> | |
48 | <a name="l00008"></a>00008 <span class="comment"> See http://opensource.adobe.com/gil for most recent version including documentation.</span> | |
49 | <a name="l00009"></a>00009 <span class="comment">*/</span> | |
50 | <a name="l00010"></a>00010 <span class="comment">/*************************************************************************************************/</span> | |
51 | <a name="l00011"></a>00011 | |
52 | <a name="l00012"></a>00012 <span class="preprocessor">#ifndef GIL_ITERATOR_FROM_2D_H</span> | |
53 | <a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#define GIL_ITERATOR_FROM_2D_H</span> | |
54 | <a name="l00014"></a>00014 <span class="preprocessor"></span> | |
55 | <a name="l00023"></a>00023 | |
56 | <a name="l00024"></a>00024 <span class="preprocessor">#include <cassert></span> | |
57 | <a name="l00025"></a>00025 <span class="preprocessor">#include <boost/iterator/iterator_facade.hpp></span> | |
58 | <a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="g_i_l_0092.html" title="Concept check classes for GIL concepts.">gil_concept.hpp</a>"</span> | |
59 | <a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="g_i_l_0094.html" title="GIL configuration file.">gil_config.hpp</a>"</span> | |
60 | <a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="g_i_l_0243.html" title="pixel iterator support">pixel_iterator.hpp</a>"</span> | |
61 | <a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="locator_8hpp.html" title="pixel 2D locator">locator.hpp</a>"</span> | |
62 | <a name="l00030"></a>00030 | |
63 | <a name="l00031"></a>00031 <span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>gil { | |
64 | <a name="l00032"></a>00032 | |
65 | <a name="l00038"></a>00038 | |
66 | <a name="l00039"></a>00039 | |
67 | <a name="l00043"></a>00043 | |
68 | <a name="l00044"></a>00044 | |
69 | <a name="l00050"></a>00050 | |
70 | <a name="l00051"></a>00051 <span class="keyword">template</span> <<span class="keyword">typename</span> Loc2> <span class="comment">// Models PixelLocatorConcept</span> | |
71 | <a name="l00052"></a><a class="code" href="g_i_l_0042.html">00052</a> <span class="keyword">class </span><a class="code" href="g_i_l_0042.html" title="Provides 1D random-access navigation to the pixels of the image. Models: PixelIteratorConcept...">iterator_from_2d</a> : <span class="keyword">public</span> iterator_facade<iterator_from_2d<Loc2>, | |
72 | <a name="l00053"></a>00053 typename Loc2::value_type, | |
73 | <a name="l00054"></a>00054 random_access_traversal_tag, | |
74 | <a name="l00055"></a>00055 typename Loc2::reference, | |
75 | <a name="l00056"></a>00056 typename Loc2::coord_t> { | |
76 | <a name="l00057"></a>00057 GIL_CLASS_REQUIRE(Loc2, boost::gil, <a class="code" href="g_i_l_0354.html" title="GIL&#39;s 2-dimensional locator over immutable GIL pixels.">PixelLocatorConcept</a>) | |
77 | <a name="l00058"></a>00058 <span class="keyword">public</span>: | |
78 | <a name="l00059"></a>00059 <span class="keyword">typedef</span> iterator_facade<iterator_from_2d<Loc2>, | |
79 | <a name="l00060"></a>00060 <span class="keyword">typename</span> Loc2::value_type, | |
80 | <a name="l00061"></a>00061 random_access_traversal_tag, | |
81 | <a name="l00062"></a>00062 <span class="keyword">typename</span> Loc2::reference, | |
82 | <a name="l00063"></a>00063 <span class="keyword">typename</span> Loc2::coord_t> parent_t; | |
83 | <a name="l00064"></a>00064 <span class="keyword">typedef</span> <span class="keyword">typename</span> parent_t::reference reference; | |
84 | <a name="l00065"></a>00065 <span class="keyword">typedef</span> <span class="keyword">typename</span> parent_t::difference_type difference_type; | |
85 | <a name="l00066"></a>00066 <span class="keyword">typedef</span> <span class="keyword">typename</span> Loc2::x_iterator x_iterator; | |
86 | <a name="l00067"></a>00067 <span class="keyword">typedef</span> <span class="keyword">typename</span> Loc2::point_t point_t; | |
87 | <a name="l00068"></a>00068 | |
88 | <a name="l00069"></a>00069 std::ptrdiff_t width()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _width; } <span class="comment">// number of pixels per image row</span> | |
89 | <a name="l00070"></a>00070 std::ptrdiff_t x_pos()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _coords.<a class="code" href="g_i_l_0060.html#9a4f74af87a76a4c3dcb729cb0e68f8d">x</a>; } <span class="comment">// current x position</span> | |
90 | <a name="l00071"></a>00071 std::ptrdiff_t y_pos()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _coords.<a class="code" href="g_i_l_0060.html#1cb2b5ea04251d543e49356ef54eb853">y</a>; } <span class="comment">// current y position</span> | |
91 | <a name="l00072"></a>00072 | |
92 | <a name="l00075"></a><a class="code" href="g_i_l_0042.html#de1279c4ed222b6efb0867c038765ea1">00075</a> reference <a class="code" href="g_i_l_0042.html#de1279c4ed222b6efb0867c038765ea1">operator[]</a>(difference_type d)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> *(*<span class="keyword">this</span>+d); } | |
93 | <a name="l00076"></a>00076 | |
94 | <a name="l00077"></a>00077 <span class="keywordtype">bool</span> is_1d_traversable()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _p.is_1d_traversable(width()); } <span class="comment">// is there no gap at the end of each row?</span> | |
95 | <a name="l00078"></a>00078 x_iterator& x() { <span class="keywordflow">return</span> _p.x(); } | |
96 | <a name="l00079"></a>00079 | |
97 | <a name="l00080"></a>00080 iterator_from_2d(){} | |
98 | <a name="l00081"></a>00081 iterator_from_2d(<span class="keyword">const</span> Loc2& p, std::ptrdiff_t width, std::ptrdiff_t x=0, std::ptrdiff_t y=0) : _coords(x,y), _width(width), _p(p) {} | |
99 | <a name="l00082"></a>00082 iterator_from_2d(<span class="keyword">const</span> iterator_from_2d& pit) : _coords(pit._coords), _width(pit._width), _p(pit._p) {} | |
100 | <a name="l00083"></a>00083 <span class="keyword">template</span> <<span class="keyword">typename</span> Loc> iterator_from_2d(<span class="keyword">const</span> iterator_from_2d<Loc>& pit) : _coords(pit._coords), _width(pit._width), _p(pit._p) {} | |
101 | <a name="l00084"></a>00084 | |
102 | <a name="l00085"></a>00085 <span class="keyword">private</span>: | |
103 | <a name="l00086"></a>00086 <span class="keyword">template</span> <<span class="keyword">typename</span> Loc> <span class="keyword">friend</span> <span class="keyword">class </span>iterator_from_2d; | |
104 | <a name="l00087"></a>00087 <span class="keyword">friend</span> <span class="keyword">class </span>boost::iterator_core_access; | |
105 | <a name="l00088"></a>00088 reference dereference()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> *_p; } | |
106 | <a name="l00089"></a>00089 <span class="keywordtype">void</span> increment() { | |
107 | <a name="l00090"></a>00090 ++_coords.x; | |
108 | <a name="l00091"></a>00091 ++_p.x(); | |
109 | <a name="l00092"></a>00092 <span class="keywordflow">if</span> (_coords.x>=_width) { | |
110 | <a name="l00093"></a>00093 _coords.x=0; | |
111 | <a name="l00094"></a>00094 ++_coords.y; | |
112 | <a name="l00095"></a>00095 _p+=point_t(-_width,1); | |
113 | <a name="l00096"></a>00096 } | |
114 | <a name="l00097"></a>00097 } | |
115 | <a name="l00098"></a>00098 <span class="keywordtype">void</span> decrement() { | |
116 | <a name="l00099"></a>00099 --_coords.x; | |
117 | <a name="l00100"></a>00100 --_p.x(); | |
118 | <a name="l00101"></a>00101 <span class="keywordflow">if</span> (_coords.x<0) { | |
119 | <a name="l00102"></a>00102 _coords.x=_width-1; | |
120 | <a name="l00103"></a>00103 --_coords.y; | |
121 | <a name="l00104"></a>00104 _p+=point_t(_width,-1); | |
122 | <a name="l00105"></a>00105 } | |
123 | <a name="l00106"></a>00106 } | |
124 | <a name="l00107"></a>00107 | |
125 | <a name="l00108"></a>00108 GIL_FORCEINLINE <span class="keywordtype">void</span> advance(difference_type d) { | |
126 | <a name="l00109"></a>00109 <span class="keywordflow">if</span> (_width==0) <span class="keywordflow">return</span>; <span class="comment">// unfortunately we need to check for that. Default-constructed images have width of 0 and the code below will throw if executed.</span> | |
127 | <a name="l00110"></a>00110 point_t delta; | |
128 | <a name="l00111"></a>00111 <span class="keywordflow">if</span> (_coords.x+d>=0) { <span class="comment">// not going back to a previous row?</span> | |
129 | <a name="l00112"></a>00112 delta.x=(_coords.x+(std::ptrdiff_t)d)%_width - _coords.x; | |
130 | <a name="l00113"></a>00113 delta.y=(_coords.x+(std::ptrdiff_t)d)/_width; | |
131 | <a name="l00114"></a>00114 } <span class="keywordflow">else</span> { | |
132 | <a name="l00115"></a>00115 delta.x=(_coords.x+(std::ptrdiff_t)d*(1-_width))%_width -_coords.x; | |
133 | <a name="l00116"></a>00116 delta.y=-(_width-_coords.x-(std::ptrdiff_t)d-1)/_width; | |
134 | <a name="l00117"></a>00117 } | |
135 | <a name="l00118"></a>00118 _p+=delta; | |
136 | <a name="l00119"></a>00119 _coords.x+=delta.x; | |
137 | <a name="l00120"></a>00120 _coords.y+=delta.y; | |
138 | <a name="l00121"></a>00121 } | |
139 | <a name="l00122"></a>00122 | |
140 | <a name="l00123"></a>00123 difference_type distance_to(<span class="keyword">const</span> iterator_from_2d& it)<span class="keyword"> const </span>{ | |
141 | <a name="l00124"></a>00124 <span class="keywordflow">if</span> (_width==0) <span class="keywordflow">return</span> 0; | |
142 | <a name="l00125"></a>00125 <span class="keywordflow">return</span> (it.y_pos()-_coords.y)*_width + (it.x_pos()-_coords.x); | |
143 | <a name="l00126"></a>00126 } | |
144 | <a name="l00127"></a>00127 | |
145 | <a name="l00128"></a>00128 <span class="keywordtype">bool</span> <a class="code" href="g_i_l_0214.html#g4ed3cf71cb0fbf435d1389df8567a4e5" title="std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d">equal</a>(<span class="keyword">const</span> iterator_from_2d& it)<span class="keyword"> const </span>{ | |
146 | <a name="l00129"></a>00129 assert(_width==it.width()); <span class="comment">// they must belong to the same image</span> | |
147 | <a name="l00130"></a>00130 <span class="keywordflow">return</span> _coords==it._coords && _p==it._p; | |
148 | <a name="l00131"></a>00131 } | |
149 | <a name="l00132"></a>00132 | |
150 | <a name="l00133"></a>00133 point2<std::ptrdiff_t> _coords; | |
151 | <a name="l00134"></a>00134 std::ptrdiff_t _width; | |
152 | <a name="l00135"></a>00135 Loc2 _p; | |
153 | <a name="l00136"></a>00136 }; | |
154 | <a name="l00137"></a>00137 | |
155 | <a name="l00138"></a>00138 <span class="keyword">template</span> <<span class="keyword">typename</span> Loc> <span class="comment">// Models PixelLocatorConcept</span> | |
156 | <a name="l00139"></a>00139 <span class="keyword">struct </span>const_iterator_type<iterator_from_2d<Loc> > { | |
157 | <a name="l00140"></a>00140 <span class="keyword">typedef</span> iterator_from_2d<typename Loc::const_t> type; | |
158 | <a name="l00141"></a>00141 }; | |
159 | <a name="l00142"></a>00142 | |
160 | <a name="l00143"></a>00143 <span class="keyword">template</span> <<span class="keyword">typename</span> Loc> <span class="comment">// Models PixelLocatorConcept</span> | |
161 | <a name="l00144"></a>00144 <span class="keyword">struct </span>iterator_is_mutable<iterator_from_2d<Loc> > : <span class="keyword">public</span> iterator_is_mutable<typename Loc::x_iterator> {}; | |
162 | <a name="l00145"></a>00145 | |
163 | <a name="l00146"></a>00146 | |
164 | <a name="l00148"></a>00148 <span class="comment">// HasDynamicXStepTypeConcept</span> | |
165 | <a name="l00150"></a>00150 <span class="comment"></span> | |
166 | <a name="l00151"></a>00151 <span class="keyword">template</span> <<span class="keyword">typename</span> Loc> | |
167 | <a name="l00152"></a>00152 <span class="keyword">struct </span>dynamic_x_step_type<iterator_from_2d<Loc> > { | |
168 | <a name="l00153"></a>00153 <span class="keyword">typedef</span> iterator_from_2d<typename dynamic_x_step_type<Loc>::type> type; | |
169 | <a name="l00154"></a>00154 }; | |
170 | <a name="l00155"></a>00155 | |
171 | <a name="l00156"></a>00156 | |
172 | <a name="l00158"></a>00158 <span class="comment">// PixelBasedConcept</span> | |
173 | <a name="l00160"></a>00160 <span class="comment"></span> | |
174 | <a name="l00161"></a>00161 <span class="keyword">template</span> <<span class="keyword">typename</span> Loc> <span class="comment">// Models PixelLocatorConcept</span> | |
175 | <a name="l00162"></a>00162 <span class="keyword">struct </span>color_space_type<iterator_from_2d<Loc> > : <span class="keyword">public</span> color_space_type<Loc> {}; | |
176 | <a name="l00163"></a>00163 | |
177 | <a name="l00164"></a>00164 <span class="keyword">template</span> <<span class="keyword">typename</span> Loc> <span class="comment">// Models PixelLocatorConcept</span> | |
178 | <a name="l00165"></a>00165 <span class="keyword">struct </span>channel_mapping_type<iterator_from_2d<Loc> > : <span class="keyword">public</span> channel_mapping_type<Loc> {}; | |
179 | <a name="l00166"></a>00166 | |
180 | <a name="l00167"></a>00167 <span class="keyword">template</span> <<span class="keyword">typename</span> Loc> <span class="comment">// Models PixelLocatorConcept</span> | |
181 | <a name="l00168"></a>00168 <span class="keyword">struct </span>is_planar<iterator_from_2d<Loc> > : <span class="keyword">public</span> is_planar<Loc> {}; | |
182 | <a name="l00169"></a>00169 | |
183 | <a name="l00170"></a>00170 <span class="keyword">template</span> <<span class="keyword">typename</span> Loc> <span class="comment">// Models PixelLocatorConcept</span> | |
184 | <a name="l00171"></a>00171 <span class="keyword">struct </span>channel_type<iterator_from_2d<Loc> > : <span class="keyword">public</span> channel_type<Loc> {}; | |
185 | <a name="l00172"></a>00172 | |
186 | <a name="l00173"></a>00173 } } <span class="comment">// namespace boost::gil</span> | |
187 | <a name="l00174"></a>00174 | |
188 | <a name="l00175"></a>00175 <span class="preprocessor">#endif</span> | |
189 | </pre></div></div> | |
190 | <hr size="1"><address style="text-align: right;"><small>Generated on Sat May 2 13:50:14 2009 for Generic Image Library by | |
191 | <a href="http://www.doxygen.org/index.html"> | |
192 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> | |
193 | </body> | |
194 | </html> |