From 8579de6325d4e067dd6ef453d6a3ee2a88ec010e Mon Sep 17 00:00:00 2001
From: Andrea Censi <andrea@cds.caltech.edu>
Date: Fri, 19 Jun 2009 02:38:17 +0000
Subject: [PATCH] decimate program

---
 sm/CMakeLists.txt           |  1 +
 sm/apps/json_decimate.c     | 53 +++++++++++++++++++++++++++++++++++++
 sm/apps/ld_remove_doubles.c |  9 ++++++-
 3 files changed, 62 insertions(+), 1 deletion(-)
 create mode 100644 sm/apps/json_decimate.c

diff --git a/sm/CMakeLists.txt b/sm/CMakeLists.txt
index 5ad869f..dbcc191 100644
--- a/sm/CMakeLists.txt
+++ b/sm/CMakeLists.txt
@@ -84,6 +84,7 @@ new_executable(sm2)
 new_executable(sm3)
 new_executable(json_extract)
 new_executable(json_extract_field)
+new_executable(json_decimate)
 new_executable(json_split)
 new_executable(json_pipe)
 new_executable(carmen2json)
diff --git a/sm/apps/json_decimate.c b/sm/apps/json_decimate.c
new file mode 100644
index 0000000..366722a
--- /dev/null
+++ b/sm/apps/json_decimate.c
@@ -0,0 +1,53 @@
+#include <options/options.h>
+#include "../csm/csm_all.h"
+
+int main(int argc, const char * argv[]) {
+	sm_set_program_name(argv[0]);
+	
+	int period;
+	const char*input_filename;
+	const char*output_filename;
+	
+	struct option* ops = options_allocate(3);
+	options_int(ops, "period", &period, 1, "Period of objects to extract.");
+	options_string(ops, "in", &input_filename, "stdin", "input file (JSON)");
+	options_string(ops, "out", &output_filename, "stdout", "output file (JSON)");
+	
+	if(!options_parse_args(ops, argc, argv)) {
+		fprintf(stderr, "%s : decimates a JSON stream."
+			"\n\nOptions:\n", argv[0]);
+		options_print_help(ops, stderr);
+		return -1;
+	}
+	
+	if(period < 1) {
+		sm_error("Period must be >= 1.\n");
+		return 2;
+	}
+	
+	FILE * input_stream = open_file_for_reading(input_filename);
+	FILE *output_stream = open_file_for_writing(output_filename);
+	
+	if(!input_stream || !output_stream) return -1;
+	
+	
+	int count = 0;
+	while(1) { 
+		JO jo = json_read_stream(stdin);
+		if(!jo) {
+			if(feof(stdin)) break;
+			sm_error("Malformed JSON\n");
+			return -1;
+		}
+		
+		if(count % period == 0) {
+			const char * s = json_object_to_json_string(jo);
+			puts(s); puts("\n");
+		} 
+		
+		jo_free(jo);
+		count++;
+	}
+	
+	return 0;
+}
diff --git a/sm/apps/ld_remove_doubles.c b/sm/apps/ld_remove_doubles.c
index ac65fed..73d594f 100644
--- a/sm/apps/ld_remove_doubles.c
+++ b/sm/apps/ld_remove_doubles.c
@@ -10,14 +10,21 @@ int main(int argc, const char*argv[]) {
 	sm_set_program_name(argv[0]);
 	
 	double epsilon;
+	int debug;
+	
 	
 	struct option* ops = options_allocate(3);
-	options_double(ops, "epsilon", &epsilon, 0.0001, "epsilon");
+	options_double(ops, "epsilon", &epsilon, 0.0001, "minimum difference between rays to be used");
+	
+	
 	if(!options_parse_args(ops, argc, argv)) {
 		options_print_help(ops, stderr);
 		return -1;
 	}
 	
+	sm_debug_write(debug);
+	
+	
 	/* Read first scan */
 	LDP laser_ref=0, laser_sens;
 		
-- 
GitLab