Added standalone bottleneck-distance.cpp dev
authorDmitriy Morozov <dmitriy@mrzv.org>
Fri Apr 26 22:31:58 2013 -0700 (2013-04-26)
branchdev
changeset 273815d6a978c6c
parent 272 29306411272b
child 274 73d69c01ed6c
Added standalone bottleneck-distance.cpp
examples/CMakeLists.txt
examples/bottleneck-distance.cpp
     1.1 --- a/examples/CMakeLists.txt	Thu Feb 28 11:12:02 2013 +0800
     1.2 +++ b/examples/CMakeLists.txt	Fri Apr 26 22:31:58 2013 -0700
     1.3 @@ -1,3 +1,6 @@
     1.4 +add_executable                  (bottleneck-distance bottleneck-distance.cpp)
     1.5 +target_link_libraries           (bottleneck-distance ${libraries} ${Boost_PROGRAM_OPTIONS_LIBRARY})
     1.6 +
     1.7  add_subdirectory			(alphashapes)
     1.8  #add_subdirectory			(ar-vineyard)
     1.9  add_subdirectory			(cech-complex)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/examples/bottleneck-distance.cpp	Fri Apr 26 22:31:58 2013 -0700
     2.3 @@ -0,0 +1,67 @@
     2.4 +#include <utilities/types.h>
     2.5 +#include <topology/persistence-diagram.h>
     2.6 +
     2.7 +#include <string>
     2.8 +#include <iostream>
     2.9 +#include <fstream>
    2.10 +#include <sstream>
    2.11 +#include <boost/archive/binary_iarchive.hpp>
    2.12 +#include <boost/serialization/map.hpp>
    2.13 +
    2.14 +#include <boost/program_options.hpp>
    2.15 +
    2.16 +
    2.17 +typedef PersistenceDiagram<>                    PDgm;
    2.18 +
    2.19 +namespace po = boost::program_options;
    2.20 +
    2.21 +
    2.22 +void read_diagram(PDgm& dgm, const std::string& filename)
    2.23 +{
    2.24 +    std::ifstream in(filename.c_str());
    2.25 +    std::string line;
    2.26 +    std::getline(in, line);
    2.27 +    while (in)
    2.28 +    {
    2.29 +        std::istringstream sin(line);
    2.30 +        double x,y;
    2.31 +        sin >> x >> y;
    2.32 +        dgm.push_back(PDgm::Point(x,y));
    2.33 +        std::getline(in, line);
    2.34 +    }
    2.35 +}
    2.36 +
    2.37 +int main(int argc, char* argv[])
    2.38 +{
    2.39 +    std::string     filename1, filename2;
    2.40 +
    2.41 +    po::options_description hidden("Hidden options");
    2.42 +    hidden.add_options()
    2.43 +        ("input-file1",  po::value<std::string>(&filename1), "The first collection of persistence diagrams")
    2.44 +        ("input-file2",  po::value<std::string>(&filename2), "The second collection of persistence diagrams");
    2.45 +
    2.46 +    po::positional_options_description p;
    2.47 +    p.add("input-file1", 1);
    2.48 +    p.add("input-file2", 2);
    2.49 +
    2.50 +    po::options_description all; all.add(hidden);
    2.51 +
    2.52 +    po::variables_map vm;
    2.53 +    po::store(po::command_line_parser(argc, argv).
    2.54 +                  options(all).positional(p).run(), vm);
    2.55 +    po::notify(vm);
    2.56 +
    2.57 +    if (!vm.count("input-file1") || !vm.count("input-file2"))
    2.58 +    {
    2.59 +        std::cout << "Usage: " << argv[0] << " input-file1 input-file2" << std::endl;
    2.60 +        return 1;
    2.61 +    }
    2.62 +
    2.63 +    PDgm dgm1, dgm2;
    2.64 +    read_diagram(dgm1, filename1);
    2.65 +    read_diagram(dgm2, filename2);
    2.66 +    std::cout << "Size dgm1: " << dgm1.size() << std::endl;
    2.67 +    std::cout << "Size dgm2: " << dgm2.size() << std::endl;
    2.68 +
    2.69 +    std::cout << "Distance: " << bottleneck_distance(dgm1, dgm2) << std::endl;
    2.70 +}