DGtalTools  1.2.0
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 
51 using namespace DGtal;
52 
101 int main( int argc, char** argv )
102 {
103 
104 
105 // parse command line using CLI ----------------------------------------------
106  CLI::App app;
107  std::string inputFileName;
108  bool oneline {false};
109  bool info {false};
110 
111  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");
112  app.add_option("-i,--input,1", inputFileName, "Input freeman chain file name." )
113  ->required()
114  ->check(CLI::ExistingFile);
115  app.add_flag("-o,--oneLine", oneline, "output the digital contour in one line like: X0 Y0 X1 Y1 ... XN YN");
116  app.add_flag("--info", info, "adds some info as comments at the beginning of the file.");
117 
118 
119  app.get_formatter()->column_width(40);
120  CLI11_PARSE(app, argc, argv);
121  // END parse command line using CLI ----------------------------------------------
122 
123 
124  typedef FreemanChain<Z2i::Integer> FreemanChain;
125 
126  std::vector< FreemanChain > vectFcs = PointListReader< Z2i::Point >:: getFreemanChainsFromFile<Z2i::Integer> (inputFileName);
127 
128  for(unsigned int i=0; i< vectFcs.size(); i++){
129  bool isClosed = vectFcs.at(i).isClosed();
130  std::cout << "# grid curve " << i+1 << "/" << vectFcs.size()
131  << ( (isClosed)?" closed":" open" ) << std::endl;
132  if (info)
133  std::cout << "# SDP contour" << i+1<< "/" << vectFcs.size() << " "
134  << "# size=" << vectFcs.at(i).size() << std::endl;
135  std::vector<Z2i::Point> vectPts;
136  FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
137  for(unsigned int k=0; k < vectPts.size(); k++){
138  std::cout << vectPts.at(k)[0] << " "<< vectPts.at(k)[1] ;
139  if(!oneline)
140  {
141  std::cout << std::endl;
142  }
143  else
144  {
145  std::cout << " ";
146  }
147 
148  }
149  std::cout << std::endl;
150  }
151 
152 }
153 
Definition: ATu0v1.h:57