Skip to content
Snippets Groups Projects
Commit 8579de63 authored by Andrea Censi's avatar Andrea Censi
Browse files

decimate program

parent 02920989
No related branches found
No related tags found
No related merge requests found
...@@ -84,6 +84,7 @@ new_executable(sm2) ...@@ -84,6 +84,7 @@ new_executable(sm2)
new_executable(sm3) new_executable(sm3)
new_executable(json_extract) new_executable(json_extract)
new_executable(json_extract_field) new_executable(json_extract_field)
new_executable(json_decimate)
new_executable(json_split) new_executable(json_split)
new_executable(json_pipe) new_executable(json_pipe)
new_executable(carmen2json) new_executable(carmen2json)
......
#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;
}
...@@ -10,14 +10,21 @@ int main(int argc, const char*argv[]) { ...@@ -10,14 +10,21 @@ int main(int argc, const char*argv[]) {
sm_set_program_name(argv[0]); sm_set_program_name(argv[0]);
double epsilon; double epsilon;
int debug;
struct option* ops = options_allocate(3); 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)) { if(!options_parse_args(ops, argc, argv)) {
options_print_help(ops, stderr); options_print_help(ops, stderr);
return -1; return -1;
} }
sm_debug_write(debug);
/* Read first scan */ /* Read first scan */
LDP laser_ref=0, laser_sens; LDP laser_ref=0, laser_sens;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment