Add json only input.
This commit is contained in:
parent
c9c98f91dc
commit
afbacca3f4
21 changed files with 89611 additions and 118 deletions
10
README.md
10
README.md
|
@ -9,10 +9,10 @@ docker pull jmsgrogan/python-generator
|
||||||
Launch:
|
Launch:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python generate_image.py -height 120.0 -radius 150.0 -r 100.0 -g 0.0 -b 0.0 -o 1 -s 0
|
python generate_shape.py <json>
|
||||||
|
python apply_texture.py <json>
|
||||||
|
python final_render.py <json>
|
||||||
```
|
```
|
||||||
|
|
||||||
`-o` is a unique output identifier added to file names.
|
The output for the first two scripts is a file `$prefix_lamp.png` in the launch directory.
|
||||||
`-s` is the generation stage. Stage 0 generates shapes. Stage 1 generates textures.
|
The output for the last script is three files `$prefix_lamp_kitchen.png`, `$prefix_lamp_hall.png`, `$prefix_lamp_landing.png` in the launch directory.
|
||||||
|
|
||||||
The output is a file `lamp_$o.png` in the launch directory, where `$o` is the unique output identifier. Three temporary files with suffix `_$o.stl` are also created.
|
|
||||||
|
|
|
@ -1,66 +1,59 @@
|
||||||
|
import os
|
||||||
|
import os
|
||||||
|
import product_gen.generate_lamp_base
|
||||||
|
import product_gen.generate_shades
|
||||||
|
import product_gen.render_lamp
|
||||||
|
|
||||||
import sys
|
def generate(shape, height, radius, color, output_prefix,
|
||||||
from argparse import ArgumentParser
|
is_final=False):
|
||||||
# freecad setup
|
thickness = 3.0
|
||||||
FREECADPATH = "/usr/lib/freecad/lib/"
|
|
||||||
sys.path.append(FREECADPATH)
|
|
||||||
import numpy as np
|
|
||||||
import FreeCAD
|
|
||||||
import Part
|
|
||||||
|
|
||||||
def generate_chord(height, radius, thickness):
|
prefix = os.getcwd() + "/" + output_prefix + "/" + output_prefix
|
||||||
|
|
||||||
edge0 = Part.makeLine((0.0, height, 0),
|
if shape == "cone":
|
||||||
(-radius, 0.0, 0))
|
shade = product_gen.generate_shades.generate_cone_shade(height, radius, thickness)
|
||||||
edge1 = Part.makeLine((-radius, 0.0, 0),
|
elif shape == "mesh":
|
||||||
(-radius -thickness, 0.0, 0))
|
shade = product_gen.generate_shades.generate_mesh_shade(height, radius, thickness)
|
||||||
edge2 = Part.makeLine((-radius -thickness, 0.0, 0),
|
elif shape == "bio":
|
||||||
(-radius -thickness, height, 0))
|
shade = product_gen.generate_shades.generate_bio_shade(height, radius, thickness)
|
||||||
edge3 = Part.makeLine((-radius -thickness, height, 0),
|
|
||||||
(0.0, height, 0))
|
|
||||||
wire1 = Part.Wire([edge0, edge1, edge2, edge3])
|
|
||||||
face = Part.Face([wire1,])
|
|
||||||
|
|
||||||
pos = FreeCAD.Vector(0.0, 0.0, 0.0)
|
shade.exportStl(prefix + "_temp_shade.stl")
|
||||||
vec = FreeCAD.Vector(0.0, 1.0, 0.0)
|
|
||||||
angle = 360
|
|
||||||
solid = face.revolve(pos, vec, angle)
|
|
||||||
return solid
|
|
||||||
|
|
||||||
def generate_base(height, radius, thickness):
|
base_height = 20.0
|
||||||
|
base_radius = 15.0
|
||||||
|
thickness = 3.0
|
||||||
|
base = product_gen.generate_lamp_base.generate_base(base_height,
|
||||||
|
base_radius,
|
||||||
|
thickness)
|
||||||
|
base.exportStl(prefix + "_temp_base.stl")
|
||||||
|
|
||||||
edge0 = Part.makeLine((0.0, 0.0, 0),
|
chord_height = 150.0
|
||||||
(-radius, -height, 0))
|
chord_radius = 2.0
|
||||||
edge1 = Part.makeLine((-radius, -height, 0),
|
thickness = 1.0
|
||||||
(-radius -thickness, -height, 0))
|
chord = product_gen.generate_lamp_base.generate_chord(chord_height,
|
||||||
edge2 = Part.makeLine((-radius -thickness, -height, 0),
|
chord_radius,
|
||||||
(-thickness, 0.0, 0))
|
thickness)
|
||||||
edge3 = Part.makeLine((-thickness, 0.0, 0),
|
chord.exportStl(prefix + "_temp_chord.stl")
|
||||||
(0.0, 0.0, 0))
|
|
||||||
wire1 = Part.Wire([edge0, edge1, edge2, edge3])
|
|
||||||
face = Part.Face([wire1,])
|
|
||||||
|
|
||||||
pos = FreeCAD.Vector(0.0, 0.0, 0.0)
|
if not is_final:
|
||||||
vec = FreeCAD.Vector(0.0, 1.0, 0.0)
|
product_gen.render_lamp.render_lamp(prefix + "_temp_shade.stl",
|
||||||
angle = 360
|
prefix + "_temp_base.stl",
|
||||||
solid = face.revolve(pos, vec, angle)
|
prefix + "_temp_chord.stl",
|
||||||
return solid
|
prefix + ".png",
|
||||||
|
color = color)
|
||||||
def generate_shade(height, radius, thickness):
|
else:
|
||||||
|
product_gen.render_lamp.render_lamp(prefix + "_temp_shade.stl",
|
||||||
edge0 = Part.makeLine((0.0, 0.0, 0),
|
prefix + "_temp_base.stl",
|
||||||
(-radius, -height, 0))
|
prefix + "_temp_chord.stl",
|
||||||
edge1 = Part.makeLine((-radius, -height, 0),
|
prefix + "_kitchen.png",
|
||||||
(-radius -thickness, -height, 0))
|
color = color)
|
||||||
edge2 = Part.makeLine((-radius -thickness, -height, 0),
|
product_gen.render_lamp.render_lamp(prefix + "_temp_shade.stl",
|
||||||
(-thickness, 0.0, 0))
|
prefix + "_temp_base.stl",
|
||||||
edge3 = Part.makeLine((-thickness, 0.0, 0),
|
prefix + "_temp_chord.stl",
|
||||||
(0.0, 0.0, 0))
|
prefix + "_hall.png",
|
||||||
wire1 = Part.Wire([edge0, edge1, edge2, edge3])
|
color = color)
|
||||||
face = Part.Face([wire1,])
|
product_gen.render_lamp.render_lamp(prefix + "_temp_shade.stl",
|
||||||
|
prefix + "_temp_base.stl",
|
||||||
pos = FreeCAD.Vector(0.0, 0.0, 0.0)
|
prefix + "_temp_chord.stl",
|
||||||
vec = FreeCAD.Vector(0.0, 1.0, 0.0)
|
prefix + "_landing.png",
|
||||||
angle = 360
|
color = color)
|
||||||
solid = face.revolve(pos, vec, angle)
|
|
||||||
return solid
|
|
Binary file not shown.
46
src/product_gen/generate_lamp_base.py
Normal file
46
src/product_gen/generate_lamp_base.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
|
||||||
|
import sys
|
||||||
|
# freecad setup
|
||||||
|
FREECADPATH = "/usr/lib/freecad/lib/"
|
||||||
|
sys.path.append(FREECADPATH)
|
||||||
|
import numpy as np
|
||||||
|
import FreeCAD
|
||||||
|
import Part
|
||||||
|
|
||||||
|
def generate_chord(height, radius, thickness):
|
||||||
|
|
||||||
|
edge0 = Part.makeLine((0.0, height, 0),
|
||||||
|
(-radius, 0.0, 0))
|
||||||
|
edge1 = Part.makeLine((-radius, 0.0, 0),
|
||||||
|
(-radius -thickness, 0.0, 0))
|
||||||
|
edge2 = Part.makeLine((-radius -thickness, 0.0, 0),
|
||||||
|
(-radius -thickness, height, 0))
|
||||||
|
edge3 = Part.makeLine((-radius -thickness, height, 0),
|
||||||
|
(0.0, height, 0))
|
||||||
|
wire1 = Part.Wire([edge0, edge1, edge2, edge3])
|
||||||
|
face = Part.Face([wire1,])
|
||||||
|
|
||||||
|
pos = FreeCAD.Vector(0.0, 0.0, 0.0)
|
||||||
|
vec = FreeCAD.Vector(0.0, 1.0, 0.0)
|
||||||
|
angle = 360
|
||||||
|
solid = face.revolve(pos, vec, angle)
|
||||||
|
return solid
|
||||||
|
|
||||||
|
def generate_base(height, radius, thickness):
|
||||||
|
|
||||||
|
edge0 = Part.makeLine((0.0, 0.0, 0),
|
||||||
|
(-radius, -height, 0))
|
||||||
|
edge1 = Part.makeLine((-radius, -height, 0),
|
||||||
|
(-radius -thickness, -height, 0))
|
||||||
|
edge2 = Part.makeLine((-radius -thickness, -height, 0),
|
||||||
|
(-thickness, 0.0, 0))
|
||||||
|
edge3 = Part.makeLine((-thickness, 0.0, 0),
|
||||||
|
(0.0, 0.0, 0))
|
||||||
|
wire1 = Part.Wire([edge0, edge1, edge2, edge3])
|
||||||
|
face = Part.Face([wire1,])
|
||||||
|
|
||||||
|
pos = FreeCAD.Vector(0.0, 0.0, 0.0)
|
||||||
|
vec = FreeCAD.Vector(0.0, 1.0, 0.0)
|
||||||
|
angle = 360
|
||||||
|
solid = face.revolve(pos, vec, angle)
|
||||||
|
return solid
|
BIN
src/product_gen/generate_lamp_base.pyc
Normal file
BIN
src/product_gen/generate_lamp_base.pyc
Normal file
Binary file not shown.
65
src/product_gen/generate_shades.py
Normal file
65
src/product_gen/generate_shades.py
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
|
||||||
|
import sys
|
||||||
|
# freecad setup
|
||||||
|
FREECADPATH = "/usr/lib/freecad/lib/"
|
||||||
|
sys.path.append(FREECADPATH)
|
||||||
|
import numpy as np
|
||||||
|
import FreeCAD
|
||||||
|
import Part
|
||||||
|
|
||||||
|
def generate_cone_shade(height, radius, thickness):
|
||||||
|
|
||||||
|
edge0 = Part.makeLine((0.0, 0.0, 0),
|
||||||
|
(-radius, -height, 0))
|
||||||
|
edge1 = Part.makeLine((-radius, -height, 0),
|
||||||
|
(-radius -thickness, -height, 0))
|
||||||
|
edge2 = Part.makeLine((-radius -thickness, -height, 0),
|
||||||
|
(-thickness, 0.0, 0))
|
||||||
|
edge3 = Part.makeLine((-thickness, 0.0, 0),
|
||||||
|
(0.0, 0.0, 0))
|
||||||
|
wire1 = Part.Wire([edge0, edge1, edge2, edge3])
|
||||||
|
face = Part.Face([wire1,])
|
||||||
|
|
||||||
|
pos = FreeCAD.Vector(0.0, 0.0, 0.0)
|
||||||
|
vec = FreeCAD.Vector(0.0, 1.0, 0.0)
|
||||||
|
angle = 360
|
||||||
|
solid = face.revolve(pos, vec, angle)
|
||||||
|
return solid
|
||||||
|
|
||||||
|
def generate_mesh_shade(height, radius, thickness):
|
||||||
|
|
||||||
|
edge0 = Part.makeLine((0.0, 0.0, 0),
|
||||||
|
(-radius, -height, 0))
|
||||||
|
edge1 = Part.makeLine((-radius, -height, 0),
|
||||||
|
(-radius -thickness, -height, 0))
|
||||||
|
edge2 = Part.makeLine((-radius -thickness, -height, 0),
|
||||||
|
(-thickness, 0.0, 0))
|
||||||
|
edge3 = Part.makeLine((-thickness, 0.0, 0),
|
||||||
|
(0.0, 0.0, 0))
|
||||||
|
wire1 = Part.Wire([edge0, edge1, edge2, edge3])
|
||||||
|
face = Part.Face([wire1,])
|
||||||
|
|
||||||
|
pos = FreeCAD.Vector(0.0, 0.0, 0.0)
|
||||||
|
vec = FreeCAD.Vector(0.0, 1.0, 0.0)
|
||||||
|
angle = 360
|
||||||
|
solid = face.revolve(pos, vec, angle)
|
||||||
|
return solid
|
||||||
|
|
||||||
|
def generate_bio_shade(height, radius, thickness):
|
||||||
|
|
||||||
|
edge0 = Part.makeLine((0.0, 0.0, 0),
|
||||||
|
(-radius, -height, 0))
|
||||||
|
edge1 = Part.makeLine((-radius, -height, 0),
|
||||||
|
(-radius -thickness, -height, 0))
|
||||||
|
edge2 = Part.makeLine((-radius -thickness, -height, 0),
|
||||||
|
(-thickness, 0.0, 0))
|
||||||
|
edge3 = Part.makeLine((-thickness, 0.0, 0),
|
||||||
|
(0.0, 0.0, 0))
|
||||||
|
wire1 = Part.Wire([edge0, edge1, edge2, edge3])
|
||||||
|
face = Part.Face([wire1,])
|
||||||
|
|
||||||
|
pos = FreeCAD.Vector(0.0, 0.0, 0.0)
|
||||||
|
vec = FreeCAD.Vector(0.0, 1.0, 0.0)
|
||||||
|
angle = 360
|
||||||
|
solid = face.revolve(pos, vec, angle)
|
||||||
|
return solid
|
BIN
src/product_gen/generate_shades.pyc
Normal file
BIN
src/product_gen/generate_shades.pyc
Normal file
Binary file not shown.
|
@ -12,8 +12,8 @@ def render_lamp(shade_file_path,
|
||||||
ren.SetBackground(1.0, 1.0, 1.0)
|
ren.SetBackground(1.0, 1.0, 1.0)
|
||||||
renWin = vtk.vtkRenderWindow()
|
renWin = vtk.vtkRenderWindow()
|
||||||
renWin.AddRenderer(ren)
|
renWin.AddRenderer(ren)
|
||||||
WIDTH=640
|
WIDTH=640*2
|
||||||
HEIGHT=480
|
HEIGHT=480*2
|
||||||
renWin.SetSize(WIDTH,HEIGHT)
|
renWin.SetSize(WIDTH,HEIGHT)
|
||||||
|
|
||||||
# create a renderwindowinteractor
|
# create a renderwindowinteractor
|
||||||
|
|
Binary file not shown.
28
src/utility/apply_texture.py
Normal file
28
src/utility/apply_texture.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import random
|
||||||
|
import json
|
||||||
|
import product_gen.generate_lamp
|
||||||
|
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
shape_params = json.loads(sys.argv[1])
|
||||||
|
shape = shape_params['shape']
|
||||||
|
output = shape_params['output']
|
||||||
|
|
||||||
|
if not os.path.exists(os.getcwd() + "/" + output):
|
||||||
|
os.makedirs(os.getcwd() + "/" + output)
|
||||||
|
|
||||||
|
height = shape_params["height"]
|
||||||
|
radius = shape_params["radius"]
|
||||||
|
color = [random.random()*255.0,
|
||||||
|
random.random()*255.0,
|
||||||
|
random.random()*255.0]
|
||||||
|
product_gen.generate_lamp.generate(shape, height, radius, color, output)
|
||||||
|
|
||||||
|
shape_parameters = shape_params
|
||||||
|
shape_parameters["color"] = color
|
||||||
|
with open(os.getcwd() + "/" + output + "/"+ output + '.json', 'w') as outfile:
|
||||||
|
json.dump(shape_parameters, outfile)
|
22
src/utility/final_render.py
Normal file
22
src/utility/final_render.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import random
|
||||||
|
import json
|
||||||
|
import product_gen.generate_lamp
|
||||||
|
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
shape_params = json.loads(sys.argv[1])
|
||||||
|
shape = shape_params['shape']
|
||||||
|
output = shape_params['output']
|
||||||
|
|
||||||
|
if not os.path.exists(os.getcwd() + "/" + output):
|
||||||
|
os.makedirs(os.getcwd() + "/" + output)
|
||||||
|
|
||||||
|
height = shape_params["height"]
|
||||||
|
radius = shape_params["radius"]
|
||||||
|
color = shape_params["color"]
|
||||||
|
product_gen.generate_lamp.generate(shape, height, radius,
|
||||||
|
color, output, is_final=True)
|
|
@ -1,51 +0,0 @@
|
||||||
import os
|
|
||||||
import product_gen.generate_lamp
|
|
||||||
import product_gen.render_lamp
|
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
|
||||||
|
|
||||||
def run(height, radius, color, output_id):
|
|
||||||
thickness = 3.0
|
|
||||||
shade = product_gen.generate_lamp.generate_shade(height, radius, thickness)
|
|
||||||
work_dir = os.getcwd()
|
|
||||||
shade.exportStl(work_dir + "/shade_" + output_id + ".stl")
|
|
||||||
|
|
||||||
base_height = 20.0
|
|
||||||
base_radius = 15.0
|
|
||||||
thickness = 3.0
|
|
||||||
base = product_gen.generate_lamp.generate_base(base_height,
|
|
||||||
base_radius,
|
|
||||||
thickness)
|
|
||||||
base.exportStl(work_dir + "/base_" + output_id + ".stl")
|
|
||||||
|
|
||||||
chord_height = 150.0
|
|
||||||
chord_radius = 2.0
|
|
||||||
thickness = 1.0
|
|
||||||
chord = product_gen.generate_lamp.generate_chord(chord_height,
|
|
||||||
chord_radius,
|
|
||||||
thickness)
|
|
||||||
chord.exportStl(work_dir + "/chord_" + output_id + ".stl")
|
|
||||||
|
|
||||||
product_gen.render_lamp.render_lamp(work_dir + "/shade_" + output_id + ".stl",
|
|
||||||
work_dir + "/base_" + output_id + ".stl",
|
|
||||||
work_dir + "/chord_" + output_id + ".stl",
|
|
||||||
work_dir + "/lamp_" + output_id + ".png",
|
|
||||||
color = color)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
parser = ArgumentParser()
|
|
||||||
parser.add_argument('-height', type=float, help='Height.')
|
|
||||||
parser.add_argument('-radius', type=float, help='Radius.')
|
|
||||||
parser.add_argument('-r', type=float, help='Red intensity.')
|
|
||||||
parser.add_argument('-g', type=float, help='Green intensity.')
|
|
||||||
parser.add_argument('-b', type=float, help='Blue intensity.')
|
|
||||||
parser.add_argument('-o', type=str, help='Output identifier.')
|
|
||||||
parser.add_argument('-s', type=int, help='Stage identifier.')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
color = [args.r, args.g, args.b]
|
|
||||||
if args.s == 0:
|
|
||||||
color = [18.0, 18.0, 18.0]
|
|
||||||
|
|
||||||
run(args.height, args.radius, color, args.o)
|
|
||||||
|
|
28
src/utility/generate_shape.py
Normal file
28
src/utility/generate_shape.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import random
|
||||||
|
import json
|
||||||
|
import product_gen.generate_lamp
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
shape_params = json.loads(sys.argv[1])
|
||||||
|
shape = shape_params['shape']
|
||||||
|
output = shape_params['output']
|
||||||
|
|
||||||
|
if not os.path.exists(os.getcwd() + "/" + output):
|
||||||
|
os.makedirs(os.getcwd() + "/" + output)
|
||||||
|
|
||||||
|
height = 100.0 + random.random()*150.0
|
||||||
|
radius = 20.0 + random.random()*100.0
|
||||||
|
color = [18.0, 18.0, 18.0]
|
||||||
|
|
||||||
|
product_gen.generate_lamp.generate(shape, height, radius, color, output)
|
||||||
|
|
||||||
|
shape_parameters = {"shape": shape,
|
||||||
|
"height": height,
|
||||||
|
"radius": radius,
|
||||||
|
"color": color}
|
||||||
|
with open(os.getcwd() + "/" + output + "/"+ output + '.json', 'w') as outfile:
|
||||||
|
json.dump(shape_parameters, outfile)
|
1
src/utility/test123/test123.json
Normal file
1
src/utility/test123/test123.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"color": [18.0, 18.0, 18.0], "shape": "cone", "radius": 77.62212089695586, "height": 114.09765555398143}
|
BIN
src/utility/test123/test123.png
Normal file
BIN
src/utility/test123/test123.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
src/utility/test123/test123_hall.png
Normal file
BIN
src/utility/test123/test123_hall.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
BIN
src/utility/test123/test123_kitchen.png
Normal file
BIN
src/utility/test123/test123_kitchen.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
BIN
src/utility/test123/test123_landing.png
Normal file
BIN
src/utility/test123/test123_landing.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
33819
src/utility/test123/test123_temp_base.stl
Normal file
33819
src/utility/test123/test123_temp_base.stl
Normal file
File diff suppressed because it is too large
Load diff
15171
src/utility/test123/test123_temp_chord.stl
Normal file
15171
src/utility/test123/test123_temp_chord.stl
Normal file
File diff suppressed because it is too large
Load diff
40371
src/utility/test123/test123_temp_shade.stl
Normal file
40371
src/utility/test123/test123_temp_shade.stl
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue