blob: 4ef1dbfabca0308b9f52de7f86fe09ff1ac2ee26 [file] [log] [blame]
<!-- Copyright 2008 Lubomir Bourdev and Hailin Jin
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
-->
<!--
Copyright 2005-2007 Adobe Systems Incorporated
Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
or a copy at http://stlab.adobe.com/licenses.html)
Some files are held under additional license.
Please see "http://stlab.adobe.com/licenses.html" for more information.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<TITLE>Generic Image Library: virtual_locator.hpp Source File</TITLE>
<META HTTP-EQUIV="content-type" CONTENT="text/html;charset=ISO-8859-1"/>
<LINK TYPE="text/css" REL="stylesheet" HREF="adobe_source.css"/>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" style='width: 100%; margin: 0; padding: 0'><tr>
<td width="100%" valign="top" style='padding-left: 10px; padding-right: 10px; padding-bottom: 10px'>
<div class="qindex"><a class="qindex" href="index.html">Modules</a>
| <a class="qindex" href="classes.html">Alphabetical List</a>
| <a class="qindex" href="annotated.html">Class List</a>
| <a class="qindex" href="dirs.html">Directories</a>
| <a class="qindex" href="files.html">File List</a>
| <a class="qindex" href="../index.html">GIL Home Page</a>
</div>
<!-- End Header -->
<!-- Generated by Doxygen 1.5.6 -->
<div class="navpath"><a class="el" href="g_i_l_0076.html">boost</a>&nbsp;&raquo&nbsp;<a class="el" href="g_i_l_0079.html">gil</a>
</div>
<div class="contents">
<h1>virtual_locator.hpp</h1><a href="g_i_l_0645.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> Copyright 2005-2007 Adobe Systems Incorporated</span>
<a name="l00003"></a>00003 <span class="comment"> </span>
<a name="l00004"></a>00004 <span class="comment"> Use, modification and distribution are subject to the Boost Software License,</span>
<a name="l00005"></a>00005 <span class="comment"> Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span>
<a name="l00006"></a>00006 <span class="comment"> http://www.boost.org/LICENSE_1_0.txt).</span>
<a name="l00007"></a>00007 <span class="comment"></span>
<a name="l00008"></a>00008 <span class="comment"> See http://opensource.adobe.com/gil for most recent version including documentation.</span>
<a name="l00009"></a>00009 <span class="comment">*/</span>
<a name="l00010"></a>00010
<a name="l00011"></a>00011 <span class="comment">/*************************************************************************************************/</span>
<a name="l00012"></a>00012
<a name="l00013"></a>00013 <span class="preprocessor">#ifndef GIL_VIRTUAL_LOCATOR_HPP</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define GIL_VIRTUAL_LOCATOR_HPP</span>
<a name="l00015"></a>00015 <span class="preprocessor"></span>
<a name="l00024"></a>00024
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;boost/iterator/iterator_facade.hpp&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="g_i_l_0256.html" title="Locator for virtual image views.">position_iterator.hpp</a>"</span>
<a name="l00027"></a>00027
<a name="l00028"></a>00028 <span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>gil {
<a name="l00029"></a>00029
<a name="l00033"></a>00033 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Deref, <span class="keywordtype">bool</span> IsTransposed&gt; <span class="comment">// A function object that given a point returns a reference. Models PixelDereferenceAdaptorConcept</span>
<a name="l00034"></a><a class="code" href="g_i_l_0064.html">00034</a> <span class="keyword">class </span><a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">virtual_2d_locator</a> : <span class="keyword">public</span> <a class="code" href="g_i_l_0058.html" title="base class for models of PixelLocatorConceptPixel locator is similar to a pixel iterator...">pixel_2d_locator_base</a>&lt;virtual_2d_locator&lt;Deref,IsTransposed&gt;, position_iterator&lt;Deref,IsTransposed&gt;, position_iterator&lt;Deref,1-IsTransposed&gt; &gt; {
<a name="l00035"></a>00035 <span class="keyword">typedef</span> <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">virtual_2d_locator&lt;Deref,IsTransposed&gt;</a> <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">this_t</a>;
<a name="l00036"></a>00036 <span class="keyword">public</span>:
<a name="l00037"></a>00037 <span class="keyword">typedef</span> <a class="code" href="g_i_l_0058.html" title="base class for models of PixelLocatorConceptPixel locator is similar to a pixel iterator...">pixel_2d_locator_base&lt;virtual_2d_locator&lt;Deref,IsTransposed&gt;</a>, <a class="code" href="g_i_l_0617.html" title="An iterator that remembers its current X,Y position and invokes a function object...">position_iterator&lt;Deref,IsTransposed&gt;</a>, <a class="code" href="g_i_l_0617.html" title="An iterator that remembers its current X,Y position and invokes a function object...">position_iterator</a>&lt;Deref,1-IsTransposed&gt; &gt; <a class="code" href="g_i_l_0058.html" title="base class for models of PixelLocatorConceptPixel locator is similar to a pixel iterator...">parent_t</a>;
<a name="l00038"></a>00038 <span class="keyword">typedef</span> <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">virtual_2d_locator&lt;typename Deref::const_t,IsTransposed&gt;</a> <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">const_t</a>;
<a name="l00039"></a>00039
<a name="l00040"></a>00040 <span class="keyword">typedef</span> Deref deref_fn_t;
<a name="l00041"></a>00041 <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="g_i_l_0060.html" title="2D point both axes of which have the same dimension typeModels: Point2DConcept">parent_t::point_t</a> <a class="code" href="g_i_l_0060.html" title="2D point both axes of which have the same dimension typeModels: Point2DConcept">point_t</a>;
<a name="l00042"></a>00042
<a name="l00043"></a>00043 <span class="keyword">typedef</span> <span class="keyword">typename</span> parent_t::coord_t coord_t;
<a name="l00044"></a>00044 <span class="keyword">typedef</span> <span class="keyword">typename</span> parent_t::x_coord_t x_coord_t;
<a name="l00045"></a>00045 <span class="keyword">typedef</span> <span class="keyword">typename</span> parent_t::y_coord_t y_coord_t;
<a name="l00046"></a>00046 <span class="keyword">typedef</span> <span class="keyword">typename</span> parent_t::x_iterator x_iterator;
<a name="l00047"></a>00047 <span class="keyword">typedef</span> <span class="keyword">typename</span> parent_t::y_iterator y_iterator;
<a name="l00048"></a>00048
<a name="l00049"></a>00049 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> NewDeref&gt; <span class="keyword">struct </span>add_deref {
<a name="l00050"></a>00050 <span class="keyword">typedef</span> <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">virtual_2d_locator&lt;deref_compose&lt;NewDeref,Deref&gt;</a>,IsTransposed &gt; type;
<a name="l00051"></a>00051 <span class="keyword">static</span> type make(<span class="keyword">const</span> <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">virtual_2d_locator&lt;Deref,IsTransposed&gt;</a>&amp; loc, <span class="keyword">const</span> NewDeref&amp; nderef) {
<a name="l00052"></a>00052 <span class="keywordflow">return</span> type(loc.<a class="code" href="g_i_l_0064.html#aa3dcf1288cb11be49a44552d5916f9b">pos</a>(), loc.<a class="code" href="g_i_l_0064.html#fe5624cfe9b661059ebf68a2c2659275">step</a>(), <a class="code" href="g_i_l_0024.html" title="Composes two dereference function objects. Similar to std::unary_compose but needs...">deref_compose&lt;NewDeref,Deref&gt;</a>(nderef,loc.<a class="code" href="g_i_l_0064.html#e75df2849bc94fdefa19b47d25d287d4">deref_fn</a>()));
<a name="l00053"></a>00053 }
<a name="l00054"></a>00054 };
<a name="l00055"></a>00055
<a name="l00056"></a>00056 <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">virtual_2d_locator</a>(<span class="keyword">const</span> <a class="code" href="g_i_l_0060.html" title="2D point both axes of which have the same dimension typeModels: Point2DConcept">point_t</a>&amp; p=<a class="code" href="g_i_l_0060.html" title="2D point both axes of which have the same dimension typeModels: Point2DConcept">point_t</a>(0,0), <span class="keyword">const</span> <a class="code" href="g_i_l_0060.html" title="2D point both axes of which have the same dimension typeModels: Point2DConcept">point_t</a>&amp; step=<a class="code" href="g_i_l_0060.html" title="2D point both axes of which have the same dimension typeModels: Point2DConcept">point_t</a>(1,1), <span class="keyword">const</span> deref_fn_t&amp; d=deref_fn_t()) : _p(p,step,d) {}
<a name="l00057"></a>00057 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> D, <span class="keywordtype">bool</span> TR&gt; <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">virtual_2d_locator</a>(<span class="keyword">const</span> <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">virtual_2d_locator&lt;D,TR&gt;</a>&amp; loc, coord_t y_step)
<a name="l00058"></a>00058 : _p(loc.<a class="code" href="g_i_l_0064.html#aa3dcf1288cb11be49a44552d5916f9b">pos</a>(), <a class="code" href="g_i_l_0060.html" title="2D point both axes of which have the same dimension typeModels: Point2DConcept">point_t</a>(loc.<a class="code" href="g_i_l_0064.html#fe5624cfe9b661059ebf68a2c2659275">step</a>().<a class="code" href="g_i_l_0060.html#9a4f74af87a76a4c3dcb729cb0e68f8d">x</a>,loc.<a class="code" href="g_i_l_0064.html#fe5624cfe9b661059ebf68a2c2659275">step</a>().<a class="code" href="g_i_l_0060.html#1cb2b5ea04251d543e49356ef54eb853">y</a>*y_step), loc.<a class="code" href="g_i_l_0064.html#e75df2849bc94fdefa19b47d25d287d4">deref_fn</a>()) {}
<a name="l00059"></a>00059 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> D, <span class="keywordtype">bool</span> TR&gt; virtual_2d_locator(<span class="keyword">const</span> <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">virtual_2d_locator&lt;D,TR&gt;</a>&amp; loc, coord_t x_step, coord_t y_step, <span class="keywordtype">bool</span> transpose=<span class="keyword">false</span>)
<a name="l00060"></a>00060 : _p(loc.<a class="code" href="g_i_l_0064.html#aa3dcf1288cb11be49a44552d5916f9b">pos</a>(), transpose ?
<a name="l00061"></a>00061 <a class="code" href="g_i_l_0060.html" title="2D point both axes of which have the same dimension typeModels: Point2DConcept">point_t</a>(loc.<a class="code" href="g_i_l_0064.html#fe5624cfe9b661059ebf68a2c2659275">step</a>().<a class="code" href="g_i_l_0060.html#9a4f74af87a76a4c3dcb729cb0e68f8d">x</a>*y_step,loc.<a class="code" href="g_i_l_0064.html#fe5624cfe9b661059ebf68a2c2659275">step</a>().<a class="code" href="g_i_l_0060.html#1cb2b5ea04251d543e49356ef54eb853">y</a>*x_step) :
<a name="l00062"></a>00062 <a class="code" href="g_i_l_0060.html" title="2D point both axes of which have the same dimension typeModels: Point2DConcept">point_t</a>(loc.<a class="code" href="g_i_l_0064.html#fe5624cfe9b661059ebf68a2c2659275">step</a>().<a class="code" href="g_i_l_0060.html#9a4f74af87a76a4c3dcb729cb0e68f8d">x</a>*x_step,loc.<a class="code" href="g_i_l_0064.html#fe5624cfe9b661059ebf68a2c2659275">step</a>().<a class="code" href="g_i_l_0060.html#1cb2b5ea04251d543e49356ef54eb853">y</a>*y_step), loc.<a class="code" href="g_i_l_0064.html#e75df2849bc94fdefa19b47d25d287d4">deref_fn</a>()) { assert(transpose==(IsTransposed!=TR));}
<a name="l00063"></a>00063
<a name="l00064"></a>00064 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> D, <span class="keywordtype">bool</span> TR&gt; virtual_2d_locator(<span class="keyword">const</span> <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">virtual_2d_locator&lt;D,TR&gt;</a>&amp; pl) : _p(pl.<a class="code" href="g_i_l_0064.html#1404c8a095151ac2c2dc5ba6372f42c6">_p</a>) {}
<a name="l00065"></a>00065 virtual_2d_locator(<span class="keyword">const</span> virtual_2d_locator&amp; pl) : _p(pl.<a class="code" href="g_i_l_0064.html#1404c8a095151ac2c2dc5ba6372f42c6">_p</a>) {}
<a name="l00066"></a>00066
<a name="l00067"></a>00067 <span class="keywordtype">bool</span> operator==(<span class="keyword">const</span> <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">this_t</a>&amp; p)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _p==p.<a class="code" href="g_i_l_0064.html#1404c8a095151ac2c2dc5ba6372f42c6">_p</a>; }
<a name="l00068"></a>00068
<a name="l00069"></a>00069 x_iterator&amp; x() { <span class="keywordflow">return</span> *gil_reinterpret_cast&lt;x_iterator*&gt;(<span class="keyword">this</span>); }
<a name="l00070"></a>00070 y_iterator&amp; y() { <span class="keywordflow">return</span> _p; }
<a name="l00071"></a>00071 x_iterator <span class="keyword">const</span>&amp; x()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> *gil_reinterpret_cast_c&lt;x_iterator const*&gt;(<span class="keyword">this</span>); }
<a name="l00072"></a>00072 y_iterator <span class="keyword">const</span>&amp; y()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _p; }
<a name="l00073"></a>00073
<a name="l00074"></a>00074 <span class="comment">// Returns the y distance between two x_iterators given the difference of their x positions</span>
<a name="l00075"></a>00075 y_coord_t y_distance_to(<span class="keyword">const</span> <a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">this_t</a>&amp; it2, x_coord_t xDiff)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> (it2.<a class="code" href="g_i_l_0064.html#aa3dcf1288cb11be49a44552d5916f9b">pos</a>()[1-IsTransposed] - pos()[1-IsTransposed])/step()[1-IsTransposed]; }
<a name="l00076"></a>00076 <span class="keywordtype">bool</span> is_1d_traversable(x_coord_t)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <span class="keyword">false</span>; } <span class="comment">// is there no gap at the end of each row? I.e. can we use x_iterator to visit every pixel instead of nested loops?</span>
<a name="l00077"></a>00077
<a name="l00078"></a>00078 <span class="comment">// Methods specific for virtual 2D locator</span>
<a name="l00079"></a>00079 <span class="keyword">const</span> <a class="code" href="g_i_l_0060.html" title="2D point both axes of which have the same dimension typeModels: Point2DConcept">point_t</a>&amp; pos()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _p.pos(); }
<a name="l00080"></a>00080 <span class="keyword">const</span> <a class="code" href="g_i_l_0060.html" title="2D point both axes of which have the same dimension typeModels: Point2DConcept">point_t</a>&amp; step()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _p.step(); }
<a name="l00081"></a>00081 <span class="keyword">const</span> deref_fn_t&amp; deref_fn()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _p.deref_fn(); }
<a name="l00082"></a>00082 <span class="keyword">private</span>:
<a name="l00083"></a>00083 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> D, <span class="keywordtype">bool</span> TR&gt; <span class="keyword">friend</span> <span class="keyword">class </span>virtual_2d_locator;
<a name="l00084"></a>00084 y_iterator _p; <span class="comment">// contains the current position, the step and the dereference object</span>
<a name="l00085"></a>00085 };
<a name="l00086"></a>00086
<a name="l00088"></a>00088 <span class="comment">// PixelBasedConcept</span>
<a name="l00090"></a>00090 <span class="comment"></span>
<a name="l00091"></a>00091 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> D, <span class="keywordtype">bool</span> TR&gt;
<a name="l00092"></a>00092 <span class="keyword">struct </span>channel_type&lt;<a class="code" href="g_i_l_0064.html" title="A 2D locator over a virtual image. Upon dereferencing, invokes a given function object...">virtual_2d_locator</a>&lt;D,TR&gt; &gt; : <span class="keyword">public</span> channel_type&lt;typename virtual_2d_locator&lt;D,TR&gt;::parent_t&gt; {
<a name="l00093"></a>00093 };
<a name="l00094"></a>00094
<a name="l00095"></a>00095 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> D, <span class="keywordtype">bool</span> TR&gt;
<a name="l00096"></a>00096 <span class="keyword">struct </span>color_space_type&lt;virtual_2d_locator&lt;D,TR&gt; &gt; : <span class="keyword">public</span> color_space_type&lt;typename virtual_2d_locator&lt;D,TR&gt;::parent_t&gt; {
<a name="l00097"></a>00097 };
<a name="l00098"></a>00098
<a name="l00099"></a>00099 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> D, <span class="keywordtype">bool</span> TR&gt;
<a name="l00100"></a>00100 <span class="keyword">struct </span>channel_mapping_type&lt;virtual_2d_locator&lt;D,TR&gt; &gt; : <span class="keyword">public</span> channel_mapping_type&lt;typename virtual_2d_locator&lt;D,TR&gt;::parent_t&gt; {
<a name="l00101"></a>00101 };
<a name="l00102"></a>00102
<a name="l00103"></a>00103 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> D, <span class="keywordtype">bool</span> TR&gt;
<a name="l00104"></a>00104 <span class="keyword">struct </span>is_planar&lt;virtual_2d_locator&lt;D,TR&gt; &gt; : <span class="keyword">public</span> is_planar&lt;typename virtual_2d_locator&lt;D,TR&gt;::parent_t&gt; {
<a name="l00105"></a>00105 };
<a name="l00106"></a>00106
<a name="l00108"></a>00108 <span class="comment">// HasDynamicXStepTypeConcept</span>
<a name="l00110"></a>00110 <span class="comment"></span>
<a name="l00111"></a>00111 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> D, <span class="keywordtype">bool</span> TR&gt;
<a name="l00112"></a>00112 <span class="keyword">struct </span>dynamic_x_step_type&lt;virtual_2d_locator&lt;D,TR&gt; &gt; {
<a name="l00113"></a>00113 <span class="keyword">typedef</span> virtual_2d_locator&lt;D,TR&gt; type;
<a name="l00114"></a>00114 };
<a name="l00115"></a>00115
<a name="l00117"></a>00117 <span class="comment">// HasDynamicYStepTypeConcept</span>
<a name="l00119"></a>00119 <span class="comment"></span>
<a name="l00120"></a>00120 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> D, <span class="keywordtype">bool</span> TR&gt;
<a name="l00121"></a>00121 <span class="keyword">struct </span>dynamic_y_step_type&lt;virtual_2d_locator&lt;D,TR&gt; &gt; {
<a name="l00122"></a>00122 <span class="keyword">typedef</span> virtual_2d_locator&lt;D,TR&gt; type;
<a name="l00123"></a>00123 };
<a name="l00124"></a>00124
<a name="l00126"></a>00126 <span class="comment">// HasTransposedTypeConcept</span>
<a name="l00128"></a>00128 <span class="comment"></span>
<a name="l00129"></a>00129 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> D, <span class="keywordtype">bool</span> IsTransposed&gt;
<a name="l00130"></a>00130 <span class="keyword">struct </span>transposed_type&lt;virtual_2d_locator&lt;D,IsTransposed&gt; &gt; {
<a name="l00131"></a>00131 <span class="keyword">typedef</span> virtual_2d_locator&lt;D,1-IsTransposed&gt; type;
<a name="l00132"></a>00132 };
<a name="l00133"></a>00133
<a name="l00134"></a>00134 } } <span class="comment">// namespace boost::gil</span>
<a name="l00135"></a>00135
<a name="l00136"></a>00136 <span class="preprocessor">#endif</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sat May 2 13:50:15 2009 for Generic Image Library by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>