forked from abey79/vpype
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added hatched and show commands, plus various improvements
- Loading branch information
Showing
8 changed files
with
146 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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,29 @@ | ||
# TODO | ||
|
||
## Generator | ||
|
||
- (MVP) load svg | ||
- primitives: segment, square, circle, polygon | ||
- (MVP) script: python file which returns a mls!! | ||
- 3D with _lines_ | ||
- _neonlines_ | ||
|
||
## Filters | ||
|
||
- geometry: mask with rectangle, circle, etc. | ||
- (MVP) matrix: static, dynamic | ||
|
||
## Output | ||
|
||
- (MVP) png | ||
- (MVP) svg option | ||
- scale to phyisical size | ||
- output format (A4, A3, letter, etc.) | ||
- axidraw api | ||
|
||
## hatched | ||
|
||
- pitch can be float | ||
- add logging | ||
- add progress bar? | ||
- add CLI to hatched directly? (rather point to vpype) |
This file contains 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[build-system] | ||
requires = ["setuptools", "wheel", "numpy"] | ||
|
||
[tool.black] | ||
line-length = 95 | ||
target_version = ['py37'] |
This file contains 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 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 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 |
---|---|---|
@@ -1,15 +1,11 @@ | ||
from .vpype import cli, processor, generator | ||
|
||
# noinspection PyUnresolvedReferences | ||
from .transforms import * | ||
|
||
# noinspection PyUnresolvedReferences | ||
# register all commands | ||
from .generators import * | ||
|
||
# noinspection PyUnresolvedReferences | ||
from .hatch import * | ||
from .transforms import * | ||
from .files import * | ||
|
||
# noinspection PyUnresolvedReferences | ||
from .frames import * | ||
from .show import * | ||
|
||
__all__ = ["cli"] |
This file contains 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 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,72 @@ | ||
import cv2 | ||
import hatched | ||
|
||
|
||
import logging | ||
|
||
import click | ||
|
||
from .vpype import cli, generator | ||
|
||
|
||
@cli.command("hatched") | ||
@click.argument("filename", type=click.Path(exists=True)) | ||
@click.option( | ||
"-l", | ||
"--levels", | ||
nargs=3, | ||
type=int, | ||
default=(64, 128, 192), | ||
help="Pixel value of the 3 threshold between black, dark, light and white (0-255)", | ||
) | ||
@click.option("-s", "--scale", default=1.0, help="Scale factor to apply to the image") | ||
@click.option( | ||
"-i", | ||
"--interpolation", | ||
default="linear", | ||
type=click.Choice(["linear", "nearest"], case_sensitive=False), | ||
help="Interpolation used for scaling", | ||
) | ||
@click.option("-b", "--blur", default=0, type=int, help="Blur radius to apply to the image") | ||
@click.option("-p", "--pitch", default=5, type=int, help="Densest hatching pitch (pixels)") | ||
@click.option( | ||
"-x", "--invert", is_flag=True, help="Invert the image (and levels) before processing" | ||
) | ||
@click.option("-c", "--circular", is_flag=True, help="Use circular instead of diagonal hatches") | ||
@click.option( | ||
"-d", "--show-plot", is_flag=True, help="Display the contours and resulting pattern" | ||
) | ||
@generator | ||
def hatched_gen( | ||
filename: str, | ||
levels, | ||
scale: float, | ||
interpolation: str, | ||
blur: int, | ||
pitch: int, | ||
invert: bool, | ||
circular: bool, | ||
show_plot: bool, | ||
): | ||
""" | ||
Generate hatched pattern from an image (see `hatched` library) | ||
""" | ||
logging.info(f"generating hatches from {filename}") | ||
|
||
interp = cv2.INTER_LINEAR | ||
if interpolation == 'nearest': | ||
interp = cv2.INTER_NEAREST | ||
|
||
return hatched.hatch( | ||
file_path=filename, | ||
levels=levels, | ||
image_scale=scale, | ||
interpolation=interp, | ||
blur_radius=blur, | ||
hatch_pitch=pitch, | ||
invert=invert, | ||
circular=circular, | ||
show_plot=show_plot, | ||
h_mirror=False, # this is best handled by vpype | ||
save_svg=False, # this is best handled by vpype | ||
) |
This file contains 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,32 @@ | ||
import logging | ||
|
||
import click | ||
from shapely.geometry import MultiLineString | ||
import matplotlib.pyplot as plt | ||
|
||
from .vpype import cli, processor | ||
|
||
|
||
@cli.command() | ||
@click.option("-a", "--show-axes", is_flag=True, help="display matplotlib axes") | ||
@click.option("-g", "--show-grid", is_flag=True, help="display matplotlib grid (implies -a)") | ||
@processor | ||
def show(mls: MultiLineString, show_axes: bool, show_grid: bool): | ||
""" | ||
Display the geometry using matplotlib | ||
""" | ||
logging.info(f"running matplotlib display") | ||
|
||
for ls in mls: | ||
plt.plot(*ls.xy, "-k", lw=0.5) | ||
plt.gca().invert_yaxis() | ||
plt.axis("equal") | ||
if show_axes or show_grid: | ||
plt.axis("on") | ||
else: | ||
plt.axis("off") | ||
if show_grid: | ||
plt.grid("on") | ||
plt.show() | ||
|
||
return mls |