Moved files around: lsvineyard.h -> include/topology, examples/grid -> examples/pl-functions
1 #include <utilities/log.h>
8 #include <topology/lsvineyard.h>
10 #include <boost/program_options.hpp>
11 #include <boost/iterator/counting_iterator.hpp>
12 #include <boost/function.hpp>
13 #include <boost/bind.hpp>
14 #include <boost/lambda/lambda.hpp>
15 namespace bl = boost::lambda;
18 typedef float VertexValue;
19 typedef unsigned Vertex;
20 typedef std::vector<VertexValue> VertexVector;
21 struct SubscriptFunctor: public std::unary_function<Vertex, VertexValue>
23 SubscriptFunctor(const VertexVector& v): vec(&v) {} 24 float operator()(Vertex i) const { return (*vec)[i]; } 25 SubscriptFunctor& operator=(const SubscriptFunctor& other) { vec = other.vec; return *this; } 26 const VertexVector* vec;
28 typedef SubscriptFunctor VertexEvaluator;
29 typedef std::vector<VertexVector> VertexVectorVector;
30 typedef LSVineyard<Vertex, VertexEvaluator> PLVineyard;
31 typedef PLVineyard::Simplex Smplx; // gotta start using namespaces
33 void program_options(int argc, char* argv[], std::string& complex_fn,
34 std::string& values_fn,
35 std::string& output_prefix,
36 bool& skip_infinite_vines,
38 bool& explicit_events);
39 void read_simplices(const std::string& complex_fn, PLVineyard::LSFiltration& simplices);
40 void read_vertices(const std::string& vertex_fn, VertexVectorVector& vertices);
43 int main(int argc, char** argv)
46 rlog::RLogInit(argc, argv);
49 std::string complex_fn, values_fn, output_prefix;
50 bool skip_infinite_vines = false, explicit_events = false, save_vines = false;
51 program_options(argc, argv, complex_fn, values_fn, output_prefix, skip_infinite_vines, save_vines, explicit_events);
54 // Read in the complex
55 PLVineyard::LSFiltration simplices;
56 read_simplices(complex_fn, simplices);
57 std::cout << "Complex read, size: " << simplices.size() << std::endl;
59 // Read in vertex values
60 VertexVectorVector vertices;
61 read_vertices(values_fn, vertices);
64 VertexEvaluator veval(vertices[0]);
65 PLVineyard::VertexComparison vcmp(veval);
66 PLVineyard::SimplexComparison scmp(vcmp);
68 PLVineyard v(boost::counting_iterator<Vertex>(0),
69 boost::counting_iterator<Vertex>(vertices[0].size()),
71 std::cout << "Pairing computed" << std::endl;
74 for (size_t i = 1; i < vertices.size(); ++i)
76 veval = VertexEvaluator(vertices[i]);
77 v.compute_vineyard(veval, explicit_events);
78 std::cout << "Processed frame: " << i << std::endl;
80 std::cout << "Vineyard computed" << std::endl;
83 v.vineyard().save_vines(output_prefix, skip_infinite_vines);
85 v.vineyard().save_edges(output_prefix, skip_infinite_vines);
89 void read_simplices(const std::string& complex_fn, PLVineyard::LSFiltration& simplices)
91 std::ifstream in(complex_fn.c_str());
93 while (std::getline(in, line))
95 std::istringstream strin(line);
96 simplices.push_back(Smplx(std::istream_iterator<Vertex>(strin), std::istream_iterator<Vertex>()));
98 std::cout << "Simplices read:" << std::endl;
99 std::copy(simplices.begin(), simplices.end(), std::ostream_iterator<Smplx>(std::cout, "\n"));
102 void read_vertices(const std::string& vertex_fn, VertexVectorVector& vertices)
104 std::ifstream in(vertex_fn.c_str());
106 while (std::getline(in, line))
108 std::istringstream strin(line);
109 vertices.push_back(VertexVector(std::istream_iterator<VertexValue>(strin), std::istream_iterator<VertexValue>()));
111 std::cout << "Vertex values read:" << std::endl;
112 for (size_t i = 0; i < vertices.size(); ++i)
114 std::copy(vertices[i].begin(), vertices[i].end(), std::ostream_iterator<VertexValue>(std::cout, " "));
115 std::cout << std::endl;
119 void program_options(int argc, char* argv[], std::string& complex_fn,
120 std::string& values_fn,
121 std::string& output_prefix,
122 bool& skip_infinite_vines,
124 bool& explicit_events)
126 namespace po = boost::program_options;
128 po::options_description hidden("Hidden options"); 130 ("complex-file", po::value<std::string>(&complex_fn), "file listing the simplices of the complex") 131 ("values-file", po::value<std::string>(&values_fn), "file listing the values at the vertices") 132 ("output-prefix", po::value<std::string>(&output_prefix), "output prefix"); 134 po::options_description visible("Allowed options", 100); 135 visible.add_options()
136 ("skip-infinite,s", po::bool_switch(&skip_infinite_vines), "skip infinite vines in the output") 137 ("explicit-events,e", po::bool_switch(&explicit_events), "process kinetic sort events one by one") 138 ("save-vines,v", po::bool_switch(&save_vines), "save vines instead of edges") 139 ("help,h", "produce help message"); 141 std::vector<std::string> log_channels;
142 visible.add_options()
143 ("log,l", po::value< std::vector<std::string> >(&log_channels), "log channels to turn on (info, debug, etc)"); 146 po::positional_options_description pos;
147 pos.add("complex-file", 1); 148 pos.add("values-file", 1); 149 pos.add("output-prefix", 1); 151 po::options_description all; all.add(visible).add(hidden);
153 po::variables_map vm;
154 po::store(po::command_line_parser(argc, argv).
155 options(all).positional(pos).run(), vm);
159 for (std::vector<std::string>::const_iterator cur = log_channels.begin(); cur != log_channels.end(); ++cur)
160 stderrLog.subscribeTo( RLOG_CHANNEL(cur->c_str()) );
163 if (vm.count("help") || !vm.count("complex-file") || !vm.count("values-file") || !vm.count("output-prefix")) 165 std::cout << "Usage: " << argv[0] << " [options] complex-file values-file output-prefix" << std::endl;
166 std::cout << visible << std::endl;