contrek 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +84 -0
  6. data/LICENSE.md +9 -0
  7. data/README.md +118 -0
  8. data/Rakefile +19 -0
  9. data/contrek.gemspec +23 -0
  10. data/contrek.png +0 -0
  11. data/ext/cpp_polygon_finder/PolygonFinder/.cproject +136 -0
  12. data/ext/cpp_polygon_finder/PolygonFinder/.project +27 -0
  13. data/ext/cpp_polygon_finder/PolygonFinder/.settings/org.eclipse.ltk.core.refactoring.prefs +2 -0
  14. data/ext/cpp_polygon_finder/PolygonFinder/images/labyrinth.png +0 -0
  15. data/ext/cpp_polygon_finder/PolygonFinder/src/Main.cpp +41 -0
  16. data/ext/cpp_polygon_finder/PolygonFinder/src/Tests.cpp +69 -0
  17. data/ext/cpp_polygon_finder/PolygonFinder/src/Tests.h +19 -0
  18. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/Bitmap.cpp +52 -0
  19. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/Bitmap.h +32 -0
  20. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/FastPngBitmap.cpp +656 -0
  21. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/FastPngBitmap.h +42 -0
  22. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/PngBitmap.cpp +48 -0
  23. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/PngBitmap.h +32 -0
  24. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/RemoteFastPngBitmap.cpp +30 -0
  25. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/RemoteFastPngBitmap.h +26 -0
  26. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/X_picopng.cpp +576 -0
  27. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/List.cpp +120 -0
  28. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/List.h +40 -0
  29. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Lists.cpp +36 -0
  30. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Lists.h +30 -0
  31. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Node.cpp +111 -0
  32. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Node.h +80 -0
  33. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/NodeCluster.cpp +325 -0
  34. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/NodeCluster.h +59 -0
  35. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.cpp +206 -0
  36. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.h +69 -0
  37. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/optionparser.h +2858 -0
  38. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/Matcher.cpp +23 -0
  39. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/Matcher.h +23 -0
  40. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBMatcher.cpp +20 -0
  41. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBMatcher.h +23 -0
  42. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBNotMatcher.cpp +20 -0
  43. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBNotMatcher.h +23 -0
  44. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/ValueNotMatcher.cpp +20 -0
  45. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/ValueNotMatcher.h +21 -0
  46. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/LinearReducer.cpp +40 -0
  47. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/LinearReducer.h +23 -0
  48. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/Reducer.cpp +19 -0
  49. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/Reducer.h +25 -0
  50. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/UniqReducer.cpp +30 -0
  51. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/UniqReducer.h +21 -0
  52. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/VisvalingamReducer.cpp +50 -0
  53. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/VisvalingamReducer.h +121 -0
  54. data/ext/cpp_polygon_finder/cpp_polygon_finder.cpp +260 -0
  55. data/ext/cpp_polygon_finder/extconf.rb +2 -0
  56. data/lib/contrek/bitmaps/bitmap.rb +21 -0
  57. data/lib/contrek/bitmaps/chunky_bitmap.rb +33 -0
  58. data/lib/contrek/bitmaps/painting.rb +40 -0
  59. data/lib/contrek/bitmaps/png_bitmap.rb +62 -0
  60. data/lib/contrek/bitmaps/rgb_color.rb +25 -0
  61. data/lib/contrek/finder/list.rb +132 -0
  62. data/lib/contrek/finder/list_entry.rb +11 -0
  63. data/lib/contrek/finder/listable.rb +8 -0
  64. data/lib/contrek/finder/lists.rb +25 -0
  65. data/lib/contrek/finder/node.rb +126 -0
  66. data/lib/contrek/finder/node_cluster.rb +294 -0
  67. data/lib/contrek/finder/polygon_finder.rb +121 -0
  68. data/lib/contrek/map/mercator_projection.rb +76 -0
  69. data/lib/contrek/matchers/matcher.rb +20 -0
  70. data/lib/contrek/matchers/matcher_hsb.rb +24 -0
  71. data/lib/contrek/matchers/value_not_matcher.rb +9 -0
  72. data/lib/contrek/reducers/linear_reducer.rb +25 -0
  73. data/lib/contrek/reducers/reducer.rb +14 -0
  74. data/lib/contrek/reducers/uniq_reducer.rb +9 -0
  75. data/lib/contrek/reducers/visvalingam_reducer.rb +139 -0
  76. data/lib/contrek/version.rb +3 -0
  77. data/lib/contrek.rb +58 -0
  78. metadata +175 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 784d6fa77c94f481b71bd4ae7ab7a6210e28c4376829612a9e1357669155b370
4
+ data.tar.gz: e2a2ac6b417c3818b5509b7f43fd51874c30f7eea2290946323a6a5c3a952220
5
+ SHA512:
6
+ metadata.gz: fa138802fd7e343e65aa3ca853406ad57c90e2103f1441057efb703f2135eb1b132544033aa1aca0b1e9f405e77f79e705efd7acf975ca72cf3b29ac417ceaf3
7
+ data.tar.gz: 52da9f3b406533fa0d96267324605a807ac6e27cf8882e5f4a1aab30c651ed1bab682f7d3fb9bc04168c600d1a495b263c271e608326df5237ad9d0926cbd5c6
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /pkg/
2
+
3
+ # rspec failure tracking
4
+ .rspec_status
5
+
6
+ /ext/cpp_polygon_finder/PolygonFinder/Debug/*
7
+ /ext/cpp_polygon_finder/.metadata/
8
+ /ext/cpp_polygon_finder/RemoteSystemsTempFiles/
9
+ /ext/cpp_polygon_finder/Makefile
10
+ /ext/cpp_polygon_finder/cpp_polygon_finder.o
11
+ /ext/cpp_polygon_finder/cpp_polygon_finder.so
12
+ /ext/cpp_polygon_finder/mkmf.log
13
+ /lib/cpp_polygon_finder.so
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ contrek (1.0.0)
5
+ chunky_png (~> 1.4)
6
+ rice (~> 4.5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.3)
12
+ chunky_png (1.4.0)
13
+ diff-lcs (1.6.1)
14
+ json (2.11.3)
15
+ language_server-protocol (3.17.0.4)
16
+ lint_roller (1.1.0)
17
+ parallel (1.27.0)
18
+ parser (3.3.8.0)
19
+ ast (~> 2.4.1)
20
+ racc
21
+ prism (1.4.0)
22
+ racc (1.8.1)
23
+ rainbow (3.1.1)
24
+ regexp_parser (2.10.0)
25
+ rice (4.5.0)
26
+ rspec (3.13.0)
27
+ rspec-core (~> 3.13.0)
28
+ rspec-expectations (~> 3.13.0)
29
+ rspec-mocks (~> 3.13.0)
30
+ rspec-core (3.13.3)
31
+ rspec-support (~> 3.13.0)
32
+ rspec-expectations (3.13.3)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.13.0)
35
+ rspec-mocks (3.13.2)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.13.0)
38
+ rspec-support (3.13.2)
39
+ rubocop (1.75.3)
40
+ json (~> 2.3)
41
+ language_server-protocol (~> 3.17.0.2)
42
+ lint_roller (~> 1.1.0)
43
+ parallel (~> 1.10)
44
+ parser (>= 3.3.0.2)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 2.9.3, < 3.0)
47
+ rubocop-ast (>= 1.44.0, < 2.0)
48
+ ruby-progressbar (~> 1.7)
49
+ unicode-display_width (>= 2.4.0, < 4.0)
50
+ rubocop-ast (1.44.1)
51
+ parser (>= 3.3.7.2)
52
+ prism (~> 1.4)
53
+ rubocop-performance (1.25.0)
54
+ lint_roller (~> 1.1)
55
+ rubocop (>= 1.75.0, < 2.0)
56
+ rubocop-ast (>= 1.38.0, < 2.0)
57
+ ruby-progressbar (1.13.0)
58
+ standard (1.49.0)
59
+ language_server-protocol (~> 3.17.0.2)
60
+ lint_roller (~> 1.0)
61
+ rubocop (~> 1.75.2)
62
+ standard-custom (~> 1.0.0)
63
+ standard-performance (~> 1.8)
64
+ standard-custom (1.0.2)
65
+ lint_roller (~> 1.0)
66
+ rubocop (~> 1.50)
67
+ standard-performance (1.8.0)
68
+ lint_roller (~> 1.1)
69
+ rubocop-performance (~> 1.25.0)
70
+ unicode-display_width (3.1.4)
71
+ unicode-emoji (~> 4.0, >= 4.0.4)
72
+ unicode-emoji (4.0.4)
73
+
74
+ PLATFORMS
75
+ ruby
76
+ x86_64-linux
77
+
78
+ DEPENDENCIES
79
+ contrek!
80
+ rspec (~> 3.10)
81
+ standard (~> 1.49)
82
+
83
+ BUNDLED WITH
84
+ 2.6.6
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License
2
+
3
+ Copyright 2018 -- 2025 by Emanuele Cesaroni.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # Contrek
2
+ Contrek is a Ruby library (C++ powered) to trace png bitmap areas polygonal contours. Manages png images usign png++ and picoPNG (version 20101224) libraries.
3
+
4
+ ## About Contrek library
5
+ Contrek (contour trekking) simply scans your png bitmap and returns shape contour as close polygonal lines, both for the external and internal sides. It can compute the nesting level of the polygons found with a tree structure. It supports various levels and modes of compression and approximation of the found coordinates.
6
+
7
+ In the following image all the non-white pixels have been examined and the result is the red polygon for the outer contour and the green one for the inner one
8
+ ![alt text](contrek.png "Contour tracing")
9
+
10
+ ## Install
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'contrek'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ bundle install
21
+
22
+ This will install the gem and compile the native extensions. If you get
23
+ `fatal error: png++/png.hpp: No such file or directory`
24
+
25
+ means that you have to install png++ on your system which Contrek C++ code depends on; visit http://download.savannah.nongnu.org/releases/pngpp/
26
+ Grab the lattest file (here 0.2.9)
27
+ Go to download directory. Extract to /usr/src with
28
+
29
+ sudo tar -zxf png++-0.2.9.tar.gz -C /usr/src
30
+ Change directory to
31
+
32
+ cd /usr/src/png++-0.2.9/
33
+ Do make and make install
34
+
35
+ make
36
+ make install
37
+
38
+ ## Usage
39
+ In this example we are asking to examine any pixel that does not have the red color.
40
+
41
+ ```ruby
42
+ result = Contrek.contour!(
43
+ png_file_path: "labyrinth3.png",
44
+ options: {
45
+ class: "value_not_matcher",
46
+ color: {r: 255, g: 0, b: 0, a: 255}
47
+ }
48
+ )
49
+ ```
50
+ The result reports information about the execution times (microseconds), the polygons found, their coordinates and the nesting tree.
51
+ ```ruby
52
+ {:benchmarks=>{"build_tangs_sequence"=>0.129, "compress"=>0.037, "plot"=>0.198, "scan"=>0.114, "total"=>0.478}, :groups=>2, :named_sequence=>"", :polygons=>[...], :treemap=>[]}
53
+
54
+ ```
55
+
56
+ By default the C++ version is used. If you want run pure but slower ruby implementation
57
+ ```ruby
58
+ result = Contrek.contour!(
59
+ png_file_path: "labyrinth3.png",
60
+ options: {
61
+ native: false, # force ruby pure
62
+ class: "value_not_matcher",
63
+ color: {r: 241, g: 156, b: 156, a: 255}
64
+ }
65
+
66
+ ```
67
+
68
+ You can bypass the helper and access low level (here the CPP classes)
69
+
70
+ ```ruby
71
+ png_bitmap = CPPPngBitMap.new("labyrinth3.png")
72
+ rgb_matcher = CPPRGBNotMatcher.new(png_bitmap.rgb_value_at(0, 0))
73
+ polygonfinder = CPPPolygonFinder.new(png_bitmap,
74
+ rgb_matcher,
75
+ nil,
76
+ {versus: :a, compress: {visvalingam: {tolerance: 1.5}}})
77
+ result = polygonfinder.process_info
78
+ # draws the polygons found
79
+ Contrek::Bitmaps::Painting.direct_draw_polygons(result[:polygons], png_image)
80
+ png_image.save('result.png') # => inspect the image to feedback the result
81
+ ```
82
+
83
+ You can also read base64 png images
84
+ ```ruby
85
+ png_bitmap = CPPRemotePngBitMap.new("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==")
86
+ ```
87
+
88
+ ## Performances native vs pure
89
+ One of the most complex test you can find under the spec folder is named "scans poly 1200x800", scans this [image](spec/files/images/sample_1200x800.png) computing coordinates to draw polygons you can see in this [result](spec/files/stored_samples/sample_1200x800.png).
90
+ On pure ruby implementation this is the time
91
+ ```ruby
92
+ { :scan=>1063.146,
93
+ :build_tangs_sequence=>287.114,
94
+ :plot=>79.329,
95
+ :compress=>0.001,
96
+ :total=>1429.59}
97
+ ```
98
+ This the one for the native C++
99
+ ```ruby
100
+ { :scan=>43.521,
101
+ :build_tangs_sequence=>44.105,
102
+ :plot=>35.718,
103
+ :compress=>0.001,
104
+ :total=>123.34500000000001}
105
+ ```
106
+
107
+ About 10 x faster. Times are in microseconds; system: AMD Ryzen 7 3700X 8-Core Processor (BogoMIPS: 7199,99).
108
+
109
+ ## License
110
+
111
+ This project is licensed under the terms of the MIT license.
112
+
113
+ See [LICENSE.md](LICENSE.md).
114
+
115
+ ## History
116
+ The algorithm was originally developed by me in 2018 when I was commissioned to create a Rails web application whose main objective was to census buildings from GoogleMAPS; the end user had to be able to select their home building by clicking its roof on the map which had to be identified as a clickable polygon. The solution was to configure GoogleMAPS to render buildings of a well-defined color (red), and at each refresh of the same to transform the div into an image (html2canvas) then process it server side returning the polygons to be superimposed again on the map. This required very fast polygons determination. Searching for a library for tracing the contours I was not able to find anything better except OpenCV which however seemed to me to be a very heavy dependency. So I decided to write my algorithm directly in the context of the ROR application. Once perfected, it was already usable but a bit slow in the higher image resolutions. So I decided to write the counterpart in C++, which came out much faster and which I then used as an extension on Ruby by means of Rice.
117
+
118
+ I thought that the algorithm had excellent qualities but I never had the time to develop it further. A few months ago I decided to publish it as a gem, freely usable. The gem includes the C++ extension. There is also a [Rails 7.1 demo project](https://github.com/runout77/contrek_rails) that uses the gem and proposes the same scheme I described above. Starting from a GoogleMAPS map, the server receives the image and returns the outlines to be drawn again on the same. It is a great way to test an applicative use of this gem. Enjoy!.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require "rake"
2
+
3
+ desc "compiles c++ extension"
4
+ task :compile do |t|
5
+ Dir.chdir("ext/cpp_polygon_finder") do
6
+ system "ruby", "extconf.rb"
7
+ system "make", "-B"
8
+ system "cp cpp_polygon_finder.so ./../../lib"
9
+ end
10
+ end
11
+
12
+ desc "builds gem"
13
+ task :build do |t|
14
+ system "gem", "build"
15
+ system "mv *.gem pkg"
16
+ Dir.chdir("pkg") do
17
+ system "gem install contrek"
18
+ end
19
+ end
data/contrek.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "contrek/version"
4
+ Gem::Specification.new do |s|
5
+ s.name = "contrek"
6
+ s.version = Contrek::VERSION
7
+ s.summary = "Contour finder"
8
+ s.description = "Shape contour finder"
9
+ s.authors = ["Emanuele Cesaroni"]
10
+ s.email = "cesaroni.emanuele77@gmail.com"
11
+ s.homepage = "https://rubygems.org/gems/hola"
12
+ s.license = "MIT"
13
+ s.files = Dir.chdir(File.expand_path("..", __FILE__)) do
14
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(pkg|spec)/}) }
15
+ end
16
+
17
+ s.add_development_dependency "rspec", "~> 3.10"
18
+ s.add_development_dependency "standard", "~> 1.49"
19
+ s.add_dependency "chunky_png", "~> 1.4"
20
+ s.add_dependency "rice", "~> 4.5"
21
+
22
+ s.extensions = %w[ext/cpp_polygon_finder/extconf.rb]
23
+ end
data/contrek.png ADDED
Binary file
@@ -0,0 +1,136 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
3
+ <storageModule moduleId="org.eclipse.cdt.core.settings">
4
+ <cconfiguration id="cdt.managedbuild.config.gnu.exe.debug.230092677">
5
+ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.230092677" moduleId="org.eclipse.cdt.core.settings" name="Debug">
6
+ <externalSettings/>
7
+ <extensions>
8
+ <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
9
+ <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
10
+ <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
11
+ <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
12
+ <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
13
+ <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
14
+ </extensions>
15
+ </storageModule>
16
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
17
+ <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.230092677" name="Debug" parent="cdt.managedbuild.config.gnu.exe.debug">
18
+ <folderInfo id="cdt.managedbuild.config.gnu.exe.debug.230092677." name="/" resourcePath="">
19
+ <toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.1239797023" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
20
+ <targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.1171825928" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
21
+ <builder buildPath="${workspace_loc:/PolygonFinder}/Debug" id="cdt.managedbuild.target.gnu.builder.exe.debug.1257678896" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
22
+ <tool id="cdt.managedbuild.tool.gnu.archiver.base.1856002595" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
23
+ <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.2115733171" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
24
+ <option id="gnu.cpp.compiler.exe.debug.option.optimization.level.1326185101" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
25
+ <option id="gnu.cpp.compiler.exe.debug.option.debugging.level.1247115604" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
26
+ <option id="gnu.cpp.compiler.option.other.other.741409039" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" useByScannerDiscovery="false" value="-c -fmessage-length=0 -std=c++11" valueType="string"/>
27
+ <option id="gnu.cpp.compiler.option.dialect.std.354652968" superClass="gnu.cpp.compiler.option.dialect.std" value="gnu.cpp.compiler.dialect.default" valueType="enumerated"/>
28
+ <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.633512179" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
29
+ </tool>
30
+ <tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1037594756" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug">
31
+ <option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.exe.debug.option.optimization.level.400575370" name="Optimization Level" superClass="gnu.c.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
32
+ <option id="gnu.c.compiler.exe.debug.option.debugging.level.335517367" name="Debug Level" superClass="gnu.c.compiler.exe.debug.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
33
+ <option id="gnu.c.compiler.option.dialect.std.447995157" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.default" valueType="enumerated"/>
34
+ <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.98002247" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
35
+ </tool>
36
+ <tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.1946335522" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug"/>
37
+ <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.888672614" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug">
38
+ <option id="gnu.cpp.link.option.libs.392256841" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
39
+ <listOptionValue builtIn="false" value="png"/>
40
+ </option>
41
+ <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1499348319" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
42
+ <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
43
+ <additionalInput kind="additionalinput" paths="$(LIBS)"/>
44
+ </inputType>
45
+ </tool>
46
+ <tool id="cdt.managedbuild.tool.gnu.assembler.exe.debug.1643445143" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.debug">
47
+ <inputType id="cdt.managedbuild.tool.gnu.assembler.input.2006340935" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
48
+ </tool>
49
+ </toolChain>
50
+ </folderInfo>
51
+ <sourceEntries>
52
+ <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
53
+ </sourceEntries>
54
+ </configuration>
55
+ </storageModule>
56
+ <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
57
+ </cconfiguration>
58
+ <cconfiguration id="cdt.managedbuild.config.gnu.exe.release.1889533389">
59
+ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.1889533389" moduleId="org.eclipse.cdt.core.settings" name="Release">
60
+ <externalSettings/>
61
+ <extensions>
62
+ <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
63
+ <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
64
+ <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
65
+ <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
66
+ <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
67
+ <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
68
+ </extensions>
69
+ </storageModule>
70
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
71
+ <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.1889533389" name="Release" parent="cdt.managedbuild.config.gnu.exe.release">
72
+ <folderInfo id="cdt.managedbuild.config.gnu.exe.release.1889533389." name="/" resourcePath="">
73
+ <toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.1325837642" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release">
74
+ <targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.219395500" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/>
75
+ <builder buildPath="${workspace_loc:/PolygonFinder}/Release" id="cdt.managedbuild.target.gnu.builder.exe.release.943964203" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/>
76
+ <tool id="cdt.managedbuild.tool.gnu.archiver.base.1855153254" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
77
+ <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.899886102" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release">
78
+ <option id="gnu.cpp.compiler.exe.release.option.optimization.level.981249657" name="Optimization Level" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
79
+ <option id="gnu.cpp.compiler.exe.release.option.debugging.level.302462699" name="Debug Level" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
80
+ <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.561634342" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
81
+ </tool>
82
+ <tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.327745473" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release">
83
+ <option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.exe.release.option.optimization.level.706749095" name="Optimization Level" superClass="gnu.c.compiler.exe.release.option.optimization.level" valueType="enumerated"/>
84
+ <option id="gnu.c.compiler.exe.release.option.debugging.level.2093011643" name="Debug Level" superClass="gnu.c.compiler.exe.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/>
85
+ <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.635848800" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
86
+ </tool>
87
+ <tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.368376046" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release"/>
88
+ <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.1612063391" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release">
89
+ <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.6860118" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
90
+ <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
91
+ <additionalInput kind="additionalinput" paths="$(LIBS)"/>
92
+ </inputType>
93
+ </tool>
94
+ <tool id="cdt.managedbuild.tool.gnu.assembler.exe.release.860205816" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.release">
95
+ <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1581025119" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
96
+ </tool>
97
+ </toolChain>
98
+ </folderInfo>
99
+ <sourceEntries>
100
+ <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
101
+ </sourceEntries>
102
+ </configuration>
103
+ </storageModule>
104
+ <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
105
+ </cconfiguration>
106
+ </storageModule>
107
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
108
+ <project id="PolygonFinder.cdt.managedbuild.target.gnu.exe.1715238056" name="Executable" projectType="cdt.managedbuild.target.gnu.exe"/>
109
+ </storageModule>
110
+ <storageModule moduleId="scannerConfiguration">
111
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
112
+ <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1889533389;cdt.managedbuild.config.gnu.exe.release.1889533389.;cdt.managedbuild.tool.gnu.c.compiler.exe.release.327745473;cdt.managedbuild.tool.gnu.c.compiler.input.635848800">
113
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
114
+ </scannerConfigBuildInfo>
115
+ <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.230092677;cdt.managedbuild.config.gnu.exe.debug.230092677.;cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1037594756;cdt.managedbuild.tool.gnu.c.compiler.input.98002247">
116
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
117
+ </scannerConfigBuildInfo>
118
+ <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.230092677;cdt.managedbuild.config.gnu.exe.debug.230092677.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.2115733171;cdt.managedbuild.tool.gnu.cpp.compiler.input.633512179">
119
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
120
+ </scannerConfigBuildInfo>
121
+ <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1889533389;cdt.managedbuild.config.gnu.exe.release.1889533389.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.899886102;cdt.managedbuild.tool.gnu.cpp.compiler.input.561634342">
122
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
123
+ </scannerConfigBuildInfo>
124
+ </storageModule>
125
+ <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
126
+ <storageModule moduleId="refreshScope" versionNumber="2">
127
+ <configuration configurationName="Release">
128
+ <resource resourceType="PROJECT" workspacePath="/PolygonFinder"/>
129
+ </configuration>
130
+ <configuration configurationName="Debug">
131
+ <resource resourceType="PROJECT" workspacePath="/PolygonFinder"/>
132
+ </configuration>
133
+ </storageModule>
134
+ <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
135
+ <storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
136
+ </cproject>
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>PolygonFinder</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
10
+ <triggers>clean,full,incremental,</triggers>
11
+ <arguments>
12
+ </arguments>
13
+ </buildCommand>
14
+ <buildCommand>
15
+ <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
16
+ <triggers>full,incremental,</triggers>
17
+ <arguments>
18
+ </arguments>
19
+ </buildCommand>
20
+ </buildSpec>
21
+ <natures>
22
+ <nature>org.eclipse.cdt.core.cnature</nature>
23
+ <nature>org.eclipse.cdt.core.ccnature</nature>
24
+ <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
25
+ <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
26
+ </natures>
27
+ </projectDescription>
@@ -0,0 +1,2 @@
1
+ eclipse.preferences.version=1
2
+ org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
@@ -0,0 +1,41 @@
1
+ //============================================================================
2
+ // Name : PolygonFinder.cpp
3
+ // Author : Emanuele Cesaroni
4
+ // Version :
5
+ // Copyright : 2025 Emanuele Cesaroni
6
+ // Description :
7
+ //============================================================================
8
+
9
+ #include <iostream>
10
+ #include <string.h>
11
+ #include <list>
12
+ #include <map>
13
+ #include <string>
14
+ #include "polygon/finder/PolygonFinder.h"
15
+ #include "polygon/bitmaps/Bitmap.h"
16
+ #include "polygon/bitmaps/PngBitmap.h"
17
+ #include "polygon/bitmaps/FastPngBitmap.h"
18
+ #include "polygon/bitmaps/RemoteFastPngBitmap.h"
19
+ #include "polygon/matchers/Matcher.h"
20
+ #include "polygon/matchers/RGBMatcher.h"
21
+ #include "polygon/matchers/RGBNotMatcher.h"
22
+ #include "polygon/matchers/ValueNotMatcher.h"
23
+ #include "polygon/finder/optionparser.h"
24
+ #include "Tests.h"
25
+ using namespace std;
26
+
27
+ int main() {
28
+ Tests *test_suite = new Tests;
29
+ test_suite->test_a();
30
+
31
+ FastPngBitmap png_bitmap("images/labyrinth.png");
32
+ std::cout << "image_w=" << png_bitmap.w() << " image_h=" << png_bitmap.h() << std::endl;
33
+ std::cout << "load_error=" << png_bitmap.error() << std::endl;
34
+
35
+ std::string data_url = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==";
36
+ data_url.erase(0, 22);
37
+ RemoteFastPngBitmap bitmap(&data_url);
38
+ std::cout << "image_w=" << bitmap.w() << " image_h=" << bitmap.h() << std::endl;
39
+ std::cout << "load_error=" << bitmap.error() << std::endl;
40
+ return 0;
41
+ }
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Tests.cpp
3
+ *
4
+ * Created on: 16 feb 2021
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #include "Tests.h"
10
+ #include <iostream>
11
+ #include <string.h>
12
+ #include <list>
13
+ #include <map>
14
+ #include <vector>
15
+ #include <string>
16
+ #include "polygon/finder/PolygonFinder.h"
17
+ #include "polygon/bitmaps/Bitmap.h"
18
+ #include "polygon/bitmaps/PngBitmap.h"
19
+ #include "polygon/bitmaps/FastPngBitmap.h"
20
+ #include "polygon/bitmaps/RemoteFastPngBitmap.h"
21
+ #include "polygon/matchers/Matcher.h"
22
+ #include "polygon/matchers/RGBMatcher.h"
23
+ #include "polygon/matchers/RGBNotMatcher.h"
24
+ #include "polygon/matchers/ValueNotMatcher.h"
25
+ #include "polygon/finder/optionparser.h"
26
+ using namespace std;
27
+
28
+ Tests::Tests() {
29
+ }
30
+
31
+ Tests::~Tests() {
32
+ }
33
+
34
+ void Tests::test_a()
35
+ { string chunk =
36
+ "0000000000000000"\
37
+ "00000000000B0000"\
38
+ "000000AAAAAA0000"\
39
+ "000000BB00FF0000"\
40
+ "000000CC00EE0000"\
41
+ "000000DDDDDD0000"\
42
+ "0000000000000000";
43
+
44
+ std::vector<std::string> arguments = {"--versus=a", "--compress_uniq", "--treemap"};
45
+ ValueNotMatcher matcher('0');
46
+ Bitmap b(chunk, 16);
47
+ PolygonFinder pl(&b, &matcher, nullptr, &arguments);
48
+ ProcessResult *o = pl.process_info();
49
+ std::vector<int> outer_array{11, 1, 6, 2, 6, 3, 6, 4, 6, 5, 11, 5, 11, 4, 11, 3, 11, 2, 11, 1};
50
+ std::vector<int> inner_array{7, 3, 10, 3, 10, 4, 7, 4};
51
+ std::vector<int> array_compare;
52
+ for (std::list<std::map<std::string, std::list<std::list<Point*>*>>>::iterator x = o->polygons.begin(); x != o->polygons.end(); ++x)
53
+ { for (std::list<Point*>::iterator y = (*x)["outer"].front()->begin(); y != (*x)["outer"].front()->end(); ++y)
54
+ { array_compare.push_back((*y)->x);
55
+ array_compare.push_back((*y)->y);
56
+ }
57
+ if (outer_array != array_compare) throw;
58
+ array_compare.clear();
59
+
60
+ for (std::list<std::list<Point*>*>::iterator z = (*x)["inner"].begin(); z != (*x)["inner"].end(); ++z)
61
+ { for (std::list<Point*>::iterator y = (*z)->begin(); y != (*z)->end(); ++y)
62
+ { array_compare.push_back((*y)->x);
63
+ array_compare.push_back((*y)->y);
64
+ }
65
+ }
66
+ if (inner_array != array_compare) throw;
67
+ }
68
+ }
69
+
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Tests.h
3
+ *
4
+ * Created on: 16 feb 2021
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #ifndef TESTS_H_
10
+ #define TESTS_H_
11
+
12
+ class Tests {
13
+ public:
14
+ Tests();
15
+ virtual ~Tests();
16
+ virtual void test_a();
17
+ };
18
+
19
+ #endif /* TESTS_H_ */
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Bitmap.cpp
3
+ *
4
+ * Created on: 25 nov 2018
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #include "Bitmap.h"
10
+ #include <string.h>
11
+ #include <iostream>
12
+ #include <string>
13
+ #include "../matchers/Matcher.h"
14
+
15
+ Bitmap::Bitmap(std::string data, int mod) {
16
+ module = mod;
17
+ raw = data;
18
+ }
19
+
20
+ Bitmap::~Bitmap() {
21
+ }
22
+
23
+ int Bitmap::w() {
24
+ return module;
25
+ }
26
+ int Bitmap::h() {
27
+ return raw.length() / module;
28
+ }
29
+ int Bitmap::error() {
30
+ return 0;
31
+ }
32
+ char Bitmap::value_at(int x, int y) {
33
+ return raw.at(y * module + x);
34
+ }
35
+ void Bitmap::value_set(int x, int y, char value) {
36
+ if (y >= h() || x >= w()) return;
37
+ if (value_at(x, y) != '0') value = 'X';
38
+ raw[y*module + x] = value;
39
+ }
40
+ void Bitmap::print() {
41
+ std::cout << "----------------------------"<< std::endl;
42
+ for (int x = 0; x < h(); x++)
43
+ { std::cout << raw.substr(module * x, module) << std::endl;
44
+ }
45
+ std::cout << "----------------------------"<< std::endl;
46
+ }
47
+ bool Bitmap::pixel_match(int x, int y, Matcher *matcher)
48
+ { return(matcher->match(value_at(x, y)));
49
+ }
50
+ void Bitmap::clear(char value = '0')
51
+ { for (unsigned int i = 0; i < raw.length(); i++) raw[i] = value;
52
+ }