program_options + trajectory knees ar
authorDmitriy Morozov <morozov@cs.duke.edu>
Wed, 27 Feb 2008 16:32:12 -0500
branchar
changeset 77 8e55bf20802a
parent 76 66622c6bf8cf
child 78 20e1dff50d03
program_options + trajectory knees - added boost::program_options - recording knees when trajectories change
.issues/d2ab07329c3588ca
examples/ar-vineyard/CMakeLists.txt
examples/ar-vineyard/ar-vineyard.cpp
examples/ar-vineyard/ar-vineyard.h
examples/ar-vineyard/ar-vineyard.hpp
include/topology/vineyard.h
include/topology/vineyard.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.issues/d2ab07329c3588ca	Wed Feb 27 16:32:12 2008 -0500
@@ -0,0 +1,9 @@
+From artemis Wed Feb 27 21:31:41 2008
+From: Dmitriy Morozov <morozov@cs.duke.edu>
+Date: Wed, 27 Feb 2008 16:30:57 -0500
+State: new
+Subject: Segfault with topology/vineyard log enabled
+Message-Id: <d2ab07329c3588ca-0-artemis@metatron>
+
+The code segfaults in Vineyard::record_knee() if we subscribe to
+topology/vineyard log.
--- a/examples/ar-vineyard/CMakeLists.txt	Wed Feb 27 07:57:45 2008 -0500
+++ b/examples/ar-vineyard/CMakeLists.txt	Wed Feb 27 16:32:12 2008 -0500
@@ -3,10 +3,13 @@
 	
 find_library                (boost_signals_LIBRARY      NAMES boost_signals
                                                         PATHS ${Boost_LIBRARY_DIR})
+find_library                (boost_program_options_LIBRARY      NAME boost_program_options
+                                                                PATHS ${Boost_LIBRARY_DIR})
 
 add_definitions				(${cgal_cxxflags})
 foreach 					(t ${targets})
 	add_executable			(${t} ${t}.cpp ${external_sources})
 	target_link_libraries	(${t}   ${libraries} ${cgal_libraries} 
-                                    ${synaps_libraries} ${boost_signals_LIBRARY})
+                                    ${synaps_libraries} ${boost_signals_LIBRARY} 
+                                    ${boost_program_options_LIBRARY})
 endforeach 					(t)
--- a/examples/ar-vineyard/ar-vineyard.cpp	Wed Feb 27 07:57:45 2008 -0500
+++ b/examples/ar-vineyard/ar-vineyard.cpp	Wed Feb 27 16:32:12 2008 -0500
@@ -4,41 +4,75 @@
 
 #include <iostream>
 #include <fstream>
+#include <string>
+#include <vector>
+
+#include <boost/program_options.hpp>
+namespace po = boost::program_options;
 
 
 int main(int argc, char** argv) 
 {
 #ifdef LOGGING
 	rlog::RLogInit(argc, argv);
+	stderrLog.subscribeTo( RLOG_CHANNEL("error") );
+#endif
 
-	stderrLog.subscribeTo( RLOG_CHANNEL("error") );
-    //stdoutLog.subscribeTo( RLOG_CHANNEL("ar/vineyard") );
-    //stdoutLog.subscribeTo( RLOG_CHANNEL("ar/function-kernel/value") );
-    //stdoutLog.subscribeTo( RLOG_CHANNEL("geometry/simulator") );
+	std::string infilename;
+	double zx,zy,zz;
+	std::string outfilename;
+
+    po::options_description hidden("Hidden options");
+    hidden.add_options()
+        ("input-file",  po::value<std::string>(&infilename), "Points file")
+        ("x",  po::value<double>(&zx), "x")
+        ("y",  po::value<double>(&zy), "y")
+        ("z",  po::value<double>(&zz), "z")
+        ("output-file",  po::value<std::string>(&outfilename), "Vineyard edges output");
 
-	//stdoutLog.subscribeTo( RLOG_CHANNEL("topology/filtration") );
-	//stdoutLog.subscribeTo( RLOG_CHANNEL("topology/cycle") );
-	//stdoutLog.subscribeTo( RLOG_CHANNEL("topology/vineyard") );
-	//stdoutLog.subscribeTo( RLOG_CHANNEL("topology/filtration/transpositions") );
-	//stdoutLog.subscribeTo( RLOG_CHANNEL("topology/lowerstar") );
+    std::vector<std::string> log_channels;
+    po::options_description visible("Allowed options");
+    visible.add_options()
+        ("help,h",      "produce help message");
+#if LOGGING
+    visible.add_options()
+        ("log,l",       po::value< std::vector<std::string> >(&log_channels),
+                        "log channels to turn on");
+#endif
+    
+    po::positional_options_description p;
+    p.add("input-file", 1).add("x", 1).add("y", 1).add("z", 1).add("output-file", 1);
+    
+    po::options_description all; all.add(visible).add(hidden);
+
+    po::variables_map vm;
+    po::store(po::command_line_parser(argc, argv).
+                  options(all).positional(p).run(), vm);
+    po::notify(vm);
+
+#if LOGGING
+    for (std::vector<std::string>::const_iterator cur = log_channels.begin(); cur != log_channels.end(); ++cur)
+        stdoutLog.subscribeTo( RLOG_CHANNEL(cur->c_str()) );
+    /* Interesting channels
+     * "ar/vineyard", "ar/function-kernel/value", "geometry/simulator",
+     * "topology/filtration", "topology/cycle", "topology/vineyard",
+     * "topology/filtration/transpositions", "topology/lowerstar"
+     */
 #endif
 
 	// Read command-line arguments
-	if (argc < 6)
+	if (vm.count("help") || !vm.count("input-file") || !vm.count("output-file") 
+                         || !vm.count("x") || !vm.count("y") || !vm.count("z"))
 	{
-		std::cout << "Usage: ar-vineyard POINTS X Y Z OUTFILENAME" << std::endl;
+		std::cout << "Usage: ar-vineyard [OPTIONS] POINTS X Y Z OUTFILENAME" << std::endl;
 		std::cout << "  POINTS       - filename containing points" << std::endl;
 		std::cout << "  X,Y,Z        - center-point z at which to compute the vineyard" << std::endl;
 		std::cout << "  OUTFILENAME  - filename for the resulting vineyard" << std::endl;
+        std::cout << visible << std::endl;
 		std::cout << std::endl;
 		std::cout << "Computes an (alpha,r)-vineyard of the given pointset around the given point." << std::endl;
-		exit(0);
+		return 1;
 	}
-	std::string infilename = argv[1];
-	double zx,zy,zz; std::istringstream(argv[2]) >> zx;
-	std::istringstream(argv[3]) >> zy; std::istringstream(argv[4]) >> zz;
-	std::string outfilename = argv[5];
-	
 	
 	// Read in the point set and compute its Delaunay triangulation
 	std::ifstream in(infilename.c_str());
--- a/examples/ar-vineyard/ar-vineyard.h	Wed Feb 27 07:57:45 2008 -0500
+++ b/examples/ar-vineyard/ar-vineyard.h	Wed Feb 27 16:32:12 2008 -0500
@@ -156,16 +156,31 @@
 
 //BOOST_CLASS_EXPORT(ARVineyard)
 
+#ifdef COUNTERS
+static Counter*  cARVineyardTrajectoryKnee =		 GetCounter("ar/vineyard/trajectoryknee");
+#endif
+
 class ARVineyard::ThresholdChangeSlot
 {   
     public:
-                                ThresholdChangeSlot(SimplexSortIterator iter, SimplexSort* sort):
-                                    iter_(iter), sort_(sort)                                    { iter_->element->new_max_signal().connect(*this); }
-        void                    operator()(Simulator* simulator)                                { sort_->update_trajectory(iter_, simulator); }
+                                ThresholdChangeSlot(SimplexSortIterator iter, SimplexSort* sort, Vineyard* vineyard):
+                                    iter_(iter), sort_(sort), vineyard_(vineyard)               { iter_->element->new_max_signal().connect(*this); }
+        void                    operator()(Simulator* simulator)                                
+        { 
+            Count(cARVineyardTrajectoryKnee); 
+            sort_->update_trajectory(iter_, simulator); 
+            if (iter_->element->sign()) 
+                vineyard_->record_knee(iter_->element);
+            else
+                vineyard_->record_knee(iter_->element->pair());
+        }
     
     private:
         SimplexSortIterator     iter_;
-        SimplexSort*            sort_;
+        SimplexSort*            sort_;              // could make both of these static
+        Vineyard*               vineyard_;          // currently inefficient since there is
+                                                    // only one SimplexSort and one Vineyard, 
+                                                    // but each is stored in every slot
 };
 
 class ARVineyard::StaticEvaluator: public Evaluator
--- a/examples/ar-vineyard/ar-vineyard.hpp	Wed Feb 27 07:57:45 2008 -0500
+++ b/examples/ar-vineyard/ar-vineyard.hpp	Wed Feb 27 16:32:12 2008 -0500
@@ -107,7 +107,7 @@
     std::vector<ThresholdChangeSlot> slots; 
     slots.reserve(filtration_->size());
     for (SimplexSortIterator cur = simplex_sort.begin(); cur != simplex_sort.end(); ++cur)
-        slots.push_back(ThresholdChangeSlot(cur, &simplex_sort));
+        slots.push_back(ThresholdChangeSlot(cur, &simplex_sort, vineyard_));
     rLog(rlARVineyardComputing, "Signals and slots connected");
 	
     // Simulate
--- a/include/topology/vineyard.h	Wed Feb 27 07:57:45 2008 -0500
+++ b/include/topology/vineyard.h	Wed Feb 27 16:32:12 2008 -0500
@@ -47,6 +47,7 @@
 
 		void							start_vines(Index bg, Index end);
 		void							switched(Index i, Index j);
+		void							record_knee(Index i);
 		void							record_diagram(Index bg, Index end);
 
 		void							set_evaluator(Evaluator* eval)				{ evaluator = eval; }
@@ -57,7 +58,6 @@
 		typename Knee::SimplexList  	resolve_cycle(Index i) const;
 
 	private:
-		void							record_knee(Index i);
 		void							start_vine(Index i);
 
 	private:
@@ -126,6 +126,8 @@
 		void 					add(RealType b, RealType d, RealType t)			{ push_back(Knee(b,d,t)); }
 		void 					add(const Knee& k)								{ push_back(k); }
 
+        std::ostream&           operator<<(std::ostream& out) const             { for (const_knee_iterator cur = begin(); cur != end(); ++cur) out << *cur; return out; }
+
 		using VineRepresentation::begin;
 		using VineRepresentation::end;
 		using VineRepresentation::front;
@@ -143,6 +145,9 @@
 		void 					serialize(Archive& ar, version_type );
 };
 
+template<class S>
+std::ostream& operator<<(std::ostream& out, const Vine<S>& v) 					{ return v.operator<<(out); }
+
 
 #include "vineyard.hpp"
 
--- a/include/topology/vineyard.hpp	Wed Feb 27 07:57:45 2008 -0500
+++ b/include/topology/vineyard.hpp	Wed Feb 27 16:32:12 2008 -0500
@@ -122,6 +122,7 @@
 		rLog(rlVineyard, "Creating knee");
 		Knee k(evaluator->value(*i), evaluator->value(*(i->pair())), evaluator->time());
 		rLog(rlVineyard, "Knee created: %s", tostring(k).c_str());
+        rLog(rlVineyard, "Vine: %s", tostring(*(i->vine())).c_str());
 
 		if (!k.is_diagonal() || i->vine()->empty())			// non-diagonal k, or empty vine
 		{