DGtalTools 2.0.0
Loading...
Searching...
No Matches
freeman2sdp.cpp
1
30#include <iostream>
31
32#include "DGtal/base/Common.h"
33#include "DGtal/helpers/StdDefs.h"
34
35//image
36#include "DGtal/io/readers/PointListReader.h"
37
38
39//contour
40#include "DGtal/geometry/curves/FreemanChain.h"
41
42
43//STL
44#include <vector>
45#include <string>
46
47
48#include "CLI11.hpp"
49
50
51using namespace DGtal;
52
102int main( int argc, char** argv )
103{
104
105
106// parse command line using CLI ----------------------------------------------
107 CLI::App app;
108 std::string inputFileName;
109 bool oneline {false};
110 bool info {false};
111
112 app.description("Transform freeman chain into a Sequence of Discrete Points. Result is given to std output.\n Example:\n freeman2sdp ${DGtal}/tests/samples/contourS.fc > contourS.sdp \n");
113 app.add_option("-i,--input,1", inputFileName, "Input freeman chain file name." )
114 ->required()
115 ->check(CLI::ExistingFile);
116 app.add_flag("-o,--oneLine", oneline, "output the digital contour in one line like: X0 Y0 X1 Y1 ... XN YN");
117 app.add_flag("--info", info, "adds some info as comments at the beginning of the file.");
118
119
120 app.get_formatter()->column_width(40);
121 CLI11_PARSE(app, argc, argv);
122 // END parse command line using CLI ----------------------------------------------
123
124
125 typedef FreemanChain<Z2i::Integer> FreemanChain;
126
127 std::vector< FreemanChain > vectFcs = PointListReader< Z2i::Point >:: getFreemanChainsFromFile<Z2i::Integer> (inputFileName);
128
129 for(unsigned int i=0; i< vectFcs.size(); i++){
130 bool isClosed = vectFcs.at(i).isClosed();
131 std::cout << "# grid curve " << i+1 << "/" << vectFcs.size()
132 << ( (isClosed)?" closed":" open" ) << std::endl;
133 if (info)
134 std::cout << "# SDP contour" << i+1<< "/" << vectFcs.size() << " "
135 << "# size=" << vectFcs.at(i).size() << std::endl;
136 std::vector<Z2i::Point> vectPts;
137 FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
138 for(unsigned int k=0; k < vectPts.size(); k++){
139 std::cout << vectPts.at(k)[0] << " "<< vectPts.at(k)[1] ;
140 if(!oneline)
141 {
142 std::cout << std::endl;
143 }
144 else
145 {
146 std::cout << " ";
147 }
148
149 }
150 std::cout << std::endl;
151 }
152
153}
154
Definition ATu0v1.h:57