Skip to content
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

Optimize Token VBL Generation #1218

Closed
4 tasks done
Phergus opened this issue Feb 1, 2020 · 13 comments
Closed
4 tasks done

Optimize Token VBL Generation #1218

Phergus opened this issue Feb 1, 2020 · 13 comments
Assignees
Labels
feature Adding functionality that adds value macro changes This issue adds or changes macro functions. Extra work is required (testing, wiki, code editor) tested This issue has been QA tested by someone other than the developer.

Comments

@Phergus
Copy link
Contributor

Phergus commented Feb 1, 2020

Is your feature request related to a problem? Please describe.
Token VBL generation produces very complex VBL structures leading to poor performance. Especially when used on map images.

Describe the solution you'd like
Use the polygon simplification of the JTS libs to reduce the number of points and edges produced by the VBL generation.

TODO:

  • ALL the UI, but must first determine what UI is needed
  • Create Issue
  • Take work off the UI thread?
  • Going to need some wiki docs

Additional context
JTS Lib Simplify

Campaign file with two maps and closed/open object images.
VBL Simplified Test-cmpgn.zip

@Phergus Phergus added feature Adding functionality that adds value documentation needed Missing, out-of-date or bad documentation labels Feb 1, 2020
@Phergus
Copy link
Contributor Author

Phergus commented Feb 1, 2020

D-P simplify cannot handle images with holes but does a great job on images that are otherwise solid.

MT 1.5.12
Token VBL 1 5 12

MT 1.6 develop
Token VBL 1 6 dev

See campaign attached to top for closed form images.

@Phergus
Copy link
Contributor Author

Phergus commented Feb 1, 2020

Need to test with the other simplify methods.

Update: The other simplify methods are also unable to handle shapes with holes in them.

@JamzTheMan
Copy link
Member

I think I one of the methods had a second option that may need to be explored.

I assume we want holes for things like caverns and such.

I'm liking the reduction in points though!

@Phergus
Copy link
Contributor Author

Phergus commented Feb 2, 2020

Need to look at the options and see if they can help.

@JamzTheMan
Copy link
Member

Lots of options added to the VBL panel 😨
Most are temporary until we find the best JTS method (I don't think we need to supply an option here, and will always optimize I think is best)

Color picking isn't enabled yet but I see that replacing "Sensitivity" (the old Alpha Sensitivity" and let you pick a RGBA instead. So you could pick "black" vs just alpha.

Added an Inverse button so you can generate VBL around an object vs over now, good for maps!

FWIW the Image -> Area is the longest (10+ seconds for maps) but the Optimization is in milliseconds usually so I started to cache the Image -> Area work and it's only redone if you change sensitivity or click the generate button. There is still some bugs on opening up the dialog and keeping state for that so, ya. More to do...

image

@JamzTheMan
Copy link
Member

JamzTheMan commented Feb 22, 2020

Oh, and I added point counts to the preview for debugging but thinking of leaving it in permanently, or at least the optimized number)

AND also added zooming/panning to the preview window! Gotta see those pixels!

Here are some maps I used for testing. It Seems to handle holes ok in all JTS optimizations...
(I photoshopped them to remove backgrounds and replace with transparency)

image

Phergus added a commit that referenced this issue Feb 22, 2020
@Phergus
Copy link
Contributor Author

Phergus commented Feb 22, 2020

Try these:
Square Hollow

MapTool VBL Demo 01 VBL Mask bigger

@JamzTheMan
Copy link
Member

Now using .setEnsureValid(false) and not forcing valid "geometry" any more seems to fix the issue.

May need to test a few more odd shapes here and there...

@JamzTheMan
Copy link
Member

Optimized the image translation to Area, by slicing the image up I got over 32x performance increase on this map!

*Note I was going to multi-thread it into slices but even before that, just by slicing the image into 100x100 chunks, the Area.add math is a lot less intensive, The following image use to take 32 seconds and now averages < 1 second.

I may still throw this into a thread pool and see if we can do this in 100-200 ms instead for even better UX (right now this is still on the UI thread...)

Cave1---Transparent

@JamzTheMan
Copy link
Member

OK, I believe I'm all done with this issue, barring any bugs/suggestions.

Here is a macro for fun and documented usage:

[h: sensitivity = 10]
[h: inverse = 0]

<!-- Black -->
[h: red   = 0]
[h: green = 0]
[h: blue  = 0]
[h: alpha = 255]

[h: level = 2]
[h: method = "Douglas Peucker"]
[h: method2 = "Topology Preserving"]
[h: method2 = "VW Simplifier"]
[h: method2 = "No Optimization"]

<!-- Options with color -->
[h: options = json.set("{}", "shape", "auto", "inverse", inverse, "r", red, "g", green, "b", blue, "a", alpha)]

<!-- Options with default color of transparent -->
[h: options = json.set("{}", "shape", "auto", "sensitivity", sensitivity, "inverse", inverse, "level", level, "method", method)]

[h: startTime = json.get(getInfo("Client"), "timeInMs")]
[h: pointCount = setTokenVBL(options)]
[h: endTime = json.get(getInfo("Client"), "timeInMs")]

[h: timeToComplete = endTime - startTime]

Results using <i>{method}</i>: {pointCount} points, and took {timeToComplete}ms

@Phergus Phergus added macro changes This issue adds or changes macro functions. Extra work is required (testing, wiki, code editor) and removed documentation needed Missing, out-of-date or bad documentation labels Apr 1, 2020
@Phergus
Copy link
Contributor Author

Phergus commented Apr 1, 2020

Intro to Tokens - VBL page updated
setTokenVBL page updated

@Phergus Phergus added the tested This issue has been QA tested by someone other than the developer. label Apr 2, 2020
@Phergus
Copy link
Contributor Author

Phergus commented Apr 2, 2020

Tested and working as expected. Closing.

@Phergus Phergus closed this as completed Apr 2, 2020
Merudo added a commit to Merudo/maptool that referenced this issue Apr 14, 2020
- Fix VBL color cursor not longing changing to the crosshair cursor after being used once
- Issue discussed in RPTools#1218
@Merudo
Copy link
Member

Merudo commented Apr 14, 2020

There is a small bug in a token editor: after the VBL color has been picked once, the cursor no longer changes to the crosshair cursor. PR #1544 fixes this.

Merudo added a commit to Merudo/maptool that referenced this issue Apr 14, 2020
- Fix VBL color cursor not longing changing to the crosshair cursor after being used once
- Issue discussed in RPTools#1218
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adding functionality that adds value macro changes This issue adds or changes macro functions. Extra work is required (testing, wiki, code editor) tested This issue has been QA tested by someone other than the developer.
Projects
None yet
Development

No branches or pull requests

3 participants