DGtal  1.5.beta
examplePreimage.cpp File Reference

An example file for Preimage2D. More...

#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/geometry/tools/Preimage2D.h"
#include "DGtal/shapes/fromPoints/StraightLineFrom2Points.h"
#include "DGtal/shapes/fromPoints/CircleFrom2Points.h"
#include "DGtal/io/boards/Board2D.h"
Include dependency graph for examplePreimage.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

An example file for Preimage2D.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2011/09/21

This file is part of the DGtal library.

Definition in file examplePreimage.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

[PreimageTypedefFromStraightLine]

[PreimageTypedefFromStraightLine]

[PreimageUsageFromIncidentPointsRange]

[PreimageUsageFromIncidentPointsRange]

[PreimageTypedefFromCircle]

[PreimageTypedefFromCircle]

Definition at line 59 of file examplePreimage.cpp.

60 {
61  trace.beginBlock ( "Example for Preimage computation" );
62  trace.info() << "Args:";
63  for ( int i = 0; i < argc; ++i )
64  trace.info() << " " << argv[ i ];
65  trace.info() << endl;
66 
67  std::string filename = examplesPath + "samples/DSS.dat";
68  ifstream instream; // input stream
69  instream.open (filename.c_str(), ifstream::in);
70 
71  Curve c; //grid curve
72  c.initFromVectorStream(instream);
73 
74 {
75  trace.beginBlock("Simple preimage example");
76 
78  typedef StraightLineFrom2Points<Curve::Point> StraightLine;
79  StraightLine aStraightLine; //instance of straight line
82 
83 
85  Curve::IncidentPointsRange r = c.getIncidentPointsRange(); //range
86  Curve::IncidentPointsRange::ConstIterator it (r.begin()); //iterators
88 
89  //preimage computation
90  Preimage2D thePreimage(it->first, it->second, aStraightLine);
91  ++it;
92  while ( (it != itEnd) &&
93  (thePreimage.addFront(it->first, it->second)) )
94  {
95  ++it;
96  }
97  trace.info() << thePreimage << endl;
98  //display
99  Board2D board;
100  board.setUnit(Board2D::UCentimeter);
101  board << r << thePreimage;
102  board.saveEPS( "PreimageExample.eps" );
104 
105  trace.endBlock();
106 }
107 
108 {
109  trace.beginBlock("Preimage example with circles");
110  Curve::Point pole(7,2);
111 
113  typedef CircleFrom2Points<Curve::Point> Circle;
114  Circle aCircle( pole ); //instance of circle passing through point 'pole'
117 
118  Curve::IncidentPointsRange r = c.getIncidentPointsRange(); //range
119  Curve::IncidentPointsRange::ConstIterator it (r.begin()); //iterators
121 
122  //preimage computation
123  Preimage2D thePreimage(it->first, it->second, aCircle);
124  ++it;
125  while ( (it != itEnd) &&
126  (thePreimage.addFront(it->first, it->second)) )
127  {
128  ++it;
129  }
130  trace.info() << thePreimage << endl;
131  //display
132  Board2D board;
133  board.setUnit(Board2D::UCentimeter);
134  board << r << SetMode(pole.className(),"Grid") << pole << thePreimage;
135  board.saveEPS( "PreimageExample2.eps" );
136  board.saveSVG( "PreimageExample2.svg" );
137 #ifdef WITH_CAIRO
138  board.saveCairo("PreimageExample2.pdf", Board2D::CairoPDF);
139 #endif
140 
141  trace.endBlock();
142 }
143 
144  return 0;
145 }
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: Represents a circle that passes through a given point and that is thus uniquely defined by two o...
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:173
bool initFromVectorStream(std::istream &in)
Storage::const_iterator ConstIterator
Definition: GridCurve.h:314
Aim: Computes the preimage of the 2D Euclidean shapes crossing a sequence of n straigth segments in O...
Definition: Preimage2D.h:94
Aim: Represents a straight line uniquely defined by two 2D points and that is able to return for any ...
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:804
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1011
void setUnit(Unit unit)
Definition: Board.cpp:239
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1138
Trace trace
Definition: Common.h:153
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247

References DGtal::Preimage2D< Shape >::addFront(), DGtal::Trace::beginBlock(), DGtal::PointVector< dim, TEuclideanRing, TContainer >::className(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::GridCurve< TKSpace >::initFromVectorStream(), LibBoard::Board::saveCairo(), LibBoard::Board::saveEPS(), LibBoard::Board::saveSVG(), LibBoard::Board::setUnit(), and DGtal::trace.