Fixed distance to diagonal calculation + added stand-alone bottleneck distance tool dev
authorDmitriy Morozov <dmitriy@mrzv.org>
Thu, 09 Apr 2009 12:58:10 -0700
branchdev
changeset 120 3c830b15d694
parent 119 505b3795d239
child 121 b2103b289f06
Fixed distance to diagonal calculation + added stand-alone bottleneck distance tool
include/topology/persistence-diagram.h
tools/CMakeLists.txt
tools/matching/CMakeLists.txt
tools/matching/bottleneck.cpp
--- a/include/topology/persistence-diagram.h	Wed Mar 25 09:56:52 2009 -0700
+++ b/include/topology/persistence-diagram.h	Thu Apr 09 12:58:10 2009 -0700
@@ -148,7 +148,7 @@
                                                                                                       std::abs(p1.y() - p2.y())); }
     
     template<class Point>
-    RealType            diagonal(const Point& p) const                              { return std::abs(p.y() - p.x()); }
+    RealType            diagonal(const Point& p) const                              { return std::abs(p.y() - p.x())/2; }
 };
 
 // Function: bottleneck_distance(dgm1, dgm2)
--- a/tools/CMakeLists.txt	Wed Mar 25 09:56:52 2009 -0700
+++ b/tools/CMakeLists.txt	Thu Apr 09 12:58:10 2009 -0700
@@ -9,3 +9,4 @@
 #include_directories         (${QGLViewer_INCLUDE_DIR})
 
 add_subdirectory            (diagram-viewer)
+add_subdirectory            (matching)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/matching/CMakeLists.txt	Thu Apr 09 12:58:10 2009 -0700
@@ -0,0 +1,6 @@
+set                             (libraries                      ${libraries} 
+                                                                ${Boost_PROGRAM_OPTIONS_LIBRARY})
+
+# Build compare-diagrams
+add_executable                  (bottleneck                     bottleneck.cpp)
+target_link_libraries           (bottleneck                     ${libraries})
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/matching/bottleneck.cpp	Thu Apr 09 12:58:10 2009 -0700
@@ -0,0 +1,65 @@
+#include <iostream>
+#include <fstream>
+
+#include <topology/persistence-diagram.h>
+
+#include <boost/program_options.hpp>
+namespace po = boost::program_options;
+
+typedef PersistenceDiagram<>                    PDgm;
+typedef PDgm::Point                             Point;
+
+
+void    read_diagram(const std::string& filename, PDgm& dgm);
+void    process_program_options(int argc, char* argv[], std::string& filename1, std::string& filename2);
+
+
+int main(int argc, char* argv[])
+{
+    std::string     filename1, filename2;
+    process_program_options(argc, argv, filename1, filename2);
+
+    PDgm dgm1, dgm2;
+    read_diagram(filename1, dgm1);
+    read_diagram(filename2, dgm2);
+
+    std::cout << "Distance: " << bottleneck_distance(dgm1, dgm2) << std::endl;
+}
+
+
+void    read_diagram(const std::string& filename, PDgm& dgm)
+{
+    std::ifstream in(filename.c_str());
+    double birth, death;
+    while(in)
+    {
+        in >> birth >> death;
+        if (in)
+            dgm.push_back(Point(birth, death));
+    }
+}
+
+void    process_program_options(int     argc, char* argv[], std::string& filename1, std::string& filename2)
+{
+    po::options_description hidden("Hidden options");
+    hidden.add_options()
+        ("input-file1",  po::value<std::string>(&filename1), "The first collection of persistence diagrams")
+        ("input-file2",  po::value<std::string>(&filename2), "The second collection of persistence diagrams");
+
+    po::positional_options_description p;
+    p.add("input-file1", 1);
+    p.add("input-file2", 2);
+    
+    po::options_description all; all.add(hidden);
+
+    po::variables_map vm;
+    po::store(po::command_line_parser(argc, argv).
+                  options(all).positional(p).run(), vm);
+    po::notify(vm);
+
+    if (!vm.count("input-file1") || !vm.count("input-file2"))
+    { 
+        std::cout << "Usage: " << argv[0] << " input-file1 input-file2" << std::endl;
+        std::abort();
+    }
+}