DGtalTools  0.9.4
freeman2sdp.cpp
1 
29 #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 //boost
44 #include <boost/program_options/options_description.hpp>
45 #include <boost/program_options/parsers.hpp>
46 #include <boost/program_options/variables_map.hpp>
47 
48 //STL
49 #include <vector>
50 #include <string>
51 
52 using namespace DGtal;
53 
99 namespace po = boost::program_options;
101 
102 int main( int argc, char** argv )
103 {
104  // parse command line ----------------------------------------------
105  po::options_description general_opt("Allowed options are: ");
106  general_opt.add_options()
107  ("help,h", "display this message")
108  ("input,i", po::value<std::string>(), "Input freeman chain file name.")
109  ("info", "adds some info as comments at the beginning of the file.")
110  ("oneLine,o", " output the digital contour in one line like: X0 Y0 X1 Y1 ... XN YN");
111 
112 
113 
115 
116 
117  bool parseOK=true;
118  po::variables_map vm;
119  try{
120  po::store(po::parse_command_line(argc, argv, general_opt), vm);
121  }catch(const std::exception& ex){
122  parseOK=false;
123  trace.info()<< "Error checking program options: "<< ex.what()<< std::endl;
124  }
125 
126  po::notify(vm);
127  if(!parseOK||vm.count("help")||argc<=1 || (!(vm.count("input")) ) )
128  {
129  trace.info()<< "Transform freeman chain into a Sequence of Discrete Points. Result is given to std output. " <<std::endl << "Basic usage: "<<std::endl
130  << "\t freeman2sdp [input] > out.sdp "<<std::endl
131  << general_opt << "\n";
132  trace.info() << "Example:\n"
133  << "freeman2sdp -i ${DGtal}/tests/samples/contourS.fc > contourS.sdp \n";
134 
135  return 0;
136  }
137 
138  bool oneline = vm.count("oneLine");
139  if( vm.count("input") ){
140  std::string fileName = vm["input"].as<std::string>();
141  std::vector< FreemanChain > vectFcs = PointListReader< Z2i::Point >:: getFreemanChainsFromFile<Z2i::Integer> (fileName);
142 
143  for(unsigned int i=0; i< vectFcs.size(); i++){
144  bool isClosed = vectFcs.at(i).isClosed();
145  std::cout << "# grid curve " << i+1 << "/" << vectFcs.size()
146  << ( (isClosed)?" closed":" open" ) << std::endl;
147  if ( vm.count("info"))
148  std::cout << "# SDP contour" << i+1<< "/" << vectFcs.size() << " "
149  << "# size=" << vectFcs.at(i).size() << std::endl;
150  std::vector<Z2i::Point> vectPts;
151  FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
152  for(unsigned int k=0; k < vectPts.size(); k++){
153  std::cout << vectPts.at(k)[0] << " "<< vectPts.at(k)[1] ;
154  if(!oneline){
155  std::cout << std::endl;
156  }else
157  {
158  std::cout << " ";
159  }
160 
161  }
162  std::cout << std::endl;
163  }
164 
165  }
166 
167 
168 }
169 
Trace trace(traceWriterTerm)
std::ostream & info()
static void getContourPoints(const FreemanChain &fc, std::vector< Point > &aVContour)