Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
a855d230
Commit
a855d230
authored
Apr 18, 2015
by
S. Garrido
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
completing and fixing gen_pattern.py for 2.4 branch
parent
8c2bde2a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
32 deletions
+29
-32
gen_pattern.py
doc/pattern_tools/gen_pattern.py
+29
-32
No files found.
doc/pattern_tools/gen_pattern.py
View file @
a855d230
#!/usr/bin/env python
#!/usr/bin/env python
"""gen_pattern.py
"""gen_pattern.py
To run:
Usage example:
-c 10 -r 12 -o out.svg
python gen_pattern.py -o out.svg -r 11 -c 8 -T circles -s 20.0 -R 5.0 -u mm -w 216 -h 279
-T type of pattern, circles, acircles, checkerboard
-s --square_size size of squares in pattern
-o, --output - output file (default out.svg)
-u --units mm, inches, px, m
-r, --rows - pattern rows (default 11)
-w page width in units
-c, --columns - pattern columns (default 8)
-h page height in units
-T, --type - type of pattern, circles, acircles, checkerboard (default circles)
-s, --square_size - size of squares in pattern (default 20.0)
-R, --radius_rate - circles_radius = square_size/radius_rate (default 5.0)
-u, --units - mm, inches, px, m (default mm)
-w, --page_width - page width in units (default 216)
-h, --page_height - page height in units (default 279)
-H, --help - show help
"""
"""
from
svgfig
import
*
from
svgfig
import
*
...
@@ -16,18 +22,20 @@ import sys
...
@@ -16,18 +22,20 @@ import sys
import
getopt
import
getopt
class
PatternMaker
:
class
PatternMaker
:
def
__init__
(
self
,
cols
,
rows
,
output
,
units
,
square_size
,
page_width
,
page_height
):
def
__init__
(
self
,
cols
,
rows
,
output
,
units
,
square_size
,
radius_rate
,
page_width
,
page_height
):
self
.
cols
=
cols
self
.
cols
=
cols
self
.
rows
=
rows
self
.
rows
=
rows
self
.
output
=
output
self
.
output
=
output
self
.
units
=
units
self
.
units
=
units
self
.
square_size
=
square_size
self
.
square_size
=
square_size
self
.
radius_rate
=
radius_rate
self
.
width
=
page_width
self
.
width
=
page_width
self
.
height
=
page_height
self
.
height
=
page_height
self
.
g
=
SVG
(
"g"
)
# the svg group container
self
.
g
=
SVG
(
"g"
)
# the svg group container
def
makeCirclesPattern
(
self
):
def
makeCirclesPattern
(
self
):
spacing
=
self
.
square_size
spacing
=
self
.
square_size
r
=
spacing
/
5.0
#radius is a 5th of the spacing TODO parameteriz
e
r
=
spacing
/
self
.
radius_rat
e
for
x
in
range
(
1
,
self
.
cols
+
1
):
for
x
in
range
(
1
,
self
.
cols
+
1
):
for
y
in
range
(
1
,
self
.
rows
+
1
):
for
y
in
range
(
1
,
self
.
rows
+
1
):
dot
=
SVG
(
"circle"
,
cx
=
x
*
spacing
,
cy
=
y
*
spacing
,
r
=
r
,
fill
=
"black"
)
dot
=
SVG
(
"circle"
,
cx
=
x
*
spacing
,
cy
=
y
*
spacing
,
r
=
r
,
fill
=
"black"
)
...
@@ -35,7 +43,7 @@ class PatternMaker:
...
@@ -35,7 +43,7 @@ class PatternMaker:
def
makeACirclesPattern
(
self
):
def
makeACirclesPattern
(
self
):
spacing
=
self
.
square_size
spacing
=
self
.
square_size
r
=
spacing
/
5.0
r
=
spacing
/
self
.
radius_rate
for
i
in
range
(
0
,
self
.
rows
):
for
i
in
range
(
0
,
self
.
rows
):
for
j
in
range
(
0
,
self
.
cols
):
for
j
in
range
(
0
,
self
.
cols
):
dot
=
SVG
(
"circle"
,
cx
=
((
j
*
2
+
i
%
2
)
*
spacing
)
+
spacing
,
cy
=
self
.
height
-
(
i
*
spacing
+
spacing
),
r
=
r
,
fill
=
"black"
)
dot
=
SVG
(
"circle"
,
cx
=
((
j
*
2
+
i
%
2
)
*
spacing
)
+
spacing
,
cy
=
self
.
height
-
(
i
*
spacing
+
spacing
),
r
=
r
,
fill
=
"black"
)
...
@@ -43,37 +51,23 @@ class PatternMaker:
...
@@ -43,37 +51,23 @@ class PatternMaker:
def
makeCheckerboardPattern
(
self
):
def
makeCheckerboardPattern
(
self
):
spacing
=
self
.
square_size
spacing
=
self
.
square_size
r
=
spacing
/
5.0
for
x
in
range
(
1
,
self
.
cols
+
1
):
for
x
in
range
(
1
,
self
.
cols
+
1
):
for
y
in
range
(
1
,
self
.
rows
+
1
):
for
y
in
range
(
1
,
self
.
rows
+
1
):
#TODO make a checkerboard pattern
if
x
%
2
==
y
%
2
:
dot
=
SVG
(
"circle"
,
cx
=
x
*
spacing
,
cy
=
y
*
spacing
,
r
=
r
,
fill
=
"black"
)
dot
=
SVG
(
"rect"
,
x
=
x
*
spacing
,
y
=
y
*
spacing
,
width
=
spacing
,
height
=
spacing
,
stroke_width
=
"0"
,
fill
=
"black"
)
self
.
g
.
append
(
dot
)
self
.
g
.
append
(
dot
)
def
save
(
self
):
def
save
(
self
):
c
=
canvas
(
self
.
g
,
width
=
"
%
d
%
s"
%
(
self
.
width
,
self
.
units
),
height
=
"
%
d
%
s"
%
(
self
.
height
,
self
.
units
),
viewBox
=
"0 0
%
d
%
d"
%
(
self
.
width
,
self
.
height
))
c
=
canvas
(
self
.
g
,
width
=
"
%
d
%
s"
%
(
self
.
width
,
self
.
units
),
height
=
"
%
d
%
s"
%
(
self
.
height
,
self
.
units
),
viewBox
=
"0 0
%
d
%
d"
%
(
self
.
width
,
self
.
height
))
c
.
inkview
(
self
.
output
)
c
.
inkview
(
self
.
output
)
def
makePattern
(
cols
,
rows
,
output
,
p_type
,
units
,
square_size
,
page_width
,
page_height
):
width
=
page_width
spacing
=
square_size
height
=
page_height
r
=
spacing
/
5.0
g
=
SVG
(
"g"
)
# the svg group container
for
x
in
range
(
1
,
cols
+
1
):
for
y
in
range
(
1
,
rows
+
1
):
if
"circle"
in
p_type
:
dot
=
SVG
(
"circle"
,
cx
=
x
*
spacing
,
cy
=
y
*
spacing
,
r
=
r
,
fill
=
"black"
)
g
.
append
(
dot
)
c
=
canvas
(
g
,
width
=
"
%
d
%
s"
%
(
width
,
units
),
height
=
"
%
d
%
s"
%
(
height
,
units
),
viewBox
=
"0 0
%
d
%
d"
%
(
width
,
height
))
c
.
inkview
(
output
)
def
main
():
def
main
():
# parse command line options, TODO use argparse for better doc
# parse command line options, TODO use argparse for better doc
try
:
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"
ho:c:r:T:u:s:w:h:"
,
[
"help"
,
"output"
,
"columns"
,
"rows
"
,
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"
Ho:c:r:T:u:s:R:w:h:"
,
[
"help"
,
"output="
,
"columns="
,
"rows=
"
,
"type
"
,
"units"
,
"square_size"
,
"page_width
"
,
"type
="
,
"units="
,
"square_size="
,
"radius_rate=
"
,
"page_
height
"
])
"page_
width="
,
"page_height=
"
])
except
getopt
.
error
,
msg
:
except
getopt
.
error
,
msg
:
print
msg
print
msg
print
"for help use --help"
print
"for help use --help"
...
@@ -84,11 +78,12 @@ def main():
...
@@ -84,11 +78,12 @@ def main():
p_type
=
"circles"
p_type
=
"circles"
units
=
"mm"
units
=
"mm"
square_size
=
20.0
square_size
=
20.0
radius_rate
=
5.0
page_width
=
216
#8.5 inches
page_width
=
216
#8.5 inches
page_height
=
279
#11 inches
page_height
=
279
#11 inches
# process options
# process options
for
o
,
a
in
opts
:
for
o
,
a
in
opts
:
if
o
in
(
"-
h
"
,
"--help"
):
if
o
in
(
"-
H
"
,
"--help"
):
print
__doc__
print
__doc__
sys
.
exit
(
0
)
sys
.
exit
(
0
)
elif
o
in
(
"-r"
,
"--rows"
):
elif
o
in
(
"-r"
,
"--rows"
):
...
@@ -103,11 +98,13 @@ def main():
...
@@ -103,11 +98,13 @@ def main():
units
=
a
units
=
a
elif
o
in
(
"-s"
,
"--square_size"
):
elif
o
in
(
"-s"
,
"--square_size"
):
square_size
=
float
(
a
)
square_size
=
float
(
a
)
elif
o
in
(
"-R"
,
"--radius_rate"
):
radius_rate
=
float
(
a
)
elif
o
in
(
"-w"
,
"--page_width"
):
elif
o
in
(
"-w"
,
"--page_width"
):
page_width
=
float
(
a
)
page_width
=
float
(
a
)
elif
o
in
(
"-h"
,
"--page_height"
):
elif
o
in
(
"-h"
,
"--page_height"
):
page_height
=
float
(
a
)
page_height
=
float
(
a
)
pm
=
PatternMaker
(
columns
,
rows
,
output
,
units
,
square_size
,
page_width
,
page_height
)
pm
=
PatternMaker
(
columns
,
rows
,
output
,
units
,
square_size
,
radius_rate
,
page_width
,
page_height
)
#dict for easy lookup of pattern type
#dict for easy lookup of pattern type
mp
=
{
"circles"
:
pm
.
makeCirclesPattern
,
"acircles"
:
pm
.
makeACirclesPattern
,
"checkerboard"
:
pm
.
makeCheckerboardPattern
}
mp
=
{
"circles"
:
pm
.
makeCirclesPattern
,
"acircles"
:
pm
.
makeACirclesPattern
,
"checkerboard"
:
pm
.
makeCheckerboardPattern
}
mp
[
p_type
]()
mp
[
p_type
]()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment