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:
|
||||
|
||||
```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.
|
||||
`-s` is the generation stage. Stage 0 generates shapes. Stage 1 generates textures.
|
||||
|
||||
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.
|
||||
The output for the first two scripts is a file `$prefix_lamp.png` in the launch directory.
|
||||
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.
|
||||
|
|
|
@ -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
|
||||
from argparse import ArgumentParser
|
||||
# freecad setup
|
||||
FREECADPATH = "/usr/lib/freecad/lib/"
|
||||
sys.path.append(FREECADPATH)
|
||||
import numpy as np
|
||||
import FreeCAD
|
||||
import Part
|
||||
def generate(shape, height, radius, color, output_prefix,
|
||||
is_final=False):
|
||||
thickness = 3.0
|
||||
|
||||
def generate_chord(height, radius, thickness):
|
||||
prefix = os.getcwd() + "/" + output_prefix + "/" + output_prefix
|
||||
|
||||
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,])
|
||||
if shape == "cone":
|
||||
shade = product_gen.generate_shades.generate_cone_shade(height, radius, thickness)
|
||||
elif shape == "mesh":
|
||||
shade = product_gen.generate_shades.generate_mesh_shade(height, radius, thickness)
|
||||
elif shape == "bio":
|
||||
shade = product_gen.generate_shades.generate_bio_shade(height, radius, thickness)
|
||||
|
||||
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
|
||||
shade.exportStl(prefix + "_temp_shade.stl")
|
||||
|
||||
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),
|
||||
(-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,])
|
||||
chord_height = 150.0
|
||||
chord_radius = 2.0
|
||||
thickness = 1.0
|
||||
chord = product_gen.generate_lamp_base.generate_chord(chord_height,
|
||||
chord_radius,
|
||||
thickness)
|
||||
chord.exportStl(prefix + "_temp_chord.stl")
|
||||
|
||||
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_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
|
||||
if not is_final:
|
||||
product_gen.render_lamp.render_lamp(prefix + "_temp_shade.stl",
|
||||
prefix + "_temp_base.stl",
|
||||
prefix + "_temp_chord.stl",
|
||||
prefix + ".png",
|
||||
color = color)
|
||||
else:
|
||||
product_gen.render_lamp.render_lamp(prefix + "_temp_shade.stl",
|
||||
prefix + "_temp_base.stl",
|
||||
prefix + "_temp_chord.stl",
|
||||
prefix + "_kitchen.png",
|
||||
color = color)
|
||||
product_gen.render_lamp.render_lamp(prefix + "_temp_shade.stl",
|
||||
prefix + "_temp_base.stl",
|
||||
prefix + "_temp_chord.stl",
|
||||
prefix + "_hall.png",
|
||||
color = color)
|
||||
product_gen.render_lamp.render_lamp(prefix + "_temp_shade.stl",
|
||||
prefix + "_temp_base.stl",
|
||||
prefix + "_temp_chord.stl",
|
||||
prefix + "_landing.png",
|
||||
color = color)
|
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)
|
||||
renWin = vtk.vtkRenderWindow()
|
||||
renWin.AddRenderer(ren)
|
||||
WIDTH=640
|
||||
HEIGHT=480
|
||||
WIDTH=640*2
|
||||
HEIGHT=480*2
|
||||
renWin.SetSize(WIDTH,HEIGHT)
|
||||
|
||||
# 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