optional listing of polygon points (more accurate than rectangular box, but requires separate relation): --list-polygon-points v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 16 Apr 2021 23:18:03 +0200
branchv_0
changeset 4 500ce0b934e7
parent 3 18bb23fc811f
child 5 8f434dc38444
optional listing of polygon points (more accurate than rectangular box, but requires separate relation): --list-polygon-points
bash-completion.sh
src/CLIParser.h
src/Configuration.h
src/QRCommand.h
--- a/bash-completion.sh	Thu Apr 15 20:45:10 2021 +0200
+++ b/bash-completion.sh	Fri Apr 16 23:18:03 2021 +0200
@@ -27,12 +27,10 @@
 		"false"
 	)
 
-	  if [[ "$w1" == "--list-xxx"                                       ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
-	elif [[ "$w1" == "--list-zzz"                                       ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
+	  if [[ "$w1" == "--list-polygon-points"                            ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
 	else
 		OPTIONS=(
-			"--list-xxx"
-			"--list-zzz"
+			"--list-polygon-points"
 		)
 		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
 	fi
--- a/src/CLIParser.h	Thu Apr 15 20:45:10 2021 +0200
+++ b/src/CLIParser.h	Fri Apr 16 23:18:03 2021 +0200
@@ -48,7 +48,7 @@
 
 public:
 
-	static const relpipe::common::type::StringX OPTION_LIST_XXX;
+	static const relpipe::common::type::StringX OPTION_LIST_POLYGON_POINTS;
 	static const relpipe::common::type::StringX OPTION_LIST_ZZZ;
 
 	Configuration parse(const std::vector<relpipe::common::type::StringX>& arguments) {
@@ -57,10 +57,8 @@
 		for (int i = 0; i < arguments.size();) {
 			relpipe::common::type::StringX option = readNext(arguments, i);
 
-			if (option == OPTION_LIST_XXX) {
-				c.listXXX = parseBoolean(readNext(arguments, i));
-			} else if (option == OPTION_LIST_ZZZ) {
-				c.listZZZ = parseBoolean(readNext(arguments, i));
+			if (option == OPTION_LIST_POLYGON_POINTS) {
+				c.listPolygonPoints = parseBoolean(readNext(arguments, i));
 			} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
 		}
 
@@ -71,8 +69,7 @@
 	}
 };
 
-const relpipe::common::type::StringX CLIParser::OPTION_LIST_XXX = L"--list-xxx";
-const relpipe::common::type::StringX CLIParser::OPTION_LIST_ZZZ = L"--list-zzz";
+const relpipe::common::type::StringX CLIParser::OPTION_LIST_POLYGON_POINTS = L"--list-polygon-points";
 
 }
 }
--- a/src/Configuration.h	Thu Apr 15 20:45:10 2021 +0200
+++ b/src/Configuration.h	Fri Apr 16 23:18:03 2021 +0200
@@ -28,8 +28,7 @@
 
 class Configuration {
 public:
-	bool listXXX = false;
-	bool listZZZ = false;
+	bool listPolygonPoints = false;
 
 	virtual ~Configuration() {
 	}
--- a/src/QRCommand.h	Thu Apr 15 20:45:10 2021 +0200
+++ b/src/QRCommand.h	Fri Apr 16 23:18:03 2021 +0200
@@ -40,6 +40,7 @@
 
 	void process(Configuration& configuration, std::shared_ptr<writer::RelationalWriter> writer, std::function<void() > relationalWriterFlush) {
 
+		// TODO: require PNM input and get rid off the ImageMagick dependency?
 		Magick::Image magick("/dev/stdin");
 		int width = magick.columns();
 		int height = magick.rows();
@@ -51,7 +52,8 @@
 		zbar::Image image(width, height, "Y800", raw, width * height);
 		zbar::ImageScanner scanner;
 
-		writer->startRelation(L"qr",{
+		writer->startRelation(L"symbol",{
+			{L"id", relpipe::writer::TypeId::INTEGER},
 			{L"type", relpipe::writer::TypeId::STRING},
 			// {L"addon_name", relpipe::writer::TypeId::STRING},
 			{L"value", relpipe::writer::TypeId::STRING},
@@ -64,7 +66,9 @@
 
 		int n = scanner.scan(image);
 
-		for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol) {
+		relpipe::common::type::Integer id = 0;
+		for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol, id++) {
+			writer->writeAttribute(&id, typeid (id));
 			writer->writeAttribute(convertor.from_bytes(symbol->get_type_name()));
 			// writer->writeAttribute(convertor.from_bytes(symbol->get_addon_name()));
 			writer->writeAttribute(convertor.from_bytes(symbol->get_data()));
@@ -94,6 +98,28 @@
 			writer->writeAttribute(&height, typeid (height));
 		}
 
+		if (configuration.listPolygonPoints) {
+			relpipe::common::type::Integer id = 0;
+
+			writer->startRelation(L"polygon_point",{
+				{L"symbol", relpipe::writer::TypeId::INTEGER},
+				{L"point", relpipe::writer::TypeId::INTEGER},
+				{L"x", relpipe::writer::TypeId::INTEGER},
+				{L"y", relpipe::writer::TypeId::INTEGER},
+			}, true);
+
+			for (zbar::Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol, id++) {
+				for (relpipe::common::type::Integer i = 0, locationSize = symbol->get_location_size(); i < locationSize; i++) {
+					relpipe::common::type::Integer x = symbol->get_location_x(i);
+					relpipe::common::type::Integer y = symbol->get_location_y(i);
+					writer->writeAttribute(&id, typeid (id));
+					writer->writeAttribute(&i, typeid (i));
+					writer->writeAttribute(&x, typeid (x));
+					writer->writeAttribute(&y, typeid (y));
+				}
+			}
+		}
+
 		image.set_data(nullptr, 0);
 	}
 };