<NME> main.cpp
<BEF> // OpenVoronoi example. Build VD for a single glyph from true-type-tracer.
// true-type-tracer is from https://github.com/aewallin/truetype-tracer

#include <string>
#include <iostream>

#include <boost/foreach.hpp>
#include <boost/timer.hpp>

#include <openvoronoi/voronoidiagram.hpp>
#include <openvoronoi/checker.hpp>
#include <openvoronoi/checker.hpp>
#include <openvoronoi/version.hpp>
#include <openvoronoi/common/point.hpp>
#include <openvoronoi/utility/vd2svg.hpp>

#include <truetypetracer/ttt.hpp>

#define TTFONT "/usr/share/fonts/truetype/freefont/FreeSerif.ttf"

Loops get_ttt_loops() {
    SEG_Writer my_writer; // this Writer writes G-code
    my_writer.set_scale(  2.5095362377e-4 );
    Ttt t( &my_writer, "P", false , TTFONT ); // ( Writer*, text, unicode?, path-to-font )
    
    Loops all_loops = my_writer.get_loops();
    
    
    extents ext = my_writer.get_extents();
    std::cout << "ttt glyph: " << glyph << "\n";
    std::cout << "    x-range : " << ext.minx << " - " << ext.maxx << "\n";
    std::cout << "    y-range : " << ext.miny << " - " << ext.maxy << "\n";  
    std::cout << "    Loops   : " << all_loops.size() << "\n";
    Loops mod_loops;
    // ttt returns loops with duplicate start/endpoints
    // to avoid duplicates, remove the first point from each loop
    BOOST_FOREACH(Loop l, all_loops) {
        std::reverse(l.begin(), l.end());
        l.erase(l.begin()); // remove first element of loop
    return mod_loops;
}

// ttt example program
int main() {
    
    Loops all_loops = get_ttt_loops();
    
    // print out the points
    int nloop =0;
    desc.add_options()
        ("help", "produce help message")
        ("c", po::value<int>(), "set character, an int in [0,51] ")
        ("d", "run in debug mode")
    ;

    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, desc), vm);
    po::notify(vm);
    
    if (vm.count("help")) {
        std::cout << desc << "\n";
        return 1;
    }
    
    bool debug=false;
    if (vm.count("d")) {
        std::cout << "Debug mode!" << "\n";
        debug = true;
    }
    
    int char_index = 0;

    if (vm.count("c")) {
        int c = vm["c"].as<int>();
        if ( 0<=c && c<= 51 )
            char_index = c;
        else {
            std::cout << "--c option out of range!\n";
            return 1;
        }
    }
    Loops all_loops = get_ttt_loops(char_index);
        
    ovd::VoronoiDiagram* vd = new ovd::VoronoiDiagram(1,50);
    if (debug)
        vd->debug_on();

    std::cout << "OpenVoronoi version: " << ovd::version() << "\n";
    
    // store the verted IDs here, for later inserting line-segments
    std::cout << n_linesites << " LineSites:s inserted in  " << tmr.elapsed() << " seconds\n" << std::flush;
    
    // write vd to svg file
    std::string filename = "ttt_glypoh.svg";
    vd2svg(filename, vd);
    std::cout << "Output written to SVG file: " << filename << "\n"; //tmr.elapsed() << " seconds\n" << std::flush;
    
        BOOST_FOREACH( Point pt, loop) {
            loop_id.push_back( vd->insert_point_site( ovd::Point(pt.x,pt.y)) ); 
            std::cout << "    Inserted PointSite: id=" << loop_id.back() << "  (" << pt.x << ", "<< pt.y << ")" << "\n" << std::flush;
            n_points++;
        }
        loops_id.push_back(loop_id);
    }
    std::cout << n_points << " PointSites inserted in  " << tmr.elapsed() << " seconds\n" << std::flush;
    
    // now we insert LineSite:s
    tmr.restart();
    int n_linesites=0;
    BOOST_FOREACH( std::vector<int> loop_id, loops_id) {
        std::cout << " Inserting " << loop_id.size() << " LineSites \n" << std::flush;
        for( unsigned int n=0; n<loop_id.size();n++) {
            int next = n+1;
            if (n==loop_id.size()-1)
                next = 0;
            
            std::cout << "    Inserting LineSite: " << loop_id[n] << " - " << loop_id[next] << "\n" << std::flush;

            vd->insert_line_site( loop_id[n], loop_id[next]); 
            n_linesites++;
        }
    }
    std::cout << n_linesites << " LineSites:s inserted in  " << tmr.elapsed() << " seconds\n" << std::flush;
    
    // write vd to svg file
    std::string filename = "ttt_glyph.svg";
    vd2svg(filename, vd);
    std::cout << "Output written to SVG file: " << filename << "\n"; //tmr.elapsed() << " seconds\n" << std::flush;
    
    // sanity-check
    ovd::VoronoiDiagramChecker check(vd->get_graph_reference());
    if (!check.is_valid())
        return -1;
    else
        std::cout << "ovd::VoronoiDiagramChecker OK!\n";
    
    delete vd;
    return 0;
}

<MSG> use program-options to select glyph

<DFF> @@ -6,6 +6,7 @@
 
 #include <boost/foreach.hpp>
 #include <boost/timer.hpp>
+#include <boost/program_options.hpp>
 
 #include <openvoronoi/voronoidiagram.hpp>
 #include <openvoronoi/checker.hpp>
@@ -18,10 +19,16 @@
 
 #define TTFONT "/usr/share/fonts/truetype/freefont/FreeSerif.ttf"
 
-Loops get_ttt_loops() {
+Loops get_ttt_loops(int char_index=0) {
     SEG_Writer my_writer; // this Writer writes G-code
     my_writer.set_scale(  2.5095362377e-4 );
-    Ttt t( &my_writer, "P", false , TTFONT ); // ( Writer*, text, unicode?, path-to-font )
+    
+    std::string all_glyphs = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+    char c = all_glyphs.at(char_index);
+    std::string glyph(&c,1); //all_glyphs.at(char_index);
+    std::cout << " ttt glyph is " << glyph << "\n";
+    
+    Ttt t( &my_writer, glyph, false , TTFONT ); // ( Writer*, text, unicode?, path-to-font )
     
     Loops all_loops = my_writer.get_loops();
     
@@ -40,10 +47,38 @@ Loops get_ttt_loops() {
     return mod_loops;
 }
 
+namespace po = boost::program_options;
+
 // ttt example program
-int main() {
+int main(int argc,char *argv[]) {
+    // Declare the supported options.
+    po::options_description desc("This program calculates the voronoi diagram for a glyph from truetype-tracer.\nAllowed options");
+    desc.add_options()
+        ("help", "produce help message")
+        ("c", po::value<int>(), "set character, an int in [0,51] ")
+    ;
+
+    po::variables_map vm;
+    po::store(po::parse_command_line(argc, argv, desc), vm);
+    po::notify(vm);
     
-    Loops all_loops = get_ttt_loops();
+    if (vm.count("help")) {
+        std::cout << desc << "\n";
+        return 1;
+    }
+    
+    int char_index = 0;
+
+    if (vm.count("c")) {
+        int c = vm["c"].as<int>();
+        if ( 0<=c && c<= 51 )
+            char_index = c;
+        else {
+            std::cout << "--c option out of range!\n";
+            return 1;
+        }
+    }
+    Loops all_loops = get_ttt_loops(char_index);
     
     // print out the points
     int nloop =0;
@@ -91,7 +126,7 @@ int main() {
     std::cout << n_linesites << " LineSites:s inserted in  " << tmr.elapsed() << " seconds\n" << std::flush;
     
     // write vd to svg file
-    std::string filename = "ttt_glypoh.svg";
+    std::string filename = "ttt_glyph.svg";
     vd2svg(filename, vd);
     std::cout << "Output written to SVG file: " << filename << "\n"; //tmr.elapsed() << " seconds\n" << std::flush;
     

{'commit': 'diff --git a/cpp_examples/ttt_glyph/main.cpp b/cpp_examples/ttt_glyph/main.cpp\nindex 48a3311..b09b324 100644\n--- a/cpp_examples/ttt_glyph/main.cpp\n+++ b/cpp_examples/ttt_glyph/main.cpp\n@@ -6,6 +6,7 @@\n \n #include <boost/foreach.hpp>\n #include <boost/timer.hpp>\n+#include <boost/program_options.hpp>\n \n #include <openvoronoi/voronoidiagram.hpp>\n #include <openvoronoi/checker.hpp>\n@@ -18,10 +19,16 @@\n \n #define TTFONT "/usr/share/fonts/truetype/freefont/FreeSerif.ttf"\n \n-Loops get_ttt_loops() {\n+Loops get_ttt_loops(int char_index=0) {\n     SEG_Writer my_writer; // this Writer writes G-code\n     my_writer.set_scale(  2.5095362377e-4 );\n-    Ttt t( &my_writer, "P", false , TTFONT ); // ( Writer*, text, unicode?, path-to-font )\n+    \n+    std::string all_glyphs = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";\n+    char c = all_glyphs.at(char_index);\n+    std::string glyph(&c,1); //all_glyphs.at(char_index);\n+    std::cout << " ttt glyph is " << glyph << "\\n";\n+    \n+    Ttt t( &my_writer, glyph, false , TTFONT ); // ( Writer*, text, unicode?, path-to-font )\n     \n     Loops all_loops = my_writer.get_loops();\n     \n@@ -40,10 +47,38 @@ Loops get_ttt_loops() {\n     return mod_loops;\n }\n \n+namespace po = boost::program_options;\n+\n // ttt example program\n-int main() {\n+int main(int argc,char *argv[]) {\n+    // Declare the supported options.\n+    po::options_description desc("This program calculates the voronoi diagram for a glyph from truetype-tracer.\\nAllowed options");\n+    desc.add_options()\n+        ("help", "produce help message")\n+        ("c", po::value<int>(), "set character, an int in [0,51] ")\n+    ;\n+\n+    po::variables_map vm;\n+    po::store(po::parse_command_line(argc, argv, desc), vm);\n+    po::notify(vm);\n     \n-    Loops all_loops = get_ttt_loops();\n+    if (vm.count("help")) {\n+        std::cout << desc << "\\n";\n+        return 1;\n+    }\n+    \n+    int char_index = 0;\n+\n+    if (vm.count("c")) {\n+        int c = vm["c"].as<int>();\n+        if ( 0<=c && c<= 51 )\n+            char_index = c;\n+        else {\n+            std::cout << "--c option out of range!\\n";\n+            return 1;\n+        }\n+    }\n+    Loops all_loops = get_ttt_loops(char_index);\n     \n     // print out the points\n     int nloop =0;\n@@ -91,7 +126,7 @@ int main() {\n     std::cout << n_linesites << " LineSites:s inserted in  " << tmr.elapsed() << " seconds\\n" << std::flush;\n     \n     // write vd to svg file\n-    std::string filename = "ttt_glypoh.svg";\n+    std::string filename = "ttt_glyph.svg";\n     vd2svg(filename, vd);\n     std::cout << "Output written to SVG file: " << filename << "\\n"; //tmr.elapsed() << " seconds\\n" << std::flush;\n     \n', 'commit_subject': 'use program-options to select glyph', 'repo_name': 'aewallin/openvoronoi', 'committer': {'name': 'Anders Wallin', 'email': '46e6e0f6418f24468c511f428fbf311ae6ff961b@gmail.com', 'time_sec': '1332173209', 'tz_offset': '120', 'date': {'seconds': '1332173209'}}, 'commit_tree': 'c39378ea7d2c7cb029d0ae48744ae2fa5005a4c5', 'commit_message': 'use program-options to select glyph\n', 'language_name': 'C++', 'license': 'lgpl-2.1', 'hunks': '@@ -6,6 +6,7 @@\n \n #include <boost/foreach.hpp>\n #include <boost/timer.hpp>\n+#include <boost/program_options.hpp>\n \n #include <openvoronoi/voronoidiagram.hpp>\n #include <openvoronoi/checker.hpp>\n@@ -18,10 +19,16 @@\n \n #define TTFONT "/usr/share/fonts/truetype/freefont/FreeSerif.ttf"\n \n-Loops get_ttt_loops() {\n+Loops get_ttt_loops(int char_index=0) {\n     SEG_Writer my_writer; // this Writer writes G-code\n     my_writer.set_scale(  2.5095362377e-4 );\n-    Ttt t( &my_writer, "P", false , TTFONT ); // ( Writer*, text, unicode?, path-to-font )\n+    \n+    std::string all_glyphs = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";\n+    char c = all_glyphs.at(char_index);\n+    std::string glyph(&c,1); //all_glyphs.at(char_index);\n+    std::cout << " ttt glyph is " << glyph << "\\n";\n+    \n+    Ttt t( &my_writer, glyph, false , TTFONT ); // ( Writer*, text, unicode?, path-to-font )\n     \n     Loops all_loops = my_writer.get_loops();\n     \n@@ -40,10 +47,38 @@ Loops get_ttt_loops() {\n     return mod_loops;\n }\n \n+namespace po = boost::program_options;\n+\n // ttt example program\n-int main() {\n+int main(int argc,char *argv[]) {\n+    // Declare the supported options.\n+    po::options_description desc("This program calculates the voronoi diagram for a glyph from truetype-tracer.\\nAllowed options");\n+    desc.add_options()\n+        ("help", "produce help message")\n+        ("c", po::value<int>(), "set character, an int in [0,51] ")\n+    ;\n+\n+    po::variables_map vm;\n+    po::store(po::parse_command_line(argc, argv, desc), vm);\n+    po::notify(vm);\n     \n-    Loops all_loops = get_ttt_loops();\n+    if (vm.count("help")) {\n+        std::cout << desc << "\\n";\n+        return 1;\n+    }\n+    \n+    int char_index = 0;\n+\n+    if (vm.count("c")) {\n+        int c = vm["c"].as<int>();\n+        if ( 0<=c && c<= 51 )\n+            char_index = c;\n+        else {\n+            std::cout << "--c option out of range!\\n";\n+            return 1;\n+        }\n+    }\n+    Loops all_loops = get_ttt_loops(char_index);\n     \n     // print out the points\n     int nloop =0;\n@@ -91,7 +126,7 @@ int main() {\n     std::cout << n_linesites << " LineSites:s inserted in  " << tmr.elapsed() << " seconds\\n" << std::flush;\n     \n     // write vd to svg file\n-    std::string filename = "ttt_glypoh.svg";\n+    std::string filename = "ttt_glyph.svg";\n     vd2svg(filename, vd);\n     std::cout << "Output written to SVG file: " << filename << "\\n"; //tmr.elapsed() << " seconds\\n" << std::flush;\n     \n', 'addition_count': 40, 'deletion_count': 5, 'src_file': 'a/cpp_examples/ttt_glyph/main.cpp', 'tgt_file': 'b/cpp_examples/ttt_glyph/main.cpp', 'file_extension': '.cpp', 'before_file': '// OpenVoronoi example. Build VD for a single glyph from true-type-tracer.\n// true-type-tracer is from https://github.com/aewallin/truetype-tracer\n\n#include <string>\n#include <iostream>\n\n#include <boost/foreach.hpp>\n#include <boost/timer.hpp>\n\n#include <openvoronoi/voronoidiagram.hpp>\n#include <openvoronoi/checker.hpp>\n#include <openvoronoi/checker.hpp>\n#include <openvoronoi/version.hpp>\n#include <openvoronoi/common/point.hpp>\n#include <openvoronoi/utility/vd2svg.hpp>\n\n#include <truetypetracer/ttt.hpp>\n\n#define TTFONT "/usr/share/fonts/truetype/freefont/FreeSerif.ttf"\n\nLoops get_ttt_loops() {\n    SEG_Writer my_writer; // this Writer writes G-code\n    my_writer.set_scale(  2.5095362377e-4 );\n    Ttt t( &my_writer, "P", false , TTFONT ); // ( Writer*, text, unicode?, path-to-font )\n    \n    Loops all_loops = my_writer.get_loops();\n    \n    \n    extents ext = my_writer.get_extents();\n    std::cout << "ttt glyph: " << glyph << "\\n";\n    std::cout << "    x-range : " << ext.minx << " - " << ext.maxx << "\\n";\n    std::cout << "    y-range : " << ext.miny << " - " << ext.maxy << "\\n";  \n    std::cout << "    Loops   : " << all_loops.size() << "\\n";\n    Loops mod_loops;\n    // ttt returns loops with duplicate start/endpoints\n    // to avoid duplicates, remove the first point from each loop\n    BOOST_FOREACH(Loop l, all_loops) {\n        std::reverse(l.begin(), l.end());\n        l.erase(l.begin()); // remove first element of loop\n    return mod_loops;\n}\n\n// ttt example program\nint main() {\n    \n    Loops all_loops = get_ttt_loops();\n    \n    // print out the points\n    int nloop =0;\n    desc.add_options()\n        ("help", "produce help message")\n        ("c", po::value<int>(), "set character, an int in [0,51] ")\n        ("d", "run in debug mode")\n    ;\n\n    po::variables_map vm;\n    po::store(po::parse_command_line(argc, argv, desc), vm);\n    po::notify(vm);\n    \n    if (vm.count("help")) {\n        std::cout << desc << "\\n";\n        return 1;\n    }\n    \n    bool debug=false;\n    if (vm.count("d")) {\n        std::cout << "Debug mode!" << "\\n";\n        debug = true;\n    }\n    \n    int char_index = 0;\n\n    if (vm.count("c")) {\n        int c = vm["c"].as<int>();\n        if ( 0<=c && c<= 51 )\n            char_index = c;\n        else {\n            std::cout << "--c option out of range!\\n";\n            return 1;\n        }\n    }\n    Loops all_loops = get_ttt_loops(char_index);\n        \n    ovd::VoronoiDiagram* vd = new ovd::VoronoiDiagram(1,50);\n    if (debug)\n        vd->debug_on();\n\n    std::cout << "OpenVoronoi version: " << ovd::version() << "\\n";\n    \n    // store the verted IDs here, for later inserting line-segments\n    std::cout << n_linesites << " LineSites:s inserted in  " << tmr.elapsed() << " seconds\\n" << std::flush;\n    \n    // write vd to svg file\n    std::string filename = "ttt_glypoh.svg";\n    vd2svg(filename, vd);\n    std::cout << "Output written to SVG file: " << filename << "\\n"; //tmr.elapsed() << " seconds\\n" << std::flush;\n    \n        BOOST_FOREACH( Point pt, loop) {\n            loop_id.push_back( vd->insert_point_site( ovd::Point(pt.x,pt.y)) ); \n            std::cout << "    Inserted PointSite: id=" << loop_id.back() << "  (" << pt.x << ", "<< pt.y << ")" << "\\n" << std::flush;\n            n_points++;\n        }\n        loops_id.push_back(loop_id);\n    }\n    std::cout << n_points << " PointSites inserted in  " << tmr.elapsed() << " seconds\\n" << std::flush;\n    \n    // now we insert LineSite:s\n    tmr.restart();\n    int n_linesites=0;\n    BOOST_FOREACH( std::vector<int> loop_id, loops_id) {\n        std::cout << " Inserting " << loop_id.size() << " LineSites \\n" << std::flush;\n        for( unsigned int n=0; n<loop_id.size();n++) {\n            int next = n+1;\n            if (n==loop_id.size()-1)\n                next = 0;\n            \n            std::cout << "    Inserting LineSite: " << loop_id[n] << " - " << loop_id[next] << "\\n" << std::flush;\n\n            vd->insert_line_site( loop_id[n], loop_id[next]); \n            n_linesites++;\n        }\n    }\n    std::cout << n_linesites << " LineSites:s inserted in  " << tmr.elapsed() << " seconds\\n" << std::flush;\n    \n    // write vd to svg file\n    std::string filename = "ttt_glyph.svg";\n    vd2svg(filename, vd);\n    std::cout << "Output written to SVG file: " << filename << "\\n"; //tmr.elapsed() << " seconds\\n" << std::flush;\n    \n    // sanity-check\n    ovd::VoronoiDiagramChecker check(vd->get_graph_reference());\n    if (!check.is_valid())\n        return -1;\n    else\n        std::cout << "ovd::VoronoiDiagramChecker OK!\\n";\n    \n    delete vd;\n    return 0;\n}\n', 'message': 'use program-options to select glyph\n', 'author_name': 'Anders Wallin', 'lang': 'cpp'}