<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>DGtal: Tutorial &quot;File -&gt; Grid Curve -&gt; Ranges&quot;</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">DGtal
   &#160;<span id="projectnumber">1.4.2</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('tutoFileGridCurveRanges.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">Tutorial "File -&gt; Grid Curve -&gt; Ranges" </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#secttutofileGridCurveRanges0">Declaration</a></li>
<li class="level1"><a href="#secttutofileGridCurveRanges1">Reading a grid curve from a file</a></li>
<li class="level1"><a href="#secttutofileGridCurveRanges2">Displaying a grid curve with Board2D</a></li>
<li class="level1"><a href="#secttutofileGridCurveRanges3">Ranges</a></li>
<li class="level1"><a href="#secttutofileGridCurveRanges4">Required includes</a></li>
</ul>
</div>
<div class="textblock"><dl class="section user"><dt>Author(s) of this documentation: </dt><dd>Tristan Roussillon</dd></dl>
<h1><a class="anchor" id="secttutofileGridCurveRanges0"></a>
Declaration</h1>
<p>In this example, we show how to use the <a class="el" href="classDGtal_1_1GridCurve.html" title="Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...">GridCurve</a> object, which is key to analyze digital curves. <br  />
</p>
<p>Using the <a class="el" href="namespaceDGtal_1_1Z2i.html" title="Z2i this namespace gathers the standard of types for 2D imagery.">Z2i</a> shortcut, you can merely declare it as follows:</p>
<div class="fragment"><div class="line">  <a class="code" href="namespaceDGtal_1_1Z2i.html#a503faf4d34b6500e8f14035911fa04d5">Z2i::Curve</a> c; </div>
<div class="ttc" id="anamespaceDGtal_1_1Z2i_html_a503faf4d34b6500e8f14035911fa04d5"><div class="ttname"><a href="namespaceDGtal_1_1Z2i.html#a503faf4d34b6500e8f14035911fa04d5">DGtal::Z2i::Curve</a></div><div class="ttdeci">GridCurve&lt; K2 &gt; Curve</div><div class="ttdef"><b>Definition:</b> <a href="StdDefs_8h_source.html#l00116">StdDefs.h:116</a></div></div>
</div><!-- fragment --> <dl class="section note"><dt>Note</dt><dd>The <a class="el" href="classDGtal_1_1GridCurve.html" title="Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...">GridCurve</a> object stands for an open or closed oriented grid curve, i.e. an alternating sequence of signed 0- and 1-cells.</dd></dl>
<h1><a class="anchor" id="secttutofileGridCurveRanges1"></a>
Reading a grid curve from a file</h1>
<p>You can load your grid curve from a text file that contains the coordinates of some points (each coordinate separated by a white space and one point per line).</p>
<div class="fragment"><div class="line">  std::string <a class="code" href="namespaceDGtal_1_1functions.html#ac8e2160844093488cdd738354027daa1">square</a> = examplesPath + <span class="stringliteral">&quot;samples/smallSquare.dat&quot;</span>;  </div>
<div class="ttc" id="anamespaceDGtal_1_1functions_html_ac8e2160844093488cdd738354027daa1"><div class="ttname"><a href="namespaceDGtal_1_1functions.html#ac8e2160844093488cdd738354027daa1">DGtal::functions::square</a></div><div class="ttdeci">T square(T x)</div><div class="ttdef"><b>Definition:</b> <a href="BasicMathFunctions_8h_source.html#l00133">BasicMathFunctions.h:133</a></div></div>
</div><!-- fragment --><p> For instance, the file smallSquare.dat used above contains: </p><div class="fragment"><div class="line">0 0</div>
<div class="line">0 1</div>
<div class="line">0 2</div>
<div class="line">0 3</div>
<div class="line">1 3</div>
<div class="line">...</div>
</div><!-- fragment --><p>Using the STL file stream, you can initialize your grid curve from the file data as follows:</p>
<div class="fragment"><div class="line">  std::fstream inputStream;</div>
<div class="line">  inputStream.open (<a class="code" href="namespaceDGtal_1_1functions.html#ac8e2160844093488cdd738354027daa1">square</a>.c_str(), std::ios::in);</div>
<div class="line">  c.initFromVectorStream(inputStream);</div>
<div class="line">  inputStream.close();  </div>
</div><!-- fragment --> <dl class="section note"><dt>Note</dt><dd>The coordinates of each point are assumed to be the digital coordinates of the 0-cells. These points are thus assumed to be 4-connected. The grid curve is assumed to be closed iff the first and last point are equal or 4-connected.</dd>
<dd>
A <a class="el" href="classDGtal_1_1IOException.html">DGtal::IOException</a> is raised in the case of IO errors and a <a class="el" href="classDGtal_1_1ConnectivityException.html">DGtal::ConnectivityException</a> is raised if the points are not 4-connected.</dd></dl>
<h1><a class="anchor" id="secttutofileGridCurveRanges2"></a>
Displaying a grid curve with Board2D</h1>
<p><a class="el" href="classDGtal_1_1Board2D.html" title="Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with &lt;&lt;)....">DGtal::Board2D</a> is a nice way of displaying many 2D objects. <br  />
 See <a class="el" href="moduleBoard2D.html">Board2D: a stream mechanism for displaying 2D digital objects</a> for further details.</p>
<div class="fragment"><div class="line">  <a class="code" href="classDGtal_1_1Board2D.html">DGtal::Board2D</a> aBoard;</div>
<div class="ttc" id="aclassDGtal_1_1Board2D_html"><div class="ttname"><a href="classDGtal_1_1Board2D.html">DGtal::Board2D</a></div><div class="ttdoc">Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with &lt;&lt;)....</div><div class="ttdef"><b>Definition:</b> <a href="Board2D_8h_source.html#l00070">Board2D.h:71</a></div></div>
</div><!-- fragment --><p> Using the stream mechanism of <a class="el" href="classDGtal_1_1Board2D.html" title="Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with &lt;&lt;)....">DGtal::Board2D</a>, you can write your grid curve in a vector-graphics file (here in postscript, but xfig, svg, pdf are other available formats).</p>
<div class="fragment"><div class="line">  aBoard &lt;&lt; c;  </div>
<div class="line">  aBoard.<a class="code" href="classLibBoard_1_1Board.html#ac39d5033a3a95e50f8ab7772e24c56bb">saveEPS</a>(<span class="stringliteral">&quot;DisplayGridCurveTuto.eps&quot;</span>);</div>
<div class="ttc" id="aclassLibBoard_1_1Board_html_ac39d5033a3a95e50f8ab7772e24c56bb"><div class="ttname"><a href="classLibBoard_1_1Board.html#ac39d5033a3a95e50f8ab7772e24c56bb">LibBoard::Board::saveEPS</a></div><div class="ttdeci">void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const</div><div class="ttdef"><b>Definition:</b> <a href="Board_8cpp_source.html#l00804">Board.cpp:804</a></div></div>
</div><!-- fragment --><p> Here is a png conversion of the resulting image:</p>
<div class="image">
<img src="DisplayGridCurveTuto.png" alt=""/>
<div class="caption">
A small closed grid curve</div></div>
 <h1><a class="anchor" id="secttutofileGridCurveRanges3"></a>
Ranges</h1>
<p>A same digital curve may be viewed in very different ways: <br  />
 either as an alternating sequence of cells, or as a sequence of points, or as a sequence of codes, and so one. <br  />
 Moreover, some processing algorithms require a specific type of elements: either 4-connected points, 8-connected points, grid edges, and so one. <br  />
 That is why the <a class="el" href="classDGtal_1_1GridCurve.html" title="Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...">GridCurve</a> object provides many ranges, i.e. <br  />
 objects that provides services to iterate over a sequence of elements. <br  />
</p>
<p>For instance, if you have to (or want to) work with 8-connected digital curves, you can get the grid curve inner points as follows: <br  />
</p>
<div class="fragment"><div class="line">  <a class="code" href="classDGtal_1_1GridCurve.html#a87afc16bfc83d8ac12bf20e8d864b038">Z2i::Curve::InnerPointsRange</a> r1 = c.getInnerPointsRange(); </div>
<div class="line">  aBoard &lt;&lt; r1; </div>
<div class="ttc" id="aclassDGtal_1_1GridCurve_html_a87afc16bfc83d8ac12bf20e8d864b038"><div class="ttname"><a href="classDGtal_1_1GridCurve.html#a87afc16bfc83d8ac12bf20e8d864b038">DGtal::GridCurve::InnerPointsRange</a></div><div class="ttdeci">ConstRangeAdapter&lt; typename Storage::const_iterator, functors::SCellToInnerPoint&lt; KSpace &gt;, Point &gt; InnerPointsRange</div><div class="ttdef"><b>Definition:</b> <a href="GridCurve_8h_source.html#l00457">GridCurve.h:457</a></div></div>
</div><!-- fragment --> <div class="image">
<img src="DisplayInnerPointsTuto.png" alt=""/>
<div class="caption">
Inner points</div></div>
 <p>If you have to (or want to) work with separating algorithms, you can get the grid curve incident points as follows:</p>
<div class="fragment"><div class="line">  <a class="code" href="classDGtal_1_1GridCurve.html#a9c658d0cc9f74f944149e985341f74ea">Z2i::Curve::IncidentPointsRange</a> r2 = c.getIncidentPointsRange(); </div>
<div class="line">  aBoard &lt;&lt; r2; </div>
<div class="ttc" id="aclassDGtal_1_1GridCurve_html_a9c658d0cc9f74f944149e985341f74ea"><div class="ttname"><a href="classDGtal_1_1GridCurve.html#a9c658d0cc9f74f944149e985341f74ea">DGtal::GridCurve::IncidentPointsRange</a></div><div class="ttdeci">ConstRangeAdapter&lt; typename Storage::const_iterator, functors::SCellToIncidentPoints&lt; KSpace &gt;, std::pair&lt; Point, Point &gt; &gt; IncidentPointsRange</div><div class="ttdef"><b>Definition:</b> <a href="GridCurve_8h_source.html#l00481">GridCurve.h:481</a></div></div>
</div><!-- fragment --> <div class="image">
<img src="DisplayIncidentPointsTuto.png" alt=""/>
<div class="caption">
Incident points</div></div>
 <p>See <a class="el" href="classDGtal_1_1GridCurve.html" title="Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...">GridCurve</a> for the exhaustive list of available ranges and their basic usage. See <a class="el" href="moduleGridCurveAnalysis.html">Analysis of one-dimensional discrete structures</a> for a general introduction about digital curves analysis.</p>
<h1><a class="anchor" id="secttutofileGridCurveRanges4"></a>
Required includes</h1>
<p>Here are the basic includes:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;DGtal/base/Common.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;DGtal/helpers/StdDefs.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;ConfigExamples.h&quot;</span></div>
</div><!-- fragment --> <dl class="section note"><dt>Note</dt><dd><a class="el" href="StdDefs_8h_source.html">StdDefs.h</a> contains the <a class="el" href="namespaceDGtal_1_1Z2i.html" title="Z2i this namespace gathers the standard of types for 2D imagery.">Z2i</a> namespace, which provides many type shortcuts. It includes the header required for the <a class="el" href="classDGtal_1_1GridCurve.html" title="Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...">GridCurve</a> object. ConfigExamples.h only provides the files sample path.</dd></dl>
<p>In order to use the drawing mechanism, you have to include:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;DGtal/io/boards/Board2D.h&quot;</span></div>
</div><!-- fragment --></div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="index.html">DGtal - Digital Geometry Tools and Algorithms Library.</a></li><li class="navelem"><a class="el" href="packageTutorials.html">Tutorials</a></li>
    <li class="footer">Generated on Mon Dec 23 2024 13:18:57 for DGtal by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>