Added options to configure Bentley Ottmann
This commit is contained in:
parent
7f5069387d
commit
920e0aefc2
@ -42,17 +42,27 @@
|
||||
<separator/>
|
||||
<vbox>
|
||||
<label appearance="header">Trimming</label>
|
||||
<param name="trimming_path_types" type="optiongroup" appearance="combo" gui-text="Trimming selection" gui-description="Process open paths by other open paths, closed paths by other closed paths, or all paths by all other paths. This selection does not apply for paths which intersect themselves!">
|
||||
<option value="both">all:all paths</option>
|
||||
<option value="open_paths">open:open paths</option>
|
||||
<option value="closed_paths">closed:closed paths</option>
|
||||
</param>
|
||||
<param name="trimming_path_types" type="optiongroup" appearance="combo" gui-text="Trimming selection" gui-description="Process open paths by other open paths, closed paths by other closed paths, or all paths by all other paths. This selection does not apply for paths which intersect themselves!">
|
||||
<option value="both">all:all paths</option>
|
||||
<option value="open_paths">open:open paths</option>
|
||||
<option value="closed_paths">closed:closed paths</option>
|
||||
</param>
|
||||
<param name="draw_trimmed" type="bool" gui-text="Draw trimmed lines">false</param>
|
||||
<param name="combine_nonintersects" type="bool" gui-text="Chain + combine non-intersected lines" gui-description="This will colorize all paths segments which were not intersected ('non-intersected lines'). If the whole path was not intersected at all, it will get another color ('non-intersected paths').">true</param>
|
||||
<param name="remove_duplicates" type="bool" gui-text="Remove duplicate trim lines">true</param>
|
||||
<param name="reverse_removal_order" type="bool" gui-text="Reverse removal order" gui-description="Reverses the order of removal. Relevant for keeping certain styles of elements">false</param>
|
||||
<param name="bezier_trimming" type="bool" gui-text="Trim original beziers (not working yet)" gui-description="If enabled we try to split the original bezier paths at the intersections points by finding the correct bezier segments and calculating t parameters from trimmed sub split lines. Not working yet. Will just print debug info if debug is enabled.">true</param>
|
||||
<param name="keep_original_after_trim" type="bool" gui-text="Keep original paths after trimming">false</param>
|
||||
<label appearance="header">Bentley Ottmann Sweep Line Settings</label>
|
||||
<param name="bent_ott_use_ignore_segment_endings" type="bool" gui-text="Ignore segment endings" gui-description="Whether to ignore intersections of line segments when both their end points form the intersection point">true</param>
|
||||
<param name="bent_ott_use_debug" type="bool" gui-text="Debug">false</param>
|
||||
<param name="bent_ott_use_verbose" type="bool" gui-text="Verbose">false</param>
|
||||
<param name="bent_ott_use_paranoid" type="bool" gui-text="Paranoid checks">false</param>
|
||||
<param name="bent_ott_use_vertical" type="bool" gui-text="Support vertical segments">true</param>
|
||||
<param name="bent_ott_number_type" type="optiongroup" appearance="combo" gui-text="Number type">
|
||||
<option value="native">native (default)</option>
|
||||
<option value="numpy">numpy</option>
|
||||
</param>
|
||||
</vbox>
|
||||
</hbox>
|
||||
</page>
|
||||
|
@ -452,6 +452,13 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
|
||||
pars.add_argument("--reverse_removal_order", type=inkex.Boolean, default=False, help="Reverses the order of removal. Relevant for keeping certain styles of elements")
|
||||
pars.add_argument("--keep_original_after_trim", type=inkex.Boolean, default=False, help="Keep original paths after trimming")
|
||||
|
||||
pars.add_argument("--bent_ott_use_ignore_segment_endings", type=inkex.Boolean, default=True, help="Whether to ignore intersections of line segments when both their end points form the intersection point")
|
||||
pars.add_argument("--bent_ott_use_debug", type=inkex.Boolean, default=False)
|
||||
pars.add_argument("--bent_ott_use_verbose", type=inkex.Boolean, default=False)
|
||||
pars.add_argument("--bent_ott_use_paranoid", type=inkex.Boolean, default=False)
|
||||
pars.add_argument("--bent_ott_use_vertical", type=inkex.Boolean, default=True)
|
||||
pars.add_argument("--bent_ott_number_type", default="native")
|
||||
|
||||
#Style - General Style
|
||||
pars.add_argument("--strokewidth", type=float, default=1.0, help="Stroke width (px)")
|
||||
pars.add_argument("--dotsize_intersections", type=int, default=30, help="Dot size (px) for self-intersecting and global intersection points")
|
||||
@ -719,7 +726,34 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
|
||||
now we intersect the sub split lines to find the global intersection points using Bentley-Ottmann algorithm (contains self-intersections too!)
|
||||
'''
|
||||
if so.draw_trimmed is True:
|
||||
try:
|
||||
try:
|
||||
#some config for Bentley Ottmann
|
||||
poly_point_isect.USE_IGNORE_SEGMENT_ENDINGS = so.bent_ott_use_ignore_segment_endings
|
||||
poly_point_isect.USE_DEBUG = so.bent_ott_use_debug
|
||||
poly_point_isect.USE_VERBOSE = so.bent_ott_use_verbose
|
||||
if so.show_debug is False:
|
||||
poly_point_isect.USE_VERBOSE = False
|
||||
poly_point_isect.USE_PARANOID = so.bent_ott_use_paranoid
|
||||
poly_point_isect.USE_VERTICAL = so.bent_ott_use_vertical
|
||||
NUMBER_TYPE = so.bent_ott_number_type
|
||||
if NUMBER_TYPE == 'native':
|
||||
Real = float
|
||||
NUM_EPS = Real("1e-10")
|
||||
NUM_INF = Real(float("inf"))
|
||||
elif NUMBER_TYPE == 'numpy':
|
||||
import numpy
|
||||
Real = numpy.float64
|
||||
del numpy
|
||||
NUM_EPS = Real("1e-10")
|
||||
NUM_INF = Real(float("inf"))
|
||||
poly_point_isect.Real = Real
|
||||
poly_point_isect.NUM_EPS = NUM_EPS
|
||||
poly_point_isect.NUM_INF = NUM_INF
|
||||
poly_point_isect.NUM_EPS_SQ = NUM_EPS * NUM_EPS
|
||||
poly_point_isect.NUM_ZERO = Real(0.0)
|
||||
poly_point_isect.NUM_ONE = Real(1.0)
|
||||
|
||||
|
||||
allSubSplitLineStrings = []
|
||||
for subSplitLine in subSplitLineArray:
|
||||
csp = subSplitLine.path.to_arrays()
|
||||
@ -735,10 +769,12 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
|
||||
|
||||
# Very small step sizes over near-vertical lines can cause errors. We hide exceptions with try-catch, thus we disabled the debugging in poly_point_isect:
|
||||
# by setting USE_DEBUG = False (True was default setting)
|
||||
if so.show_debug is True:
|
||||
self.msg("Going to calculate intersections using Bentley Ottmann Sweep Line Algorithm")
|
||||
globalIntersectionPoints = MultiPoint(isect_segments(allSubSplitLineStrings, validate=True))
|
||||
|
||||
if so.show_debug is True:
|
||||
self.msg("global intersection points count: {}".format(len(globalIntersectionPoints)))
|
||||
self.msg("global intersection points count: {}".format(len(globalIntersectionPoints)))
|
||||
if len(globalIntersectionPoints) > 0:
|
||||
if so.visualize_global_intersections is True:
|
||||
self.visualize_global_intersections(globalIntersectionPoints)
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
# BentleyOttmann sweep-line implementation
|
||||
# (for finding all intersections in a set of line segments)
|
||||
|
||||
from __future__ import annotations
|
||||
import inkex
|
||||
|
||||
__all__ = (
|
||||
"isect_segments",
|
||||
@ -26,7 +26,7 @@ __all__ = (
|
||||
# their end points form the intersection point.
|
||||
USE_IGNORE_SEGMENT_ENDINGS = True
|
||||
|
||||
USE_DEBUG = False
|
||||
USE_DEBUG = True
|
||||
|
||||
USE_VERBOSE = False
|
||||
|
||||
@ -590,7 +590,7 @@ def isect_segments_impl(segments, *, include_segments=False, validate=True) -> l
|
||||
|
||||
while len(queue.events_scan) > 0:
|
||||
if USE_VERBOSE:
|
||||
print(len(queue.events_scan), sweep_line._current_event_point_x)
|
||||
inkex.utils.debug("event {}: x={}".format(len(queue.events_scan), sweep_line._current_event_point_x))
|
||||
p, e_ls = queue.poll()
|
||||
for events_current in e_ls:
|
||||
if events_current:
|
||||
|
Reference in New Issue
Block a user