32 #include "DGtal/base/Common.h" 33 #include "DGtal/helpers/StdDefs.h" 36 #include "DGtal/io/readers/PointListReader.h" 40 #include "DGtal/geometry/curves/FreemanChain.h" 44 #include <boost/program_options/options_description.hpp> 45 #include <boost/program_options/parsers.hpp> 46 #include <boost/program_options/variables_map.hpp> 52 using namespace DGtal;
103 namespace po = boost::program_options;
106 int main(
int argc,
char** argv )
109 po::options_description general_opt(
"Allowed options are: ");
110 general_opt.add_options()
111 (
"help,h",
"display this message")
112 (
"input,i", po::value<std::string>(),
"Input freeman chain file name.")
113 (
"info",
"adds some info as comments at the beginning of the file.")
114 (
"oneLine,o",
" output the digital contour in one line like: X0 Y0 X1 Y1 ... XN YN");
118 typedef FreemanChain<Z2i::Integer> FreemanChain;
122 po::variables_map vm;
124 po::store(po::parse_command_line(argc, argv, general_opt), vm);
125 }
catch(
const std::exception& ex){
127 trace.info()<<
"Error checking program options: "<< ex.what()<< std::endl;
131 if(!parseOK||vm.count(
"help")||argc<=1 || (!(vm.count(
"input")) ) )
133 trace.info()<<
"Transform freeman chain into a Sequence of Discrete Points. Result is given to std output " <<std::endl <<
"Basic usage: "<<std::endl
134 <<
"\t freeman2sdp [input] > out.sdp "<<std::endl
135 << general_opt <<
"\n";
136 trace.info() <<
"Example:\n" 137 <<
"freeman2sdp -i ${DGtal}/tests/samples/contourS.fc > contourS.sdp \n";
142 bool oneline = vm.count(
"oneLine");
143 if( vm.count(
"input") ){
144 std::string fileName = vm[
"input"].as<std::string>();
145 std::vector< FreemanChain > vectFcs = PointListReader< Z2i::Point >:: getFreemanChainsFromFile<Z2i::Integer> (fileName);
147 for(
unsigned int i=0; i< vectFcs.size(); i++){
148 bool isClosed = vectFcs.at(i).isClosed();
149 std::cout <<
"# grid curve " << i+1 <<
"/" << vectFcs.size()
150 << ( (isClosed)?
" closed":
" open" ) << std::endl;
151 if ( vm.count(
"info"))
152 std::cout <<
"# SDP contour" << i+1<<
"/" << vectFcs.size() <<
" " 153 <<
"# size=" << vectFcs.at(i).size() << std::endl;
154 std::vector<Z2i::Point> vectPts;
155 FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
156 for(
unsigned int k=0; k < vectPts.size(); k++){
157 std::cout << vectPts.at(k)[0] <<
" "<< vectPts.at(k)[1];
159 std::cout << std::endl;
162 std::cout << std::endl;