-
-
Notifications
You must be signed in to change notification settings - Fork 47
fix(core)!: prevent holes during SVG generation #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
72a6a7a
modifications to svg extraction
Krasner aac9407
updated method for hole-free svg
Krasner 7e5ac60
clean up
Krasner 37309f0
When merging contours consider thickness - set a minimum thickness to…
Krasner b37807e
update python arguments to include min_thickness
Krasner 761fd24
formatting
Krasner 7cbded3
missing bracket
Krasner 51348fc
Merge branch 'dev' into dev/core-opt
Krasner b4ee348
add emsdk dev ownsership
Krasner 9efab7c
allow dev permissions to uv
Krasner 02cc692
formatting
Krasner 0e973cb
hardcode userid and groupid to be 1000 to match host machine - is thi…
Krasner 8e35991
remove dev user. everything should be root
Krasner 680922e
Merge branch 'dev' into dev/core-opt
Krasner 6da4d6f
Install UV in development Dockerfile
Krasner 7aa21d7
Refactor Dockerfile.dev to match dev branch
Krasner b3dc95c
Merge branch 'dev' into dev/core-opt
Krasner 0017754
Merge branch 'dev' into dev/core-opt
Krasner b728615
remove rw
Krasner 8160c24
Apply suggestions from code review
Krasner 1cb1f87
Apply suggestions from code review
Krasner b9864ce
docs(core): doxygen comment for coupled_smooth_junctions in contours.h
Ryan-Millard c2bc23b
docs(core): doxygen comment for getPixel and analyzeJunctions in graph.h
Ryan-Millard df07f98
chore(core): remove console prints in contours.cpp
Ryan-Millard b3e33ef
docs(core): add doxygen comment to min_thickness of ImageToSvgConfig …
Ryan-Millard d6f29a1
chore: delete accidentally-committed image
Ryan-Millard 9360efa
clean up old code
Krasner b3d016e
update readme svgs
Krasner 7dcf8aa
Merge branch 'dev' into dev/core-opt
Krasner b2a8c27
formatting/ apply PR suggestions
Krasner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #ifndef DOUGLAS_PEUCKER_H | ||
| #define DOUGLAS_PEUCKER_H | ||
|
|
||
| #include "internal/contours.h" | ||
|
|
||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| /** | ||
| * `@brief` Douglas-Peucker contour point reduction with junction locking and retraction bounds. | ||
| * | ||
| * Reduces each contour's point count while preserving junctions and preventing gaps. | ||
| * Fixed junctions marked by `fixed[i][k] != 0` are kept as exact shared endpoints. | ||
| * Simplification is bounded to never retract a boundary inward past the inter-region | ||
| * overlap margin, preventing gaps between neighboring regions. Kept points are emitted | ||
| * as straight-line quadratic Bezier segments for compatibility with existing SVG output. | ||
| * | ||
| * `@param` chains Input polyline chains | ||
| * `@param` fixed Junction mask: fixed[i][k] != 0 marks point k of chain i as a junction to preserve | ||
| * `@param` results Output straight-line QuadBezier segments for each chain | ||
| * `@param` eps Overall deviation tolerance in pixels (overridable via IMG2NUM_DP_EPS env var) | ||
| * | ||
| * `@note` retract_eps (max inward boundary move) defaults to min(eps, 0.5px) and can be | ||
| * overridden via IMG2NUM_DP_RETRACT environment variable. | ||
| */ | ||
| void dp_curve_reduction( | ||
| const std::vector<std::vector<Point>>& chains, const std::vector<std::vector<uint8_t>>& fixed, | ||
| std::vector<std::vector<QuadBezier>>& results, float eps | ||
| ); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,36 @@ class Graph { | |
| void hash_node_ids(void); | ||
| void process_overlapping_edges(); | ||
|
|
||
| /** | ||
| * `@brief` Safely retrieves a pixel value from a binary image with bounds checking. | ||
| * | ||
| * `@param` img Binary image buffer | ||
| * `@param` w Image width | ||
| * `@param` h Image height | ||
| * `@param` x Pixel x-coordinate | ||
| * `@param` y Pixel y-coordinate | ||
| * `@return` Pixel value at (x, y), or 0 if out of bounds | ||
| */ | ||
| inline uint8_t getPixel(const std::vector<uint8_t>& img, int w, int h, int x, int y) { | ||
| if (x < 0 || x >= w || y < 0 || y >= h) | ||
| return 0; // Boundary check | ||
| return img[y * w + x]; | ||
| } | ||
|
Comment on lines
+42
to
+56
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably schedule a refactor to make the library use the image class wherever possible because we repeat this pattern a lot. |
||
|
|
||
| /** | ||
| * `@brief` Analyzes a skeleton image to detect junction points using 8-neighbor | ||
| * crossing-number. | ||
| * | ||
| * Scans the skeleton image and marks pixels as junctions where three or more branches meet, | ||
| * using the crossing-number method (counts 0→1 transitions in the 8-neighbor ring). | ||
| * | ||
| * `@param` skel Binary skeleton image (nonzero = skeleton pixel) | ||
| * `@param` w Image width | ||
| * `@param` h Image height | ||
| * `@return` Junction mask with nonzero entries marking junction pixels | ||
| */ | ||
| std::vector<uint8_t> analyzeJunctions(const std::vector<uint8_t>& skel, int w, int h); | ||
|
Ryan-Millard marked this conversation as resolved.
|
||
|
|
||
| public: | ||
| inline Graph(std::unique_ptr<std::vector<Node_ptr>>& nodes, int width, int height) | ||
| : m_nodes(std::move(nodes)) | ||
|
|
@@ -71,7 +101,7 @@ class Graph { | |
| void discover_edges( | ||
| const std::vector<int32_t>& region_labels, const int32_t width, const int32_t height | ||
| ); | ||
| void merge_small_area_nodes(const int32_t min_area); | ||
| void merge_small_area_nodes(const int32_t min_area, const int32_t min_thickness = 0); | ||
| void compute_contours(); | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #ifndef SHARED_CONTOURS_H | ||
| #define SHARED_CONTOURS_H | ||
|
|
||
| #include "internal/contours.h" // QuadBezier | ||
| #include "internal/Point.h" | ||
|
|
||
| #include <cstdint> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| /** | ||
| * `@brief` Build crack-grid shared boundary loops for each region. | ||
| * | ||
| * Builds region boundaries on the pixel-corner ("crack") grid rather than on | ||
| * pixel centres. Shared edges are extracted once, simplified once, and reused | ||
| * by both adjacent regions so neighbouring loops stay exactly coincident. | ||
| * | ||
| * `@param` labels Per-pixel region ids in row-major order (`w * h` entries). | ||
| * `@param` w Image width in pixels. | ||
| * `@param` h Image height in pixels. | ||
| * `@param` eps Curve-fit tolerance applied to each canonical edge. | ||
| * `@return` Per-region closed boundary loops in corner coordinates. | ||
| */ | ||
| std::unordered_map<int32_t, std::vector<std::vector<QuadBezier>>> | ||
| build_shared_loops(const std::vector<int32_t>& labels, int w, int h, float eps); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.