DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ArithmeticalDSS.cpp
1 
32 
33 #include <iostream>
34 #include "DGtal/base/Common.h"
36 
37 #include "DGtal/geometry/curves/ArithmeticalDSS.h"
38 #include "DGtal/geometry/curves/FreemanChain.h"
39 #include "DGtal/base/BasicTypes.h"
40 #include "DGtal/io/boards/Board2D.h"
41 #include "DGtal/helpers/StdDefs.h"
42 
43 using namespace std;
44 using namespace DGtal;
45 using namespace Z2i;
46 
48 
49 int main()
50 {
51 
52 
54  {
56  typedef PointVector<2,int> Point;
57  typedef std::vector<Point> Range;
58  typedef std::vector<Point>::const_iterator ConstIterator;
60 
61  // Input points
62  Range contour;
63  contour.push_back(Point(0,0));
64  contour.push_back(Point(1,0));
65  contour.push_back(Point(1,1));
66  contour.push_back(Point(2,1));
67  contour.push_back(Point(3,1));
68  contour.push_back(Point(3,2));
69  contour.push_back(Point(4,2));
70  contour.push_back(Point(5,2));
71  contour.push_back(Point(6,2));
72  contour.push_back(Point(6,3));
73  contour.push_back(Point(6,4));
74 
75 
76  // Add points while it is possible
77  DSS4 theDSS4;
78  theDSS4.init( contour.begin() );
79  while ( ( theDSS4.end() != contour.end() )
80  &&( theDSS4.extendForward() ) ) {}
81 
82  // Output parameters
83  cout << theDSS4 << endl;
85 
87  // Draw the grid
88  Board2D board;
89 
90  Domain domain( Point(0,0), Point(8,8) );
91  board << SetMode(domain.className(), "Grid")
92  << domain;
93 
94  // Draw the points of the DSS
95  board << SetMode("PointVector", "Grid")
96  << SetMode(theDSS4.className(), "Points")
97  << theDSS4;
98  // Draw the bounding box
99  board << SetMode(theDSS4.className(), "BoundingBox")
100  << theDSS4;
101 
102  board.saveSVG("DSS4.svg");
104  }
105 
107  {
109  typedef PointVector<2,int> Point;
110  typedef std::vector<Point> Range;
111  typedef std::vector<Point>::const_iterator ConstIterator;
113 
114  // Input points
115  Range boundary;
116  boundary.push_back(Point(0,0));
117  boundary.push_back(Point(1,1));
118  boundary.push_back(Point(2,1));
119  boundary.push_back(Point(3,2));
120  boundary.push_back(Point(4,2));
121  boundary.push_back(Point(5,2));
122  boundary.push_back(Point(6,3));
123  boundary.push_back(Point(6,4));
124 
125  // Add points while it is possible
126  DSS8 theDSS8;
127  theDSS8.init( boundary.begin() );
128  while ( ( theDSS8.end() != boundary.end() )
129  &&( theDSS8.extendForward() ) ) {}
130 
131 
132  // Output parameters
133  cout << theDSS8 << endl;
135 
137  //Draw the pixels
138  Board2D board;
139  Domain domain( Point(0,0), Point(8,8) );
140  board << SetMode(domain.className(), "Paving")
141  << domain;
142 
143  //Draw the points of the DSS
144  board << SetMode("PointVector", "Both");
145  board << SetMode(theDSS8.className(), "Points")
146  << theDSS8;
147 
148  //Draw the bounding box of the DSS
149  board << SetMode(theDSS8.className(), "BoundingBox")
150  << theDSS8;
151 
152  board.saveSVG("DSS8.svg");
154  }
155 
156  return 1;
157 }
158 // //